KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > dev > wizard > 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.websvc.dev.wizard;
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
34 import org.openide.ErrorManager;
35 import org.openide.filesystems.FileObject;
36 import org.openide.nodes.Children;
37 import org.openide.nodes.Node;
38
39 /**
40  * Provides EJB tree of all open projects. This class is not used for displaying Enterprise Beans node in project view.
41  */

42 public final class EJBListViewChildren extends Children.Keys {
43
44     public static final String JavaDoc KEY_EJBS = "ejbKey"; //NOI18N
45

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