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.deployment;
021:
022: import org.apache.axiom.om.OMAttribute;
023: import org.apache.axiom.om.OMElement;
024: import org.apache.axis2.AxisFault;
025: import org.apache.axis2.context.ConfigurationContext;
026: import org.apache.axis2.description.AxisService;
027: import org.apache.axis2.description.AxisServiceGroup;
028: import org.apache.axis2.description.ModuleConfiguration;
029: import org.apache.axis2.description.ParameterInclude;
030: import org.apache.axis2.i18n.Messages;
031:
032: import javax.xml.namespace.QName;
033: import java.util.ArrayList;
034: import java.util.HashMap;
035: import java.util.Iterator;
036:
037: public class ServiceGroupBuilder extends DescriptionBuilder {
038: private OMElement serviceElement;
039: private HashMap wsdlServices;
040:
041: public ServiceGroupBuilder(OMElement service, HashMap wsdlServices,
042: ConfigurationContext configCtx) {
043: this .serviceElement = service;
044: this .wsdlServices = wsdlServices;
045: this .configCtx = configCtx;
046: this .axisConfig = this .configCtx.getAxisConfiguration();
047: }
048:
049: public ArrayList populateServiceGroup(
050: AxisServiceGroup axisServiceGroup)
051: throws DeploymentException {
052: ArrayList serviceList = new ArrayList();
053:
054: try {
055:
056: // Processing service level parameters
057: Iterator itr = serviceElement
058: .getChildrenWithName(new QName(TAG_PARAMETER));
059:
060: processParameters(itr, axisServiceGroup, axisServiceGroup
061: .getParent());
062:
063: Iterator moduleConfigs = serviceElement
064: .getChildrenWithName(new QName(TAG_MODULE_CONFIG));
065:
066: processServiceModuleConfig(moduleConfigs, axisServiceGroup
067: .getParent(), axisServiceGroup);
068:
069: // processing service-wide modules which required to engage globally
070: Iterator moduleRefs = serviceElement
071: .getChildrenWithName(new QName(TAG_MODULE));
072:
073: processModuleRefs(moduleRefs, axisServiceGroup);
074:
075: Iterator serviceitr = serviceElement
076: .getChildrenWithName(new QName(TAG_SERVICE));
077:
078: while (serviceitr.hasNext()) {
079: OMElement service = (OMElement) serviceitr.next();
080: OMAttribute serviceNameatt = service
081: .getAttribute(new QName(ATTRIBUTE_NAME));
082: if (serviceNameatt == null) {
083: throw new DeploymentException(
084: Messages
085: .getMessage(DeploymentErrorMsgs.SERVICE_NAME_ERROR));
086: }
087: String serviceName = serviceNameatt.getAttributeValue();
088:
089: if (serviceName == null || "".equals(serviceName)) {
090: throw new DeploymentException(
091: Messages
092: .getMessage(DeploymentErrorMsgs.SERVICE_NAME_ERROR));
093: } else {
094: AxisService axisService = (AxisService) wsdlServices
095: .get(serviceName);
096:
097: if (axisService == null) {
098: axisService = new AxisService(serviceName);
099: } else {
100: axisService.setWsdlFound(true);
101: axisService.setCustomWsdl(true);
102: }
103:
104: // the service that has to be deployed
105: axisService.setParent(axisServiceGroup);
106: axisService.setClassLoader(axisServiceGroup
107: .getServiceGroupClassLoader());
108:
109: ServiceBuilder serviceBuilder = new ServiceBuilder(
110: configCtx, axisService);
111: AxisService as = serviceBuilder
112: .populateService(service);
113: serviceList.add(as);
114: }
115: }
116: } catch (AxisFault e) {
117: throw new DeploymentException(e);
118: }
119:
120: return serviceList;
121: }
122:
123: /**
124: * Gets the list of modules that is required to be engaged globally.
125: *
126: * @param moduleRefs <code>java.util.Iterator</code>
127: * @throws DeploymentException <code>DeploymentException</code>
128: */
129: protected void processModuleRefs(Iterator moduleRefs,
130: AxisServiceGroup axisServiceGroup)
131: throws DeploymentException {
132: try {
133: while (moduleRefs.hasNext()) {
134: OMElement moduleref = (OMElement) moduleRefs.next();
135: OMAttribute moduleRefAttribute = moduleref
136: .getAttribute(new QName(TAG_REFERENCE));
137:
138: if (moduleRefAttribute != null) {
139: String refName = moduleRefAttribute
140: .getAttributeValue();
141:
142: if (axisConfig.getModule(refName) == null) {
143: throw new DeploymentException(
144: Messages
145: .getMessage(
146: DeploymentErrorMsgs.MODULE_NOT_FOUND,
147: refName));
148: } else {
149: axisServiceGroup.addModuleref(refName);
150: }
151: }
152: }
153: } catch (AxisFault axisFault) {
154: throw new DeploymentException(axisFault);
155: }
156: }
157:
158: protected void processServiceModuleConfig(Iterator moduleConfigs,
159: ParameterInclude parent, AxisServiceGroup axisService)
160: throws DeploymentException {
161: while (moduleConfigs.hasNext()) {
162: OMElement moduleConfig = (OMElement) moduleConfigs.next();
163: OMAttribute moduleName_att = moduleConfig
164: .getAttribute(new QName(ATTRIBUTE_NAME));
165:
166: if (moduleName_att == null) {
167: throw new DeploymentException(
168: Messages
169: .getMessage(DeploymentErrorMsgs.INVALID_MODULE_CONFIG));
170: } else {
171: String module = moduleName_att.getAttributeValue();
172: ModuleConfiguration moduleConfiguration = new ModuleConfiguration(
173: module, parent);
174: Iterator parameters = moduleConfig
175: .getChildrenWithName(new QName(TAG_PARAMETER));
176:
177: processParameters(parameters, moduleConfiguration,
178: parent);
179: axisService.addModuleConfig(moduleConfiguration);
180: }
181: }
182: }
183: }
|