1 23 24 29 30 package com.sun.jdo.spi.persistence.support.ejb.enhancer.meta; 31 32 import java.lang.reflect.Modifier ; 33 import java.util.ArrayList ; 34 import java.util.List ; 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 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 public String [] getKnownClasses() 63 throws JDOMetaDataUserException, JDOMetaDataFatalError { 64 throw new UnsupportedOperationException (); 65 } 66 67 public String [] getKnownFields(String classPath) 68 throws JDOMetaDataUserException, JDOMetaDataFatalError { 69 return getManagedFields(classPath); 70 } 71 72 public String getFieldType(String classPath, String fieldName) 73 throws JDOMetaDataUserException, JDOMetaDataFatalError { 74 final String className = pathToName(classPath); 75 String ftype = model.getFieldType(className, fieldName); 76 77 return nameToPath(ftype); 78 } 79 80 public int getClassModifiers(String classPath) 81 throws JDOMetaDataUserException, JDOMetaDataFatalError { 82 return Modifier.PUBLIC; 83 } 84 85 public int getFieldModifiers(String classPath, String fieldName) 86 throws JDOMetaDataUserException, JDOMetaDataFatalError { 87 final String className = pathToName(classPath); 88 return model.getModifiers(model.getField(className, fieldName)); 89 } 90 91 public String getKeyClass(String classPath) 92 throws JDOMetaDataUserException, JDOMetaDataFatalError { 93 final String className = pathToName(classPath); 94 String 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 classPath, 103 String fieldName, String fieldSig) 104 throws JDOMetaDataUserException, JDOMetaDataFatalError { 105 return !isPersistentField(classPath, fieldName); 106 } 107 108 public boolean isManagedField(String classPath, String fieldName) 109 throws JDOMetaDataUserException, JDOMetaDataFatalError { 110 return (isPersistentField(classPath, fieldName) 111 || isTransactionalField(classPath, fieldName)); 112 } 113 114 public boolean isKeyField(String classPath, String fieldName) 115 throws JDOMetaDataUserException, JDOMetaDataFatalError { 116 return isPrimaryKeyField(classPath, fieldName); 117 } 118 119 public boolean isPrimaryKeyField(String classPath, String fieldName) 120 throws JDOMetaDataUserException, JDOMetaDataFatalError 121 { 122 final String 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 classPath, String 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 143 if (isTransactionalField(classPath, fieldName)) { 144 affirm(!isPersistentField(classPath, fieldName)); 145 affirm(!isKeyField(classPath, fieldName)); 146 return CHECK_WRITE; 149 } 150 affirm(isPersistentField(classPath, fieldName)); 152 153 if (isKeyField(classPath, fieldName)) { 154 return MEDIATE_WRITE; 157 } 158 160 if (isDefaultFetchGroupField(classPath, fieldName)) { 161 return CHECK_READ | CHECK_WRITE; 162 } 163 165 return MEDIATE_READ | MEDIATE_WRITE; 166 } 167 168 public int[] getFieldFlags(String classPath, String [] 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 [] getFieldType(String className, String [] fieldNames) 179 throws JDOMetaDataUserException, JDOMetaDataFatalError { 180 final int n = (fieldNames != null ? fieldNames.length : 0); 181 final String [] types = new String [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 classPath, String [] 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 [] getKeyFields(String classPath) 199 throws JDOMetaDataUserException, JDOMetaDataFatalError { 200 final List keys = new ArrayList (); 201 final String [] 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 [])keys.toArray(new String [keys.size()]); 209 } 210 211 public String getPersistenceCapableSuperClass(String classPath) 212 throws JDOMetaDataUserException, JDOMetaDataFatalError { 213 return null; 214 } 215 216 public String getSuperKeyClass(String classPath) 217 throws JDOMetaDataUserException, JDOMetaDataFatalError { 218 return null; 219 } 220 } 221 | Popular Tags |