KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ondemand > WebServiceGroup


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
24 package com.sun.enterprise.server.ondemand;
25
26
27 import java.util.logging.Logger JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.config.*;
32 import com.sun.enterprise.config.serverbeans.*;
33 import com.sun.appserv.server.ServerLifecycle;
34 import com.sun.appserv.server.ServerLifecycleException;
35 import com.sun.enterprise.server.ondemand.entry.EntryContext;
36 import com.sun.enterprise.server.ondemand.entry.EntryPoint;
37 import com.sun.enterprise.server.ServerContext;
38 import com.sun.enterprise.appclient.jws.AppclientJWSSupportManager;
39
40 /**
41  * Represents the group services needed by web apps. The main components
42  * of this servicegroup Webcontainer and admin apps.
43  *
44  * @author Binod PG
45  * @see ServiceGroup
46  * @see ServiceGroupBuilder
47  */

48 public class WebServiceGroup extends ServiceGroup {
49
50     /**
51      * Triggers the start of the servicegroup. The entry context
52      * that caused this startup is used by the servicegroup to obtain
53      * any startup information it require.
54      *
55      * @param context EntryContext object.
56      * @see EntryContext.
57      */

58     public void start(EntryContext context) throws ServiceGroupException {
59         try {
60             startLifecycleServices(context.getServerContext());
61             loadSystemApps();
62             AppclientJWSSupportManager.getInstance().
63             startJWSServicesForDeployedAppclients();
64             setState(ServiceGroup.STARTED);
65         } catch (Exception JavaDoc e) {
66             throw new ServiceGroupException (e);
67         }
68     }
69
70     /**
71      * Loads all the system apps belongs to this servicegroup.
72      * @see OnDemandServices
73      * @see SystemAppLoader
74      */

75     private void loadSystemApps() {
76         SystemAppLoader loader = OnDemandServer.getSystemAppLoader();
77         loader.loadSystemApps(loader.getWebServiceGroupSystemApps());
78     }
79
80     /**
81      * Analyse the entrycontext and specifies whether this servicegroup
82      * can be started or not.
83      *
84      * @return boolean If true is returned, this servicegroup can be started
85      * If false is returned, the entrycontext is not recognized by the
86      * servicegroup.
87      */

88     public boolean analyseEntryContext( EntryContext context ) {
89
90         if (_logger.isLoggable(Level.FINER)) {
91             _logger.log(Level.FINER,
92             "Analysing the context in Web ServiceGroup :" + context);
93         }
94
95         if (context.get() == null) {
96             return false;
97         }
98
99         boolean result = false;
100         try {
101             ConfigContext ctxt = context.getServerContext().getConfigContext();
102             Config conf = ServerBeansFactory.getConfigBean( ctxt );
103
104             if (context.getEntryPointType() == EntryPoint.APPLOADER ) {
105                 Descriptor desc = (Descriptor) context.get();
106                 if (desc instanceof Application) {
107                     // has atleast one webcomponent or
108
// Atleast one component has webservice
109
result = !((Application) desc).getWebBundleDescriptors().isEmpty() ||
110                              !((Application) desc).getWebServiceDescriptors().isEmpty();
111                 } else if (desc instanceof EjbBundleDescriptor) {
112                     result = ((EjbBundleDescriptor) desc).hasWebServices();
113                 } else if (desc instanceof EjbAbstractDescriptor) {
114                     result = ((EjbAbstractDescriptor) desc).hasWebServiceEndpointInterface();
115                 } else {
116                     result = desc instanceof WebBundleDescriptor ||
117                              desc instanceof WebServicesDescriptor;
118                 }
119             }
120
121             if ( context.getEntryPointType() == EntryPoint.JNDI ) {
122                /*
123                no.op. You cant access this servicegroup via JNDI.
124                */

125             }
126
127             if ( context.getEntryPointType() == EntryPoint.PORT ) {
128             // Start HTTP listener ports
129
HttpService httpService = conf.getHttpService();
130             HttpListener[] httpListeners = httpService.getHttpListener();
131             for ( int i=0; i<httpListeners.length; i++ ) {
132                 int port = Integer.parseInt(httpListeners[i].getPort());
133                     if (port == ((Integer JavaDoc) context.get()).intValue() ) {
134                         result = true;
135                     }
136                 }
137         }
138
139             if (context.getEntryPointType() == EntryPoint.MBEAN) {
140                 result = analyseObjectName((ObjectName JavaDoc) context.get());
141             }
142         } catch (Exception JavaDoc e) {
143             e.printStackTrace();
144             result = false;
145         }
146
147         return result;
148     }
149
150     // Does the objectname belongs to any of the system apps
151
// in this servicegroup.
152
private boolean analyseObjectName(ObjectName JavaDoc name) {
153
154         /*
155         if (name == null) {
156             return true;
157         }
158
159         String cat = name.getKeyProperty("category");
160         if (cat != null && cat.equals("monitor")) {
161             return true;
162         }
163         */

164
165         String JavaDoc type = name.getKeyProperty("type");
166         if ((type != null) && type.equals("Loader")) {
167              return true;
168         }
169
170         String JavaDoc j2eeType = name.getKeyProperty("j2eeType");
171         if ((j2eeType != null) &&
172              j2eeType.equals("WebModule")) {
173              return true;
174         }
175
176         if (name.getKeyProperty("WebModule") != null) {
177             return true;
178         }
179
180         String JavaDoc nameStr = name.getKeyProperty("name");
181         String JavaDoc ref = name.getKeyProperty("ref");
182         String JavaDoc app = name.getKeyProperty("J2EEApplication");
183
184         return belongsToThisServiceGroup(nameStr) ||
185                   belongsToThisServiceGroup(ref) ||
186                   belongsToThisServiceGroup(app);
187
188
189     }
190
191     private boolean belongsToThisServiceGroup(String JavaDoc name) {
192       SystemAppLoader appLoader = OnDemandServer.getSystemAppLoader();
193         if (appLoader != null) {
194             for (Object JavaDoc n : appLoader.getWebServiceGroupSystemApps()) {
195                 if (((String JavaDoc) n).equals(name)) {
196                     return true;
197                 }
198             }
199         }
200         return false;
201     }
202  
203
204     /**
205      * Start lifecycles belonging to this service group.
206      * @see OnDemandServices
207      */

208     private void startLifecycleServices(ServerContext context) {
209         String JavaDoc[][] services = OnDemandServices.getWebServiceGroupServices();
210         super.startLifecycleServices(services, context);
211     }
212
213     /**
214      * Stop the servicegroup. It stops all the lifecycle modules belongs to this
215      * servicegroup.
216      */

217     public void stop(EntryContext context) throws ServiceGroupException {
218        super.stopLifecycleServices();
219     }
220
221     /**
222      * Abort the servicegroup. This is not called from anywhere as of now.
223      */

224     public void abort(EntryContext context) {
225        super.stopLifecycleServices();
226     }
227 }
228
Popular Tags