1 22 package org.jboss.ejb.plugins.cmp.ejbql; 23 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.jboss.ejb.plugins.cmp.bridge.EntityBridge; 29 import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge; 30 31 37 public final class IdentifierManager { 38 private final Catalog catalog; 39 private final Map pathLists = new HashMap (); 40 private final Map fieldLists = new HashMap (); 41 private final Map identifiers = new HashMap (); 42 43 public IdentifierManager(Catalog catalog) { 44 this.catalog = catalog; 45 } 46 47 public void declareRangeVariable( 48 String identifier, 49 String abstractSchemaName) { 50 51 identifiers.put( 52 identifier, 53 catalog.getEntityByAbstractSchemaName(abstractSchemaName)); 54 } 55 56 public void declareCollectionMember( 57 String identifier, 58 String path) { 59 60 List fieldList = (List )fieldLists.get(path); 61 Object field = fieldList.get(fieldList.size()-1); 62 if(!(field instanceof CMRFieldBridge)) { 63 throw new IllegalArgumentException ("Path is collection valued: "+path); 64 } 65 CMRFieldBridge cmrField = (CMRFieldBridge)field; 66 if(cmrField.isSingleValued()) { 67 throw new IllegalArgumentException ("Path is collection valued: "+path); 68 } 69 identifiers.put(identifier, cmrField.getRelatedEntity()); 70 } 71 72 public EntityBridge getEntity(String identificationVariable) { 73 return (EntityBridge)identifiers.get(identificationVariable); 74 } 75 76 public void registerPath( 77 String path, 78 List pathList, 79 List fieldList) { 80 81 if(pathList.size() != fieldList.size()) { 82 throw new IllegalArgumentException ("Path list and field list must " + 83 "have the same size: pathList.size=" + pathList.size() + 84 " fieldList.size=" + fieldList.size()); 85 } 86 pathLists.put(path, pathList); 87 fieldLists.put(path, fieldList); 88 } 89 90 public List getPathList(String path) { 91 return (List )pathLists.get(path); 92 } 93 94 public List getFieldList(String path) { 95 return (List )fieldLists.get(path); 96 } 97 98 } 99 100 | Popular Tags |