KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > EjbJarMultiViewDataObject


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
20 package org.netbeans.modules.j2ee.ddloaders.multiview;
21
22 import org.netbeans.api.java.project.JavaProjectConstants;
23 import org.netbeans.api.project.FileOwnerQuery;
24 import org.netbeans.api.project.Project;
25 import org.netbeans.api.project.ProjectUtils;
26 import org.netbeans.api.project.SourceGroup;
27 import org.netbeans.api.project.Sources;
28 import org.netbeans.api.xml.cookies.ValidateXMLCookie;
29 import org.netbeans.core.spi.multiview.MultiViewElement;
30 import org.netbeans.modules.j2ee.common.Util;
31 import org.netbeans.modules.j2ee.dd.api.common.RootInterface;
32 import org.netbeans.modules.j2ee.dd.api.ejb.*;
33 import org.netbeans.modules.j2ee.dd.impl.common.DDUtils;
34 import org.netbeans.modules.j2ee.dd.impl.ejb.EjbJarProxy;
35 import org.netbeans.modules.j2ee.ddloaders.ejb.DDChangeEvent;
36 import org.netbeans.modules.j2ee.ddloaders.ejb.DDChangeListener;
37 import org.netbeans.modules.j2ee.ddloaders.ejb.EjbJarDataLoader;
38 import org.netbeans.modules.j2ee.common.DDEditorNavigator;
39 import org.netbeans.modules.xml.multiview.DesignMultiViewDesc;
40 import org.netbeans.modules.xml.multiview.SectionNode;
41 import org.netbeans.modules.xml.multiview.ui.SectionNodeInnerPanel;
42 import org.netbeans.modules.xml.multiview.ui.SectionNodeView;
43 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement;
44 import org.netbeans.spi.xml.cookies.DataObjectAdapters;
45 import org.netbeans.spi.xml.cookies.ValidateXMLSupport;
46 import org.openide.ErrorManager;
47 import org.openide.cookies.ViewCookie;
48 import org.openide.filesystems.*;
49 import org.openide.loaders.DataFolder;
50 import org.openide.loaders.DataObject;
51 import org.openide.loaders.DataObjectExistsException;
52 import org.openide.nodes.CookieSet;
53 import org.openide.nodes.Node;
54 import org.openide.util.HelpCtx;
55 import org.openide.util.NbBundle;
56 import org.openide.util.RequestProcessor;
57 import org.openide.util.Utilities;
58 import org.xml.sax.InputSource JavaDoc;
59
60 import javax.swing.event.ChangeListener JavaDoc;
61 import java.awt.*;
62 import java.beans.PropertyChangeEvent JavaDoc;
63 import java.beans.PropertyChangeListener JavaDoc;
64 import java.beans.PropertyVetoException JavaDoc;
65 import java.io.IOException JavaDoc;
66 import java.util.ArrayList JavaDoc;
67 import java.util.Arrays JavaDoc;
68 import java.util.HashMap JavaDoc;
69 import java.util.List JavaDoc;
70 import java.util.Map JavaDoc;
71 import org.openide.awt.HtmlBrowser;
72 import org.openide.loaders.MultiDataObject;
73
74 /**
75  * Represents a DD object in the Repository.
76  *
77  * @author pfiala
78  */

