1 23 24 package org.objectweb.jorm.metainfo.lib; 25 26 import org.objectweb.jorm.metainfo.api.*; 27 import org.objectweb.jorm.metainfo.api.Class; 28 29 import java.util.ArrayList ; 30 import java.util.Iterator ; 31 import java.util.Collection ; 32 import java.util.List ; 33 34 42 public abstract class BasicClassMapping extends BasicCommonClassMapping 43 implements ClassMapping { 44 50 private List fieldNames; 51 private List referenceMappings; 52 53 56 protected List parentClassMappings; 57 58 64 public BasicClassMapping(String ruleName, MetaObject linkedMO, 65 MetaObject parent) { 66 super(ruleName, linkedMO, parent); 67 referenceMappings = new ArrayList (); 68 parentClassMappings = new ArrayList (); 69 fieldNames = new ArrayList (); 70 } 71 72 76 82 public Class getJormClass() { 83 return (Class ) linkedMO; 84 } 85 86 91 public void addReferenceMapping(ReferenceMapping refMapping) { 92 Reference r = (Reference) refMapping.getLinkedMO().getParent(); 93 referenceMappings.add(refMapping); 94 fieldNames.add(r.getName()); 95 101 102 } 103 104 public ReferenceMapping createReferenceMapping(String ruleName, NameDef nd) { 105 ReferenceMapping res = super.createReferenceMapping(ruleName, nd); 106 addReferenceMapping(res); 107 return res; 108 } 109 110 public ReferenceMapping getReferenceMapping(String referenceName) { 111 int idx = fieldNames.indexOf(referenceName); 112 ReferenceMapping res = null; 113 if (idx == -1) { 114 for (Iterator it = iterateParentClassMappings(); it.hasNext();) { 115 ParentClassMapping pcm = (ParentClassMapping) it.next(); 116 Class pc = pcm.getMOClass(); 117 ClassMapping cm = pc.getClassMapping(getProjectName(), getMapperName()); 118 if ((res = cm.getReferenceMapping(referenceName)) != null) { 119 return res; 120 } 121 } 122 return res; 123 } else { 124 return (ReferenceMapping) referenceMappings.get(idx); 125 } 126 } 127 128 133 public Iterator iterateReferenceMappings() { 134 return referenceMappings.iterator(); 135 } 136 137 142 public Collection getReferenceMappings() { 143 return referenceMappings; 144 } 145 146 151 public void addParentClassMapping(ParentClassMapping pcm) { 152 parentClassMappings.add(pcm); 153 } 154 155 161 public ParentClassMapping createParentClassMapping(String ruleName, Class superClass) { 162 ParentClassMapping pcm = new BasicParentClassMapping(ruleName, superClass, this); 163 addParentClassMapping(pcm); 164 return pcm; 165 } 166 167 172 public Iterator iterateParentClassMappings() { 173 return parentClassMappings.iterator(); 174 } 175 176 181 public Collection getParentClassMappings() { 182 return parentClassMappings; 183 } 184 189 public ParentClassMapping getParentClassMapping(String classFQName) { 190 for (Iterator pcmIt = parentClassMappings.iterator(); pcmIt.hasNext();) { 191 ParentClassMapping pcm = (ParentClassMapping) pcmIt.next(); 192 if (pcm.getFQName().equals(classFQName)) { 193 return pcm; 194 } 195 } 196 return null; 197 } 198 protected Collection getChildren() { 199 Collection al = super.getChildren(); 200 al.addAll(parentClassMappings); 201 al.addAll(referenceMappings); 202 return al; 203 } 204 205 206 } 207 | Popular Tags |