KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > EjbJarRoot


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.sun.share.configbean;
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import java.beans.PropertyChangeEvent JavaDoc;
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
33 import javax.enterprise.deploy.model.DDBean JavaDoc;
34 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
35 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
36 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
37 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
38
39 import org.xml.sax.SAXException JavaDoc;
40
41 import org.openide.DialogDisplayer;
42 import org.openide.ErrorManager;
43 import org.openide.NotifyDescriptor;
44
45 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
46 import org.netbeans.modules.j2ee.sun.dd.api.DDException;
47 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
48 import org.netbeans.modules.j2ee.sun.dd.api.common.DefaultResourcePrincipal;
49 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination;
50 import org.netbeans.modules.j2ee.sun.dd.api.ejb.CmpResource;
51 import org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans;
52 import org.netbeans.modules.j2ee.sun.dd.api.ejb.PmDescriptors;
53 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SchemaGeneratorProperties;
54 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar;
55 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
56
57 import org.netbeans.modules.j2ee.deployment.common.api.SourceFileMap;
58 import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
59
60 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet;
61
62 // ValidationSupport should either be deprecated or moved from package ...customizers.common to ...configbean
63
import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport;
64
65 import com.sun.jdo.api.persistence.mapping.ejb.beans.SunCmpMappings;
66 import com.sun.jdo.api.persistence.mapping.ejb.EJBInfoHelper;
67 import com.sun.jdo.api.persistence.mapping.ejb.ConversionHelper;
68 import com.sun.jdo.modules.persistence.mapping.core.util.MappingContext;
69 import com.sun.jdo.modules.persistence.mapping.ejb.EJBDevelopmentInfoHelper;
70 import com.sun.jdo.modules.persistence.mapping.ejb.util.MappingConverter;
71 import com.sun.jdo.modules.persistence.mapping.ejb.util.SunOneUtilsCMP;
72
73 // TODO - consider moving all the model imports and handling to another class
74
import com.sun.jdo.api.persistence.model.Model;
75 import com.sun.jdo.api.persistence.model.ModelException;
76 import com.sun.jdo.api.persistence.model.jdo.PersistenceClassElement;
77 import com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement;
78 import com.sun.jdo.api.persistence.model.jdo.PersistenceElementProperties;
79 import com.sun.jdo.api.persistence.model.jdo.RelationshipElement;
80 import com.sun.jdo.api.persistence.model.mapping.MappingClassElement;
81 import com.sun.jdo.api.persistence.model.mapping.MappingElementProperties;
82 import com.sun.jdo.api.persistence.model.jdo.impl.PersistenceFieldElementImpl;
83 import com.sun.jdo.api.persistence.model.jdo.impl.RelationshipElementImpl;
84 import com.sun.jdo.api.persistence.model.mapping.MappingFieldElement;
85 import com.sun.jdo.api.persistence.model.mapping.impl.MappingFieldElementImpl;
86 import com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl;
87 // end TODO
88

89
90 /**
91  *
92  * @author vkraemer
93  */

94 public class EjbJarRoot extends BaseRoot implements javax.enterprise.deploy.spi.DConfigBean JavaDoc {
95
96     public static final String JavaDoc CMP_MAPPINGS_CHANGED = "CmpMappingsChanged"; //NOI18N
97

98     private static final String JavaDoc ABSOLUTE_XPATH_ROOT = "/ejb-jar/"; // NOI18N
99

100     private static final String JavaDoc SECURITY_ROLE_R_XPATH = "assembly-descriptor/security-role"; // NOI18N
101
static final String JavaDoc SECURITY_ROLE_XPATH = ABSOLUTE_XPATH_ROOT + SECURITY_ROLE_R_XPATH;
102
103     private static final String JavaDoc ENTITY_R_XPATH = "enterprise-beans/entity"; // NOI18N
104
static final String JavaDoc ENTITY_XPATH = ABSOLUTE_XPATH_ROOT + ENTITY_R_XPATH;
105
106     private static final String JavaDoc SESSION_R_XPATH = "enterprise-beans/session"; // NOI18N
107
static final String JavaDoc SESSION_XPATH = ABSOLUTE_XPATH_ROOT + SESSION_R_XPATH;
108
109     private static final String JavaDoc MD_R_XPATH = "enterprise-beans/message-driven"; // NOI18N
110
static final String JavaDoc MD_XPATH = ABSOLUTE_XPATH_ROOT + MD_R_XPATH;
111
112     private static final String JavaDoc CMP_FIELD_XPATH = ENTITY_XPATH + "/cmp-field"; // NOI18N
113
private static final String JavaDoc CMP_FIELD_NAME_XPATH = CMP_FIELD_XPATH + "/field-name"; // NOI18N
114
private static final String JavaDoc EJB_RELATION_XPATH = "/ejb-jar/relationships/ejb-relation"; // NOI18N
115
private static final String JavaDoc CMR_FIELD_XPATH = EJB_RELATION_XPATH + "/ejb-relationship-role/cmr-field"; // NOI18N
116
private static final String JavaDoc CMR_FIELD_NAME_XPATH = CMR_FIELD_XPATH + "/cmr-field-name"; // NOI18N
117
private static final String JavaDoc CMP_MAPPING_FILE = "sun-cmp-mappings.xml"; // NOI18N
118

119
120     /** Holds value of property name. */
121     private String JavaDoc name;
122
123     /** Holds value of property pmDescriptors. */
124     private PmDescriptors pmDescriptors;
125
126     /** Holds value of property cmpResource. */
127     private CmpResource cmpResource;
128
129     /** Holds list of MessageDestination properties. */
130     private List JavaDoc messageDestinations;
131
132     /** Holds the value of the cmp mapping info */
133     private MappingContext mappingContext;
134
135     /** Holds the value of the cmp mapping info helper */
136     private EJBInfoHelper ejbInfoHelper;
137
138     /** Holds the value of the source file map passed to ejbInfoHelper to prevent it
139      * from being garbage collected.
140      */

141     private SourceFileMap sourceFileMap;
142     
143     /** Holds the value of the cmp mapping conversion helper */
144     private ConversionHelper conversionHelper;
145
146     private PropertyChangeListener JavaDoc cmpMappingListener =
147         new PropertyChangeListener JavaDoc() {
148             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
149                 Object JavaDoc source = evt.getSource();
150                 String JavaDoc propName = evt.getPropertyName();
151
152                 if (((source instanceof MappingClassElement) &&
153                     MappingElementProperties.PROP_MODIFIED.equals(propName)) ||
154                     ((source instanceof PersistenceClassElement) &&
155                     PersistenceElementProperties.PROP_MODIFIED.equals(propName)))
156                 {
157                     boolean modified =
158                         ((Boolean JavaDoc)evt.getNewValue()).booleanValue();
159
160                     // only set if true -- otherwise could be endless loop
161
if (modified)
162                         getPCS().firePropertyChange("mapping", null, null);
163                 }
164             }
165         };
166
167     /** Creates a new instance of EjbJarRoot */
168     public EjbJarRoot() {
169         setDescriptorElement(bundle.getString("BDN_EjbJarRoot")); // NOI18N
170
}
171
172     protected void init(DDBeanRoot JavaDoc dDBean, SunONEDeploymentConfiguration dc, DDBean JavaDoc ddbExtra) throws ConfigurationException JavaDoc {
173         super.init(dDBean, dc, ddbExtra);
174
175         loadFromPlanFile(dc);
176     }
177
178     /** -----------------------------------------------------------------------
179      * Validation implementation
180      */

