KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > entres > EJBListViewChildren


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.ejbcore.ui.logicalview.entres;
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.api.java.classpath.ClassPath;
26 import org.netbeans.api.java.project.JavaProjectConstants;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.api.project.ProjectUtils;
29 import org.netbeans.api.project.SourceGroup;
30 import org.netbeans.api.project.Sources;
31 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
32 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView;
33 import org.openide.ErrorManager;
34 import org.openide.filesystems.FileObject;
35 import org.openide.nodes.Children;
36 import org.openide.nodes.Node;
37
38 /**
39  * Provides EJB tree of all open projects. This class is not used for displaying Enterprise Beans node in project view.
40  */

41 public final class EJBListViewChildren extends Children.Keys<EJBListViewChildren.KEY> {
42
43     public enum KEY { EJB }
44     
45     private final Sources sources;
46     private final ClassPath classPath;
47     private final Project project;
48
49     public EJBListViewChildren(Project project) {
50         assert project != null;
51         this.project = project;
52         sources = ProjectUtils.getSources(project);
53         assert sources != null;
54         classPath = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(getRoots());
55     }
56
57     private FileObject[] getRoots() {
58         SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
59         FileObject[] roots = new FileObject[groups.length];
60         for (int i = 0; i < groups.length; i++) {
61             roots[i] = groups[i].getRootFolder();
62         }
63         return roots;
64     }
65
66     @Override JavaDoc
67     protected void addNotify() {
68         super.addNotify();
69         createNodes();
70     }
71
72     private void createNodes() {
73         List JavaDoc<KEY> keys = new ArrayList JavaDoc<KEY>();
74         keys.add(KEY.EJB);
75         setKeys(keys);
76     }
77
78     @Override JavaDoc
79     protected void removeNotify() {
80         setKeys(Collections.<KEY>emptySet());
81         super.removeNotify();
82     }
83
84     public Node[] createNodes(KEY key) {
85         Node node = null;
86         if (key == KEY.EJB) {
87             EjbJar[] apiEjbJars = EjbJar.getEjbJars(project);
88             org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null;
89             try {
90                 ejbJar = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(apiEjbJars[0].getMetadataUnit());
91             } catch (IOException JavaDoc ioe) {
92                 ErrorManager.getDefault().notify(ioe);
93             }
94             if (ejbJar != null) {
95                 node = J2eeProjectView.createEjbsView(ejbJar, classPath, apiEjbJars[0].getDeploymentDescriptor(), project);
96             }
97         }
98         return node == null ? new Node[0] : new Node[] {node};
99     }
100
101 }
102
103
104
Popular Tags