1 22 package org.jboss.metadata; 23 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 28 import org.w3c.dom.Element ; 29 import org.jboss.deployment.DeploymentException; 30 import org.jboss.logging.Logger; 31 import org.jboss.util.Strings; 32 33 50 public class EntityMetaData 51 extends BeanMetaData 52 { 53 public final static int CMP_VERSION_1 = 1; 55 public final static int CMP_VERSION_2 = 2; 56 public static final String DEFAULT_ENTITY_INVOKER_PROXY_BINDING = 57 "entity-unified-invoker"; 58 public static final String DEFAULT_CLUSTERED_ENTITY_INVOKER_PROXY_BINDING = 59 "clustered-entity-rmi-invoker"; 60 61 private boolean cmp; 63 private String primaryKeyClass; 64 private boolean reentrant; 65 private int cmpVersion; 66 private String abstractSchemaName; 67 private ArrayList <String > cmpFields = new ArrayList <String >(); 68 private String primKeyField; 69 private ArrayList <QueryMetaData> queries = new ArrayList <QueryMetaData>(); 70 private boolean readOnly = false; 71 private boolean doDistCachInvalidations = false; 72 private CacheInvalidationConfigMetaData cacheInvalidConfig = null; 73 74 private static Logger log = Logger.getLogger( EntityMetaData.class ); 76 77 public EntityMetaData( ApplicationMetaData app ) 79 { 80 super(app, BeanMetaData.ENTITY_TYPE); 81 } 82 83 public boolean isCMP() 85 { 86 return cmp; 87 } 88 89 public void setCmp(boolean cmp) 90 { 91 this.cmp = cmp; 92 } 93 94 public boolean isCMP1x() 95 { 96 return cmp && (cmpVersion==1); 97 } 98 99 public boolean isCMP2x() 100 { 101 return cmp && (cmpVersion==2); 102 } 103 104 public boolean isBMP() 105 { 106 return !cmp; 107 } 108 109 110 public String getAbstractSchemaName() 111 { 112 return abstractSchemaName; 113 } 114 115 public void setAbstractSchemaName(String abstractSchemaName) 116 { 117 this.abstractSchemaName = abstractSchemaName; 118 } 119 120 public CacheInvalidationConfigMetaData getCacheInvalidConfig() 121 { 122 return cacheInvalidConfig; 123 } 124 125 public void setCacheInvalidConfig( 126 CacheInvalidationConfigMetaData cacheInvalidConfig) 127 { 128 this.cacheInvalidConfig = cacheInvalidConfig; 129 } 130 131 public ArrayList <String > getCmpFields() 132 { 133 return cmpFields; 134 } 135 136 public void setCmpFields(ArrayList <String > cmpFields) 137 { 138 this.cmpFields = cmpFields; 139 } 140 141 public int getCmpVersion() 142 { 143 return cmpVersion; 144 } 145 146 public void setCmpVersion(int cmpVersion) 147 { 148 this.cmpVersion = cmpVersion; 149 } 150 151 public boolean isDoDistCachInvalidations() 152 { 153 return doDistCachInvalidations; 154 } 155 156 public void setDoDistCachInvalidations(boolean doDistCachInvalidations) 157 { 158 this.doDistCachInvalidations = doDistCachInvalidations; 159 } 160 161 public String getPrimaryKeyClass() 162 { 163 return primaryKeyClass; 164 } 165 166 public void setPrimaryKeyClass(String primaryKeyClass) 167 { 168 this.primaryKeyClass = primaryKeyClass; 169 } 170 171 public boolean isReadOnly() 172 { 173 return readOnly; 174 } 175 176 public void setReadOnly(boolean readOnly) 177 { 178 this.readOnly = readOnly; 179 } 180 181 public boolean isReentrant() 182 { 183 return reentrant; 184 } 185 186 public void setReentrant(boolean reentrant) 187 { 188 this.reentrant = reentrant; 189 } 190 191 public void setPrimKeyField(String primKeyField) 192 { 193 this.primKeyField = primKeyField; 194 } 195 196 public void setQueries(ArrayList queries) 197 { 198 this.queries = queries; 199 } 200 201 205 public Iterator getCMPFields() 206 { 207 return cmpFields.iterator(); 208 } 209 210 public String getPrimKeyField() 211 { 212 return primKeyField; 213 } 214 215 public Iterator getQueries() 216 { 217 return queries.iterator(); 218 } 219 220 public void addQuery(QueryMetaData query) 221 { 222 queries.add(query); 223 } 224 225 public String getDefaultConfigurationName() 226 { 227 if (isCMP()) 228 { 229 if(getApplicationMetaData().isEJB2x()) 230 { 231 if (isClustered()) 232 { 233 return ConfigurationMetaData.CLUSTERED_CMP_2x_13; 234 } 235 else 236 { 237 return ConfigurationMetaData.CMP_2x_13; 238 } 239 } 240 else 241 { 242 if (isClustered()) 243 { 244 return ConfigurationMetaData.CLUSTERED_CMP_1x_13; 245 } 246 else 247 { 248 return ConfigurationMetaData.CMP_1x_13; 249 } 250 } 251 } 252 else 253 { 254 if (isClustered()) 255 { 256 return ConfigurationMetaData.CLUSTERED_BMP_13; 257 } 258 else 259 { 260 return ConfigurationMetaData.BMP_13; 261 } 262 } 263 } 264 265 public boolean doDistributedCacheInvalidations () 266 { 267 return this.doDistCachInvalidations ; 268 } 269 270 public CacheInvalidationConfigMetaData getDistributedCacheInvalidationConfig () 271 { 272 return this.cacheInvalidConfig ; 273 } 274 275 public void importEjbJarXml( Element element ) 276 throws DeploymentException 277 { 278 super.importEjbJarXml(element); 279 280 String persistenceType = getElementContent(getUniqueChild(element, 282 "persistence-type")); 283 if( persistenceType.equals("Bean") ) 284 { 285 cmp = false; 286 } 287 else if( persistenceType.equals("Container") ) 288 { 289 cmp = true; 290 } 291 else 292 { 293 throw new DeploymentException( getEjbName() + ": " + 294 "persistence-type must be 'Bean' or 'Container'!" ); 295 } 296 297 primaryKeyClass = getElementContent(getUniqueChild(element, 299 "prim-key-class")); 300 301 reentrant = Boolean.valueOf(getElementContent(getUniqueChild(element, 303 "reentrant"))).booleanValue(); 304 305 if( isCMP() ) 306 { 307 if( getApplicationMetaData().isEJB2x() ) 309 { 310 String cmpVersionString = getElementContent( 311 getOptionalChild(element, "cmp-version")); 312 313 if( cmpVersionString == null ) 314 { 315 cmpVersion = CMP_VERSION_2; 317 } 318 else 319 { 320 if( "1.x".equals(cmpVersionString) ) 321 { 322 cmpVersion = 1; 323 } 324 else if( "2.x".equals(cmpVersionString) ) 325 { 326 cmpVersion = 2; 327 } 328 else 329 { 330 throw new DeploymentException( getEjbName() + ": " + 331 "cmp-version must be '1.x' or '2.x', if specified" ); 332 } 333 } 334 } 335 else 336 { 337 cmpVersion = CMP_VERSION_1; 339 } 340 341 abstractSchemaName = getOptionalChildContent(element, 343 "abstract-schema-name"); 344 345 if( cmpVersion == 2 ) 346 { 347 350 String ejbName = getEjbName(); 351 352 if( !Strings.isValidJavaIdentifier(ejbName) ) 354 { 355 throw new DeploymentException( "The ejb-name for a CMP" + 356 "2.x Entity must be a valid Java Identifier" ); 357 } 358 359 if( Strings.isEjbQlIdentifier(ejbName) ) 360 { 361 log.warn( ejbName + ": The ejb-name for a CMP 2.x Entity " + 362 "should not be a reserved EJB-QL keyword" ); 363 } 364 365 if( abstractSchemaName == null ) 367 { 368 throw new DeploymentException( "The abstract-schema-name " + 369 "must be specified for CMP 2.x Beans" ); 370 } 371 372 if( !Strings.isValidJavaIdentifier(abstractSchemaName) ) 373 { 374 throw new DeploymentException( "The abstract-schema-name " + 375 "must be a valid Java Identifier '" + abstractSchemaName + 376 "'"); 377 } 378 379 if( Strings.isEjbQlIdentifier(abstractSchemaName) ) 380 { 381 log.warn( ejbName + ": The abstract-schema-name should " + 382 "not be a reserved EJB-QL Identifier '" + 383 abstractSchemaName + "'" ); 384 } 385 } 386 387 Iterator iterator = getChildrenByTagName( element, "cmp-field" ); 389 while( iterator.hasNext() ) 390 { 391 Element field = (Element )iterator.next(); 392 cmpFields.add(getElementContent(getUniqueChild(field, 393 "field-name"))); 394 } 395 396 primKeyField = getElementContent(getOptionalChild(element, 398 "primkey-field")); 399 if( primKeyField != null && !cmpFields.contains(primKeyField) ) 400 { 401 throw new DeploymentException( "primkey-field " + primKeyField + 403 " is not a cmp-field"); 404 } 405 406 iterator = getChildrenByTagName(element, "query"); 408 while( iterator.hasNext() ) 409 { 410 Element queryElement = (Element ) iterator.next(); 411 412 QueryMetaData queryMetaData = new QueryMetaData(); 413 queryMetaData.importEjbJarXml(queryElement); 414 415 queries.add(queryMetaData); 416 } 417 } 418 } 419 420 protected void defaultInvokerBindings() 421 { 422 this.invokerBindings = new HashMap (); 423 if( isClustered() ) 424 { 425 this.invokerBindings.put( 426 DEFAULT_CLUSTERED_ENTITY_INVOKER_PROXY_BINDING, getJndiName()); 427 } 428 else 429 { 430 this.invokerBindings.put( 431 DEFAULT_ENTITY_INVOKER_PROXY_BINDING, getJndiName()); 432 } 433 } 434 435 public void importJbossXml( Element element ) 436 throws DeploymentException 437 { 438 super.importJbossXml(element); 439 String readOnlyString = getElementContent(getOptionalChild( 441 element, "read-only")); 442 if( readOnlyString != null ) 443 { 444 readOnly = Boolean.valueOf(readOnlyString).booleanValue(); 445 } 446 String distCacheInvalidations = getElementContent(getOptionalChild( element, 449 "cache-invalidation"), (this.doDistCachInvalidations ? "True" : "False") ); 450 this.doDistCachInvalidations = distCacheInvalidations.equalsIgnoreCase ("True"); 451 452 Element cacheInvalidConfigElement = getOptionalChild(element, 453 "cache-invalidation-config"); 454 455 this.cacheInvalidConfig = new CacheInvalidationConfigMetaData(); 456 this.cacheInvalidConfig.init(this); 457 if (cacheInvalidConfigElement != null) 458 { 459 this.cacheInvalidConfig.importJbossXml(cacheInvalidConfigElement); 460 } 461 462 463 } 464 465 467 469 471 } 473 476 | Popular Tags |