79 public class EjbJarMultiViewDataObject extends DDMultiViewDataObject
80         implements DDChangeListener, DDEditorNavigator, FileChangeListener, ChangeListener {
81     private EjbJarProxy ejbJar;
82     private FileObject srcRoots[];
83     private PropertyChangeListener JavaDoc ejbJarChangeListener;
84     private Map JavaDoc entityHelperMap = new HashMap JavaDoc();
85     private Map JavaDoc sessionHelperMap = new HashMap JavaDoc();
86     
87     private static final long serialVersionUID = 8857563089355069362L;
88     
89     /**
90      * Property name for documentDTD property
91      */

92     public static final String JavaDoc PROP_DOCUMENT_DTD = "documentDTD"; // NOI18N
93

94     private static final int HOME = 10;
95     private static final int REMOTE = 20;
96     private static final int LOCAL_HOME = 30;
97     private static final int LOCAL = 40;
98     private static final String JavaDoc OVERVIEW = "Overview"; //NOI18N
99
private static final String JavaDoc CMP_RELATIONSHIPS = "CmpRelationships"; //NOI18N
100

101     public EjbJarMultiViewDataObject(FileObject pf, EjbJarDataLoader loader) throws DataObjectExistsException {
102         super(pf, loader);
103         
104         // added ValidateXMLCookie
105
InputSource JavaDoc in = DataObjectAdapters.inputSource(this);
106         ValidateXMLCookie validateCookie = new ValidateXMLSupport(in);
107         CookieSet set = getCookieSet();
108         set.add(validateCookie);
109         CookieSet.Factory viewCookieFactory = new ViewCookieFactory();
110         set.add(ViewCookie.class, viewCookieFactory);
111         
112         
113         Project project = getProject();
114         if (project != null) {
115             Sources sources = ProjectUtils.getSources(project);
116             sources.addChangeListener(this);
117         }
118         refreshSourceFolders();
119     }
120     
121     
122     private void refreshSourceFolders() {
123         ArrayList JavaDoc srcRootList = new ArrayList JavaDoc();
124         
125         SourceGroup[] groups;
126         Project project = getProject();
127         if (project != null) {
128             Sources sources = ProjectUtils.getSources(project);
129             groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
130         } else {
131             groups = null;
132         }
133         if (groups != null) {
134             for (int i = 0; i < groups.length; i++) {
135                 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(groups[i].getRootFolder());
136                 if ((ejbModule != null) && (ejbModule.getDeploymentDescriptor() != null)) {
137                     try {
138                         FileObject fo = groups[i].getRootFolder();
139                         srcRootList.add(groups[i].getRootFolder());
140                         FileSystem fs = fo.getFileSystem();
141                         fs.removeFileChangeListener(this); //avoid being added multiple times
142
fs.addFileChangeListener(this);
143                     } catch (FileStateInvalidException ex) {
144                         ErrorManager.getDefault().notify(ex);
145                     }
146                 }
147             }
148         }
149         srcRoots = (FileObject[]) srcRootList.toArray(new FileObject[srcRootList.size()]);
150     }
151     
152     
153     private Project getProject() {
154         return FileOwnerQuery.getOwner(getPrimaryFile());
155     }
156     
157     public FileObject getProjectDirectory() {
158         Project project = getProject();
159         return project == null ? null : project.getProjectDirectory();
160     }
161     
162     public SourceGroup[] getSourceGroups() {
163         Project project = getProject();
164         if (project != null) {
165             return ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
166         } else {
167             return null;
168         }
169     }
170     
171     private String JavaDoc getPackageName(FileObject clazz) {
172         for (int i = 0; i < srcRoots.length; i++) {
173             String JavaDoc rp = FileUtil.getRelativePath(srcRoots[i], clazz);
174             if (rp != null) {
175                 if (clazz.getExt().length() > 0) {
176                     rp = rp.substring(0, rp.length() - clazz.getExt().length() - 1);
177                 }
178                 return rp.replace('/', '.');
179             }
180         }
181         return null;
182     }
183     
184     public EjbJar getEjbJar() {
185         if (ejbJar == null) {
186             try {
187                 parseDocument();
188             } catch (IOException JavaDoc e) {
189                 Utils.notifyError(e);
190             }
191         }
192         return ejbJar;
193     }
194     
195     protected Node createNodeDelegate() {
196         return new EjbJarMultiViewDataNode(this);
197     }
198     
199     /**
200      * gets the Icon Base for node delegate when parser accepts the xml document as valid
201      * <p/>
202      * PENDING: move into node
203      *
204      * @return Icon Base for node delegate
205      */

206     protected String JavaDoc getIconBaseForValidDocument() {
207         return Utils.ICON_BASE_DD_VALID;
208     }
209     
210     /**
211      * gets the Icon Base for node delegate when parser finds error(s) in xml document
212      *
213      * @return Icon Base for node delegate
214      * <p/>
215      * PENDING: move into node
216      */

217     protected String JavaDoc getIconBaseForInvalidDocument() {
218         return Utils.ICON_BASE_DD_INVALID; // NOI18N
219
}
220     
221     protected DataObject handleCopy(DataFolder f) throws IOException JavaDoc {
222         DataObject dataObject = super.handleCopy(f);
223         try {
224             dataObject.setValid(false);
225         } catch (PropertyVetoException JavaDoc e) {
226             // should not occur
227
}
228         return dataObject;
229     }
230     
231     /**
232      * This methods gets called when servlet is changed
233      *
234      * @param evt - object that describes the change.
235      */

236     public void deploymentChange(DDChangeEvent evt) {
237     }
238     
239     
240     public HelpCtx getHelpCtx() {
241         return HelpCtx.DEFAULT_HELP;
242     }
243     
244     private RequestProcessor.Task elementTask;
245     private List JavaDoc deletedEjbNames;
246     private List JavaDoc newFileNames;
247     
248     private void elementCreated(final String JavaDoc elementName) {
249         synchronized (this) {
250             if (newFileNames == null) {
251                 newFileNames = new ArrayList JavaDoc();
252             }
253             newFileNames.add(elementName);
254         }
255         
256         if (elementTask == null) {
257             elementTask = RequestProcessor.getDefault().post(new Runnable JavaDoc() {
258                 public void run() {
259                     if (deletedEjbNames != null) {
260                         for (int i = 0; i < deletedEjbNames.size(); i++) {
261                             String JavaDoc deletedServletName = (String JavaDoc) deletedEjbNames.get(i);
262                             String JavaDoc deletedName = deletedServletName;
263                             int index = deletedServletName.lastIndexOf("."); //NOI18N
264
if (index > 0) {
265                                 deletedName = deletedServletName.substring(index + 1);
266                             }
267                             boolean found = false;
268                             for (int j = 0; j < newFileNames.size(); j++) {
269                                 String JavaDoc newFileName = (String JavaDoc) newFileNames.get(j);
270                                 String JavaDoc newName = newFileName;
271                                 int ind = newFileName.lastIndexOf("."); //NOI18N
272
if (ind > 0) {
273                                     newName = newFileName.substring(ind + 1);
274                                 }
275                                 if (deletedName.equals(newName)) { // servlet was removed
276
found = true;
277                                     DDChangeEvent ddEvent =
278                                             new DDChangeEvent(EjbJarMultiViewDataObject.this,
279                                             EjbJarMultiViewDataObject.this, deletedServletName, newFileName,
280                                             DDChangeEvent.EJB_CHANGED);
281                                     deploymentChange(ddEvent);
282                                     synchronized (EjbJarMultiViewDataObject.this) {
283                                         newFileNames.remove(newFileName);
284                                     }
285                                     break;
286                                 }
287                             }
288                             if (!found) {
289                                 DDChangeEvent ddEvent =
290                                         new DDChangeEvent(EjbJarMultiViewDataObject.this,
291                                         EjbJarMultiViewDataObject.this, null, deletedServletName,
292                                         DDChangeEvent.EJB_DELETED);
293                                 deploymentChange(ddEvent);
294                             }
295                         } //end for
296
synchronized (EjbJarMultiViewDataObject.this) {
297                             deletedEjbNames = null;
298                         }
299                     } // servlets
300

301                     synchronized (EjbJarMultiViewDataObject.this) {
302                         newFileNames = null;
303                     }
304                     
305                 }///end run
306

307             }, 1500, Thread.MIN_PRIORITY);
308         } else {
309             elementTask.schedule(1500);
310         }
311     }
312     
313     public void fileRenamed(FileRenameEvent fileRenameEvent) {
314         FileObject fo = fileRenameEvent.getFile();
315         String JavaDoc resourceName = getPackageName(fo);
316         if (resourceName != null) {
317             int index = resourceName.lastIndexOf("."); //NOI18N
318
String JavaDoc oldName = fileRenameEvent.getName();
319             String JavaDoc oldResourceName = (index >= 0 ? resourceName.substring(0, index + 1) : "") + oldName;
320             EjbJar ejbJar = getEjbJar();
321             if (ejbJar.getStatus() == EjbJar.STATE_VALID) {
322                 fireEvent(oldResourceName, resourceName, DDChangeEvent.EJB_CHANGED);
323             }
324         }
325     }
326     
327     public void fileFolderCreated(FileEvent fileEvent) {
328     }
329     
330     public void fileDeleted(FileEvent fileEvent) {
331         FileObject fo = fileEvent.getFile();
332         String JavaDoc resourceName = getPackageName(fo);
333         if (resourceName != null) {
334             if (newFileNames == null) {
335                 fireEvent(null, resourceName, DDChangeEvent.EJB_DELETED);
336             } else {
337                 Ejb[] ejbs = getEjbJar().getEnterpriseBeans().getEjbs();
338                 for (int i = 0; i < ejbs.length; i++) {
339                     if (resourceName.equals(ejbs[i].getEjbClass())) {
340                         synchronized (this) {
341                             if (deletedEjbNames == null) {
342                                 deletedEjbNames = new ArrayList JavaDoc();
343                             }
344                             deletedEjbNames.add(resourceName);
345                         }
346                         break;
347                     }
348                 }
349             }
350         }
351     }
352     
353     public void fileDataCreated(FileEvent fileEvent) {
354         FileObject fo = fileEvent.getFile();
355         String JavaDoc resourceName = getPackageName(fo);
356         if (resourceName != null) {
357             elementCreated(resourceName);
358         }
359     }
360     
361     public void fileChanged(FileEvent fileEvent) {
362     }
363     
364     public void fileAttributeChanged(FileAttributeEvent fileAttributeEvent) {
365     }
366     
367     public void stateChanged(javax.swing.event.ChangeEvent JavaDoc e) {
368         refreshSourceFolders();
369     }
370     
371     protected void parseDocument() throws IOException JavaDoc {
372         DDProvider ddProvider = DDProvider.getDefault();
373         if (ejbJar == null || ejbJar.getOriginal() == null) {
374             try {
375                 setEjbJar((EjbJarProxy) ddProvider.getDDRoot(getPrimaryFile()));
376             } catch (IOException JavaDoc e) {
377                 if (ejbJar == null) {
378                     setEjbJar(new EjbJarProxy(null, null));
379                 }
380             }
381         } else {
382             DDUtils.merge(ejbJar, createReader());
383         }
384         setSaxError(ejbJar.getError());
385     }
386     
387     protected void validateDocument() throws IOException JavaDoc {
388         setSaxError(DDUtils.createEjbJarProxy(createReader()).getError());
389     }
390     
391     private void setEjbJar(EjbJarProxy newEjbJar) {
392         if(ejbJar != null) {
393             ejbJar.removePropertyChangeListener(ejbJarChangeListener);
394         }
395         ejbJar = newEjbJar;
396         if (ejbJarChangeListener == null) {
397             ejbJarChangeListener = new EjbJarPropertyChangeListener();
398         }
399         ejbJar.addPropertyChangeListener(ejbJarChangeListener);
400     }
401     
402     protected RootInterface getDDModel() {
403         if (ejbJar == null) {
404             try {
405                 parseDocument();
406             } catch (IOException JavaDoc ex) {
407                 ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
408             }
409         }
410         return ejbJar;
411     }
412     
413     public boolean isDocumentParseable() {
414         return EjbJar.STATE_INVALID_UNPARSABLE != getEjbJar().getStatus();
415     }
416     
417     protected String JavaDoc getPrefixMark() {
418         return "<ejb-jar";
419     }
420     
421     /**
422      * Icon Base for MultiView editor
423      */

424     protected DesignMultiViewDesc[] getMultiViewDesc() {
425         if (Util.isJavaEE5orHigher(getProject())){
426             // only default xml view for ejb3 projects
427
return new DesignMultiViewDesc[0];
428         }
429         return new DesignMultiViewDesc[]{
430             new DDView(this, OVERVIEW),
431             new DDView(this, CMP_RELATIONSHIPS),
432         };
433     }
434     
435     /** Used to detect if data model has already been created or not.
436      * Method is called before switching to the design view from XML view when the document isn't parseable.
437      */

438     protected boolean isModelCreated() {
439         return (ejbJar!=null && ejbJar.getOriginal()!=null);
440     }
441     
442     public void showElement(final Object JavaDoc element) {
443         if (element instanceof Relationships || element instanceof EjbRelation) {
444             openView(1);
445         } else {
446             openView(0);
447         }
448         Utils.runInAwtDispatchThread(new Runnable JavaDoc() {
449             public void run() {
450                 final SectionNodeView sectionView =
451                         (SectionNodeView) EjbJarMultiViewDataObject.this .getActiveMVElement().getSectionView();
452                 final Node root = sectionView.getRoot();
453                 final SectionNode node = ((SectionNode) root.getChildren().getNodes()[0]).getNodeForElement(element);
454                 if (node != null) {
455                     sectionView.openPanel(node);
456                     ((SectionNodeInnerPanel) node.getSectionNodePanel().getInnerPanel()).focusData(element);
457                 }
458             }
459         });
460     }
461     
462
463     /**
464      * Factory for creating view cookies. <p>
465      */

466     private class ViewCookieFactory implements CookieSet.Factory {
467         
468         public Node.Cookie createCookie(Class JavaDoc klass) {
469             if (klass == ViewCookie.class) {
470                 return new ViewSupport(EjbJarMultiViewDataObject.this.getPrimaryEntry());
471             } else {
472                 return null;
473             }
474         }
475     }
476     
477     /**
478      * An implementation of ViewCookie that opens an HTML browser
479      * for viewing the file.<p>
480      */

481     private static final class ViewSupport implements ViewCookie {
482         
483         private MultiDataObject.Entry primary;
484         
485         public ViewSupport(MultiDataObject.Entry primary) {
486             this.primary = primary;
487         }
488         
489         public void view() {
490             try {
491                 HtmlBrowser.URLDisplayer.getDefault().showURL(primary.getFile().getURL());
492             } catch (FileStateInvalidException e) {
493             }
494         }
495     }
496     
497     
498     private static class DDView extends DesignMultiViewDesc implements java.io.Serializable JavaDoc {
499         
500         private String JavaDoc name;
501         static final long serialVersionUID = -8759598009819101630L;
502         
503         DDView(EjbJarMultiViewDataObject dataObject, String JavaDoc name) {
504             super(dataObject, name);
505             this.name=name;
506         }
507         
508         public MultiViewElement createElement() {
509             EjbJarMultiViewDataObject dataObject = (EjbJarMultiViewDataObject) getDataObject();
510             if (name.equals(OVERVIEW)) {
511                 return new EjbMultiViewElement(dataObject);
512             } else if (name.equals(CMP_RELATIONSHIPS)) {
513                 return new CmpRelationshipsMultiViewElement(dataObject);
514             } else {
515                 // This case should not arise
516
return null;
517             }
518         }
519         
520         public HelpCtx getHelpCtx() {
521             final EjbJarMultiViewDataObject dataObject = ((EjbJarMultiViewDataObject)getDataObject());
522             return new HelpCtx(dataObject.getActiveMVElement().getSectionView().getClass());
523         }
524         
525         public Image getIcon() {
526             return Utilities.loadImage(Utils.ICON_BASE_DD_VALID + ".gif"); //NOI18N
527
}
528         
529         public String JavaDoc preferredID() {
530             return "dd_multiview_" + name; //NOI18N
531
}
532         
533         public String JavaDoc getDisplayName() {
534             return NbBundle.getMessage(EjbJarMultiViewDataObject.class,"LBL_"+name); //NOI18N
535
}
536         
537     }
538     
539     /** Enable to access Active element
540      */

541     public ToolBarMultiViewElement getActiveMVElement() {
542         return (ToolBarMultiViewElement)super.getActiveMultiViewElement();
543     }
544     
545     private Ejb getEjbFromEjbClass(String JavaDoc ejbClassName) {
546         EnterpriseBeans enterpriseBeans = getEjbJar().getEnterpriseBeans();
547         if(enterpriseBeans != null) {
548             Ejb[] ejbs = enterpriseBeans.getEjbs();
549             for (int i = 0; i < ejbs.length; i++) {
550                 if (ejbs[i].getEjbClass() != null && ejbs[i].getEjbClass().equals(ejbClassName)) {
551                     return ejbs[i];
552                 }
553             }
554         }
555         return null;
556     }
557     
558     private int getBeanInterfaceType(String JavaDoc interfaceName) {
559         int interfaceType = -1;
560         EjbJar ejbJar = getEjbJar();
561         if (ejbJar == null) {
562             return interfaceType;
563         }
564         EnterpriseBeans eb = ejbJar.getEnterpriseBeans();
565         if (eb == null) {
566             return interfaceType;
567         }
568         EntityAndSession[] beans = eb.getSession();
569         for (int i = 0; i < beans.length; i++) {
570             if (beans[i].getHome() != null &&
571                     beans[i].getHome().equals(interfaceName)) {
572                 interfaceType = HOME;
573                 break;
574             }
575             if (beans[i].getRemote() != null &&
576                     beans[i].getRemote().equals(interfaceName)) {
577                 interfaceType = REMOTE;
578                 break;
579             }
580             if (beans[i].getLocalHome() != null &&
581                     beans[i].getLocalHome().equals(interfaceName)) {
582                 interfaceType = LOCAL_HOME;
583                 break;
584             }
585             if (beans[i].getLocal() != null &&
586                     beans[i].getLocal().equals(interfaceName)) {
587                 interfaceType = LOCAL;
588                 break;
589             }
590         }
591         return interfaceType;
592     }
593     
594     private int getSpecificEvent(int eventType, int interfaceType) {
595         if (eventType == DDChangeEvent.EJB_CHANGED) {
596             switch (interfaceType) {
597                 case HOME:
598                 {
599                     return DDChangeEvent.EJB_HOME_CHANGED;
600                 }
601                 case REMOTE:
602                 {
603                     return DDChangeEvent.EJB_REMOTE_CHANGED;
604                 }
605                 case LOCAL_HOME:
606                 {
607                     return DDChangeEvent.EJB_LOCAL_HOME_CHANGED;
608                 }
609                 case LOCAL:
610                 {
611                     return DDChangeEvent.EJB_LOCAL_CHANGED;
612                 }
613             }
614         }
615         if (eventType == DDChangeEvent.EJB_DELETED) {
616             switch (interfaceType) {
617                 case HOME:
618                 {
619                     return DDChangeEvent.EJB_HOME_DELETED;
620                 }
621                 case REMOTE:
622                 {
623                     return DDChangeEvent.EJB_REMOTE_DELETED;
624                 }
625                 case LOCAL_HOME:
626                 {
627                     return DDChangeEvent.EJB_LOCAL_HOME_DELETED;
628                 }
629                 case LOCAL:
630                 {
631                     return DDChangeEvent.EJB_LOCAL_DELETED;
632                 }
633             }
634         }
635         return -1;
636     }
637     
638     private boolean fireEvent(String JavaDoc oldResourceName, String JavaDoc resourceName, int eventType) {
639         boolean elementFound = false;
640         String JavaDoc resource;
641         int specificEventType = -1;
642         if (eventType == DDChangeEvent.EJB_CHANGED) {
643             resource = oldResourceName;
644         } else {
645             resource = resourceName;
646         }
647         Ejb ejb = getEjbFromEjbClass(resource);
648         
649         if (ejb != null) {
650             if (eventType == DDChangeEvent.EJB_CHANGED) {
651                 specificEventType = DDChangeEvent.EJB_CLASS_CHANGED;
652             } else {
653                 specificEventType = DDChangeEvent.EJB_CLASS_DELETED;
654             }
655             elementFound = true;
656         }
657         
658         if (!elementFound) {
659             int interfaceType = getBeanInterfaceType(resource);
660             
661             if (interfaceType > 0) {
662                 specificEventType =
663                         getSpecificEvent(eventType, interfaceType);
664                 elementFound = true;
665             }
666         }
667         if (elementFound) {
668             assert(specificEventType > 0);
669             DDChangeEvent ddEvent =
670                     new DDChangeEvent(this, this, oldResourceName,
671                     resourceName, specificEventType);
672             deploymentChange(ddEvent);
673         }
674         return elementFound;
675     }
676     
677     public EntityHelper getEntityHelper(Entity entity) {
678         EntityHelper entityHelper = (EntityHelper) entityHelperMap.get(entity);
679         if (entityHelper == null) {
680             entityHelper = new EntityHelper(this, entity);
681             entityHelperMap.put(entity, entityHelper);
682         }
683         return entityHelper;
684     }
685     
686     public SessionHelper getSessionHelper(Session session) {
687         SessionHelper sessionHelper = (SessionHelper) sessionHelperMap.get(session);
688         if (sessionHelper == null) {
689             sessionHelper = new SessionHelper(this, session);
690             sessionHelperMap.put(session, sessionHelper);
691         }
692         return sessionHelper;
693     }
694     
695     private class EjbJarPropertyChangeListener implements PropertyChangeListener JavaDoc {
696         
697         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
698             if (EjbJar.PROPERTY_STATUS.equals(evt.getPropertyName())) {
699                 return;
700             }
701             Object JavaDoc source = evt.getSource();
702             if (source instanceof EnterpriseBeans) {
703                 Object JavaDoc oldValue = evt.getOldValue();
704                 Object JavaDoc newValue = evt.getNewValue();
705                 if ((oldValue instanceof Entity || newValue instanceof Entity)) {
706                     entityHelperMap.keySet().retainAll(Arrays.asList(((EnterpriseBeans) source).getEntity()));
707                 } else if ((oldValue instanceof Session || newValue instanceof Session)) {
708                     sessionHelperMap.keySet().retainAll(Arrays.asList(((EnterpriseBeans) source).getSession()));
709                 }
710             }
711         }
712     }
713     
714     
715 }
716
Popular Tags