181
182     private static ValidationSupport validationSupport = new ValidationSupport();
183
184     // relative xpaths (double as field id's)
185
public static final String JavaDoc FIELD_EJBJAR_NAME = "enterprise-beans/name";
186     public static final String JavaDoc FIELD_CMP_RESOURCE = "enterprise-beans/cmp-resource";
187     public static final String JavaDoc FIELD_CMPRES_JNDI_NAME = "enterprise-beans/cmp-resource/jndi-name";
188     public static final String JavaDoc FIELD_CMPRES_DB_CREATE = "enterprise-beans/cmp-resource/create-tables-at-deploy";
189     public static final String JavaDoc FIELD_CMPRES_DB_DROP = "enterprise-beans/cmp-resource/drop-tables-at-undeploy";
190     public static final String JavaDoc FIELD_CMPRES_DB_VENDOR = "enterprise-beans/cmp-resource/database-vendor-name";
191     public static final String JavaDoc FIELD_PM_DESCRIPTORS = "enterprise-beans/pm-descriptors";
192
193     protected void updateValidationFieldList() {
194         super.updateValidationFieldList();
195
196         validationFieldList.add(FIELD_EJBJAR_NAME);
197         validationFieldList.add(FIELD_CMP_RESOURCE);
198         validationFieldList.add(FIELD_PM_DESCRIPTORS);
199     }
200
201     public boolean validateField(String JavaDoc fieldId) {
202         Collection JavaDoc/*ValidationError*/ errors = new ArrayList JavaDoc();
203
204         // !PW use visitor pattern to get rid of switch/if statement for validation
205
// field -- data member mapping.
206
//
207
// ValidationSupport can return multiple errors for a single field. We only want
208
// to display one error per field, so we'll pick the first error rather than adding
209
// them all. As the user fixes each error, the remainder will display until all of
210
// them are handled. (Hopefully the errors are generated in a nice order, e.g.
211
// check blank first, then content, etc. If not, we may have to reconsider this.)
212
//
213
String JavaDoc absoluteFieldXpath = getAbsoluteXpath(fieldId);
214         if(fieldId.equals(FIELD_EJBJAR_NAME)) {
215             errors.add(executeValidator(ValidationError.PARTITION_EJBJAR_CMP_RESOURCE,
216                     name, absoluteFieldXpath, bundle.getString("LBL_Name"))); // NOI18N
217
} else if(fieldId.equals(FIELD_CMP_RESOURCE)) {
218             // All cmp-resource fields have to be validated against each other.
219
if(hasCmpResource()) {
220                 errors.add(executeValidator(ValidationError.PARTITION_EJBJAR_CMP_RESOURCE,
221                         cmpResource.getJndiName(), getAbsoluteXpath(FIELD_CMPRES_JNDI_NAME),
222                         bundle.getString("LBL_Jndi_Name"))); // NOI18N
223
errors.add(executeValidator(ValidationError.PARTITION_EJBJAR_CMP_RESOURCE,
224                         cmpResource.getCreateTablesAtDeploy(), getAbsoluteXpath(FIELD_CMPRES_DB_CREATE),
225                         bundle.getString("LBL_Create_Table_At_Deploy"))); // NOI18N
226
errors.add(executeValidator(ValidationError.PARTITION_EJBJAR_CMP_RESOURCE,
227                         cmpResource.getDropTablesAtUndeploy(), getAbsoluteXpath(FIELD_CMPRES_DB_DROP),
228                         bundle.getString("LBL_Drop_Table_At_Undeploy"))); // NOI18N
229
errors.add(executeValidator(ValidationError.PARTITION_EJBJAR_CMP_RESOURCE,
230                         cmpResource.getDatabaseVendorName(), getAbsoluteXpath(FIELD_CMPRES_DB_VENDOR),
231                         bundle.getString("LBL_Database_Vendor_Name"))); // NOI18N
232
} else {
233                 errors.add(ValidationError.getValidationErrorMask(
234                         ValidationError.PARTITION_EJBJAR_CMP_RESOURCE, getAbsoluteXpath(FIELD_CMPRES_JNDI_NAME)));
235                 errors.add(ValidationError.getValidationErrorMask(
236                         ValidationError.PARTITION_EJBJAR_CMP_RESOURCE, getAbsoluteXpath(FIELD_CMPRES_DB_CREATE)));
237                 errors.add(ValidationError.getValidationErrorMask(
238                         ValidationError.PARTITION_EJBJAR_CMP_RESOURCE, getAbsoluteXpath(FIELD_CMPRES_DB_DROP)));
239                 errors.add(ValidationError.getValidationErrorMask(
240                         ValidationError.PARTITION_EJBJAR_CMP_RESOURCE, getAbsoluteXpath(FIELD_CMPRES_DB_VENDOR)));
241             }
242         } else if(fieldId.equals(FIELD_PM_DESCRIPTORS)) {
243             if(pmDescriptors != null && pmDescriptors.sizePmDescriptor() > 0 && pmDescriptors.getPmInuse() == null) {
244                 errors.add(ValidationError.getValidationError(ValidationError.PARTITION_EJBJAR_PM_DESCRIPTORS,
245                         getAbsoluteXpath(FIELD_PM_DESCRIPTORS), bundle.getString("ERR_PmInuseRequired"))); // NOI18N
246
} else {
247                 errors.add(ValidationError.getValidationErrorMask(ValidationError.PARTITION_EJBJAR_PM_DESCRIPTORS,
248                         getAbsoluteXpath(FIELD_PM_DESCRIPTORS)));
249             }
250         }
251
252         boolean noErrors = true;
253         Iterator JavaDoc errorIter = errors.iterator();
254
255         while(errorIter.hasNext()) {
256             ValidationError error = (ValidationError) errorIter.next();
257             getMessageDB().updateError(error);
258
259             if(Utils.notEmpty(error.getMessage())) {
260                 noErrors = false;
261             }
262         }
263
264         // return true if there was no error added
265
return noErrors;
266     }
267
268     private ValidationError executeValidator(ValidationError.Partition partition, String JavaDoc propertyValue, String JavaDoc fieldXpath, String JavaDoc fieldLabel) {
269         ValidationError error = null;
270         Collection JavaDoc messages = validationSupport.validate(propertyValue, fieldXpath, fieldLabel);
271
272         if(messages != null && messages.size() > 0) {
273             error = ValidationError.getValidationError(partition, fieldXpath, (String JavaDoc) (messages.iterator().next()));
274         } else {
275             error = ValidationError.getValidationErrorMask(partition, fieldXpath);
276         }
277
278         return error;
279     }
280
281     private boolean hasCmpDrp() {
282         if(cmpResource != null) {
283             DefaultResourcePrincipal drp = cmpResource.getDefaultResourcePrincipal();
284             if(drp != null && (Utils.notEmpty(drp.getName()) || Utils.notEmpty(drp.getPassword()))) {
285                 return true;
286             }
287         }
288
289         return false;
290     }
291
292     private boolean hasCmpSgp() {
293         if(cmpResource != null) {
294             SchemaGeneratorProperties sgp = cmpResource.getSchemaGeneratorProperties();
295             if(sgp != null && sgp.sizePropertyElement() > 0) {
296                 return true;
297             }
298         }
299
300         return false;
301     }
302
303     private boolean hasCmpResource() {
304         if(cmpResource != null) {
305             if(Utils.notEmpty(cmpResource.getJndiName()) ||
306                     Utils.notEmpty(cmpResource.getCreateTablesAtDeploy()) ||
307                     Utils.notEmpty(cmpResource.getDropTablesAtUndeploy()) ||
308                     Utils.notEmpty(cmpResource.getDatabaseVendorName()) ||
309                     cmpResource.sizePropertyElement() > 0 ||
310                     hasCmpDrp() ||
311                     hasCmpSgp()
312                     ) {
313                 return true;
314             }
315         }
316
317         return false;
318     }
319
320     protected String JavaDoc getAbsoluteXpath(String JavaDoc field) {
321         String JavaDoc baseXpath = "/sun-ejb-jar";
322         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(baseXpath.length() + field.length() + 1);
323         buf.append(baseXpath);
324         buf.append("/"); // NOI18N
325
buf.append(field);
326         return buf.toString();
327     }
328
329     /**
330      * End Validation implementation
331      * ----------------------------------------------------------------------*/

