001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.description;
021:
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.engine.AxisConfiguration;
024: import org.apache.axis2.engine.AxisEvent;
025: import org.apache.axis2.i18n.Messages;
026: import org.apache.axis2.modules.Module;
027:
028: import java.util.ArrayList;
029: import java.util.HashMap;
030: import java.util.Iterator;
031:
032: public class AxisServiceGroup extends AxisDescription {
033:
034: //to check whether user has put WWW dir or not
035: private boolean foundWebResources;
036: // to store module ref at deploy time parsing
037: private ArrayList modulesList = new ArrayList();
038:
039: // to store modeule configuration info
040: private HashMap moduleConfigmap;
041:
042: // class loader
043: private ClassLoader serviceGroupClassLoader;
044:
045: // to keep name of the service group
046: private String serviceGroupName;
047:
048: public AxisServiceGroup() {
049: moduleConfigmap = new HashMap();
050: }
051:
052: public AxisServiceGroup(AxisConfiguration axisDescription) {
053: this ();
054: setParent(axisDescription);
055: }
056:
057: /**
058: * Adds module configuration, if there is moduleConfig tag in service.
059: *
060: * @param moduleConfiguration the ModuleConfiguration to add
061: */
062: public void addModuleConfig(ModuleConfiguration moduleConfiguration) {
063: if (moduleConfigmap == null) {
064: moduleConfigmap = new HashMap();
065: }
066:
067: moduleConfigmap.put(moduleConfiguration.getModuleName(),
068: moduleConfiguration);
069: }
070:
071: public void addModuleref(String moduleref) {
072: modulesList.add(moduleref);
073: }
074:
075: public void addService(AxisService service) throws AxisFault {
076: if (service == null) {
077: return;
078: }
079:
080: if (serviceGroupName == null) {
081: // setup a temporary name based on the first service under this group
082: serviceGroupName = service.getName();
083: }
084:
085: service.setParent(this );
086:
087: AxisConfiguration axisConfig = getAxisConfiguration();
088:
089: if (axisConfig != null) {
090: for (Iterator iterator = getEngagedModules().iterator(); iterator
091: .hasNext();) {
092: Object o = iterator.next();
093: AxisModule axisModule;
094: if (o instanceof AxisModule) {
095: axisModule = (AxisModule) o;
096: } else if (o instanceof String) { //Should this be checked
097: String moduleName = (String) o;
098: axisModule = axisConfig.getModule(moduleName);
099: if (axisModule == null) {
100: throw new AxisFault(Messages.getMessage(
101: "modulenotavailble", moduleName));
102: }
103: } else {
104: throw new AxisFault(Messages
105: .getMessage("modulenotavailble"));
106: }
107: service.engageModule(axisModule);
108: }
109:
110: }
111: service.setLastupdate();
112: addChild(service);
113: if (axisConfig != null) {
114: axisConfig.addToAllServicesMap(service);
115: }
116: }
117:
118: /**
119: *
120: * @param service
121: * @throws Exception
122: * @deprecated please use addService() instead
123: */
124: public void addToGroup(AxisService service) throws Exception {
125: addService(service);
126: }
127:
128: /**
129: * When a module gets engaged on a ServiceGroup, we have to engage it for each Service.
130: *
131: * @param module the newly-engaged AxisModule
132: * @param engager
133: * @throws AxisFault if there is a problem
134: */
135: protected void onEngage(AxisModule module, AxisDescription engager)
136: throws AxisFault {
137: for (Iterator serviceIter = getServices(); serviceIter
138: .hasNext();) {
139: AxisService axisService = (AxisService) serviceIter.next();
140: axisService.engageModule(module, engager);
141: }
142: }
143:
144: public void onDisengage(AxisModule module) throws AxisFault {
145: for (Iterator serviceIter = getServices(); serviceIter
146: .hasNext();) {
147: AxisService axisService = (AxisService) serviceIter.next();
148: axisService.disengageModule(module);
149: }
150: }
151:
152: public void removeService(String name) throws AxisFault {
153: AxisService service = getService(name);
154:
155: if (service != null) {
156: getAxisConfiguration().notifyObservers(
157: AxisEvent.SERVICE_REMOVE, service);
158: }
159:
160: removeChild(name);
161: }
162:
163: public ModuleConfiguration getModuleConfig(String moduleName) {
164: return (ModuleConfiguration) moduleConfigmap.get(moduleName);
165: }
166:
167: public ArrayList getModuleRefs() {
168: return modulesList;
169: }
170:
171: public AxisService getService(String name) throws AxisFault {
172: return (AxisService) getChild(name);
173: }
174:
175: public ClassLoader getServiceGroupClassLoader() {
176: return serviceGroupClassLoader;
177: }
178:
179: public String getServiceGroupName() {
180: // Note: if the serviceGroupName is not set, then this could be null.
181: // If the serviceGroupName has not been set and a service is added to this group,
182: // then the serviceGroupName will default to the name of the first service
183: return serviceGroupName;
184: }
185:
186: public Iterator getServices() {
187: return getChildren();
188: }
189:
190: public void setAxisDescription(AxisConfiguration axisDescription) {
191: setParent(axisDescription);
192: }
193:
194: public void setServiceGroupClassLoader(
195: ClassLoader serviceGroupClassLoader) {
196: this .serviceGroupClassLoader = serviceGroupClassLoader;
197: }
198:
199: public void setServiceGroupName(String serviceGroupName) {
200: this .serviceGroupName = serviceGroupName;
201: }
202:
203: public Object getKey() {
204: // Note: if the serviceGroupName is not set, then this could be null.
205: // If the serviceGroupName has not been set and a service is added to this group,
206: // then the serviceGroupName will default to the name of the first service
207: return this .serviceGroupName;
208: }
209:
210: public boolean isFoundWebResources() {
211: return foundWebResources;
212: }
213:
214: public void setFoundWebResources(boolean foundWebResources) {
215: this.foundWebResources = foundWebResources;
216: }
217: }
|