KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbfreeform > EJBProjectNature


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.ejbfreeform;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import org.netbeans.api.java.classpath.ClassPath;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.modules.ant.freeform.spi.ProjectNature;
31 import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
32 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
33 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
34 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView;
35 import org.netbeans.spi.project.AuxiliaryConfiguration;
36 import org.netbeans.spi.project.support.ant.AntProjectHelper;
37 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
38 import org.openide.ErrorManager;
39 import org.openide.filesystems.FileObject;
40 import org.openide.filesystems.FileUtil;
41 import org.openide.loaders.DataObject;
42 import org.openide.loaders.DataObjectNotFoundException;
43 import org.openide.nodes.Node;
44 import org.openide.nodes.NodeNotFoundException;
45 import org.openide.nodes.NodeOp;
46 import org.openide.util.NbBundle;
47
48 /**
49  * @author David Konecny
50  */

51 public class EJBProjectNature implements ProjectNature {
52
53     public static final String JavaDoc NS_EJB = "http://www.netbeans.org/ns/freeform-project-ejb/1"; // NOI18N
54
public static final String JavaDoc NS_EJB_2 = "http://www.netbeans.org/ns/freeform-project-ejb/2"; // NOI18N
55
private static final String JavaDoc SCHEMA = "nbres:/org/netbeans/modules/j2ee/ejbfreeform/resources/freeform-project-ejb.xsd"; // NOI18N
56
private static final String JavaDoc SCHEMA_2 = "nbres:/org/netbeans/modules/j2ee/ejbfreeform/resources/freeform-project-ejb-2.xsd"; // NOI18N
57

58     public static final String JavaDoc EL_EJB = "ejb-data"; // NOI18N
59
public static final String JavaDoc STYLE_CONFIG_FILES = "configFiles"; // NOI18N
60
public static final String JavaDoc STYLE_EJBS = "ejbs"; // NOI18N
61

62     public EJBProjectNature() {}
63
64    
65     
66     public List JavaDoc getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
67         ArrayList JavaDoc l = new ArrayList JavaDoc();
68         if (!isMyProject(aux)) {
69             return l;
70         }
71         l.add(getExtraTarget());
72         return l;
73     }
74     
75     public Set JavaDoc/*<String>*/ getSchemas() {
76         return new HashSet JavaDoc(Arrays.asList(new String JavaDoc[] { SCHEMA, SCHEMA_2 }));
77     }
78
79     public Set JavaDoc/*<String>*/ getSourceFolderViewStyles() {
80         Set JavaDoc resultSet = new HashSet JavaDoc();
81         resultSet.add(STYLE_CONFIG_FILES);
82         resultSet.add(STYLE_EJBS);
83         return resultSet;
84     }
85     
86     public Node createSourceFolderView(Project project, FileObject folder, String JavaDoc includes, String JavaDoc excludes, String JavaDoc style, String JavaDoc name, String JavaDoc displayName) throws IllegalArgumentException JavaDoc {
87         // XXX consider using includes/excludes
88
if (style.equals(STYLE_CONFIG_FILES)) {
89             EjbJar ejbJar = EjbJar.getEjbJar(folder);
90             assert ejbJar != null;
91             return J2eeProjectView.createConfigFilesView(ejbJar.getMetaInf());
92         } else if (style.equals(STYLE_EJBS)) {
93             EjbJar ejbJar = EjbJar.getEjbJar(folder);
94             assert ejbJar != null;
95             FileObject ddFile = ejbJar.getDeploymentDescriptor();
96             org.netbeans.modules.j2ee.dd.api.ejb.EjbJar model;
97             try {
98                 model = DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit());
99                 ClassPath cp = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(ejbJar.getJavaSources());
100                 return J2eeProjectView.createEjbsView(model, cp, ddFile, project);
101             } catch (IOException JavaDoc ex) {
102                 ErrorManager.getDefault().notify(ex);
103             }
104         }
105         throw new IllegalArgumentException JavaDoc();
106     }
107
108     public Node findSourceFolderViewPath(Project project, Node root, Object JavaDoc target) {
109         // handle the Configuration Files node
110

111         DataObject rootDO = (DataObject)root.getLookup().lookup(DataObject.class);
112         if (rootDO == null) {
113             return null;
114         }
115         
116         DataObject targetDO = null;
117         
118         if (target instanceof DataObject) {
119             targetDO = (DataObject)target;
120         } else if (target instanceof FileObject) {
121             try {
122                 targetDO = DataObject.find((FileObject)target);
123             } catch (DataObjectNotFoundException ex) {
124                 return null;
125             }
126         } else {
127             return null;
128         }
129         
130         if (!FileUtil.isParentOf(rootDO.getPrimaryFile(), targetDO.getPrimaryFile())) {
131             // target is not under root
132
return null;
133         }
134         
135         try {
136             return NodeOp.findPath(root, new String JavaDoc[] { targetDO.getNodeDelegate().getName() });
137         } catch (NodeNotFoundException ex) {
138             return null;
139         }
140     }
141
142     public static boolean isMyProject(AuxiliaryConfiguration aux) {
143         return (aux.getConfigurationFragment(EL_EJB, NS_EJB, true) != null) ||
144                (aux.getConfigurationFragment(EL_EJB, NS_EJB_2, true) != null);
145     }
146     
147     public static TargetDescriptor getExtraTarget() {
148         return new TargetDescriptor("deploy", Arrays.asList(new String JavaDoc[]{"deploy", ".*deploy.*"}), // NOI18N
149
NbBundle.getMessage(EJBProjectNature.class, "LBL_TargetMappingPanel_Deploy"), // NOI18N
150
NbBundle.getMessage(EJBProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N
151
}
152     
153     
154 }
155
Popular Tags