KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > querykeys > ForeignReferenceQueryKey


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.querykeys;
23
24 import java.security.AccessController JavaDoc;
25 import java.security.PrivilegedActionException JavaDoc;
26
27 import oracle.toplink.essentials.expressions.*;
28 import oracle.toplink.essentials.exceptions.ValidationException;
29 import oracle.toplink.essentials.internal.security.PrivilegedAccessHelper;
30 import oracle.toplink.essentials.internal.security.PrivilegedClassForName;
31
32 /**
33  * <p>
34  * <b>Purpose</b>: Define an alias to a foreign object.
35  * <p>
36  * <b> Responsibilities</b>:
37  * <ul>
38  * <li> Define the reference class of the foreign object.
39  * </ul>
40  */

41 public class ForeignReferenceQueryKey extends QueryKey {
42     protected Class JavaDoc referenceClass;
43     protected String JavaDoc referenceClassName;
44     protected Expression joinCriteria;
45
46     /**
47      * INTERNAL:
48      * Convert all the class-name-based settings in this project to actual class-based
49      * settings
50      * @param classLoader
51      */

52     public void convertClassNamesToClasses(ClassLoader JavaDoc classLoader){
53         Class JavaDoc referenceClass = null;
54         try{
55             if (referenceClassName != null){
56                 if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
57                     try {
58                         referenceClass = (Class JavaDoc)AccessController.doPrivileged(new PrivilegedClassForName(referenceClassName, true, classLoader));
59                     } catch (PrivilegedActionException JavaDoc exception) {
60                         throw ValidationException.classNotFoundWhileConvertingClassNames(referenceClassName, exception.getException());
61                     }
62                 } else {
63                     referenceClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(referenceClassName, true, classLoader);
64                 }
65             }
66             setReferenceClass(referenceClass);
67         } catch (ClassNotFoundException JavaDoc exc){
68             throw ValidationException.classNotFoundWhileConvertingClassNames(referenceClassName, exc);
69         }
70     }
71
72     /**
73      * PUBLIC:
74      * Return the join expression for the relationship defined by the query key.
75      */

76     public Expression getJoinCriteria() {
77         return joinCriteria;
78     }
79
80     /**
81      * PUBLIC:
82      * Return the reference class of the relationship.
83      */

84     public Class JavaDoc getReferenceClass() {
85         return referenceClass;
86     }
87     
88     /**
89      * PUBLIC:
90      * Return the reference class name of the relationship.
91      */

92     public String JavaDoc getReferenceClassName() {
93         if (referenceClassName == null && referenceClass != null){
94             referenceClassName = referenceClass.getName();
95         }
96         return referenceClassName;
97     }
98
99     /**
100      * INTERNAL:
101      * override the isForeignReferenceQueryKey() method in the superclass to return true.
102      * @return boolean
103      */

104     public boolean isForeignReferenceQueryKey() {
105         return true;
106     }
107
108     /**
109      * PUBLIC:
110      * Set the join expression for the relationship defined by the query key.
111      * <p>Example:
112      * <pre><blockquote>
113      * builder.getField("ADDRESS.ADDRESS_ID").equal(builder.getParameter("EMPLOYEE.ADDR_ID");
114      * </blockquote></pre>
115      */

116     public void setJoinCriteria(Expression joinCriteria) {
117         this.joinCriteria = joinCriteria;
118     }
119
120     /**
121      * PUBLIC:
122      * Set the reference class of the relationship.
123      * This is not required for direct collection query keys.
124      */

125     public void setReferenceClass(Class JavaDoc referenceClass) {
126         this.referenceClass = referenceClass;
127     }
128     
129     /**
130      * PUBLIC:
131      * Set the reference class name for this relationship
132      * This is used when projects are built without using classes
133      * @param referenceClassName
134      */

135     public void setReferenceClassName(String JavaDoc referenceClassName) {
136         this.referenceClassName = referenceClassName;
137     }
138 }
139
Popular Tags