Package com.google.gwt.i18n.rebind.keygen

Examples of com.google.gwt.i18n.rebind.keygen.MethodNameKeyGenerator


            CtClass stringClass = classPool.get(String.class.getName());
            CtClass localeClass = classPool.get(Locale.class.getName());
            CtClass impl = classPool.makeClass(ifaceName+"Impl_"+locale.toString());
            impl.addInterface(iface);
           
            KeyGenerator keyGenerator = new MethodNameKeyGenerator();
            for(Object ann : iface.getAnnotations()) {
                if(ann instanceof GenerateKeys) {
                    String keyGeneratorClassName = ((GenerateKeys)ann).value();
                    Class<KeyGenerator> keyGeneratorClass;
                    try {
                        keyGeneratorClass = (Class<KeyGenerator>) Class.forName(keyGeneratorClassName);
                    } catch(ClassNotFoundException cnfe) {
                        keyGeneratorClass = (Class<KeyGenerator>) Class.forName(KeyGenerator.class.getName()+"."+keyGeneratorClassName);
                    }
                    keyGenerator = keyGeneratorClass.newInstance();
                }
            }
           
            ResourceBundle resBundle = ResourceBundle.getBundle(ifaceName, locale);
            CtConstructor ctorMethod = new CtConstructor(new CtClass[] {localeClass}, impl);
            impl.addConstructor(ctorMethod);
            ctorMethod.setModifiers(Modifier.PUBLIC);
            ctorMethod.setBody("super();");
            CtField localeField = new CtField(localeClass, "_locale", impl);
            impl.addField(localeField, CtField.Initializer.byParameter(0));
            TreeMap<String,String> keys = new TreeMap<String,String>();
            for(CtMethod method : iface.getMethods()) {
                // Only abstract methods
                if((method.getModifiers() & Modifier.ABSTRACT) == 0)
                    continue;
                CtMethod methodImpl = new CtMethod(method, impl, null);
                String methodKey = null;
                String meaning = null;
                String defaultValue = null;
                for(Object ann : method.getAnnotations()) {
                    if(ann instanceof Key) {
                        methodKey = ((Key)ann).value();
                    } else if(ann instanceof Meaning) {
                        meaning = ((Meaning)ann).value();
                    } else if(ann instanceof DefaultStringValue) {
                        defaultValue = ((DefaultStringValue)ann).value();
                    } else if(ann instanceof DefaultBooleanValue) {
                        defaultValue = String.valueOf(((DefaultBooleanValue)ann).value());
                    } else if(ann instanceof DefaultDoubleValue) {
                        defaultValue = String.valueOf(((DefaultDoubleValue)ann).value());
                    } else if(ann instanceof DefaultMessage) {
                        defaultValue = ((DefaultMessage)ann).value();
                    }
                }
                if(methodKey == null) {
                    methodKey = keyGenerator.generateKey(ifaceName, method.getName(), defaultValue, meaning);
                }
                String value;
                try {
                    value = resBundle.getString(methodKey);
                } catch (java.util.MissingResourceException mre) {
View Full Code Here


            impl.addInterface(iface);
            final CtClass resourceBundle = classPool.get(ResourceBundle.class.getName());
            CtField resField = new CtField(resourceBundle, "res", impl);
            impl.addField(resField);
           
            KeyGenerator keyGenerator = new MethodNameKeyGenerator();
            for(Object ann : iface.getAnnotations()) {
                if(ann instanceof GenerateKeys) {
                    String keyGeneratorClassName = ((GenerateKeys)ann).value();
                    Class<KeyGenerator> keyGeneratorClass;
                    try {
                        keyGeneratorClass = (Class<KeyGenerator>) Class.forName(keyGeneratorClassName);
                    } catch(ClassNotFoundException cnfe) {
                        keyGeneratorClass = (Class<KeyGenerator>) Class.forName(KeyGenerator.class.getName()+"."+keyGeneratorClassName);
                    }
                    keyGenerator = keyGeneratorClass.newInstance();
                }
            }
           
            ResourceBundle resBundle = ResourceBundle.getBundle(ifaceName, locale);
            for(CtMethod method : iface.getMethods()) {
                // Only abstract methods
                if((method.getModifiers() & Modifier.ABSTRACT) == 0)
                    continue;
                String methodKey = null;
                String meaning = null;
                Object defaultValue = null;
                for(Object ann : method.getAnnotations()) {
                    if(ann instanceof Key) {
                        methodKey = ((Key)ann).value();
                    } else if(ann instanceof Meaning) {
                        meaning = ((Meaning)ann).value();
                    } else if(ann instanceof DefaultStringValue) {
                        defaultValue = ((DefaultStringValue)ann).value();
                    } else if(ann instanceof DefaultBooleanValue) {
                        defaultValue = ((DefaultBooleanValue)ann).value();
                    } else if(ann instanceof DefaultDoubleValue) {
                        defaultValue = ((DefaultDoubleValue)ann).value();
                    } else if(ann instanceof DefaultIntValue) {
                        defaultValue = ((DefaultIntValue)ann).value();
                    } else if(ann instanceof DefaultFloatValue) {
                        defaultValue = ((DefaultFloatValue)ann).value();
                    } else if(ann instanceof DefaultMessage) {
                        defaultValue = ((DefaultMessage)ann).value();
                    }
                }
                if(methodKey == null) {
                    methodKey = keyGenerator.generateKey(ifaceName, method.getName(), String.valueOf(defaultValue), meaning);
                }
                CtMethod methodImpl = new CtMethod(method, impl, null);
                CtClass returnType = methodImpl.getReturnType();
                Initializer initializer;
                String valueString;
View Full Code Here

      } catch (ClassNotFoundException e) {
        throw new AnnotationsError("Invalid class specified to @GenerateKeys: "
            + className);
      }
    }
    return new MethodNameKeyGenerator();
  }
View Full Code Here

      } catch (ClassNotFoundException e) {
        throw new AnnotationsError("Invalid class specified to @GenerateKeys: "
            + className);
      }
    }
    return new MethodNameKeyGenerator();
  }
View Full Code Here

      } catch (ClassNotFoundException e) {
        throw new AnnotationsError("Invalid class specified to @GenerateKeys: "
            + className);
      }
    }
    return new MethodNameKeyGenerator();
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.i18n.rebind.keygen.MethodNameKeyGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.