Source Code Cross Referenced for WeavedObjectBasicIndirectionPolicy.java in  » Database-ORM » toplink » oracle » toplink » essentials » internal » indirection » 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.indirection 
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:
038:        package oracle.toplink.essentials.internal.indirection;
039:
040:        import oracle.toplink.essentials.exceptions.DescriptorException;
041:        import oracle.toplink.essentials.indirection.ValueHolder;
042:        import oracle.toplink.essentials.indirection.ValueHolderInterface;
043:        import oracle.toplink.essentials.indirection.WeavedAttributeValueHolderInterface;
044:        import oracle.toplink.essentials.internal.helper.ClassConstants;
045:        import oracle.toplink.essentials.internal.helper.ConversionManager;
046:        import oracle.toplink.essentials.internal.helper.Helper;
047:        import oracle.toplink.essentials.internal.security.PrivilegedAccessHelper;
048:        import oracle.toplink.essentials.internal.security.PrivilegedMethodInvoker;
049:        import oracle.toplink.essentials.internal.sessions.AbstractRecord;
050:        import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl;
051:        import oracle.toplink.essentials.mappings.DatabaseMapping;
052:        import oracle.toplink.essentials.mappings.ForeignReferenceMapping;
053:
054:        import java.lang.reflect.InvocationTargetException;
055:        import java.lang.reflect.Method;
056:        import java.security.AccessController;
057:        import java.security.PrivilegedActionException;
058:
059:        /**
060:         * INTERNAL:
061:         * A WeavedObjectBasicIndirectionPolicy is used by OneToOne mappings that are LAZY through weaving
062:         * and which use Property(method) access.
063:         * 
064:         * It extends BasicIndirection by providing the capability of calling the set method that was initially
065:         * mapped in addition to the set method for the weaved valueholder in order to coordinate the value of the
066:         * underlying property with the value stored in the valueholder
067:         * 
068:         * @author Tom Ware
069:         *
070:         */
071:        public class WeavedObjectBasicIndirectionPolicy extends
072:                BasicIndirectionPolicy {
073:
074:            protected String setMethodName = null; // name of the initial set method.
075:            protected Method setMethod = null; // lazily initialized set method based on the set method name
076:
077:            public WeavedObjectBasicIndirectionPolicy(String setMethodName) {
078:                super ();
079:                this .setMethodName = setMethodName;
080:            }
081:
082:            /**
083:             * INTERNAL:
084:             * Return the "real" attribute value, as opposed to any wrapper.
085:             * This will trigger the wrapper to instantiate the value. In a weaved policy, this will
086:             * also call the initial setter method to coordinate the values of the valueholder with
087:             * the underlying data
088:             * 
089:             */
090:            public Object getRealAttributeValueFromObject(Object object,
091:                    Object attribute) {
092:                Object value = super .getRealAttributeValueFromObject(object,
093:                        attribute);
094:                // Provide the indirection policy with a callback that allows it to do any updates it needs as the result of getting the value
095:                updateValueInObject(object, value, attribute);
096:                return value;
097:            }
098:
099:            /**
100:             * This method will lazily initialize the set method
101:             * Lazy initialization occurs to that we are not required to have a handle on
102:             * the actual class that we are using until runtime.  This helps to satisfy the 
103:             * weaving requirement that demands that we avoid loading domain classes into
104:             * the main class loader until after weaving occurs.
105:             * @return
106:             */
107:            protected Method getSetMethod() {
108:                if (setMethod == null) {
109:                    ForeignReferenceMapping sourceMapping = (ForeignReferenceMapping) mapping;
110:                    // The parameter type for the set method must always be the return type of the get method.
111:                    Class[] parameterTypes = new Class[1];
112:                    parameterTypes[0] = sourceMapping.getReferenceClass();
113:                    try {
114:                        setMethod = Helper.getDeclaredMethod(sourceMapping
115:                                .getDescriptor().getJavaClass(), setMethodName,
116:                                parameterTypes);
117:                    } catch (NoSuchMethodException e) {
118:                        throw DescriptorException
119:                                .errorAccessingSetMethodOfEntity(sourceMapping
120:                                        .getDescriptor().getJavaClass(),
121:                                        setMethodName, sourceMapping
122:                                                .getDescriptor(), e);
123:                    }
124:                }
125:                return setMethod;
126:            }
127:
128:            /**
129:             * Coordinate the valueholder for this mapping with the underlying property by calling the
130:             * initial setter method
131:             */
132:            public void updateValueInObject(Object object, Object value,
133:                    Object attributeValue) {
134:                setRealAttributeValueInObject(object, value);
135:                ((WeavedAttributeValueHolderInterface) attributeValue)
136:                        .setIsCoordinatedWithProperty(true);
137:            }
138:
139:            /**
140:             * INTERNAL:
141:             * Set the value of the appropriate attribute of target to attributeValue.
142:             * In this case, place the value inside the target's ValueHolder.
143:             */
144:            public void setRealAttributeValueInObject(Object target,
145:                    Object attributeValue) {
146:                Object[] parameters = new Object[1];
147:                parameters[0] = attributeValue;
148:                try {
149:                    if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
150:                        try {
151:                            AccessController
152:                                    .doPrivileged(new PrivilegedMethodInvoker(
153:                                            getSetMethod(), target, parameters));
154:                        } catch (PrivilegedActionException exception) {
155:                            Exception throwableException = exception
156:                                    .getException();
157:                            if (throwableException instanceof  IllegalAccessException) {
158:                                throw DescriptorException
159:                                        .illegalAccessWhileSettingValueThruMethodAccessor(
160:                                                setMethod.getName(),
161:                                                attributeValue,
162:                                                throwableException);
163:                            } else {
164:                                throw DescriptorException
165:                                        .targetInvocationWhileSettingValueThruMethodAccessor(
166:                                                setMethod.getName(),
167:                                                attributeValue,
168:                                                throwableException);
169:                            }
170:                        }
171:                    } else {
172:                        PrivilegedAccessHelper.invokeMethod(getSetMethod(),
173:                                target, parameters);
174:                    }
175:                } catch (IllegalAccessException exception) {
176:                    throw DescriptorException
177:                            .illegalAccessWhileSettingValueThruMethodAccessor(
178:                                    setMethod.getName(), attributeValue,
179:                                    exception);
180:                } catch (IllegalArgumentException exception) {
181:                    throw DescriptorException
182:                            .illegalArgumentWhileSettingValueThruMethodAccessor(
183:                                    setMethod.getName(), attributeValue,
184:                                    exception);
185:                } catch (InvocationTargetException exception) {
186:                    throw DescriptorException
187:                            .targetInvocationWhileSettingValueThruMethodAccessor(
188:                                    setMethod.getName(), attributeValue,
189:                                    exception);
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.