332
333     public DConfigBean JavaDoc getDConfigBean(DDBeanRoot JavaDoc dDBeanRoot) {
334         BaseRoot rootDCBean = null;
335
336         J2EEBaseVersion moduleVersion = getJ2EEModuleVersion();
337         if(moduleVersion.compareTo(EjbJarVersion.EJBJAR_2_1) >= 0) {
338             rootDCBean = createWebServicesRoot(dDBeanRoot);
339         }
340
341         return rootDCBean;
342     }
343
344
345     /** Get the ejbjar root version of this module.
346      *
347      * @return EjbJarVersion enum for the version of this module.
348      */

349      public J2EEBaseVersion getJ2EEModuleVersion() {
350         DDBeanRoot JavaDoc ddbRoot = (DDBeanRoot JavaDoc) getDDBean();
351
352         // From JSR-88 1.1
353
String JavaDoc versionString = ddbRoot.getDDBeanRootVersion();
354         if(versionString == null) {
355             // If the above doesn't get us what we want.
356
versionString = ddbRoot.getModuleDTDVersion();
357         }
358
359         J2EEBaseVersion ejbJarVersion = EjbJarVersion.getEjbJarVersion(versionString);
360         if(ejbJarVersion == null) {
361             // Default to EjbJar 2.1 if we can't find out what version this is.
362
ejbJarVersion = EjbJarVersion.EJBJAR_2_1;
363         }
364
365         return ejbJarVersion;
366     }
367
368     /** Generate a DOCTYPE string for the specified version (which may be different
369      * than the current version of the tree
370      */

371     public String JavaDoc generateDocType(ASDDVersion version) {
372         String JavaDoc ejbDocType = generateDocType("sun-ejb-jar", version.getSunEjbJarPublicId(), version.getSunEjbJarSystemId()); // NOI18N
373
String JavaDoc result = ejbDocType;
374
375         if(hasSunCmpMappings()) {
376             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(512);
377             buffer.append("sun-ejb-jar.xml: "); // NOI18N
378
buffer.append(ejbDocType); // NOI18N
379
buffer.append("\nsun-cmp-mappings.xml: "); // NOI18N
380
buffer.append(generateDocType("sun-cmp-mappings", version.getSunCmpMappingsPublicId(), version.getSunCmpMappingsSystemId())); // NOI18N
381
result = buffer.toString();
382         }
383
384         return result;
385     }
386     
387     /** Retrieves a list of the ejb child DConfigBeans contained in this ejb-jar.
388      */

389     public List JavaDoc getEjbs() {
390         List JavaDoc ejbs = new ArrayList JavaDoc();
391         for(Iterator JavaDoc iter = getChildren().iterator(); iter.hasNext(); ) {
392             Object JavaDoc child = iter.next();
393             if(child instanceof BaseEjb) {
394                 ejbs.add(child);
395             }
396         }
397         return ejbs;
398     }
399
400     public String JavaDoc getHelpId() {
401         return "AS_CFG_EjbJarRoot"; //NOI18N
402
}
403
404     /** If we saved the bean tree right now, would we write out a CMP mappings file?
405      * This logic borrowed from hasDDSnippet() in getCmpMappingSnippet() and probably
406      * could be optimized further.
407      */

408     private boolean hasSunCmpMappings() {
409         return mappingContext != null && ejbInfoHelper != null;
410     }
411
412     /* ------------------------------------------------------------------------
413      * Persistence support. Loads DConfigBeans from previously saved Deployment
414      * plan file.
415      */

