1 19 20 package org.netbeans.modules.j2ee.ejbfreeform; 21 22 import java.util.Iterator ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 25 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 26 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices; 27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 28 import org.netbeans.modules.schema2beans.BaseBean; 29 import org.netbeans.spi.project.support.ant.AntProjectHelper; 30 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 31 import org.openide.DialogDisplayer; 32 import org.openide.NotifyDescriptor; 33 import org.openide.filesystems.FileObject; 34 import org.openide.util.NbBundle; 35 36 40 public class EJBFreeformModule implements J2eeModule { 41 42 private Project project; 43 private AntProjectHelper helper; 44 private PropertyEvaluator evaluator; 45 private org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbImpl; 46 47 48 public EJBFreeformModule(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) { 49 this.project = project; 50 this.helper = helper; 51 this.evaluator = evaluator; 52 } 53 54 private org.netbeans.modules.j2ee.api.ejbjar.EjbJar getEjbModule () { 55 if (ejbImpl == null) { 56 org.netbeans.modules.j2ee.api.ejbjar.EjbJar modules[] = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project); 57 if (modules.length > 0) { 58 ejbImpl = modules[0]; 59 } 60 } 61 return ejbImpl; 62 } 63 64 public void setUrl(String url) { 65 } 66 67 public BaseBean getDeploymentDescriptor(String location) { 68 if (J2eeModule.EJBJAR_XML.equals(location)){ 69 EjbJar webApp = getEjbJar(); 70 if (webApp != null) { 71 return DDProvider.getDefault().getBaseBean(webApp); 73 } 74 } else if(J2eeModule.EJBSERVICES_XML.equals(location)){ 75 Webservices webServices = getWebservices(); 76 if(webServices != null){ 77 return DDProvider.getDefault().getBaseBean(webServices); 78 } 79 } 80 return null; 81 } 82 83 public void removeVersionListener(org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule.VersionListener listener) { 84 } 85 86 public void addVersionListener(org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule.VersionListener listener) { 87 } 88 89 public String getUrl() { 90 return ""; 91 } 92 93 public String getModuleVersion() { 94 EjbJar ejbJar = getEjbJar(); 95 return ejbJar.getVersion().toString(); 96 } 97 98 public Object getModuleType() { 99 return J2eeModule.EJB; 100 } 101 102 public FileObject getContentDirectory() throws java.io.IOException { 103 return null; 104 } 105 106 public Iterator getArchiveContents() throws java.io.IOException { 107 return null; 108 } 109 110 public FileObject getArchive() throws java.io.IOException { 111 return null; 112 } 113 114 116 private EjbJar getEjbJar() { 117 try { 118 return DDProvider.getDefault().getMergedDDRoot(getEjbModule().getMetadataUnit()); 119 } catch (java.io.IOException e) { 120 org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage()); 121 } 122 return null; 123 } 124 125 private Webservices getWebservices() { 126 FileObject wsdd = getDD(); 127 if(wsdd != null) { 128 try { 129 return org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(getDD()); 130 } catch (java.io.IOException e) { 131 org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage()); 132 } 133 } 134 135 return null; 136 } 137 138 public FileObject getDD() { 139 FileObject metaInfFo = getEjbModule().getMetaInf(); 140 if (metaInfFo==null) { 141 DialogDisplayer.getDefault().notify( 142 new NotifyDescriptor.Message(NbBundle.getMessage(EJBFreeformModule.class,"MSG_ConfigFilesCorrupted"), 143 NotifyDescriptor.ERROR_MESSAGE)); 144 return null; 145 } 146 return getEjbModule().getMetaInf().getFileObject("webservices", "xml"); } 148 149 private FileObject getFileObject(String propname) { 150 String prop = evaluator.getProperty(propname); 151 if (prop != null) { 152 return helper.resolveFileObject(prop); 153 } 154 155 return null; 156 } 157 158 } 159 | Popular Tags |