1 19 20 package org.netbeans.modules.j2ee.ejbfreeform; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.HashSet ; 26 import java.util.List ; 27 import java.util.Set ; 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 51 public class EJBProjectNature implements ProjectNature { 52 53 public static final String NS_EJB = "http://www.netbeans.org/ns/freeform-project-ejb/1"; public static final String NS_EJB_2 = "http://www.netbeans.org/ns/freeform-project-ejb/2"; private static final String SCHEMA = "nbres:/org/netbeans/modules/j2ee/ejbfreeform/resources/freeform-project-ejb.xsd"; private static final String SCHEMA_2 = "nbres:/org/netbeans/modules/j2ee/ejbfreeform/resources/freeform-project-ejb-2.xsd"; 58 public static final String EL_EJB = "ejb-data"; public static final String STYLE_CONFIG_FILES = "configFiles"; public static final String STYLE_EJBS = "ejbs"; 62 public EJBProjectNature() {} 63 64 65 66 public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { 67 ArrayList l = new ArrayList (); 68 if (!isMyProject(aux)) { 69 return l; 70 } 71 l.add(getExtraTarget()); 72 return l; 73 } 74 75 public Set getSchemas() { 76 return new HashSet (Arrays.asList(new String [] { SCHEMA, SCHEMA_2 })); 77 } 78 79 public Set getSourceFolderViewStyles() { 80 Set resultSet = new HashSet (); 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 includes, String excludes, String style, String name, String displayName) throws IllegalArgumentException { 87 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 ex) { 102 ErrorManager.getDefault().notify(ex); 103 } 104 } 105 throw new IllegalArgumentException (); 106 } 107 108 public Node findSourceFolderViewPath(Project project, Node root, Object target) { 109 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 return null; 133 } 134 135 try { 136 return NodeOp.findPath(root, new String [] { 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 []{"deploy", ".*deploy.*"}), NbBundle.getMessage(EJBProjectNature.class, "LBL_TargetMappingPanel_Deploy"), NbBundle.getMessage(EJBProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); } 152 153 154 } 155 | Popular Tags |