KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > config > 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 package org.netbeans.modules.j2ee.oc4j.config;
21
22 import java.io.File JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.enterprise.deploy.model.DDBean JavaDoc;
25 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
26 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
27 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
28 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
29 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc;
30 import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
31 import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
32 import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
33 import org.netbeans.modules.j2ee.deployment.plugins.api.ConfigurationSupport;
34
35 /**
36  * ConfigurationSupport implementation.
37  *
38  * @author sherold
39  */

40 public class ConfigurationSupportImpl extends ConfigurationSupport {
41     
42     public void setMappingInfo(DeploymentConfiguration JavaDoc config, OriginalCMPMapping[] mappings) {
43     }
44     
45     public void ensureResourceDefined(DeploymentConfiguration JavaDoc config, DDBean JavaDoc bean) {
46     }
47     
48     public String JavaDoc getWebContextRoot(DeploymentConfiguration JavaDoc config, DeployableObject JavaDoc deplObj)
49             throws ConfigurationException JavaDoc {
50         if (config.getDeployableObject().getType() != ModuleType.WAR) {
51             throw new ConfigurationException JavaDoc("This operation is supported only by the WAR modules"); // NOI18N
52
}
53         if (!(config instanceof WarDeploymentConfiguration)) {
54             throw new IllegalArgumentException JavaDoc("Wrong DeploymentConfiguration instance " + config.getClass().getName()); // NOI18N
55
}
56         return ((WarDeploymentConfiguration)config).getContextPath();
57     }
58     
59     public void setWebContextRoot(DeploymentConfiguration JavaDoc config, DeployableObject JavaDoc deplObj, String JavaDoc contextRoot)
60             throws ConfigurationException JavaDoc {
61         if (config.getDeployableObject().getType() != ModuleType.WAR) {
62             throw new ConfigurationException JavaDoc("This operation is supported only by the WAR modules."); // NOI18N
63
}
64         if (!(config instanceof WarDeploymentConfiguration)) {
65             throw new IllegalArgumentException JavaDoc("Wrong DeploymentConfiguration instance " + config.getClass().getName()); // NOI18N
66
}
67         ((WarDeploymentConfiguration)config).setContextPath(contextRoot);
68     }
69     
70     public void initConfiguration(DeploymentConfiguration JavaDoc config, File JavaDoc[] files,
71             File JavaDoc resourceDir, boolean keepUpdated) throws ConfigurationException JavaDoc {
72         if (!(config instanceof OC4JDeploymentConfiguration)) {
73             throw new IllegalArgumentException JavaDoc("Wrong DeploymentConfiguration instance " + config.getClass().getName()); // NOI18N
74
}
75         if (files == null || files.length != 1) {
76             throw new IllegalArgumentException JavaDoc("Invalid value of the files argument."); // NOI18N
77
}
78         ModuleType JavaDoc type = config.getDeployableObject().getType();
79         if (type == ModuleType.WAR) {
80             ((WarDeploymentConfiguration)config).init(files[0], resourceDir);
81         } else if (type == ModuleType.EAR) {
82             ((EarDeploymentConfiguration)config).init(files[0], resourceDir);
83         } else if (type == ModuleType.EJB) {
84             ((EjbDeploymentConfiguration)config).init(files[0], resourceDir);
85         } else {
86             assert true : "Unsupported module type: " + type.toString(); // NOI18N
87
}
88     }
89     
90     public void disposeConfiguration(DeploymentConfiguration JavaDoc config) {
91         if (!(config instanceof OC4JDeploymentConfiguration)) {
92             throw new IllegalArgumentException JavaDoc("Wrong DeploymentConfiguration instance " + config.getClass().getName()); // NOI18N
93
}
94     }
95     
96     public void updateResourceDir(DeploymentConfiguration JavaDoc config, File JavaDoc resourceDir) {
97         // no op
98
}
99     
100     public Set JavaDoc<Datasource> getDatasources(DeploymentConfiguration JavaDoc config) {
101         Set JavaDoc<Datasource> projectDS = ((OC4JDeploymentConfiguration)config).getDatasources();
102         return projectDS;
103     }
104     
105     public boolean isDatasourceCreationSupported() {
106         return true;
107     }
108     
109     public Datasource createDatasource(DeploymentConfiguration JavaDoc config, String JavaDoc jndiName, String JavaDoc url, String JavaDoc username, String JavaDoc password, String JavaDoc driver)
110             throws OperationUnsupportedException JavaDoc, ConfigurationException JavaDoc, DatasourceAlreadyExistsException {
111         OC4JDatasource ds = ((OC4JDeploymentConfiguration)config).createDatasource(jndiName, url, username, password, driver);
112         return ds;
113     }
114 }
Popular Tags