416     Collection JavaDoc getSnippets() {
417         Collection JavaDoc snippets = new ArrayList JavaDoc();
418 // Snippet snipCmpMapping = getCmpMappingSnippet();
419
Snippet snipOne = new DefaultSnippet() {
420             public CommonDDBean getDDSnippet() {
421                 SunEjbJar sej = getConfig().getStorageFactory().createSunEjbJar();
422                 String JavaDoc version = sej.getVersion().toString();
423
424                 EnterpriseBeans eb = sej.newEnterpriseBeans();
425
426                 if(null != name) {
427                     eb.setName(name);
428                 }
429
430                 PmDescriptors pmDesc = getPmDescriptors();
431                 if(pmDesc != null && (pmDesc.sizePmDescriptor() > 0 || pmDesc.getPmInuse() != null)) {
432                     eb.setPmDescriptors((PmDescriptors) pmDesc.cloneVersion(version));
433                 }
434
435                 if(hasCmpResource()) {
436                     CmpResource cmpResource = getCmpResource();
437                     eb.setCmpResource((CmpResource) cmpResource.cloneVersion(version));
438                 }
439
440                 MessageDestination [] msgDests = (MessageDestination [])
441                     Utils.listToArray(getMessageDestinations(), MessageDestination.class, version);
442                 if(msgDests != null) {
443                     eb.setMessageDestination(msgDests);
444                 }
445
446                 sej.setEnterpriseBeans(eb);
447
448                 /* IZ 84549, etc - add remaining saved named beans here. All entries that are represented
449                  * by real DConfigBeans should have been removed by now. */

450                 restoreAllNamedBeans(sej, version);
451                 
452                 // restore ejb's separately since they are embedded in enterprise-beans
453
restoreNamedBeans(getNamedBeanMap(EnterpriseBeans.EJB),
454                         EnterpriseBeans.EJB, eb, version);
455                 
456                 return sej;
457             }
458         };
459
460         snippets.add(snipOne);
461 // if (snipCmpMapping != null)
462
// snippets.add(snipCmpMapping);
463

464         return snippets;
465     }
466
467     Snippet getCmpMappingSnippet() {
468         return new Snippet() {
469             public CommonDDBean getDDSnippet() {
470                 return null;
471             }
472             public org.netbeans.modules.schema2beans.BaseBean getCmpDDSnippet() {
473                 SunCmpMappings sunCmpMappings =
474                     SunOneUtilsCMP.getSunCmpMappings(mappingContext, ejbInfoHelper);
475
476                 // iterate created MCEs mark them as unmodified after save
477
Iterator JavaDoc iterator =
478                     mappingContext.getModel().getMappingCache().values().iterator();
479                 while (iterator.hasNext()) {
480                     ((MappingClassElement)iterator.next()).setModified(false);
481                     // TODO - need to do PCEs too?
482
}
483
484                 // Set version. This is done differently for CMP than the other snippets
485
// because there is no CMP DD API yet.
486
// ASDDVersion asVersion = getConfig().getAppServerVersion();
487
// Use 8.1 because that is the tree we are using here. Need to downgrade the tree
488
// if targetting 8.0 or 7.0/1.
489
ASDDVersion asVersion = ASDDVersion.SUN_APPSERVER_8_1;
490                 sunCmpMappings.graphManager().setDoctype(
491                     asVersion.getSunCmpMappingsPublicId(), asVersion.getSunCmpMappingsSystemId());
492
493                 return sunCmpMappings;
494             }
495             public boolean hasDDSnippet() {
496                 // TODO: optimize here - no cmps, empty, or skeleton: return false
497
return mappingContext != null && ejbInfoHelper != null;
498             }
499             public String JavaDoc getFileName() {
500                 return CMP_MAPPING_FILE;
501             }
502             // Peter says these shouldn't be called
503
public String JavaDoc getPropertyName() {
504                 //control should never reach here.
505
assert(false);
506                 return null;
507             }
508             public CommonDDBean mergeIntoRootDD(CommonDDBean ddRoot) {
509                 //control should never reach here.
510
assert(false);
511                 return null;
512             }
513             public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) {
514                 //control should never reach here.
515
assert(false);
516                 return null;
517             }
518             // end Peter says these shouldn't be called
519
};
520     }
521
522     /** Calculate what the parent S2B bean should be for this child and return
523      * that bean.
524      */

525     protected CommonDDBean processParentBean(CommonDDBean bean, DConfigBean JavaDoc child) {
526         // If the child is an Ejb, we need to return the EnterpriseBeans bean
527
if(child instanceof BaseEjb) {
528             return ((SunEjbJar) bean).getEnterpriseBeans();
529         }
530
531         // All other children require no translation.
532
return bean;
533     }
534
535     /**
536      * @param dConfigBean
537      * @throws BeanNotFoundException
538      */

