KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > ConfigurationSupportImpl


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  * ConfigurationSupport.java
21  *
22  * Created on November 29, 2004, 3:22 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.j2ee;
26
27 import java.io.File JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import javax.enterprise.deploy.model.DDBean JavaDoc;
31 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
32 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
34 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc;
35 import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
36 import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
37
38 import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
39 import org.netbeans.modules.j2ee.deployment.plugins.api.ConfigurationSupport;
40 import org.netbeans.modules.j2ee.sun.share.configbean.EjbJarRoot;
41 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
42
43 /** Implementation of ConfigurationSupport.
44  *
45  * Primarily serves to delegate directly to the specified DeploymentConfiguration
46  * instance, as that is in shared code and has appropriate access and this instance
47  * is not.
48  *
49  */

50 public class ConfigurationSupportImpl extends ConfigurationSupport {
51
52     /** Creates a new instance of ConfigurationSupport */
53     public ConfigurationSupportImpl() {
54     }
55
56     
57     /** Called by j2eeserver to initialize the deployment configuration object
58      * for this J2EE project.
59      */

60     public void initConfiguration(DeploymentConfiguration JavaDoc config, File JavaDoc[] files, File JavaDoc resourceDir, boolean keepUpdated) throws ConfigurationException JavaDoc {
61         checkConfiguration(config);
62         if(files == null || files.length < 1 || files[0] == null) {
63             throw new IllegalArgumentException JavaDoc("files[] must be non-null and contain at least one non-null member.");
64         }
65         ((SunONEDeploymentConfiguration)config).init(files, resourceDir, keepUpdated);
66     }
67
68     
69     /** Called by j2eeserver to allow us to cleanup the deployment configuration object
70      * for this J2EE project.
71      */

72     public void disposeConfiguration(DeploymentConfiguration JavaDoc config) {
73         checkConfiguration(config);
74         ((SunONEDeploymentConfiguration)config).dispose();
75     }
76
77     
78     /** Called through j2eeserver when a new resource may need to be added to the
79      * user's project.
80      */

81     public void ensureResourceDefined(DeploymentConfiguration JavaDoc config, DDBean JavaDoc ddBean) {
82         checkConfiguration(config);
83         if(ddBean == null) {
84             throw new IllegalArgumentException JavaDoc("DDBean parameter cannot be null.");
85         }
86         ((SunONEDeploymentConfiguration)config).ensureResourceDefined(ddBean);
87     }
88
89     /** Called through j2eeserver when a new EJB resource may need to be added to the
90      * user's project.
91      */

92     public void ensureResourceDefined(DeploymentConfiguration JavaDoc config, DDBean JavaDoc ddBean, String JavaDoc jndiName) {
93         checkConfiguration(config);
94         if(ddBean == null) {
95             throw new IllegalArgumentException JavaDoc("DDBean parameter cannot be null.");
96         }
97         ((SunONEDeploymentConfiguration)config).ensureResourceDefinedForEjb(ddBean, jndiName);
98     }
99
100     
101     /** Conduit to pass the cmp mapping information directly to the configuration
102      * backend.
103      */

104     public void setMappingInfo(DeploymentConfiguration JavaDoc config, OriginalCMPMapping[] mapping){
105         checkConfiguration(config);
106         SunONEDeploymentConfiguration s1config = (SunONEDeploymentConfiguration) config;
107         EjbJarRoot ejbJarRoot = s1config.getEjbJarRoot();
108         if(ejbJarRoot != null) {
109             ejbJarRoot.mapCmpBeans(mapping);
110         }
111     }
112
113
114     /** Retrieves the context root field from sun-web.xml for this module, if the module is a
115      * web application. Otherwise, returns null.
116      */

117     public String JavaDoc getWebContextRoot(DeploymentConfiguration JavaDoc config, DeployableObject JavaDoc deplObj) throws ConfigurationException JavaDoc {
118         checkConfiguration(config);
119         assert config.getDeployableObject() == deplObj;
120         return ((SunONEDeploymentConfiguration)config).getContextRoot();
121     }
122
123     
124     /** Sets the context root field in sun-web.xml for this module, if the module is a
125      * web application.
126      */

127     public void setWebContextRoot(DeploymentConfiguration JavaDoc config, DeployableObject JavaDoc deplObj, String JavaDoc contextRoot) throws ConfigurationException JavaDoc {
128         checkConfiguration(config);
129         assert config.getDeployableObject() == deplObj;
130         ((SunONEDeploymentConfiguration)config).setContextRoot(contextRoot);
131     }
132     
133     
134     /** Updates the resource dir in use by this project.
135      */

136     public void updateResourceDir(DeploymentConfiguration JavaDoc config, File JavaDoc resourceDir) {
137         checkConfiguration(config);
138         ((SunONEDeploymentConfiguration) config).updateResourceDir(resourceDir);
139     }
140     
141     /** Utility method to validate the configuration object being passed to the
142      * other methods in this class.
143      */

144     private void checkConfiguration(DeploymentConfiguration JavaDoc config) {
145         if(config == null) {
146             throw new IllegalArgumentException JavaDoc("DeploymentConfiguration is null");
147         }
148         if(!(config instanceof SunONEDeploymentConfiguration)) {
149             throw new IllegalArgumentException JavaDoc("Wrong DeploymentConfiguration instance " + config.getClass().getName());
150         }
151     }
152     
153     /**
154      * Implementation of DS Management API in ConfigurationSupport
155      * @param config deployment configuration object for this J2EE project.
156      * @return Returns Set of SunDataSource's(JDBC Resources) present in this J2EE project
157      * SunDataSource is a combination of JDBC & JDBC Connection Pool Resources.
158      */

159     public Set JavaDoc getDatasources(DeploymentConfiguration JavaDoc config) {
160         checkConfiguration(config);
161         SunONEDeploymentConfiguration sunConfig = ((SunONEDeploymentConfiguration)config);
162         Set JavaDoc projectDS = sunConfig.getDatasources();
163         return projectDS;
164     }
165     
166     /**
167      * Implementation of DS Management API in ConfigurationSupport
168      * @return Returns true of plugin implements DS Management API's
169      */

170     public boolean isDatasourceCreationSupported() {
171         return true;
172     }
173     
174
175     /**
176      * Implementation of DS Management API in ConfigurationSupport
177      * Creates DataSource objects for this J2EE Project
178      * @param config deployment configuration object for this J2EE project.
179      * @param jndiName JNDI Name of JDBC Resource
180      * @param url Url for database referred to by this JDBC Resource's Connection Pool
181      * @param username UserName for database referred to by this JDBC Resource's Connection Pool
182      * @param password Password for database referred to by this JDBC Resource's Connection Pool
183      * @param driver Driver ClassName for database referred to by this JDBC Resource's Connection Pool
184      * @return Set containing SunDataSource
185      */

186     public Datasource createDatasource(DeploymentConfiguration JavaDoc config, String JavaDoc jndiName, String JavaDoc url, String JavaDoc username, String JavaDoc password, String JavaDoc driver)
187     throws OperationUnsupportedException JavaDoc, ConfigurationException JavaDoc, DatasourceAlreadyExistsException {
188         checkConfiguration(config);
189         SunONEDeploymentConfiguration sunConfig = ((SunONEDeploymentConfiguration)config);
190         return sunConfig.createDatasource(jndiName, url, username, password, driver);
191     }
192     
193 }
194
195
Popular Tags