KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > config > impl > AppServConfigProvider


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt.config.impl;
24
25 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
26 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
27 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
28
29 import java.util.List JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import com.sun.enterprise.config.serverbeans.ServerHelper;
32 import com.sun.enterprise.config.serverbeans.ApplicationHelper;
33 import com.sun.enterprise.config.ConfigBean;
34 import com.sun.enterprise.config.serverbeans.ApplicationRef;
35 import com.sun.enterprise.config.ConfigContext;
36 import com.sun.enterprise.config.ConfigException;
37 import com.sun.enterprise.server.ApplicationServer;
38
39 import com.sun.enterprise.config.serverbeans.WebServiceEndpoint;
40 import com.sun.enterprise.config.serverbeans.WebModule;
41 import com.sun.enterprise.config.serverbeans.EjbModule;
42 import com.sun.enterprise.config.serverbeans.J2eeApplication;
43
44 /**
45  * This is the mechanism to access web service management configuration.
46  * <br>
47  */

48 public class AppServConfigProvider implements ConfigProvider
49 {
50
51     /**
52      * Returns the unique identifier for this RepositoryProvider object.
53      *
54      * @return fully qualified class name of this RepositoryProvider
55      */

56     public String JavaDoc getProviderID() {
57         return ConfigFactory.CONFIG_DEFAULT_PROVIDER;
58     }
59
60     /**
61      * Returns the list of Web Service Endpoint config in this application
62      *
63      * @param appName Name of the application
64      *
65      * @return the array of WebServiceConfig
66      */

67     public WebServiceConfig[] getWebserviceConfigs(String JavaDoc appId) {
68         WebServiceEndpoint[] wsps = getWebServiceEndpoints(appId);
69
70         WebServiceConfig[] wsCfgs = new WebServiceConfig[wsps.length];
71         for (int idx =0; idx < wsps.length; idx++) {
72            wsCfgs[idx] = new WebServiceConfigImpl(wsps[idx]);
73         }
74         return wsCfgs;
75     }
76
77     WebServiceEndpoint[] getWebServiceEndpoints(String JavaDoc appId) {
78         WebServiceEndpoint[] wsps = null;
79         try {
80             ConfigContext ctx = ApplicationServer.getServerContext().
81                                                 getConfigContext();
82
83             ConfigBean cb = ApplicationHelper.findApplication(ctx, appId);
84
85             // check if web service endpoint is configured for this
86
// application/module, then ruturn this app
87

88             if ( cb instanceof WebModule) {
89                 wsps = ( (WebModule) cb).getWebServiceEndpoint();
90             } else if ( cb instanceof EjbModule) {
91                 wsps = ( (EjbModule) cb).getWebServiceEndpoint();
92             } else if (cb instanceof J2eeApplication) {
93                 wsps = ( (J2eeApplication) cb).getWebServiceEndpoint();
94             }
95
96         } catch (ConfigException ce) {
97             // XX throw exception
98
} finally {
99             return wsps;
100         }
101     }
102
103     /**
104      * Returns the list of Web Service Endpoint config in this application
105      *
106      * @param appName Name of the application
107      *
108      * @return the array of WebServiceConfig
109      */

110     public WebServiceConfig getWebServiceConfig(String JavaDoc appId, String JavaDoc modId,
111         boolean isStandalone, String JavaDoc name) {
112
113         WebServiceEndpoint[] wsps = getWebServiceEndpoints(appId);
114
115         for (int idx =0; idx < wsps.length; idx++) {
116            String JavaDoc sName = null;
117            if ( isStandalone ) {
118                 sName = name;
119            } else {
120                 sName = modId + "#" + name;
121            }
122            if ( wsps[idx].getName().equals(sName) ) {
123             return new WebServiceConfigImpl(wsps[idx]);
124            }
125         }
126         return null;
127     }
128
129
130     /**
131      * Returns the Web Service Endpoint config in this endpoint
132      *
133      * @param fqn Fully Qualified Name of the endpoint
134      *
135      * @return the WebServiceConfig
136      */

137     public WebServiceConfig getWebServiceConfig(String JavaDoc fqn) {
138
139     if (fqn==null) return null;
140     String JavaDoc appId = null;
141     int sepIdx = fqn.indexOf("#");
142     appId = fqn.substring(0, sepIdx);
143     String JavaDoc partialName = fqn.substring(sepIdx +1);
144
145         WebServiceEndpoint[] wsps = getWebServiceEndpoints(appId);
146
147         for (int idx =0; idx < wsps.length; idx++) {
148            if ( wsps[idx].getName().equals(partialName) ) {
149             return new WebServiceConfigImpl(wsps[idx]);
150            }
151         }
152         return null;
153     }
154
155     /**
156      * Returns a list of application or stand alone module ids
157      * currently configured for web service management.
158      *
159      * @return managed web service application ids
160      */

161     public List JavaDoc getManagedWebserviceApplicationIds() {
162
163         List JavaDoc aList = new ArrayList JavaDoc();
164         try {
165             ConfigContext ctx = ApplicationServer.getServerContext().
166                                                 getConfigContext();
167
168             String JavaDoc serverName =
169             ApplicationServer.getServerContext().getInstanceName();
170
171             ApplicationRef[] appRefs =ServerHelper.getApplicationReferences(ctx,
172             serverName);
173             for ( int appIdx =0; appIdx < appRefs.length; appIdx++) {
174                 String JavaDoc appName = appRefs[appIdx].getRef();
175                 ConfigBean cb = ApplicationHelper.findApplication(ctx, appName);
176                 // check if web service endpoint is configured for this
177
// application/module, then ruturn this app
178

179                 int wsSize = 0;
180
181                 if ( cb instanceof WebModule) {
182                     wsSize = ( (WebModule) cb).sizeWebServiceEndpoint();
183                 } else if ( cb instanceof EjbModule) {
184                     wsSize = ( (EjbModule) cb).sizeWebServiceEndpoint();
185                 } else if (cb instanceof J2eeApplication) {
186                     wsSize = ( (J2eeApplication) cb).sizeWebServiceEndpoint();
187                 }
188
189                 if (wsSize > 0) { aList.add(appName); }
190             }
191         } catch (ConfigException ce) {
192             // XX throw exception
193
} finally {
194             return aList;
195         }
196     }
197
198 }
199
Popular Tags