539     public void removeDConfigBean(DConfigBean JavaDoc dConfigBean) throws BeanNotFoundException JavaDoc {
540         // remove cmp before super so save works on both files
541
if ((dConfigBean != null) && (dConfigBean instanceof CmpEntityEjb))
542             removeMappingForCmp(((CmpEntityEjb)dConfigBean).getEjbName());
543         super.removeDConfigBean(dConfigBean);
544     }
545
546     // methods used to read a DConfigBean from a deployment plan
547
public class SunEjbJarParser implements ConfigParser {
548         public Object JavaDoc parse(java.io.InputStream JavaDoc stream) throws IOException JavaDoc, SAXException JavaDoc, DDException {
549             DDProvider provider = DDProvider.getDefault();
550             SunEjbJar result = null;
551
552             if(stream != null) {
553                 // Exceptions (due to bad graph or other problem) are handled by caller.
554
result = provider.getEjbDDRoot(new org.xml.sax.InputSource JavaDoc(stream));
555             } else {
556                 // If we have a null stream, return a blank graph.
557
result = (SunEjbJar) provider.newGraph(SunEjbJar.class,
558                         getConfig().getAppServerVersion().getEjbJarVersionAsString());
559             }
560
561             // First set our version to match that of this deployment descriptor.
562
getConfig().internalSetAppServerVersion(ASDDVersion.getASDDVersionFromEjbVersion(result.getVersion()));
563
564             return result;
565         }
566     }
567
568     public class EjbJarRootFinder implements ConfigFinder {
569         public Object JavaDoc find(Object JavaDoc obj) {
570             SunEjbJar retVal = (SunEjbJar) obj;
571             return retVal;
572         }
573     }
574
575     // methods used to read a DConfigBean from a deployment plan
576
public class SunCmpMappingsParser implements ConfigParser {
577         public Object JavaDoc parse(java.io.InputStream JavaDoc stream) throws IOException JavaDoc, SAXException JavaDoc, DDException {
578             SunCmpMappings result = null;
579
580             if(stream != null) {
581                 // Exceptions (due to bad graph or other problem) are handled by caller.
582
try {
583                     result = SunCmpMappings.createGraph(stream);
584                 } catch(Exception JavaDoc ex) {
585                     // This was an IllegalStateException, but the wrapped version of that isn't available
586
// in JDK 1.4. The reason we catch Exception here in the first place is because
587
// we need to absorb and correctly rethrow the Schema2beansException that can be
588
// caught here without referencing it's classtype.
589
throw new RuntimeException JavaDoc("Examine wrapped exception...", ex); // NOI18N
590
}
591             } else {
592                 // If we have a null stream, return a blank graph.
593
result = SunCmpMappings.createGraph();
594             }
595
596             // !PW FIXME What should we do if the DOCTYPE found here does not match
597
// that found for sun-ejb-jar.xml? What if sun-ejb-jar.xml wasn't found
598
// and so this is the only file to get version info from (and how would we
599
// know that?)
600
return result;
601         }
602     }
603
604     public class SunCmpMappingsRootFinder implements ConfigFinder {
605         public Object JavaDoc find(Object JavaDoc obj) {
606             SunCmpMappings retVal = (SunCmpMappings) obj;
607             return retVal;
608         }
609     }
610
611     protected ConfigParser getParser() {
612         return new SunEjbJarParser();
613     }
614
615     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
616         String JavaDoc uriText = getUriText();
617
618         SunEjbJar beanGraph = (SunEjbJar) config.getBeans(uriText, constructFileName(),
619                 getParser(), new EjbJarRootFinder());
620         boolean cmpMappingLoaded = false;
621
622         clearProperties();
623
624         if(null != beanGraph) {
625             EnterpriseBeans eb = beanGraph.getEnterpriseBeans();
626             if (null != eb) {
627                 this.name = eb.getName();
628
629                 PmDescriptors pmDesc = eb.getPmDescriptors();
630                 if(pmDesc != null && (pmDesc.sizePmDescriptor() > 0 || pmDesc.getPmInuse() != null)) {
631                     pmDescriptors = (PmDescriptors) pmDesc.clone();
632                 }
633
634                 CmpResource cr = eb.getCmpResource();
635                 if(cr != null) {
636                     cmpResource = (CmpResource) cr.clone();
637                 }
638
639                 messageDestinations = Utils.arrayToList(eb.getMessageDestination());
640             }
641             
642             // IZ 84549 - cache the data for all named beans.
643
saveAllNamedBeans(beanGraph);
644             
645             // handle ejb's separately since they are embedded in enterprise-beans
646
if(eb != null) {
647                 saveNamedBeans(EnterpriseBeans.EJB, org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb.EJB_NAME, eb.getEjb());
648             }
649         } else {
650             setDefaultProperties();
651         }
652
653         cmpMappingLoaded = loadCmpMappingsFromPlanFile(config);
654
655         return ((beanGraph != null) || cmpMappingLoaded);
656     }
657     
658     private static Collection JavaDoc ejbJarBeanSpecs = new ArrayList JavaDoc();
659     
660     static {
661 // ejbJarBeanSpecs.add(new NamedBean(SunWebApp.MESSAGE_DESTINATION,
662
// org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination.MESSAGE_DESTINATION_NAME));
663
// ejbJarBeanSpecs.add(new NamedBean(EnterpriseBeans.EJB,
664
// org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb.EJB_NAME));
665
ejbJarBeanSpecs.add(new NamedBean(SunWebApp.SECURITY_ROLE_MAPPING,
666                 org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping.ROLE_NAME));
667     }
668     
669     protected Collection JavaDoc getNamedBeanSpecs() {
670         return ejbJarBeanSpecs;
671     }
672     
673
674     public MappingContext getMappingContext () {
675         return getMappingContext(null, getEJBInfoHelper());
676     }
677
678     private MappingContext getMappingContext (SunCmpMappings beanGraph,
679             EJBInfoHelper infoHelper) {
680         if (mappingContext == null) {
681             try {
682                 mappingContext = SunOneUtilsCMP.getMappingContext(beanGraph,
683                     ejbInfoHelper);
684                 SunOneUtilsCMP.setExistingMappingContext(ejbInfoHelper,
685                     mappingContext);
686                 // iterate created MCEs and add cmpMappingListener as a
687
// PropertyChangeListener
688
Iterator JavaDoc iterator =
689                     mappingContext.getModel().getMappingCache().values().iterator();
690                 while (iterator.hasNext()) {
691                     addMappingListener((MappingClassElement)iterator.next());
692                 }
693             } catch(IllegalStateException JavaDoc ex) {
694                 // Oops, required file ejb-jar.xml does not exist.
695

696                 // !PW FIXME as currently written, this will popup a modal dialog, so if this exception
697
// occurs during startup/project loading, the IDE's main window will be blocked by the
698
// popup dialog.
699
// DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(ex.getLocalizedMessage()));
700
ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
701             } catch(Exception JavaDoc ex) {
702                 // TODO - what is proper handling of this exception? logging?
703
// TODO - narrower exceptions? (could be Model or DBException)
704
// for now, returns null
705
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
706             }
707         }
708
709         return mappingContext;
710     }
711
712     private void addMappingListener (MappingClassElement mce) {
713         mce.addPropertyChangeListener(cmpMappingListener);
714         // TODO - need to add PCE listener too? if not, maybe can
715
// simplify imports and PCL implementation above
716
}
717
718     public EJBInfoHelper getEJBInfoHelper () {
719         return getEJBInfoHelper(null);
720     }
721
722     public EJBInfoHelper getEJBInfoHelper(SunCmpMappings beanGraph) {
723         if (ejbInfoHelper == null) {
724             sourceFileMap = SourceFileMap.findSourceMap(getConfig().getDeployableObject());
725             ejbInfoHelper = new EJBDevelopmentInfoHelper(beanGraph, sourceFileMap);
726         }
727         
728         return ejbInfoHelper;
729     }
730     
731     private ConversionHelper getConversionHelper () {
732         if (conversionHelper == null) {
733             conversionHelper = getEJBInfoHelper().createConversionHelper();
734         }
735
736         return conversionHelper;
737     }
738
739     public void mapCmpBeans(OriginalCMPMapping[] mapping) {
740         SunCmpMappings beanGraph = (SunCmpMappings) getConfig().getBeans(
741             getUriText(), CMP_MAPPING_FILE, new SunCmpMappingsParser(),
742             new SunCmpMappingsRootFinder());
743         EJBInfoHelper infoHelper = getEJBInfoHelper();
744
745         // TODO: this intializes the mappingContext, but check whether
746
// it is still necessary, and if so, if it must be before creation
747
// of the mappingConverter. If it is no longer necessary, check whether
748
// beanGraph above is needed and whether infoHelper in MappingConverter's
749
// constructor can be used inline w/o the var above
750
getMappingContext(beanGraph, infoHelper);
751
752         MappingConverter mappingConverter = new MappingConverter(
753             infoHelper, SourceFileMap.findSourceMap(getConfig().getDeployableObject()));
754         Collection JavaDoc newMCEs = null;
755
756         try {
757             newMCEs = mappingConverter.toMappingClasses(mapping);
758         } catch (Exception JavaDoc e) {
759             // TODO - what is proper handling of this exception? logging?
760
// TODO - narrower exceptions? (could be Model or DBException)
761
// for now, newMCEs will be null and no registration of them
762
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
763         }
764
765         if (newMCEs != null) {
766             Iterator JavaDoc iterator = newMCEs.iterator();
767             while (iterator.hasNext()) {
768                 addMappingListener((MappingClassElement)iterator.next());
769             }
770             getPCS().firePropertyChange(CMP_MAPPINGS_CHANGED, null, newMCEs);
771         }
772     }
773
774     public void ensureCmpMappingExists (String JavaDoc beanName) {
775         try {
776             MappingContext mappingContext = getMappingContext();
777             EJBInfoHelper infoHelper = getEJBInfoHelper();
778             ConversionHelper myConversionHelper = getConversionHelper();
779
780             // if no corresponding MCE object, this must be a new
781
// bean, create the skeleton
782
if (mappingContext.getModel().getMappingClass(
783                     myConversionHelper.getMappedClassName(beanName)) == null) {
784                 MappingConverter mappingConverter = new MappingConverter(
785                     infoHelper, SourceFileMap.findSourceMap(getConfig().getDeployableObject()));
786                 MappingClassElement newMCE = null;
787                 try {
788                     newMCE = mappingConverter.toMappingClass(beanName);
789                 } catch (Exception JavaDoc e) {
790                     // TODO - what is proper handling of this exception? logging?
791
// TODO - narrower exceptions? (could be Model or DBException)
792
// for now, newMCE will be null and no registration of it
793
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
794                 }
795
796                 if (newMCE != null) {
797                     addMappingListener(newMCE);
798                     getPCS().firePropertyChange(CMP_MAPPINGS_CHANGED, null, newMCE);
799                 }
800             }
801         } catch(NullPointerException JavaDoc ex) {
802             // The intent of this handler is to safely report bugs in the persistence code
803
// while keeping the rest of the system stable.
804
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
805         }
806     }
807
808     private void removeMappingForCmp(String JavaDoc beanName) {
809         try {
810             if ((beanName != null) && (mappingContext != null)) {
811                 EJBInfoHelper infoHelper = getEJBInfoHelper();
812                 ConversionHelper myConversionHelper = getConversionHelper();
813                 Model model = mappingContext.getModel();
814                 String JavaDoc pcClassName = conversionHelper.getMappedClassName(beanName);
815                 MappingClassElement mce = model.getMappingClass(pcClassName);
816
817                 if (mce != null) {
818                     // remove the listener then the mce from model's cache
819
mce.removePropertyChangeListener(cmpMappingListener);
820                     model.updateKeyForClass(null, pcClassName);
821                 }
822             }
823         } catch(NullPointerException JavaDoc ex) {
824             // The intent of this handler is to safely report bugs in the persistence code
825
// while keeping the rest of the system stable.
826
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
827         }
828     }
829
830     private void addMappingForCmrField(String JavaDoc beanName, String JavaDoc fieldName) {
831         addMappingForCmpField(beanName, fieldName, true);
832     }
833
834     private void addMappingForCmpField(String JavaDoc beanName, String JavaDoc fieldName) {
835         addMappingForCmpField(beanName, fieldName, false);
836     }
837
838     private void addMappingForCmpField(String JavaDoc beanName, String JavaDoc fieldName,
839             boolean isRelationship) {
840         try {
841             if ((beanName != null) && (mappingContext != null)) {
842                 EJBInfoHelper infoHelper = getEJBInfoHelper();
843                 ConversionHelper myConversionHelper = getConversionHelper();
844                 Model model = mappingContext.getModel();
845                 String JavaDoc pcClassName = conversionHelper.getMappedClassName(beanName);
846                 MappingClassElement mce = model.getMappingClass(pcClassName);
847
848                 if ((mce != null) && (mce.getField(fieldName) == null)) {
849                     PersistenceClassElement pce =
850                         model.getPersistenceClass(pcClassName);
851                     // workaround - problem with timing - bean impl update doesn't
852
// seem to be done yet, so model's automatic field vs.
853
// rel check based on type doesn't work
854
// we can determine field vs. rel here, but coll vs. upper bound
855
// is not correct & inverse is not set
856
//model.addFieldElement(pce, fieldName);
857
// PersistenceFieldElement newPFE = pce.getField(fieldName);
858
PersistenceFieldElement newPFE = ((isRelationship) ?
859                         new RelationshipElement(
860                             new RelationshipElementImpl(fieldName), pce) :
861                         new PersistenceFieldElement(new
862                             PersistenceFieldElementImpl(fieldName), pce));
863
864                     try {
865                         pce.addField(newPFE);
866                         // end above timing issue
867
MappingFieldElement mfe = ((isRelationship) ?
868                             new MappingRelationshipElementImpl(fieldName, mce) :
869                             new MappingFieldElementImpl(fieldName, mce));
870                         mce.addField(mfe);
871                     } catch (ModelException e) {
872                         // TODO - what is proper handling of this exception?logging?
873
// for now, no mapping will be added
874
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
875                     }
876                 }
877             }
878         } catch(NullPointerException JavaDoc ex) {
879             // The intent of this handler is to safely report bugs in the persistence code
880
// while keeping the rest of the system stable.
881
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
882         }
883     }
884
885     private void removeMappingForCmpField(String JavaDoc beanName, String JavaDoc fieldName,
886             boolean removeInverse) {
887         try {
888             if (mappingContext != null) {
889                 EJBInfoHelper infoHelper = getEJBInfoHelper();
890                 ConversionHelper myConversionHelper = getConversionHelper();
891                 Model model = mappingContext.getModel();
892                 String JavaDoc pcClassName = conversionHelper.getMappedClassName(beanName);
893                 MappingClassElement mce = model.getMappingClass(pcClassName);
894
895                 if (mce != null) {
896                     MappingFieldElement mfe = mce.getField(fieldName);
897                     PersistenceFieldElement pfe =
898                         model.getPersistenceClass(pcClassName).getField(fieldName);
899                     RelationshipElement inverse = (
900                         (removeInverse && (pfe instanceof RelationshipElement)) ?
901                         ((RelationshipElement)pfe).getInverseRelationship(model) :
902                         null);
903
904                     try {
905                         model.removeFieldElement(pfe);
906                         if (mfe != null)
907                             mce.removeField(mfe);
908
909                         if (inverse != null) {
910                             String JavaDoc inverseName = inverse.getName();
911                             MappingClassElement inverseMCE = model.getMappingClass(
912                                 inverse.getDeclaringClass().getName());
913                             MappingFieldElement inverseMFE =
914                                 inverseMCE.getField(inverseName);
915
916                             model.removeFieldElement(inverse);
917                             if (inverseMFE != null)
918                                 inverseMCE.removeField(inverseMFE);
919                         }
920                     } catch (ModelException e) {
921                         // TODO - what is proper handling of this exception?logging?
922
// for now, no mapping will be removed
923
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
924                     }
925                 }
926             }
927         } catch(NullPointerException JavaDoc ex) {
928             // The intent of this handler is to safely report bugs in the persistence code
929
// while keeping the rest of the system stable.
930
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
931         }
932     }
933
934     private void removeMappingForCmpField(String JavaDoc beanName, String JavaDoc fieldName) {
935         removeMappingForCmpField(beanName, fieldName, false);
936     }
937
938     private void renameMappingForCmpField(String JavaDoc beanName, String JavaDoc oldFieldName,
939             String JavaDoc newFieldName) {
940         try {
941             if ((beanName != null) && (mappingContext != null)) {
942                 EJBInfoHelper infoHelper = getEJBInfoHelper();
943                 ConversionHelper myConversionHelper = getConversionHelper();
944                 Model model = mappingContext.getModel();
945                 String JavaDoc pcClassName = conversionHelper.getMappedClassName(beanName);
946                 MappingClassElement mce = model.getMappingClass(pcClassName);
947
948                 if (mce != null) {
949                     MappingFieldElement mfe = mce.getField(oldFieldName);
950                     PersistenceFieldElement pfe = model.getPersistenceClass(
951                         pcClassName).getField(oldFieldName);
952
953                     try {
954                         if (mfe != null) {
955                             mfe.setName(newFieldName);
956                         }
957
958                         if (pfe != null) {
959                             pfe.setName(newFieldName);
960                             if (pfe instanceof RelationshipElement) {
961                                 RelationshipElement relationship = (RelationshipElement)pfe;
962                                 RelationshipElement inverse = relationship.getInverseRelationship(model);
963                                 if (inverse != null) {
964                                     inverse.setInverseRelationship(relationship, model);
965                                 }
966                             }
967                         }
968                     } catch (ModelException e) {
969                         // TODO - what is proper handling of this exception?logging?
970
// for now, no mapping will be renamed
971
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
972                     }
973                 }
974             }
975         } catch(NullPointerException JavaDoc ex) {
976             // The intent of this handler is to safely report bugs in the persistence code
977
// while keeping the rest of the system stable.
978
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
979         }
980     }
981
982     boolean loadCmpMappingsFromPlanFile(SunONEDeploymentConfiguration config) {
983         SunCmpMappings beanGraph = (SunCmpMappings) config.getBeans(
984             getUriText(), CMP_MAPPING_FILE, new SunCmpMappingsParser(),
985             new SunCmpMappingsRootFinder());
986         // TODO - is this sufficient or do we need to add
987
// mappingContext and ejbInfoHelper to clearProperties? they will be
988
// assigned to new instances here
989
if (beanGraph != null) {
990             // TODO: else load schemas if they are different?
991
// also probably do if mappingContext is already non-null
992
// call intoMappingClasses in utils
993

994             // TODO put this in a background thread (at least the
995
// intoMappingClasses part), because it can take a while
996
getMappingContext(beanGraph, getEJBInfoHelper(beanGraph));
997         }
998
999         return (beanGraph != null);
1000    }
1001
1002    protected void clearProperties() {
1003        StorageBeanFactory beanFactory = getConfig().getStorageFactory();
1004
1005        name = null;
1006        pmDescriptors = beanFactory.createPmDescriptors();
1007        cmpResource = beanFactory.createCmpResource();
1008        messageDestinations = null;
1009    }
1010
1011    protected void setDefaultProperties() {
1012    }
1013
1014
1015    /* ------------------------------------------------------------------------
1016     * XPath to Factory mapping support
1017     */

