1 19 20 package org.netbeans.modules.j2ee.ejbfreeform; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.File ; 25 import org.netbeans.api.java.project.JavaProjectConstants; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.api.project.SourceGroup; 29 import org.netbeans.api.project.Sources; 30 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 31 import org.netbeans.modules.j2ee.deployment.common.api.EjbChangeDescriptor; 32 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 33 import org.netbeans.modules.j2ee.deployment.devmodules.api.ModuleChangeReporter; 34 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 35 import org.netbeans.spi.project.support.ant.AntProjectHelper; 36 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileUtil; 39 40 41 46 public class EJBFreeformProvider extends J2eeModuleProvider implements ModuleChangeReporter, 47 EjbChangeDescriptor, PropertyChangeListener { 48 49 private Project project; 50 private AntProjectHelper helper; 51 private PropertyEvaluator evaluator; 52 private EJBFreeformModule ejbModule; 53 54 55 public EJBFreeformProvider(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) { 56 this.project = project; 57 this.helper = helper; 58 this.evaluator = evaluator; 59 evaluator.addPropertyChangeListener(this); 60 } 61 62 64 65 66 public File getDeploymentConfigurationFile(String name) { 67 FileObject moduleFolder = EjbJar.getEjbJars(project)[0].getMetaInf(); 68 File configFolder = FileUtil.toFile(moduleFolder); 69 return new File (configFolder, name); 70 } 71 72 public FileObject findDeploymentConfigurationFile(String name) { 73 return EjbJar.getEjbJars(project)[0].getMetaInf().getFileObject(name); 74 } 75 76 public ModuleChangeReporter getModuleChangeReporter() { 77 return this; 78 } 79 80 void setJ2eeModule(EJBFreeformModule ejbFreeMod) { 81 ejbModule = ejbFreeMod; 82 } 83 84 public J2eeModule getJ2eeModule() { 85 return ejbModule; 86 } 87 88 90 public boolean isManifestChanged(long timestamp) { 91 return false; 92 } 93 94 public EjbChangeDescriptor getEjbChanges(long timestamp) { 95 return this; 96 } 97 98 100 public String [] getChangedEjbs() { 101 return new String [] {}; 102 } 103 104 public boolean ejbsChanged() { 105 return false; 106 } 107 108 public File getEnterpriseResourceDirectory() { 109 return getFile(EjbFreeformProperties.RESOURCE_DIR); 110 } 111 112 public boolean useDefaultServer() { 113 return false; 114 } 115 116 public FileObject[] getSourceRoots() { 117 Sources sources = ProjectUtils.getSources(project); 118 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 119 FileObject[] roots = new FileObject[groups.length+1]; 120 roots[0] = EjbJar.getEjbJars(project)[0].getMetaInf(); 121 for (int i=0; i < groups.length; i++) { 122 roots[i+1] = groups[i].getRootFolder(); 123 } 124 125 return roots; 126 } 127 128 public void setServerInstanceID(String severInstanceID) { 129 } 131 132 public String getServerInstanceID() { 133 return evaluator.getProperty(EjbFreeformProperties.J2EE_SERVER_INSTANCE); 134 } 135 136 public String getServerID() { 137 return evaluator.getProperty(EjbFreeformProperties.J2EE_SERVER_TYPE); 138 } 139 140 142 private File getFile(String propname) { 143 String prop = evaluator.getProperty(propname); 144 if (prop != null) { 145 return helper.resolveFile(prop); 146 } 147 return null; 148 } 149 150 public void propertyChange(PropertyChangeEvent evt) { 151 firePropertyChange(PROP_ENTERPRISE_RESOURCE_DIRECTORY, null, getEnterpriseResourceDirectory()); 162 } 163 } 164 | Popular Tags |