1 23 24 package org.objectweb.medor.query.jorm.lib; 25 26 import org.objectweb.jorm.metainfo.api.Class; 27 import org.objectweb.jorm.metainfo.api.Reference; 28 import org.objectweb.jorm.metainfo.api.TypedElement; 29 import org.objectweb.jorm.metainfo.api.MetaObject; 30 import org.objectweb.medor.api.MedorException; 31 import org.objectweb.medor.query.api.QueryTreeField; 32 33 import java.util.Iterator ; 34 import java.util.Map ; 35 36 40 public class ClassExtent extends BasicJormExtent { 41 42 private Class myClass; 43 44 private boolean prefetch = false; 47 48 public ClassExtent() { 49 } 50 51 public ClassExtent(String _name, String pnFieldName) { 52 super(_name, pnFieldName); 53 } 54 55 70 public ClassExtent(Class jormClass, String _name, 71 String pnameFieldName, 72 boolean classPNameOnly) throws MedorException { 73 super(_name, pnameFieldName); 74 myClass = jormClass; 75 76 identifier = new PNameField(getFieldName(name, pnameFieldName), myClass, this); 78 this.fields.add(identifier); 79 name2field.put(identifier.getName(), identifier); 80 81 if (!classPNameOnly) { 82 83 for (Iterator it = jormClass.getAllFields().iterator(); it.hasNext();) { 85 addField((TypedElement) it.next()); 86 } 87 } 88 } 89 90 104 public ClassExtent(Class jormClass, String _name, 105 String [] fieldNames, 106 boolean addPName, 107 String pnameFieldName) 108 throws MedorException { 109 super(_name, pnameFieldName); 110 myClass = jormClass; 111 112 if (addPName) { 114 PNameField nameField = new PNameField(getFieldName(name, pnameFieldName), myClass, this); 115 this.fields.add(nameField); 116 name2field.put(nameField.getName(), nameField); 117 } 118 for (int i = 0; i < fieldNames.length; i++) { 120 TypedElement te = jormClass.getTypedElement(fieldNames[i]); 121 if (te == null) 122 throw new MedorException("No field named " + fieldNames[i] + " in JORM class " + jormClass.getName()); 123 addField(te); 124 } 125 } 126 127 public Object clone(Object clone, 128 Map obj2clone) throws CloneNotSupportedException { 129 clone = super.clone(clone, obj2clone); 130 ((ClassExtent) clone).myClass = myClass; 131 return clone; 132 } 133 134 public QueryTreeField addField(String fieldName) throws MedorException { 135 if (fieldName == null) { 136 throw new java.lang.IllegalArgumentException ("Null field name"); 137 } 138 TypedElement te = myClass.getTypedElement(fieldName); 139 if (te == null) { 140 throw new MedorException("No field '" + fieldName 141 + "' found on the class '" + myClass.getName() +"'."); 142 } 143 return addField(te); 144 } 145 151 public QueryTreeField addField(TypedElement te) throws MedorException { 152 QueryTreeField basicF = null; 153 String fn = getFieldName(name, te.getName()); 154 basicF = (QueryTreeField) name2field.get(fn); 155 if (basicF != null) 156 throw new MedorException("the field " + te.getName() 157 + " is already defined (" + fn + ")"); 158 if (te instanceof Reference) 159 basicF = new PNameField(fn, myClass, this); 160 else 161 basicF = new BasicJormField(fn, this, te); 162 fields.add(basicF); 163 name2field.put(basicF.getName(), basicF); 164 return basicF; 165 } 166 167 public MetaObject getMetaObject() { 168 return myClass; 169 } 170 171 public String getJormName() { 172 return myClass.getFQName(); 173 } 174 175 public boolean isPrefetch() { 176 return prefetch; 177 } 178 public void setPrefetch(boolean prefetch) { 179 this.prefetch = prefetch; 180 } 181 } 182 | Popular Tags |