001: /*
002: * Copyright 2004,2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.axis2.description;
018:
019: import org.apache.axiom.om.OMElement;
020: import org.apache.axis2.AxisFault;
021: import org.apache.axis2.engine.AxisConfiguration;
022: import org.apache.axis2.i18n.Messages;
023: import org.apache.axis2.modules.Module;
024:
025: import javax.xml.namespace.QName;
026: import java.net.URL;
027: import java.util.ArrayList;
028: import java.util.HashMap;
029:
030: /**
031: * <p>This holds the information about a Module. </p>
032: * <ol>
033: * <li>parameters<li>
034: * <li>handlers<li>
035: * <ol>
036: * <p>Handler are registered once they are available. They are available to all services if axis2.xml
037: * has a module ref="." or available to a single service if services.xml have module ref=".."</p>
038: */
039: public class AxisModule implements ParameterInclude {
040:
041: /**
042: * Field flowInclude
043: */
044: private final FlowInclude flowInclude = new FlowInclude();
045:
046: /**
047: * Field parameters
048: */
049: private final ParameterInclude parameters = new ParameterIncludeImpl();
050: private Module module;
051: private ClassLoader moduleClassLoader;
052: // To keep the File that module came from
053: private URL fileName;
054:
055: /**
056: * Field name
057: */
058: private String name;
059:
060: //This is to keep the version number of the module, if the module name is a-b-c-1.3.mar ,
061: // then the module version would be 1.3
062: private String version;
063:
064: // to store module operations , which are suppose to be added to a service if it is engaged to a service
065: private HashMap operations = new HashMap();
066: private AxisConfiguration parent;
067:
068: /*
069: * to store policies which are valid for any service for which the module is engaged
070: */
071: private PolicyInclude policyInclude = null;
072:
073: // Small description about the module
074: private String moduleDescription;
075:
076: private String[] supportedPolicyNames;
077:
078: private QName[] localPolicyAssertions;
079: public static final String VERSION_SNAPSHOT = "SNAPSHOT";
080: public static final String MODULE_SERVICE = "moduleService";
081:
082: /**
083: * Constructor ModuleDescription.
084: */
085: public AxisModule() {
086: }
087:
088: /**
089: * Constructor ModuleDescription.
090: *
091: * @param name : Name of the module
092: */
093: public AxisModule(String name) {
094: this .name = name;
095: }
096:
097: public void addOperation(AxisOperation axisOperation) {
098: operations.put(axisOperation.getName(), axisOperation);
099: }
100:
101: /**
102: * @param param : Parameter to be added
103: */
104: public void addParameter(Parameter param) throws AxisFault {
105: if (isParameterLocked(param.getName())) {
106: throw new AxisFault(Messages.getMessage(
107: "paramterlockedbyparent", param.getName()));
108: } else {
109: parameters.addParameter(param);
110: }
111: }
112:
113: public void removeParameter(Parameter param) throws AxisFault {
114: if (isParameterLocked(param.getName())) {
115: throw new AxisFault(Messages.getMessage(
116: "paramterlockedbyparent", param.getName()));
117: } else {
118: parameters.removeParameter(param);
119: }
120: }
121:
122: public void deserializeParameters(OMElement parameterElement)
123: throws AxisFault {
124: this .parameters.deserializeParameters(parameterElement);
125: }
126:
127: /**
128: * @return Returns Flow.
129: */
130: public Flow getFaultInFlow() {
131: return flowInclude.getFaultInFlow();
132: }
133:
134: public Flow getFaultOutFlow() {
135: return flowInclude.getFaultOutFlow();
136: }
137:
138: /**
139: * @return Returns Flow.
140: */
141: public Flow getInFlow() {
142: return flowInclude.getInFlow();
143: }
144:
145: /**
146: * @return Returns Module.
147: */
148: public Module getModule() {
149: return module;
150: }
151:
152: public ClassLoader getModuleClassLoader() {
153: return moduleClassLoader;
154: }
155:
156: /**
157: * Get the name of this Module
158: * @return a String name.
159: */
160: public String getName() {
161: return name;
162: }
163:
164: public HashMap getOperations() {
165: return operations;
166: }
167:
168: /**
169: * @return Returns Flow.
170: */
171: public Flow getOutFlow() {
172: return flowInclude.getOutFlow();
173: }
174:
175: /**
176: * @return Returns Parameter.
177: */
178: public Parameter getParameter(String name) {
179: return parameters.getParameter(name);
180: }
181:
182: public ArrayList getParameters() {
183: return parameters.getParameters();
184: }
185:
186: public AxisConfiguration getParent() {
187: return parent;
188: }
189:
190: // to check whether a given parameter is locked
191: public boolean isParameterLocked(String parameterName) {
192:
193: // checking the locked value of parent
194: boolean loscked = false;
195:
196: if (this .parent != null) {
197: loscked = this .parent.isParameterLocked(parameterName);
198: }
199:
200: if (loscked) {
201: return true;
202: } else {
203: Parameter parameter = getParameter(parameterName);
204:
205: return (parameter != null) && parameter.isLocked();
206: }
207: }
208:
209: /**
210: * @param faultFlow : Arryalist of handlerDescriptions
211: */
212: public void setFaultInFlow(Flow faultFlow) {
213: flowInclude.setFaultInFlow(faultFlow);
214: }
215:
216: /**
217: * @param faultFlow : Arryalist of HandlerDescriptions
218: */
219: public void setFaultOutFlow(Flow faultFlow) {
220: flowInclude.setFaultOutFlow(faultFlow);
221: }
222:
223: public void setInFlow(Flow inFlow) {
224: flowInclude.setInFlow(inFlow);
225: }
226:
227: /**
228: * @param module : AxisModule
229: */
230: public void setModule(Module module) {
231: this .module = module;
232: }
233:
234: public void setModuleClassLoader(ClassLoader moduleClassLoader) {
235: this .moduleClassLoader = moduleClassLoader;
236: }
237:
238: /**
239: * @param name : Setting name of the module
240: */
241: public void setName(String name) {
242: this .name = name;
243: }
244:
245: public void setOutFlow(Flow outFlow) {
246: flowInclude.setOutFlow(outFlow);
247: }
248:
249: public void setParent(AxisConfiguration parent) {
250: this .parent = parent;
251: }
252:
253: public void setPolicyInclude(PolicyInclude policyInclude) {
254: this .policyInclude = policyInclude;
255: }
256:
257: public PolicyInclude getPolicyInclude() {
258: if (policyInclude == null) {
259: policyInclude = new PolicyInclude();
260: }
261: return policyInclude;
262: }
263:
264: public String getModuleDescription() {
265: return moduleDescription;
266: }
267:
268: public void setModuleDescription(String moduleDescription) {
269: this .moduleDescription = moduleDescription;
270: }
271:
272: public String[] getSupportedPolicyNamespaces() {
273: return supportedPolicyNames;
274: }
275:
276: public void setSupportedPolicyNamespaces(
277: String[] supportedPolicyNamespaces) {
278: this .supportedPolicyNames = supportedPolicyNamespaces;
279: }
280:
281: public QName[] getLocalPolicyAssertions() {
282: return localPolicyAssertions;
283: }
284:
285: public void setLocalPolicyAssertions(QName[] localPolicyAssertions) {
286: this .localPolicyAssertions = localPolicyAssertions;
287: }
288:
289: public URL getFileName() {
290: return fileName;
291: }
292:
293: public void setFileName(URL fileName) {
294: this .fileName = fileName;
295: }
296:
297: public String getVersion() {
298: return version;
299: }
300:
301: public void setVersion(String version) {
302: this.version = version;
303: }
304: }
|