KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > mavenplugin > AbstractModuleCommand


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.deployment.mavenplugin;
19
20 import java.io.IOException JavaDoc;
21 import java.io.File JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.net.URLClassLoader JavaDoc;
24
25 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
26 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
27 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager JavaDoc;
28
29 import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
30
31 /**
32  *
33  *
34  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
35  *
36  * */

37 public abstract class AbstractModuleCommand {
38     private String JavaDoc uri;
39     private String JavaDoc username;
40     private String JavaDoc password;
41
42     public String JavaDoc getUri() {
43         return uri;
44     }
45
46     public void setUri(String JavaDoc uri) {
47         this.uri = uri;
48     }
49
50     public String JavaDoc getUsername() {
51         return username;
52     }
53
54     public void setUsername(String JavaDoc username) {
55         this.username = username;
56     }
57
58     public String JavaDoc getPassword() {
59         return password;
60     }
61
62     public void setPassword(String JavaDoc password) {
63         this.password = password;
64     }
65
66     public abstract void execute() throws Exception JavaDoc;
67
68     protected DeploymentManager JavaDoc getDeploymentManager() throws IOException JavaDoc, DeploymentManagerCreationException JavaDoc {
69         if (getUsername() == null) {
70             throw new IllegalStateException JavaDoc("No user specified");
71         }
72         if (getPassword() == null) {
73             throw new IllegalStateException JavaDoc("No password specified");
74         }
75         if (getUri() == null) {
76             throw new IllegalStateException JavaDoc("No uri specified");
77         }
78         new DeploymentFactoryImpl();
79
80         ClassLoader JavaDoc oldcl = Thread.currentThread().getContextClassLoader();
81         try {
82             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
83             DeploymentFactoryManager JavaDoc factoryManager = DeploymentFactoryManager.getInstance();
84             DeploymentManager JavaDoc manager = factoryManager.getDeploymentManager(getUri(), getUsername(), getPassword());
85             return manager;
86         } finally {
87             Thread.currentThread().setContextClassLoader(oldcl);
88         }
89     }
90 }
91
Popular Tags