KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > incrdeploy > DirectoryDeploymentFacade


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  * DirectoryDeploymentFacade.java
21  *
22  * Created on November 6, 2003, 11:25 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.j2ee.incrdeploy;
26 import java.io.File JavaDoc;
27
28 import org.netbeans.modules.j2ee.deployment.plugins.api.IncrementalDeployment;
29
30 import javax.enterprise.deploy.spi.Target JavaDoc;
31 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
32 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
33 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
34 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
35 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
36 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
37 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
38 import org.netbeans.modules.j2ee.sun.ide.j2ee.Utils;
39 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.ViewLogAction;
40 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
41 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
42 import org.netbeans.modules.j2ee.deployment.plugins.api.AppChangeDescriptor;
43
44 import org.netbeans.modules.j2ee.sun.api.ServerInterface;
45 import org.openide.ErrorManager;
46 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager;
47
48 /**
49  *
50  * @author vkraemer
51  */

52 public class DirectoryDeploymentFacade extends IncrementalDeployment {
53     
54     Object JavaDoc inner = null;
55       private File JavaDoc[] resourceDirs = null;
56     private SunDeploymentManagerInterface dm;
57    
58
59     /** Creates a new instance of DirectoryDeploymentFacade */
60     public DirectoryDeploymentFacade(DeploymentManager JavaDoc dm) {
61         //System.out.println("DirectoryDeploymentFacade called");
62
try {
63             setDeploymentManager(dm);
64             Class JavaDoc[] cls= new Class JavaDoc[1];
65             cls[0]=DeploymentManager JavaDoc.class;
66             java.lang.reflect.Constructor JavaDoc ctr =null;
67         SunDeploymentManagerInterface sdm = (SunDeploymentManagerInterface)dm;
68         ClassLoader JavaDoc loader = ServerLocationManager.getNetBeansAndServerClassLoader(sdm.getPlatformRoot());
69             ctr = loader.loadClass("org.netbeans.modules.j2ee.sun.bridge.DirectoryDeployment").getConstructor(cls);
70             Object JavaDoc[] o= new Object JavaDoc[1];
71             o[0]=dm;
72             
73             inner = ctr.newInstance(o);
74         } catch (Throwable JavaDoc t) {
75             t.printStackTrace();
76         }
77     }
78     /**
79      * @param manager
80      */

81     public void setDeploymentManager(DeploymentManager JavaDoc manager) {
82         if (null == manager){
83             throw new IllegalArgumentException JavaDoc("invalid null argumment");
84         }
85         
86         if (manager instanceof SunDeploymentManagerInterface)
87             this.dm = (SunDeploymentManagerInterface) manager;
88         else
89             throw new IllegalArgumentException JavaDoc("setDeploymentManager: Invalid manager type, expecting SunDeploymentManager and got "+manager.getClass().getName());
90     }
91     
92         
93     
94     public java.io.File JavaDoc getDirectoryForModule(javax.enterprise.deploy.spi.TargetModuleID JavaDoc module) {
95         if (null == inner){
96             return null;
97         }
98         return ((IncrementalDeployment)inner).getDirectoryForModule(module);
99     }
100     
101     public String JavaDoc getModuleUrl(javax.enterprise.deploy.spi.TargetModuleID JavaDoc module) {
102         if (null == inner){
103             return null;
104         }
105         return ((IncrementalDeployment)inner).getModuleUrl(module);
106     }
107     
108     public ProgressObject JavaDoc incrementalDeploy(TargetModuleID JavaDoc module, AppChangeDescriptor changes) {
109          //Register resources if any
110

111          // XXX
112
//No way to get resourceDirs from input parameters of this method.
113
//Initializing resourceDirs in canFileDeploy() method.
114
//Relying on the assumption that canFileDeploy() is & *will* always get
115
//called with appropriate DeployableObject before this method.
116
if((resourceDirs != null) && (dm != null)){
117             Utils.registerResources(resourceDirs, (ServerInterface)dm.getManagement());
118          }
119             if (null!=dm){
120                 ViewLogAction.viewLog(dm);
121             }
122                 
123          return ((IncrementalDeployment)inner).incrementalDeploy(module, changes);
124     }
125     
126     
127     
128     
129     public ProgressObject JavaDoc initialDeploy(Target JavaDoc target, DeployableObject JavaDoc deployableObject, DeploymentConfiguration JavaDoc deploymentConfiguration, File JavaDoc file) {
130        //Register resources if any
131
File JavaDoc[] resourceDirs = Utils.getResourceDirs(deployableObject);
132        if((resourceDirs != null) && (dm != null)) {
133            Utils.registerResources(resourceDirs, (ServerInterface)dm.getManagement());
134        }
135        if (null != dm){
136         ViewLogAction.viewLog(dm);
137        }
138         return ((IncrementalDeployment)inner).initialDeploy(target,deployableObject,deploymentConfiguration, file);
139     }
140
141     /**
142      * Whether the deployable object could be file deployed to the specified target
143      * @param target target in question
144      * @param deployable the deployable object in question
145      * @return true if it is possible to do file deployment
146      */

147     public boolean canFileDeploy(Target JavaDoc target, DeployableObject JavaDoc deployableObject) {
148         if (null == dm){
149             return false;
150         }
151         if (null == deployableObject){
152             return false;
153         }
154     if (org.netbeans.modules.j2ee.sun.ide.j2ee.PluginProperties.getDefault().isIncrementalDeploy()==false){
155             return false;
156     }
157
158         resourceDirs = Utils.getResourceDirs(deployableObject);
159         if (null == target){
160             return false;
161         }
162
163         //so far only WAR are supported for Directory based deployment
164
if ((deployableObject.getType() != ModuleType.WAR)){
165             return false;
166         }
167         return dm.isLocal();
168     }
169     
170     public File JavaDoc getDirectoryForNewApplication(javax.enterprise.deploy.spi.Target JavaDoc target, DeployableObject JavaDoc deployableObject, DeploymentConfiguration JavaDoc deploymentConfiguration) {
171         return ((IncrementalDeployment)inner).getDirectoryForNewApplication(target,deployableObject,deploymentConfiguration);
172     }
173     public File JavaDoc getDirectoryForNewApplication(String JavaDoc deploymentName, Target JavaDoc target, DeploymentConfiguration JavaDoc configuration){
174         SunONEDeploymentConfiguration s1dc =(SunONEDeploymentConfiguration) configuration;
175         s1dc.setDeploymentModuleName(deploymentName);
176     return null;
177     }
178     
179     public File JavaDoc getDirectoryForNewModule(File JavaDoc file, String JavaDoc str, DeployableObject JavaDoc deployableObject, DeploymentConfiguration JavaDoc deploymentConfiguration) {
180         return ((IncrementalDeployment)inner).getDirectoryForNewModule(file,str, deployableObject,deploymentConfiguration);
181     }
182     
183 }
184
Popular Tags