1018    private HashMap JavaDoc ejbRootFactoryMap;
1019
1020    /** Retrieve the XPathToFactory map for this DConfigBean. For AppRoot,
1021     * this maps application xpaths to factories for other contained root
1022     * objects plus a SecurityRoleModel factory
1023     * @return
1024     */

1025    protected java.util.Map JavaDoc getXPathToFactoryMap() {
1026        if(ejbRootFactoryMap == null) {
1027            ejbRootFactoryMap = new HashMap JavaDoc(17);
1028
1029            ejbRootFactoryMap.put(SECURITY_ROLE_R_XPATH, new DCBGenericFactory(SecurityRoleMapping.class));
1030            ejbRootFactoryMap.put(ENTITY_R_XPATH, new EntityEjbDCBFactory(this));
1031            ejbRootFactoryMap.put(SESSION_R_XPATH, new SessionEjbDCBFactory());
1032            ejbRootFactoryMap.put(MD_R_XPATH, new DCBGenericFactory(MDEjb.class));
1033
1034// J2EEBaseVersion moduleVersion = getJ2EEModuleVersion();
1035
// if(moduleVersion.compareTo(EjbJarVersion.EJBJAR_2_1) >= 0) {
1036
// ejbRootFactoryMap.put("message-destination", new DCBGenericFactory(MessageDestination.class)); // NOI18N
1037
// }
1038

1039            // an ejb-jar can have one CmpJar DConfigBean
1040
//DCBSingletonFactory cmpJarFactory = new DCBSingletonFactory(CmpJar.class);
1041
//ejbRootFactoryMap.put("/ejb-jar/enterprise-beans/entity/cmp-field", cmpJarFactory);
1042
//ejbRootFactoryMap.put("/ejb-jar/enterprise-beans/entity/abstract-schema-name", cmpJarFactory);
1043
// pending
1044
//ejbRootFactoryMap.put("/ejb-jar/relationships/ejb-relation/ejb-relationship-role/cmr-field/cmr-field-name",
1045
// new DCBGenericFactory(CmrField.class));
1046
}
1047
1048        return ejbRootFactoryMap;
1049    }
1050
1051
1052    public void addCmpResourceIfNotPresent() {
1053        if(null == cmpResource){
1054            cmpResource = getConfig().getStorageFactory().createCmpResource();
1055        }
1056
1057        if(!Utils.notEmpty(cmpResource.getJndiName())) {
1058            cmpResource.setJndiName(Utils.getDefaultCmpResourceJndiName(this));
1059        }
1060    }
1061
1062
1063    /** Getter for property name.
1064     * @return Value of property name.
1065     *
1066     */

