1 19 20 package org.netbeans.modules.j2ee.sun.bridge; 21 import java.io.File ; 22 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 23 import javax.enterprise.deploy.spi.status.ProgressEvent ; 24 import javax.enterprise.deploy.spi.status.ProgressListener ; 25 26 import org.netbeans.modules.j2ee.deployment.plugins.api.IncrementalDeployment; 27 import org.netbeans.modules.j2ee.deployment.plugins.api.AppChangeDescriptor; 28 29 30 import javax.enterprise.deploy.spi.Target ; 31 import javax.enterprise.deploy.spi.TargetModuleID ; 32 import javax.enterprise.deploy.spi.DeploymentManager ; 33 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 34 import javax.enterprise.deploy.model.DeployableObject ; 35 import javax.enterprise.deploy.shared.ModuleType ; 36 import javax.enterprise.deploy.spi.status.ProgressObject ; 37 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 38 import org.netbeans.modules.j2ee.sun.api.SunDeploymentConfigurationInterface; 39 40 45 public class DirectoryDeployment extends IncrementalDeployment { 46 47 private SunDeploymentManagerInterface dm; 48 49 50 51 public DirectoryDeployment() { 52 } 53 54 public DirectoryDeployment(DeploymentManager manager) { 55 setDeploymentManager( manager); 56 } 57 58 59 60 61 62 63 72 public String [] getDeploymentPlanFileNames(ModuleType type) { 73 String [] s; 74 if (type==null){ 75 throw new IllegalArgumentException ("invalid null argumment"); 76 } 77 else if(type.equals(ModuleType.WAR)){ 78 s = new String [] { "WEB-INF/sun-web.xml" }; 79 } 80 else if(type.equals(ModuleType.EJB)){ 81 s = new String [] { "META-INF/sun-ejb-jar.xml", "META-INF/sun-cmp-mappings.xml" }; 82 } 83 else if(type.equals(ModuleType.EAR)){ 84 s = new String [] { "META-INF/sun-application.xml" }; 85 } 86 else if(type.equals(ModuleType.RAR)){ 87 s = new String [] { "META-INF/sun-connector.xml" }; 88 } 89 else if(type.equals(ModuleType.CAR)){ 90 s = new String [] { "META-INF/sun-application-client.xml" }; 91 } 92 93 else{ 94 s = new String [] { ".timestamp" }; 95 } 96 97 return s; 98 } 99 100 109 public File getDirectoryForModule(TargetModuleID module) { 110 if (null == dm){ 111 throw new IllegalStateException ("invalid dm value"); 112 } 113 118 return null; 129 } 130 131 132 133 136 public void setDeploymentManager(DeploymentManager manager) { 137 if (null == manager){ 138 throw new IllegalArgumentException ("invalid null argumment"); 139 } 140 if (manager instanceof SunDeploymentManagerInterface){ 141 this.dm = (SunDeploymentManagerInterface) manager; 142 } 143 else{ 144 throw new IllegalArgumentException ("setDeploymentManager: Invalid manager type, expecting SunDeploymentManager and got "+manager.getClass().getName()); 145 } 146 } 147 148 149 154 final public ProgressObject incrementalDeploy( final TargetModuleID tmid, AppChangeDescriptor aCD) { 155 ProgressObject retVal = null; 156 try { 157 158 dm.grabInnerDM(false); 159 DirectoryDeploymentFacility ddf = new DirectoryDeploymentFacility(dm.getHost(),dm.getPort(),dm.getUserName(),dm.getPassword(),dm.isSecure()); 160 retVal = ddf.incrementalDeploy(tmid); 161 if (null != retVal) { 162 retVal.addProgressListener(new Releaser(dm)); 163 } 164 } finally { 165 if (null == retVal) { 166 dm.releaseInnerDM(); 167 } 168 } 169 return retVal; 171 } 172 173 174 175 176 177 185 public String getModuleUrl(TargetModuleID module){ 186 187 return AppServerBridge.getModuleUrl (module); 188 } 189 190 191 192 193 194 204 public ProgressObject initialDeploy(Target target, 205 DeployableObject deployableObject, 206 DeploymentConfiguration deploymentConfiguration, 207 File file) { 208 SunDeploymentConfigurationInterface s1dc =(SunDeploymentConfigurationInterface) deploymentConfiguration; 209 s1dc.getContextRoot(); 210 String moduleID= getGoodDirNameFromContextRoot(s1dc.getDeploymentModuleName()); 211 ProgressObject retVal = null; 212 try { 213 214 dm.grabInnerDM(false); 215 DirectoryDeploymentFacility ddf = new DirectoryDeploymentFacility(dm.getHost(),dm.getPort(),dm.getUserName(),dm.getPassword(),dm.isSecure()); 216 retVal = ddf.initialDeploy( target, file , moduleID); 217 if (null != retVal) { 218 retVal.addProgressListener(new Releaser(dm)); 219 } 220 } finally { 221 if (null == retVal) { 222 dm.releaseInnerDM(); 223 } 224 } 225 return retVal; 226 } 227 228 229 230 231 private String getGoodDirNameFromContextRoot(String contextRoot){ 232 String moduleID; 233 if (contextRoot==null){ 234 return "_default_"+this.hashCode() ; 235 } 236 if (contextRoot.equals("")){ 237 return "_default_"+this.hashCode(); 238 } 239 240 moduleID = contextRoot.replace(' ','_'); 241 242 moduleID = moduleID.replace('\\', '_').replace('/', '_'); 246 moduleID = moduleID.replace(':', '_').replace('*', '_'); 247 moduleID = moduleID.replace('?', '_').replace('"', '_'); 248 moduleID = moduleID.replace('<', '_').replace('>', '_'); 249 moduleID = moduleID.replace('|', '_'); 250 251 moduleID = moduleID.replace(',', '_').replace('=', '_'); 255 return moduleID; 256 257 } 258 264 public boolean canFileDeploy(Target target, DeployableObject deployableObject) { 265 if (null == target){ 266 return false; 267 } 268 if (null == deployableObject){ 269 return false; 270 } 271 if (null == dm){ 272 return false; 273 } 274 if (deployableObject.getType() == ModuleType.EAR || 275 deployableObject.getType() == ModuleType.EJB){ 276 return false; 277 } 278 return dm.isLocal(); 279 } 280 281 290 291 public java.io.File getDirectoryForNewApplication(Target target, DeployableObject deployableObject, DeploymentConfiguration deploymentConfiguration) { 292 return null; 299 } 300 301 311 public File getDirectoryForNewApplication(String deploymentName, Target target, DeploymentConfiguration configuration){ 312 313 return null; 314 316 } 317 325 326 public java.io.File getDirectoryForNewModule(File file, String str, DeployableObject deployableObject, DeploymentConfiguration deploymentConfiguration) { 327 System.out.println(" getDirectoryForNewModule" +file+str); 328 System.out.println(" getDirectoryForNewModule" +deploymentConfiguration); 329 System.out.println(" getDirectoryForNewModule" +deployableObject); 330 return new File ("C:\\tmp\\ludo222"); 331 } 332 333 private class Releaser implements ProgressListener { 334 SunDeploymentManagerInterface dm; 335 Releaser(SunDeploymentManagerInterface dm) { 336 this.dm = dm; 337 } 338 339 public void handleProgressEvent(ProgressEvent progressEvent) { 340 DeploymentStatus dms = progressEvent.getDeploymentStatus(); 341 if (!dms.isRunning()) { 342 dm.releaseInnerDM(); 343 } 344 } 345 } 346 347 } 348 349 350 | Popular Tags |