1 23 24 29 30 package com.sun.jdo.spi.persistence.support.sqlstore.query.util.type; 31 32 import java.lang.reflect.Field ; 33 import java.lang.reflect.Modifier ; 34 import java.util.ResourceBundle ; 35 36 import com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement; 37 import com.sun.jdo.api.persistence.model.jdo.RelationshipElement; 38 import com.sun.jdo.api.persistence.support.JDOFatalInternalException; 39 import com.sun.jdo.spi.persistence.utility.I18NHelper; 40 41 44 public class FieldInfo 45 { 46 49 protected String name; 50 51 54 protected ClassType classType; 55 56 59 protected Field field; 60 61 64 protected PersistenceFieldElement pfe; 65 66 69 protected final static ResourceBundle messages = I18NHelper.loadBundle( 70 "com.sun.jdo.spi.persistence.support.sqlstore.query.Bundle", FieldInfo.class.getClassLoader()); 72 73 76 public FieldInfo (Field field, ClassType classType) 77 { 78 this.name = field.getName(); 79 this.classType = classType; 80 this.field = field; 81 this.pfe = (classType.pce != null) ? classType.pce.getField(this.name) : null; 82 } 83 84 89 public boolean isPersistent() 90 { 91 if (pfe != null) 92 { 93 return pfe.getPersistenceType() == PersistenceFieldElement.PERSISTENT; 94 } 95 return false; 96 } 97 98 103 public boolean isPublic() 104 { 105 return (field != null) && Modifier.isPublic(field.getModifiers()); 106 } 107 112 public boolean isStatic() 113 { 114 return (field != null) && Modifier.isStatic(field.getModifiers()); 115 } 116 117 120 public Field getField () 121 { 122 return field; 123 } 124 125 128 public String getName () 129 { 130 return name; 131 } 132 133 137 public Type getType() 138 { 139 if (field == null) 140 return classType.typetab.errorType; 141 142 Type ret = classType.typetab.checkType(field.getType()); 143 if (ret == null) 144 ret = classType.typetab.errorType; 145 return ret; 146 147 } 148 149 152 public int getFieldNumber() 153 { 154 if (pfe != null) 155 { 156 int index = pfe.getFieldNumber(); 157 if (index < 0) 158 throw new JDOFatalInternalException(I18NHelper.getMessage( 159 messages, "query.util.type.fieldinfo.getfieldnumber.invalidfieldno", String.valueOf(index), name)); 161 return index; 162 } 163 else 164 { 165 throw new JDOFatalInternalException(I18NHelper.getMessage( 166 messages, "query.util.type.fieldinfo.getfieldnumber.missingfieldelement", name)); 168 } 169 } 170 171 174 public boolean isRelationship() 175 { 176 return ((pfe != null) && (pfe instanceof RelationshipElement)); 177 } 178 179 183 public Type getAssociatedClass() 184 { 185 Type associatedClass = null; 186 if ((pfe != null) && (pfe instanceof RelationshipElement)) 187 { 188 String className = ((RelationshipElement)pfe).getElementClass(); 189 associatedClass = classType.typetab.checkType(className); 190 } 191 return associatedClass; 192 } 193 194 } 195 | Popular Tags |