1067    public String JavaDoc getName() {
1068        return this.name;
1069    }
1070
1071
1072    /** Setter for property name.
1073     * @param name New value of property name.
1074     *
1075     * @throws PropertyVetoException
1076     *
1077     */

1078    public void setName(String JavaDoc name) throws java.beans.PropertyVetoException JavaDoc {
1079        String JavaDoc oldName = this.name;
1080        getVCS().fireVetoableChange("name", oldName, name);
1081        this.name = name;
1082        getPCS().firePropertyChange("name", oldName, name);
1083    }
1084
1085
1086    /** Getter for property pmDescriptors.
1087     * @return Value of property pmDescriptors.
1088     *
1089     */

1090    public PmDescriptors getPmDescriptors() {
1091        return this.pmDescriptors;
1092    }
1093
1094
1095    /** Setter for property pmDescriptors.
1096     * @param pmDescriptors New value of property pmDescriptors.
1097     *
1098     * @throws PropertyVetoException
1099     *
1100     */

1101    public void setPmDescriptors(PmDescriptors pmDescriptors) throws java.beans.PropertyVetoException JavaDoc {
1102        PmDescriptors oldPmDescriptors = this.pmDescriptors;
1103        getVCS().fireVetoableChange("pmDescriptors", oldPmDescriptors, pmDescriptors);
1104        this.pmDescriptors = pmDescriptors;
1105        getPCS().firePropertyChange("pmDescriptors", oldPmDescriptors, pmDescriptors);
1106    }
1107
1108
1109    /** Getter for property cmpResource.
1110     * @return Value of property cmpResource.
1111     *
1112     */

1113    public CmpResource getCmpResource() {
1114        return this.cmpResource;
1115    }
1116
1117
1118    /** Setter for property cmpResource.
1119     * @param cmpResource New value of property cmpResource.
1120     *
1121     * @throws PropertyVetoException
1122     *
1123     */

1124    public void setCmpResource(CmpResource cmpResource) throws java.beans.PropertyVetoException JavaDoc {
1125        CmpResource oldCmpResource = this.cmpResource;
1126        getVCS().fireVetoableChange("cmpResource", oldCmpResource, cmpResource);
1127        this.cmpResource = cmpResource;
1128        getPCS().firePropertyChange("cmpResource", oldCmpResource, cmpResource);
1129    }
1130
1131    /** Getter for property messageDestinations.
1132     * @return Value of property messageDestinations.
1133     *
1134     */

1135    public List JavaDoc getMessageDestinations() {
1136        return messageDestinations;
1137    }
1138
1139    public MessageDestination getMessageDestination(int index) {
1140        return (MessageDestination) messageDestinations.get(index);
1141    }
1142
1143    /** Setter for property messageDestinations.
1144     * @param messageDestinations New value of property messageDestinations.
1145     *
1146     * @throws PropertyVetoException
1147     *
1148     */

