KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > OC4JDeploymentFactory


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 package org.netbeans.modules.j2ee.oc4j;
21
22 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager JavaDoc;
23 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
24 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
25 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
26 import org.openide.util.NbBundle;
27 import java.util.HashMap JavaDoc;
28 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
29 import org.netbeans.modules.j2ee.oc4j.util.OC4JDebug;
30 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties;
31 import org.openide.ErrorManager;
32 import org.openide.util.NbPreferences;
33
34 /**
35  *
36  * @author pblaha
37  */

38 public class OC4JDeploymentFactory implements DeploymentFactory JavaDoc {
39     
40     /**
41      * oc4j URI prefix
42      */

43     public static final String JavaDoc URI_PREFIX = "deployer:oc4j"; // NOI18N
44

45     /**
46      * oc4j server root property
47      */

48     public static final String JavaDoc PROP_SERVER_ROOT = "oc4j_server_root"; // NOI18N
49

50     private static OC4JDeploymentFactory instance;
51     
52     private HashMap JavaDoc<String JavaDoc, DeploymentFactory JavaDoc> factories = new HashMap JavaDoc<String JavaDoc, DeploymentFactory JavaDoc>();
53     private HashMap JavaDoc<String JavaDoc, DeploymentManager JavaDoc> managers = new HashMap JavaDoc<String JavaDoc, DeploymentManager JavaDoc>();
54     
55     /**
56      * Returns default instance of OC4JDeploymentFactory
57      *
58      * @return DeploymentFactory
59      */

60     public static synchronized DeploymentFactory JavaDoc getDefault() {
61         if (instance == null)
62             instance = new OC4JDeploymentFactory();
63         
64         return instance;
65     }
66     
67     /**
68      *
69      * @param uri
70      * @return
71      */

72     public boolean handlesURI(String JavaDoc uri) {
73         return uri != null && uri.startsWith(URI_PREFIX);
74     }
75     
76     /**
77      *
78      * @param uri
79      * @param uname
80      * @param passwd
81      * @return
82      * @throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
83      */

84     public DeploymentManager JavaDoc getDeploymentManager(String JavaDoc uri, String JavaDoc uname, String JavaDoc passwd) throws DeploymentManagerCreationException JavaDoc {
85         if (!handlesURI(uri))
86             throw new DeploymentManagerCreationException JavaDoc("Invalid URI:" + uri); // NOI18N
87

88         DeploymentManager JavaDoc manager = managers.get(uri);
89         
90         if (null == manager) {
91             manager = new OC4JDeploymentManager(uri);
92             managers.put(uri, manager);
93         }
94         
95         return manager;
96     }
97     
98     /**
99      *
100      * @param uri
101      * @return
102      * @throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
103      */

104     public DeploymentManager JavaDoc getDisconnectedDeploymentManager(String JavaDoc uri) throws DeploymentManagerCreationException JavaDoc {
105         return getDeploymentManager(uri, null, null);
106     }
107     
108     public DeploymentFactory JavaDoc getOC4JDeploymentFactory(String JavaDoc uri) {
109         if (OC4JDebug.isEnabled())
110             System.out.println("loadDeploymentFactory");
111         
112         DeploymentFactory JavaDoc factory = factories.get(uri);
113         
114         if (null == factory) {
115             InstanceProperties ip = InstanceProperties.getInstanceProperties(uri);
116             
117             String JavaDoc serverRoot = null;
118             
119             if (null != ip)
120                 serverRoot = ip.getProperty(OC4JPluginProperties.PROPERTY_OC4J_HOME);
121             
122             if (null == serverRoot)
123                 serverRoot = NbPreferences.forModule(OC4JDeploymentFactory.class).get(PROP_SERVER_ROOT, "");
124             
125             if (OC4JDebug.isEnabled())
126                 System.out.println("loadDeplomentFactory: serverRoot=" + serverRoot);
127
128             OC4JClassLoader.getInstance(serverRoot).updateLoader();
129             
130             try {
131                 factory = (DeploymentFactory JavaDoc) OC4JClassLoader.getInstance(serverRoot).loadClass(
132                         "oracle.oc4j.admin.deploy.spi.factories.Oc4jDeploymentFactory"). // NOI18N
133
newInstance();
134             } catch (ClassNotFoundException JavaDoc e) {
135                 ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
136             } catch (InstantiationException JavaDoc e) {
137                 ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
138             } catch (IllegalAccessException JavaDoc e) {
139                 ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
140             } finally {
141                 OC4JClassLoader.getInstance(serverRoot).restoreLoader();
142             }
143             
144             factories.put(uri, factory);
145         }
146         
147         return factory;
148     }
149     
150     /**
151      *
152      * @return
153      */

154     public String JavaDoc getProductVersion() {
155         return "0.2"; // NOI18N
156
}
157     
158     /**
159      *
160      * @return
161      */

162     public String JavaDoc getDisplayName() {
163         return NbBundle.getMessage(OC4JDeploymentFactory.class, "TXT_DisplayName"); // NOI18N
164
}
165 }
Popular Tags