KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > ejb > enhancer > meta > EJBMetaDataModelImpl


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 in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
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 Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /******************************************************************************
25  *
26  * Author: Shing Wai Chan (shingwai@iplanet.com)
27  *
28  *****************************************************************************/

29
30 package com.sun.jdo.spi.persistence.support.ejb.enhancer.meta;
31
32 import java.lang.reflect.Modifier JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.List JavaDoc;
35
36 import com.sun.jdo.api.persistence.enhancer.meta.ExtendedJDOMetaData;
37 import com.sun.jdo.api.persistence.enhancer.meta.JDOMetaDataFatalError;
38 import com.sun.jdo.api.persistence.enhancer.meta.JDOMetaDataModelImpl;
39 import com.sun.jdo.api.persistence.enhancer.meta.JDOMetaDataUserException;
40 import com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement;
41 import com.sun.jdo.api.persistence.model.Model;
42
43
44 /**
45  * Provide MetaDataModel Class used by CMP code generation during
46  * EJB deployment.
47  * Note that classPath is used for I/O of MetaData and
48  * className is used for I/O of Model.
49  * @author Shing Wai Chan
50  */

51 public class EJBMetaDataModelImpl extends JDOMetaDataModelImpl
52         implements ExtendedJDOMetaData {
53
54
55     public EJBMetaDataModelImpl(Model model)
56             throws JDOMetaDataUserException, JDOMetaDataFatalError {
57         super(model);
58     }
59
60
61     //methods from ExtendedJDOMetaData, not in JDOMetaData
62
public String JavaDoc[] getKnownClasses()
63             throws JDOMetaDataUserException, JDOMetaDataFatalError {
64         throw new UnsupportedOperationException JavaDoc();
65     }
66
67     public String JavaDoc[] getKnownFields(String JavaDoc classPath)
68             throws JDOMetaDataUserException, JDOMetaDataFatalError {
69         return getManagedFields(classPath);
70     }
71
72     public String JavaDoc getFieldType(String JavaDoc classPath, String JavaDoc fieldName)
73             throws JDOMetaDataUserException, JDOMetaDataFatalError {
74         final String JavaDoc className = pathToName(classPath);
75         String JavaDoc ftype = model.getFieldType(className, fieldName);
76
77         return nameToPath(ftype);
78     }
79
80     public int getClassModifiers(String JavaDoc classPath)
81             throws JDOMetaDataUserException, JDOMetaDataFatalError {
82         return Modifier.PUBLIC;
83     }
84
85     public int getFieldModifiers(String JavaDoc classPath, String JavaDoc fieldName)
86             throws JDOMetaDataUserException, JDOMetaDataFatalError {
87         final String JavaDoc className = pathToName(classPath);
88         return model.getModifiers(model.getField(className, fieldName));
89     }
90
91     public String JavaDoc getKeyClass(String JavaDoc classPath)
92             throws JDOMetaDataUserException, JDOMetaDataFatalError {
93         final String JavaDoc className = pathToName(classPath);
94         String JavaDoc keyClass = model.getPersistenceClass(className).getKeyClass();
95         if (keyClass.toLowerCase().endsWith(".oid")) {
96             int ind = keyClass.lastIndexOf('.');
97             keyClass = keyClass.substring(0, ind) + "$Oid";
98         }
99         return nameToPath(keyClass);
100     }
101
102     public boolean isKnownNonManagedField(String JavaDoc classPath,
103             String JavaDoc fieldName, String JavaDoc fieldSig)
104             throws JDOMetaDataUserException, JDOMetaDataFatalError {
105         return !isPersistentField(classPath, fieldName);
106     }
107
108     public boolean isManagedField(String JavaDoc classPath, String JavaDoc fieldName)
109             throws JDOMetaDataUserException, JDOMetaDataFatalError {
110         return (isPersistentField(classPath, fieldName)
111                 || isTransactionalField(classPath, fieldName));
112     }
113
114     public boolean isKeyField(String JavaDoc classPath, String JavaDoc fieldName)
115             throws JDOMetaDataUserException, JDOMetaDataFatalError {
116         return isPrimaryKeyField(classPath, fieldName);
117     }
118
119     public boolean isPrimaryKeyField(String JavaDoc classPath, String JavaDoc fieldName)
120         throws JDOMetaDataUserException, JDOMetaDataFatalError
121     {
122         final String JavaDoc className = pathToName(classPath);
123         final PersistenceFieldElement pfe
124             = model.getPersistenceField(className, fieldName);
125         if (pfe != null) {
126             return pfe.isKey();
127         } else {
128             return false;
129         }
130     }
131
132     public int getFieldFlags(String JavaDoc classPath, String JavaDoc fieldName)
133             throws JDOMetaDataUserException, JDOMetaDataFatalError {
134         if (!isManagedField(classPath, fieldName)) {
135             affirm(!isTransactionalField(classPath, fieldName));
136             affirm(!isPersistentField(classPath, fieldName));
137             affirm(!isKeyField(classPath, fieldName));
138             affirm(!isDefaultFetchGroupField(classPath, fieldName));
139             return 0;
140         }
141         //affirm(isManagedField(classPath, fieldName));
142

143         if (isTransactionalField(classPath, fieldName)) {
144             affirm(!isPersistentField(classPath, fieldName));
145             affirm(!isKeyField(classPath, fieldName));
146             // ignore any dfg membership of transactional fields
147
//affirm(!isDefaultFetchGroupField(classPath, fieldName));
148
return CHECK_WRITE;
149         }
150         //affirm(!isTransactionalField(classPath, fieldName));
151
affirm(isPersistentField(classPath, fieldName));
152
153         if (isKeyField(classPath, fieldName)) {
154             // ignore any dfg membership of key fields
155
//affirm(!isDefaultFetchGroupField(classPath, fieldName));
156
return MEDIATE_WRITE;
157         }
158         //affirm(!isKeyField(classPath, fieldName));
159

160         if (isDefaultFetchGroupField(classPath, fieldName)) {
161             return CHECK_READ | CHECK_WRITE;
162         }
163         //affirm(!isDefaultFetchGroupField(classPath, fieldName));
164

165         return MEDIATE_READ | MEDIATE_WRITE;
166     }
167
168     public int[] getFieldFlags(String JavaDoc classPath, String JavaDoc[] fieldNames)
169            throws JDOMetaDataUserException, JDOMetaDataFatalError {
170         final int n = (fieldNames != null ? fieldNames.length : 0);
171         final int[] flags = new int[n];
172         for (int i = 0; i < n; i++) {
173             flags[i] = getFieldFlags(classPath, fieldNames[i]);
174         }
175         return flags;
176     }
177
178     public String JavaDoc[] getFieldType(String JavaDoc className, String JavaDoc[] fieldNames)
179             throws JDOMetaDataUserException, JDOMetaDataFatalError {
180         final int n = (fieldNames != null ? fieldNames.length : 0);
181         final String JavaDoc[] types = new String JavaDoc[n];
182         for (int i = 0; i < n; i++) {
183             types[i] = getFieldType(className, fieldNames[i]);
184         }
185         return types;
186     }
187
188     public int[] getFieldNo(String JavaDoc classPath, String JavaDoc[] fieldNames)
189             throws JDOMetaDataUserException, JDOMetaDataFatalError {
190         final int n = (fieldNames != null ? fieldNames.length : 0);
191         final int[] flags = new int[n];
192         for (int i = 0; i < n; i++) {
193             flags[i] = getFieldNo(classPath, fieldNames[i]);
194         }
195         return flags;
196     }
197
198     public String JavaDoc[] getKeyFields(String JavaDoc classPath)
199             throws JDOMetaDataUserException, JDOMetaDataFatalError {
200         final List JavaDoc keys = new ArrayList JavaDoc();
201         final String JavaDoc[] fieldNames = getManagedFields(classPath);
202         final int n = fieldNames.length;
203         for (int i = 0; i < n; i++) {
204             if (isKeyField(classPath, fieldNames[i])) {
205                 keys.add(fieldNames[i]);
206             }
207         }
208         return (String JavaDoc[])keys.toArray(new String JavaDoc[keys.size()]);
209     }
210
211     public String JavaDoc getPersistenceCapableSuperClass(String JavaDoc classPath)
212             throws JDOMetaDataUserException, JDOMetaDataFatalError {
213         return null;
214     }
215
216     public String JavaDoc getSuperKeyClass(String JavaDoc classPath)
217             throws JDOMetaDataUserException, JDOMetaDataFatalError {
218         return null;
219     }
220 }
221
Popular Tags