1 23 24 package org.objectweb.jorm.metainfo.lib; 25 26 import org.objectweb.jorm.metainfo.api.*; 27 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 import java.util.Collection ; 31 import java.util.Map ; 32 import java.util.HashMap ; 33 import java.util.Set ; 34 import java.util.HashSet ; 35 import java.util.List ; 36 import java.util.Collections ; 37 38 41 public class BasicCommonClassMapping 42 extends BasicMappingStructure 43 implements CommonClassMapping { 44 45 48 private String ruleName; 49 50 55 private Map primitiveElementMappings; 56 57 61 private IdentifierMapping identifierMapping; 62 63 private Set dependencies; 64 65 72 public BasicCommonClassMapping(String ruleName, MetaObject linkedMO, 73 MetaObject parent) { 74 super(parent, linkedMO); 75 this.ruleName = ruleName; 76 primitiveElementMappings = new HashMap (); 77 identifierMapping = null; 78 dependencies = new HashSet (); 79 } 80 81 85 89 public String getRuleName() { 90 return this.ruleName; 91 } 92 93 97 public void setRuleName(String rulename) { 98 99 this.ruleName = rulename; 100 } 101 102 106 public IdentifierMapping getIdentifierMapping() { 107 return this.identifierMapping; 108 } 109 110 114 public void setIdentifierMapping(IdentifierMapping idmapping) { 115 this.identifierMapping = idmapping; 116 } 117 118 122 public Collection getPrimitiveElementMappings() { 123 List list = null; 124 try { 125 list = new ArrayList (primitiveElementMappings.values()); 126 Collections.sort(list, FieldComparator.instance); 127 } catch (Exception e) { 128 e.printStackTrace(); } 130 return list; 131 } 132 133 134 137 public List getAllPrimitiveElementMappings() { 138 return (List ) getPrimitiveElementMappings(); 139 } 140 141 public PrimitiveElementMapping getPrimitiveElementMapping(String fieldName) { 142 return (PrimitiveElementMapping) primitiveElementMappings.get(fieldName); 143 } 144 145 146 150 public void addPrimitiveElementMapping(PrimitiveElementMapping peMapping) { 151 addPrimitiveElementMapping( 152 ((PrimitiveElement) peMapping.getLinkedMO()).getName(), peMapping); 153 } 154 155 159 public void addPrimitiveElementMapping(String fieldName, PrimitiveElementMapping peMapping) { 160 primitiveElementMappings.put(fieldName, peMapping); 161 } 163 164 168 public Iterator primitiveElementMappingsIterator() { 169 return primitiveElementMappings.values().iterator(); 170 } 171 172 173 174 179 public IdentifierMapping createIdentifierMapping(NameDef nd) { 180 IdentifierMapping res = getIdentifierMapping(); 181 if (res == null) { 182 res = new BasicIdentifierMapping(nd, this); 183 setIdentifierMapping(res); 184 } 185 return res; 186 } 187 188 194 public ReferenceMapping createReferenceMapping(String ruleName, NameDef nd) { 195 return new BasicReferenceMapping(ruleName, nd, this); 196 } 197 198 public void addDependency(String jormClassName) { 199 dependencies.add(jormClassName); 200 } 201 202 public void removeDependency(String jormClassName) { 203 dependencies.remove(jormClassName); 204 } 205 206 public Collection getDependencies() { 207 return dependencies; 208 } 209 210 protected Collection getChildren() { 211 Collection al = new ArrayList (); 212 al.add(identifierMapping); 213 al.addAll(primitiveElementMappings.values()); 214 return al; 215 } 216 217 } 218 | Popular Tags |