1 23 24 29 30 package com.sun.jdo.spi.persistence.support.ejb.ejbc; 31 32 import java.util.*; 33 34 import com.sun.enterprise.deployment.*; 35 import org.netbeans.modules.dbschema.SchemaElement; 36 37 import com.sun.jdo.api.persistence.model.Model; 38 import com.sun.jdo.api.persistence.mapping.ejb.*; 39 import com.sun.jdo.spi.persistence.support.ejb.model.DeploymentDescriptorModel; 40 import com.sun.jdo.spi.persistence.support.sqlstore.ejb.DeploymentHelper; 41 42 47 public class EJBBundleInfoHelper implements EJBInfoHelper { 48 private static final char UNDERLINE = '_'; private static final char DOT = '.'; 51 private final EjbBundleDescriptor bundleDescriptor; 52 private Collection availableSchemaNames; 53 private NameMapper nameMapper; private Model model; 55 56 62 public EJBBundleInfoHelper(EjbBundleDescriptor bundleDescriptor, 63 Collection availableSchemaNames) { 64 this(bundleDescriptor, null, null, availableSchemaNames); 65 } 66 67 79 EJBBundleInfoHelper(EjbBundleDescriptor bundleDescriptor, 80 NameMapper nameMapper, Model model, 81 Collection availableSchemaNames) { 82 this.bundleDescriptor = bundleDescriptor; 83 this.nameMapper = nameMapper; 84 this.model = model; 85 this.availableSchemaNames = availableSchemaNames; 86 } 87 88 93 private EjbBundleDescriptor getBundleDescriptor() { 94 return bundleDescriptor; 95 } 96 97 100 public String getEjbJarDisplayName() { 101 return bundleDescriptor.getName(); 102 } 103 104 109 public Collection getAvailableSchemaNames () { 110 return availableSchemaNames; 111 } 112 113 117 public String getSchemaNameToGenerate() { 118 return DeploymentHelper.getDDLNamePrefix( 120 getBundleDescriptor()).replace(DOT, UNDERLINE); 121 } 122 123 129 public SchemaElement getSchema(String schemaName) { 130 return SchemaElement.forName(schemaName, getClassLoader()); 131 } 132 133 136 public Collection getEjbNames() { 137 Iterator iterator = getBundleDescriptor().getEjbs().iterator(); 138 ArrayList returnList = new ArrayList(); 139 140 while (iterator.hasNext()) { 141 EjbDescriptor ejb = (EjbDescriptor)iterator.next(); 142 143 if (ejb instanceof EjbCMPEntityDescriptor) 144 returnList.add(ejb.getName()); 145 } 146 147 return returnList; 148 } 149 150 153 public Collection getFieldsForEjb(String ejbName) { 154 Iterator iterator = getModel().getFields(ejbName).iterator(); 155 ArrayList returnList = new ArrayList(); 156 157 while (iterator.hasNext()) 158 returnList.add(iterator.next()); 159 160 return returnList; 161 } 162 163 166 public Collection getRelationshipsForEjb(String ejbName) { 167 Iterator iterator = getBundleDescriptor().getRelationships().iterator(); 168 ArrayList returnList = new ArrayList(); 169 170 while (iterator.hasNext()) { 175 RelationshipDescriptor relD = 176 (RelationshipDescriptor)iterator.next(); 177 RelationRoleDescriptor testRole = relD.getSource(); 178 String cmrField = null; 179 180 if (ejbName.equals(testRole.getOwner().getName())) { 181 cmrField = testRole.getCMRField(); 182 if (cmrField != null) 183 returnList.add(cmrField); 184 } 185 186 testRole = relD.getSink(); 187 if (ejbName.equals(testRole.getOwner().getName())) { 188 cmrField = testRole.getCMRField(); 189 if (cmrField != null) 190 returnList.add(cmrField); 191 } 192 } 193 194 return returnList; 195 } 196 197 200 public ClassLoader getClassLoader() { 201 return bundleDescriptor.getClassLoader(); 202 } 203 204 207 public AbstractNameMapper getNameMapper() { 208 return getNameMapperInternal(); 209 } 210 211 214 public AbstractNameMapper createUniqueNameMapper() { 215 return new NameMapper(bundleDescriptor); 216 } 217 218 private NameMapper getNameMapperInternal() { 219 if (nameMapper == null) 220 nameMapper = new NameMapper(bundleDescriptor, false); 221 222 return nameMapper; 223 } 224 225 228 public ConversionHelper createConversionHelper() { 229 return new EjbConversionHelper(getNameMapperInternal()); 230 } 231 232 235 public Model getModel() { 236 if (model == null) { 237 model = new DeploymentDescriptorModel(getNameMapperInternal(), 238 getClassLoader()); 239 } 240 241 return model; 242 } 243 } 244 | Popular Tags |