Source Code Cross Referenced for ConstantsImplCreator.java in  » Ajax » GWT » com » google » gwt » i18n » rebind » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » GWT » com.google.gwt.i18n.rebind 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.i18n.rebind;
017:
018:        import com.google.gwt.core.ext.TreeLogger;
019:        import com.google.gwt.core.ext.UnableToCompleteException;
020:        import com.google.gwt.core.ext.typeinfo.JClassType;
021:        import com.google.gwt.core.ext.typeinfo.JMethod;
022:        import com.google.gwt.core.ext.typeinfo.JType;
023:        import com.google.gwt.core.ext.typeinfo.NotFoundException;
024:        import com.google.gwt.core.ext.typeinfo.TypeOracle;
025:        import com.google.gwt.core.ext.typeinfo.TypeOracleException;
026:        import com.google.gwt.i18n.rebind.util.AbstractResource;
027:        import com.google.gwt.user.rebind.SourceWriter;
028:
029:        import java.util.Map;
030:
031:        /**
032:         * Creates the class implementation for a given resource bundle using the
033:         * standard <code>AbstractGeneratorClassCreator</code>.
034:         */
035:        class ConstantsImplCreator extends AbstractLocalizableImplCreator {
036:            /**
037:             * Does a Map need to be generated in order to store complex results?
038:             */
039:            private boolean needCache = false;
040:
041:            /**
042:             * Constructor for <code>ConstantsImplCreator</code>.
043:             * 
044:             * @param logger logger to print errors
045:             * @param writer <code>Writer</code> to print to
046:             * @param localizableClass class/interface to conform to
047:             * @param messageBindings resource bundle used to generate the class
048:             * @param oracle types
049:             * @throws UnableToCompleteException
050:             */
051:            public ConstantsImplCreator(TreeLogger logger, SourceWriter writer,
052:                    JClassType localizableClass,
053:                    AbstractResource messageBindings, TypeOracle oracle)
054:                    throws UnableToCompleteException {
055:                super (writer, localizableClass, messageBindings);
056:                try {
057:                    JClassType stringClass = oracle.getType(String.class
058:                            .getName());
059:                    JClassType mapClass = oracle.getType(Map.class.getName());
060:                    JType stringArrayClass = oracle.getArrayType(stringClass);
061:                    JType intClass = oracle.parse(int.class.getName());
062:                    JType doubleClass = oracle.parse(double.class.getName());
063:                    JType floatClass = oracle.parse(float.class.getName());
064:                    JType booleanClass = oracle.parse(boolean.class.getName());
065:                    register(stringClass, new SimpleValueMethodCreator(this ,
066:                            SimpleValueMethodCreator.STRING));
067:                    register(mapClass, new ConstantsMapMethodCreator(this ));
068:                    register(intClass, new SimpleValueMethodCreator(this ,
069:                            SimpleValueMethodCreator.INT));
070:                    register(doubleClass, new SimpleValueMethodCreator(this ,
071:                            SimpleValueMethodCreator.DOUBLE));
072:                    register(floatClass, new SimpleValueMethodCreator(this ,
073:                            SimpleValueMethodCreator.FLOAT));
074:                    register(booleanClass, new SimpleValueMethodCreator(this ,
075:                            SimpleValueMethodCreator.BOOLEAN));
076:
077:                    register(stringArrayClass,
078:                            new ConstantsStringArrayMethodCreator(this ));
079:                } catch (NotFoundException e) {
080:                    throw error(logger, e);
081:                } catch (TypeOracleException e) {
082:                    throw error(logger, e);
083:                }
084:            }
085:
086:            @Override
087:            protected void classEpilog() {
088:                if (isNeedCache()) {
089:                    getWriter().println(
090:                            "java.util.Map cache = new java.util.HashMap();"
091:                                    .toString());
092:                }
093:            }
094:
095:            /**
096:             * Create the method body associated with the given method. Arguments are
097:             * arg0...argN.
098:             */
099:            @Override
100:            protected void emitMethodBody(TreeLogger logger, JMethod method)
101:                    throws UnableToCompleteException {
102:                checkConstantMethod(logger, method);
103:                delegateToCreator(logger, method);
104:            }
105:
106:            boolean isNeedCache() {
107:                return needCache;
108:            }
109:
110:            void setNeedCache(boolean needCache) {
111:                this .needCache = needCache;
112:            }
113:
114:            /**
115:             * Checks that the method has the right structure to implement
116:             * <code>Constant</code>.
117:             * 
118:             * @param method method to check
119:             */
120:            private void checkConstantMethod(TreeLogger logger, JMethod method)
121:                    throws UnableToCompleteException {
122:                if (method.getParameters().length > 0) {
123:                    String s = "Methods in interfaces extending Constant must have no parameters and a return type of  String/int/float/boolean/double/String[]/Map";
124:                    throw error(logger, s);
125:                }
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.