Source Code Cross Referenced for TypeHelperImpl.java in  » Database-ORM » toplink » oracle » toplink » essentials » internal » parsing » 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 » toplink » oracle.toplink.essentials.internal.parsing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005:         * 
006:         *
007:         * The contents of this file are subject to the terms of either the GNU
008:         * General Public License Version 2 only ("GPL") or the Common Development
009:         * and Distribution License("CDDL") (collectively, the "License").  You
010:         * may not use this file except in compliance with the License. You can obtain
011:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
013:         * language governing permissions and limitations under the License.
014:         * 
015:         * When distributing the software, include this License Header Notice in each
016:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017:         * Sun designates this particular file as subject to the "Classpath" exception
018:         * as provided by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code.  If applicable, add the following below the License
020:         * Header, with the fields enclosed by brackets [] replaced by your own
021:         * identifying information: "Portions Copyrighted [year]
022:         * [name of copyright owner]"
023:         * 
024:         * Contributor(s):
025:         * 
026:         * If you wish your version of this file to be governed by only the CDDL or
027:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
028:         * elects to include this software in this distribution under the [CDDL or GPL
029:         * Version 2] license."  If you don't indicate a single choice of license, a
030:         * recipient has the option to distribute your version of this file under
031:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
032:         * its licensees as provided above.  However, if you add GPL Version 2 code
033:         * and therefore, elected the GPL Version 2 license, then the option applies
034:         * only if the new code is made subject to such option by the copyright
035:         * holder.
036:         */
037:        package oracle.toplink.essentials.internal.parsing;
038:
039:        import java.lang.reflect.Field;
040:        import java.security.AccessController;
041:        import java.security.PrivilegedActionException;
042:
043:        import oracle.toplink.essentials.descriptors.ClassDescriptor;
044:        import oracle.toplink.essentials.mappings.AggregateMapping;
045:        import oracle.toplink.essentials.mappings.DatabaseMapping;
046:        import oracle.toplink.essentials.internal.sessions.AbstractSession;
047:        import oracle.toplink.essentials.internal.security.PrivilegedAccessHelper;
048:        import oracle.toplink.essentials.internal.security.PrivilegedClassForName;
049:        import oracle.toplink.essentials.internal.security.PrivilegedGetField;
050:        import oracle.toplink.essentials.internal.helper.BasicTypeHelperImpl;
051:
052:        /**
053:         * INTERNAL
054:         * <p><b>Purpose</b>: Implement type helper methods specified by TypeHelper.
055:         * This implementation uses Class instances to represent a type.
056:         */
057:        public class TypeHelperImpl extends BasicTypeHelperImpl implements 
058:                TypeHelper {
059:
060:            /** The session. */
061:            private final AbstractSession session;
062:
063:            /** The class loader used to resolve type names. */
064:            private final ClassLoader classLoader;
065:
066:            /** */
067:            public TypeHelperImpl(AbstractSession session,
068:                    ClassLoader classLoader) {
069:                this .session = session;
070:                this .classLoader = classLoader;
071:            }
072:
073:            /** Returns a type representation for the specified type name or null if
074:             * there is no such type. 
075:             */
076:            public Object resolveTypeName(String typeName) {
077:                try {
078:                    if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
079:                        try {
080:                            return (Class) AccessController
081:                                    .doPrivileged(new PrivilegedClassForName(
082:                                            typeName, true, classLoader));
083:                        } catch (PrivilegedActionException exception) {
084:                            return null;
085:                        }
086:                    } else {
087:                        return PrivilegedAccessHelper.getClassForName(typeName,
088:                                true, classLoader);
089:                    }
090:                } catch (ClassNotFoundException ex) {
091:                    return null;
092:                }
093:            }
094:
095:            /** Returns the type of the attribute with the specified name in the
096:             * specified owner class. 
097:             */
098:            public Object resolveAttribute(Object ownerClass, String attribute) {
099:                DatabaseMapping mapping = resolveAttributeMapping(ownerClass,
100:                        attribute);
101:                return getType(mapping);
102:            }
103:
104:            /** Returns the type of the class corresponding to the spcified abstract
105:             * schema type. 
106:             */
107:            public Object resolveSchema(String schemaName) {
108:                ClassDescriptor descriptor = session
109:                        .getDescriptorForAlias(schemaName);
110:                return (descriptor != null) ? descriptor.getJavaClass() : null;
111:            }
112:
113:            /** Returns the enum constant if the specified type denotes an enum type
114:             * and the specified constant denotes a constant of the enum type. 
115:             */
116:            public Object resolveEnumConstant(Object type, String constant) {
117:                Class clazz = getJavaClass(type);
118:                Object[] constants = clazz.getEnumConstants();
119:                if (constants != null) {
120:                    for (int i = 0; i < constants.length; i++) {
121:                        if (constant.equals(constants[i].toString())) {
122:                            return constants[i];
123:                        }
124:                    }
125:                }
126:                return null;
127:            }
128:
129:            /** Returns true if the specified type denotes an entity class. */
130:            public boolean isEntityClass(Object type) {
131:                ClassDescriptor desc = getDescriptor(type);
132:                return (desc != null) && !desc.isAggregateDescriptor();
133:            }
134:
135:            /** Returns true if the specified type denotes an embedded class. */
136:            public boolean isEmbeddable(Object type) {
137:                ClassDescriptor desc = getDescriptor(type);
138:                return (desc != null) && desc.isAggregateDescriptor();
139:            }
140:
141:            /** Returns true if the specified type denotes an embedded attribute. */
142:            public boolean isEmbeddedAttribute(Object ownerClass,
143:                    String attribute) {
144:                DatabaseMapping mapping = resolveAttributeMapping(ownerClass,
145:                        attribute);
146:                return (mapping != null) && mapping.isAggregateMapping();
147:            }
148:
149:            /** Returns true if the specified type denotes a simple state attribute. */
150:            public boolean isSimpleStateAttribute(Object ownerClass,
151:                    String attribute) {
152:                DatabaseMapping mapping = resolveAttributeMapping(ownerClass,
153:                        attribute);
154:                return (mapping != null) && mapping.isDirectToFieldMapping();
155:            }
156:
157:            /** Returns true if the specified attribute denotes a single valued
158:             * or collection valued relationship attribute. 
159:             */
160:            public boolean isRelationship(Object ownerClass, String attribute) {
161:                DatabaseMapping mapping = resolveAttributeMapping(ownerClass,
162:                        attribute);
163:                return (mapping != null)
164:                        && (mapping.isObjectReferenceMapping()
165:                                || mapping.isOneToManyMapping() || mapping
166:                                .isManyToManyMapping());
167:            }
168:
169:            /** Returns true if the specified attribute denotes a single valued
170:             * relationship attribute. 
171:             */
172:            public boolean isSingleValuedRelationship(Object ownerClass,
173:                    String attribute) {
174:                DatabaseMapping mapping = resolveAttributeMapping(ownerClass,
175:                        attribute);
176:                return (mapping != null) && mapping.isObjectReferenceMapping();
177:            }
178:
179:            /** Returns true if the specified attribute denotes a collection valued
180:             * relationship attribute. 
181:             */
182:            public boolean isCollectionValuedRelationship(Object ownerClass,
183:                    String attribute) {
184:                DatabaseMapping mapping = resolveAttributeMapping(ownerClass,
185:                        attribute);
186:                return (mapping != null)
187:                        && (mapping.isOneToManyMapping() || mapping
188:                                .isManyToManyMapping());
189:            }
190:
191:            // ===== Internal helper methods =====
192:
193:            /** Returns the class descriptor if the specified non-null type is a class
194:             * object. 
195:             */
196:            private ClassDescriptor getDescriptor(Object type) {
197:                ClassDescriptor desc = null;
198:                if (type instanceof  Class) {
199:                    desc = session.getDescriptor((Class) type);
200:                } else if (type instanceof  ClassDescriptor) {
201:                    desc = (ClassDescriptor) type;
202:                }
203:                return desc;
204:            }
205:
206:            /** Returns the mapping for the specified attribute of the psecified
207:             * class. The method returns null if the class is not known or if the
208:             * class does not have an attribute of the specified name.
209:             */
210:            private DatabaseMapping resolveAttributeMapping(Object ownerClass,
211:                    String attr) {
212:                ClassDescriptor desc = getDescriptor(ownerClass);
213:                return (desc == null) ? null : desc
214:                        .getMappingForAttributeName(attr);
215:            }
216:
217:            /** */
218:            private Object getType(DatabaseMapping mapping) {
219:                if (mapping == null) {
220:                    return null;
221:                }
222:                Object type = null;
223:                if (mapping.isForeignReferenceMapping()) {
224:                    ClassDescriptor descriptor = mapping
225:                            .getReferenceDescriptor();
226:                    type = descriptor == null ? null : descriptor
227:                            .getJavaClass();
228:                } else if (mapping.isAggregateMapping()) {
229:                    // Return the ClassDescriptor as the type representation in case
230:                    // of an embeeded. This makese sure that any property or field
231:                    // access of the embedded uses the correct mapping information and
232:                    // not the shell of the descriptors as stored by the session.
233:                    type = ((AggregateMapping) mapping)
234:                            .getReferenceDescriptor();
235:                } else {
236:                    type = mapping.getAttributeClassification();
237:                }
238:                return type;
239:            }
240:
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.