KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > WSJ2eeApplicationObject


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 package org.netbeans.modules.j2ee.websphere6;
20
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.lang.reflect.Method JavaDoc;
23 import javax.enterprise.deploy.model.*;
24 import javax.enterprise.deploy.shared.*;
25 import org.netbeans.modules.j2ee.deployment.devmodules.spi.*;
26 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider.ConfigSupport;
27 import java.util.*;
28 import org.openide.*;
29
30 /**
31  * Wrapper for the j2eeserver's implementation of DeployableObject. This
32  * class extends WSDeployableObject and all the altered logic goes in there,
33  * thus here we only delegate the calls to the j2eeserver's object
34  *
35  * @author Dmitry Lipin
36  * @author Kirill Sorokin
37  * @author Stepan Herold
38  *
39  */

40 public class WSJ2eeApplicationObject extends WSDeployableObject
41         implements J2eeApplicationObject {
42     
43     /**
44      * Handle for the j2eeserver's implementation
45      */

46     private DeployableObject j2eeApplicationObject;
47     
48     /**
49      * Creates a new instance of WSJ2eeApplicationObject.
50      *
51      * @param DeployableObject the j2eeserver's implementation
52      */

53     public WSJ2eeApplicationObject(
54             DeployableObject deployableObject) {
55         // call the WSdeployableObject's constructor
56
super(deployableObject);
57         j2eeApplicationObject=deployableObject;
58     }
59     
60     private Map<String JavaDoc, DeployableObject> buildChildMap() {
61         Map<String JavaDoc, DeployableObject> childMap = new HashMap<String JavaDoc, DeployableObject>();
62         
63         J2eeAppProvider j2eeAppProvider = null;
64         
65         try {
66             Method JavaDoc method = deployableObject.getClass().
67                     getMethod("getProvider", new Class JavaDoc[0]); // NOI18N
68
j2eeAppProvider = (J2eeAppProvider) method.
69                     invoke(deployableObject, new Object JavaDoc[0]);
70         } catch (IllegalAccessException JavaDoc e) {
71             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
72         } catch (NoSuchMethodException JavaDoc e) {
73             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
74         } catch (InvocationTargetException JavaDoc e) {
75             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
76         }
77         
78         J2eeModuleProvider[] moduleProviders = j2eeAppProvider.getChildModuleProviders();
79         
80         DDBeanRoot ddBeanRoot = deployableObject.getDDBeanRoot();
81         
82         if (ddBeanRoot != null) {
83             ArrayList<String JavaDoc> childUris = new ArrayList<String JavaDoc>();
84             childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/connector"))); // NOI18N
85
childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/ejb"))); // NOI18N
86
childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/java"))); // NOI18N
87
childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/web/web-uri"))); // NOI18N
88
for (String JavaDoc uri : childUris) {
89                 J2eeModuleProvider moduleProvider = j2eeAppProvider.getChildModuleProvider(uri);
90                 
91                 DeployableObject dObj=null;
92                 try {
93                     ConfigSupport cs = moduleProvider.getConfigSupport();
94                     
95                     Method JavaDoc method = cs.getClass().
96                             getMethod("getDeployableObject", new Class JavaDoc[] {String JavaDoc.class}); // NOI18N
97

98                     dObj = (DeployableObject) method.
99                             invoke(cs, new Object JavaDoc[] {null});
100                     
101                 } catch (IllegalAccessException JavaDoc e) {
102                     ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
103                 } catch (NoSuchMethodException JavaDoc e) {
104                     ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
105                 } catch (InvocationTargetException JavaDoc e) {
106                     ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
107                 }
108                 childMap.put(uri, dObj);
109             }
110         }
111         
112         return childMap;
113     }
114     
115     
116     /**
117      * Delegates the call to the j2eeserver's implementation, returning the
118      * result if necessary.
119      */

120     public DeployableObject[] getDeployableObjects() {
121         Map<String JavaDoc, DeployableObject> childMap = buildChildMap();
122         
123         return (DeployableObject[]) childMap.values().toArray(new DeployableObject[childMap.size()]);
124     }
125     
126     /**
127      * Delegates the call to the j2eeserver's implementation, returning the
128      * result if necessary.
129      */

130     public DeployableObject getDeployableObject(String JavaDoc uri) {
131         Map<String JavaDoc, DeployableObject> childMap = buildChildMap();
132         
133         return (DeployableObject) childMap.get(uri);
134     }
135     
136     /**
137      * Delegates the call to the j2eeserver's implementation, returning the
138      * result if necessary.
139      */

140     public DeployableObject[] getDeployableObjects(ModuleType moduleType) {
141         Map<String JavaDoc, DeployableObject> childMap = buildChildMap();
142         
143         ArrayList<DeployableObject> result = new ArrayList<DeployableObject>();
144         for (String JavaDoc uri : childMap.keySet()) {
145             DeployableObject deplObj = childMap.get(uri);
146             if (moduleType.equals(deplObj.getType())) {
147                 result.add(deplObj);
148             }
149         }
150         return (DeployableObject[]) result.toArray(new DeployableObject[result.size()]);
151     }
152     
153     /**
154      * Delegates the call to the j2eeserver's implementation, returning the
155      * result if necessary.
156      */

157     public String JavaDoc[] getText(ModuleType moduleType, String JavaDoc xpath) {
158         DeployableObject[] deployableObjects = getDeployableObjects(moduleType);
159         ArrayList<String JavaDoc> result = new ArrayList<String JavaDoc>();
160         for (DeployableObject deplObj : deployableObjects) {
161             result.addAll(Arrays.asList(deplObj.getText(xpath)));
162         }
163         return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
164     }
165     
166     /**
167      * Delegates the call to the j2eeserver's implementation, returning the
168      * result if necessary.
169      */

170     public DDBean[] getChildBean(ModuleType moduleType, String JavaDoc xpath) {
171         DeployableObject[] deployableObjects = getDeployableObjects(moduleType);
172         ArrayList<DDBean> result = new ArrayList<DDBean>();
173         for (DeployableObject deplObj : deployableObjects) {
174             result.addAll(Arrays.asList(deplObj.getChildBean(xpath)));
175         }
176         return (DDBean[]) result.toArray(new DDBean[result.size()]);
177     }
178     
179     /**
180      * Delegates the call to the j2eeserver's implementation, returning the
181      * result if necessary.
182      */

183     public String JavaDoc[] getModuleUris() {
184         Map<String JavaDoc, DeployableObject> childMap = buildChildMap();
185         
186         return (String JavaDoc[]) childMap.keySet().toArray(new String JavaDoc[childMap.size()]);
187     }
188     
189     public String JavaDoc[] getModuleUris(ModuleType type){
190         Map<String JavaDoc, DeployableObject> childMap = buildChildMap();
191         
192         ArrayList<String JavaDoc> result = new ArrayList<String JavaDoc>();
193         for (String JavaDoc uri : childMap.keySet()) {
194             if (type.equals(childMap.get(uri).getType())) {
195                 result.add(uri);
196             }
197         }
198         return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
199     }
200     
201     
202     /**
203      * Delegates the call to the j2eeserver's implementation, returning the
204      * result if necessary.
205      */

206     public void addXpathListener(ModuleType moduleType, String JavaDoc xpath,
207             XpathListener xpl) {
208         for (DeployableObject deplObj : getDeployableObjects(moduleType)) {
209             deplObj.getDDBeanRoot().addXpathListener(xpath, xpl);
210         }
211     }
212     
213     /**
214      * Delegates the call to the j2eeserver's implementation, returning the
215      * result if necessary.
216      */

217     public void removeXpathListener(ModuleType moduleType, String JavaDoc xpath,
218             XpathListener xpl) {
219         for (DeployableObject deplObj : getDeployableObjects(moduleType)) {
220             deplObj.getDDBeanRoot().removeXpathListener(xpath, xpl);
221         }
222     }
223     
224 }
225
Popular Tags