1149    public void setMessageDestinations(List JavaDoc newMessageDestinations) throws java.beans.PropertyVetoException JavaDoc {
1150        List JavaDoc oldMessageDestinations = messageDestinations;
1151        getVCS().fireVetoableChange("messageDestinations", oldMessageDestinations, newMessageDestinations); // NOI18N
1152
messageDestinations = newMessageDestinations;
1153        getPCS().firePropertyChange("messageDestinations", oldMessageDestinations, messageDestinations); // NOI18N
1154
}
1155
1156    public void addMessageDestination(MessageDestination newMessageDestination) throws java.beans.PropertyVetoException JavaDoc {
1157        getVCS().fireVetoableChange("messageDestination", null, newMessageDestination); // NOI18N
1158
if(messageDestinations == null) {
1159            messageDestinations = new ArrayList JavaDoc();
1160        }
1161        messageDestinations.add(newMessageDestination);
1162        getPCS().firePropertyChange("messageDestination", null, newMessageDestination ); // NOI18N
1163
}
1164
1165    public void removeMessageDestination(MessageDestination oldMessageDestination) throws java.beans.PropertyVetoException JavaDoc {
1166        getVCS().fireVetoableChange("messageDestination", oldMessageDestination, null); // NOI18N
1167
messageDestinations.remove(oldMessageDestination);
1168        getPCS().firePropertyChange("messageDestination", oldMessageDestination, null ); // NOI18N
1169
}
1170
1171    /** Events handled for CMP relationship management.
1172     */

1173    public void fireXpathEvent(XpathEvent JavaDoc xpathEvent) {
1174            //ADD , REMOVE or CHANGE events
1175
DDBean JavaDoc bean = xpathEvent.getBean();
1176            String JavaDoc xpath = bean.getXpath();
1177
1178            // add or remove cmp field gets this event
1179
if (CMP_FIELD_XPATH.equals(xpath)) {
1180                String JavaDoc beanName = extractBeanName(xpath, bean);
1181                String JavaDoc fieldName = extractFieldName(xpath, bean);
1182
1183                if ((beanName != null) && (fieldName != null)) {
1184                    if (xpathEvent.isAddEvent()) {
1185                        addMappingForCmpField(beanName, fieldName);
1186                    } else if (xpathEvent.isRemoveEvent()) {
1187                        removeMappingForCmpField(beanName, fieldName);
1188                    }
1189                }
1190            } else if (CMP_FIELD_NAME_XPATH.equals(xpath)) {
1191                // rename cmp field (on the method) gets this event
1192
if (xpathEvent.isChangeEvent()) {
1193                    String JavaDoc beanName = extractBeanName(xpath, bean);
1194
1195                    if (beanName != null) {
1196                        PropertyChangeEvent JavaDoc changeEvent =
1197                            xpathEvent.getChangeEvent();
1198                        renameMappingForCmpField(beanName,
1199                            changeEvent.getOldValue().toString(),
1200                            changeEvent.getNewValue().toString());
1201                    }
1202                }
1203            } else if (EJB_RELATION_XPATH.equals(xpath)) {
1204                // remove cmr fields by removing entire relationship
1205
// gets this event
1206
if (xpathEvent.isRemoveEvent()) {
1207                    String JavaDoc beanName = extractBeanName(xpath, bean);
1208                    String JavaDoc fieldName = extractFieldName(xpath, bean);
1209
1210                    // when delete from multiview editor, only get
1211
// this event (as opposed to some others below), but
1212
// only one field name is coming through,
1213
// so handle it by a flag to removeMapping
1214
// method which deletes the inverse too
1215
if ((beanName != null) && (fieldName != null)) {
1216                        removeMappingForCmpField(beanName, fieldName, true);
1217                    }
1218                }
1219            } else if (CMR_FIELD_XPATH.equals(xpath)) {
1220                // remove cmr fields by delete from the logical node
1221
// CM fields gets this event
1222
if (xpathEvent.isRemoveEvent()) {
1223                    String JavaDoc beanName = extractBeanName(xpath, bean);
1224                    String JavaDoc fieldName = extractFieldName(xpath, bean);
1225
1226                    if ((beanName != null) && (fieldName != null)) {
1227                        removeMappingForCmpField(beanName, fieldName);
1228                    }
1229                }
1230            } else if (CMR_FIELD_NAME_XPATH.equals(xpath)) {
1231                String JavaDoc beanName = extractBeanName(xpath, bean);
1232                String JavaDoc fieldName = extractFieldName(xpath, bean);
1233
1234                // add cmr fields by creating a new relationship in
1235
// the multiview editor gets this event, but can't
1236
// figure out the inverse info and cardinality,
1237
// remove events by?
1238
if ((beanName != null) && (fieldName != null)) {
1239                    if (xpathEvent.isAddEvent()) {
1240                        addMappingForCmrField(beanName, fieldName);
1241                    } else if (xpathEvent.isRemoveEvent()) {
1242                        removeMappingForCmpField(beanName, fieldName);
1243                    } else if(xpathEvent.isChangeEvent()) {
1244                        if (beanName != null) {
1245                            PropertyChangeEvent JavaDoc changeEvent =
1246                                xpathEvent.getChangeEvent();
1247                            renameMappingForCmpField(beanName,
1248                                changeEvent.getOldValue().toString(),
1249                                changeEvent.getNewValue().toString());
1250                        }
1251                    }
1252                 }
1253            }
1254    }
1255
1256    private String JavaDoc extractFieldName(String JavaDoc xpath, DDBean JavaDoc bean) {
1257        DDBean JavaDoc field = null;
1258
1259        if (CMP_FIELD_XPATH.equals(xpath)) {
1260            field = bean.getChildBean("field-name")[0]; // NOI18N
1261
} else if (EJB_RELATION_XPATH.equals(xpath)) {
1262            DDBean JavaDoc[] fields = bean.getChildBean(
1263                "ejb-relationship-role/cmr-field/cmr-field-name"); // NOI18N
1264
field = ((fields.length > 0) ? fields[0] : null);
1265        } else if (CMR_FIELD_XPATH.equals(xpath)) {
1266            DDBean JavaDoc[] fields = bean.getChildBean("cmr-field-name"); // NOI18N
1267
field = (((fields != null) && (fields.length > 0)) ?
1268                fields[0] : null);
1269        } else if (CMR_FIELD_NAME_XPATH.equals(xpath)) {
1270            field = bean;
1271        }
1272
1273        return ((field != null) ? field.getText() : null);
1274    }
1275
1276    private String JavaDoc extractBeanName(String JavaDoc xpath, DDBean JavaDoc bean) {
1277        DDBean JavaDoc entity = null;
1278
1279        if (CMP_FIELD_XPATH.equals(xpath)) {
1280            entity = bean.getChildBean("../ejb-name")[0];
1281        } else if (CMP_FIELD_NAME_XPATH.equals(xpath)) {
1282            entity = bean.getChildBean("../../ejb-name")[0]; // NOI18N
1283
} else if (EJB_RELATION_XPATH.equals(xpath)) {
1284            DDBean JavaDoc[] entities = bean.getChildBean(
1285                "ejb-relationship-role/relationship-role-source/ejb-name"); // NOI18N
1286
entity = ((entities.length > 0) ? entities[0] : null);
1287        } else if (CMR_FIELD_XPATH.equals(xpath)) {
1288            entity = bean.getChildBean("../relationship-role-source/ejb-name")[0]; // NOI18N
1289
} else if (CMR_FIELD_NAME_XPATH.equals(xpath)) {
1290            entity = bean.getChildBean(
1291                "../../relationship-role-source/ejb-name")[0];// NOI18N
1292
}
1293
1294        return ((entity != null) ? entity.getText() : null);
1295    }
1296}
1297
Popular Tags