Source Code Cross Referenced for Java5HacksHelper.java in  » Database-ORM » castor » org » exolab » javasource » 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 » Database ORM » castor » org.exolab.javasource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Werner Guttmann
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 org.exolab.javasource;
017:
018:        import java.util.HashMap;
019:
020:        /**
021:         * Makes an effort to identify where Override annotations belong. We are limited
022:         * in what we look at and we do not use reflection to identify if a class truly
023:         * extends the appropriate class. We only check the class of the arguments. This
024:         * class may not be generically useful, but is useful with the code generated by
025:         * Castor.
026:         * <br/>
027:         * Our one public method, {@link #addOverrideAnnotations(JMethodSignature)},
028:         * should only be called when you already know that you are generating Java-5
029:         * style code.
030:         * 
031:         * @author <a href="mailto:werner DOT guttmann AT gmx DOT net">Werner Guttman</a>
032:         * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
033:         * @since 1.0.4
034:         */
035:        public final class Java5HacksHelper {
036:            //--------------------------------------------------------------------------
037:
038:            /**
039:             * As a static utility class, we want a private constructor.
040:             */
041:            private Java5HacksHelper() {
042:            }
043:
044:            //--------------------------------------------------------------------------
045:
046:            private static class MethodSpec {
047:                private String _methodName;
048:                private int _paramCount;
049:                private String _param1ClassName;
050:                private String _param2ClassName;
051:
052:                public MethodSpec(final String methodName,
053:                        final int paramCount, final String param1ClassName,
054:                        final String param2ClassName) {
055:                    _methodName = methodName;
056:                    _paramCount = paramCount;
057:                    _param1ClassName = param1ClassName;
058:                    _param2ClassName = param2ClassName;
059:                }
060:
061:                public String getMethodName() {
062:                    return _methodName;
063:                }
064:
065:                public int getParamCount() {
066:                    return _paramCount;
067:                }
068:
069:                public String getParam1ClassName() {
070:                    return _param1ClassName;
071:                }
072:
073:                public String getParam2ClassName() {
074:                    return _param2ClassName;
075:                }
076:            }
077:
078:            private static final HashMap DEFINED_SPECS = new HashMap();
079:
080:            private static void createMethodSpec(final String methodName,
081:                    final int paramCount, final String param1ClassName,
082:                    final String param2ClassName) {
083:                MethodSpec temp = new MethodSpec(methodName, paramCount,
084:                        param1ClassName, param2ClassName);
085:
086:                DEFINED_SPECS.put(methodName, temp);
087:            }
088:
089:            static {
090:                createMethodSpec("getAccessMode", 0, "", "");
091:                createMethodSpec("getExtends", 0, "", "");
092:                createMethodSpec("getIdentity", 0, "", "");
093:                createMethodSpec("getJavaClass", 0, "", "");
094:                createMethodSpec("getNameSpacePrefix", 0, "", "");
095:                createMethodSpec("getNameSpaceURI", 0, "", "");
096:                createMethodSpec("getValidator", 0, "", "");
097:                createMethodSpec("getXMLName", 0, "", "");
098:                createMethodSpec("getXTransients", 0, "", "");
099:                createMethodSpec("newInstance", 1, "java.lang.Object", "");
100:                createMethodSpec("setValue", 1, "java.lang.Object", "");
101:                createMethodSpec("equals", 1, "java.lang.Object", "");
102:                createMethodSpec("getValue", 1, "java.lang.Object", "");
103:                createMethodSpec("marshal", 1, "java.io.Writer", "");
104:                createMethodSpec("newInstance", 1, "java.lang.Object", "");
105:                createMethodSpec("setValue", 2, "java.lang.Object",
106:                        "java.lang.Object");
107:                createMethodSpec("setXTransients", 1,
108:                        "org.openmrm.core.data.castor.XTransients", "");
109:            };
110:
111:            /** An override annotation we use to see if we can get others of its type. */
112:            private static final JAnnotationType OVERRIDE_ANNOTATION = new JAnnotationType(
113:                    "Override");
114:
115:            /**
116:             * Given the method signature, add the Override annotation if this class is
117:             * one that we know requires this annotation.
118:             *
119:             * @param jms The method signature to inspect.
120:             */
121:            public static void addOverrideAnnotations(final JMethodSignature jms) {
122:                String name = jms.getName();
123:                boolean addOverrideAnnotation = false;
124:
125:                // It the method already has an override annotation, then jump out
126:                JAnnotation override = jms.getAnnotation(OVERRIDE_ANNOTATION);
127:                if (override != null) {
128:                    return;
129:                }
130:
131:                // If the method name doesn't exist in our list, then jump out
132:                MethodSpec methodSpec = (MethodSpec) DEFINED_SPECS.get(name);
133:                if (methodSpec == null) {
134:                    return;
135:                }
136:
137:                // If the number of parameters isn't what we're prepared for, then jump out
138:                int paramCount = jms.getParameters().length;
139:                if (paramCount != methodSpec.getParamCount()) {
140:                    return;
141:                }
142:
143:                // Do we add the Override annotation?  Check vs number of arguments.
144:                switch (paramCount) {
145:                case 0:
146:                    addOverrideAnnotation = true;
147:                    break;
148:                case 1:
149:                    String incomingClassName1 = jms.getParameter(0).getType()
150:                            .getName();
151:                    if (incomingClassName1.equalsIgnoreCase(methodSpec
152:                            .getParam1ClassName())) {
153:                        addOverrideAnnotation = true;
154:                    }
155:                    break;
156:                case 2:
157:                    String className1 = jms.getParameter(0).getType().getName();
158:                    String className2 = jms.getParameter(1).getType().getName();
159:                    if (className1.equalsIgnoreCase(methodSpec
160:                            .getParam1ClassName())
161:                            && className2.equalsIgnoreCase(methodSpec
162:                                    .getParam2ClassName())) {
163:                        addOverrideAnnotation = true;
164:                    }
165:                    break;
166:                default:
167:                    // We aren't prepared for > 2 parameters, so we don't add an Override annotation
168:                    break;
169:                }
170:
171:                // Do the work if we need to
172:                if (addOverrideAnnotation) {
173:                    jms.addAnnotation(new JAnnotation(new JAnnotationType(
174:                            "Override")));
175:                }
176:            }
177:
178:            //--------------------------------------------------------------------------
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.