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.axiom.om.OMElement;
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.engine.Handler;
025: import org.apache.axis2.i18n.Messages;
026:
027: import java.util.ArrayList;
028:
029: /**
030: * Represents the deployment information about the handler
031: */
032: public class HandlerDescription implements ParameterInclude {
033:
034: /**
035: * Field className
036: */
037: private String className;
038:
039: private Handler handler;
040: private String name;
041: private final ParameterInclude parameterInclude;
042: private ParameterInclude parent;
043: private PhaseRule rules;
044:
045: /**
046: * Constructor HandlerDescription.
047: */
048: public HandlerDescription() {
049: this .parameterInclude = new ParameterIncludeImpl();
050: this .rules = new PhaseRule();
051: }
052:
053: /**
054: * Constructor HandlerDescription.
055: *
056: * @param name name of handler
057: */
058: public HandlerDescription(String name) {
059: this ();
060: this .name = name;
061: }
062:
063: /**
064: * Add a Parameter
065: *
066: * @param param the Parameter to associate with this HandlerDescription
067: */
068: public void addParameter(Parameter param) throws AxisFault {
069: if (isParameterLocked(param.getName())) {
070: throw new AxisFault(Messages.getMessage(
071: "paramterlockedbyparent", param.getName()));
072: } else {
073: parameterInclude.addParameter(param);
074: }
075: }
076:
077: public void removeParameter(Parameter param) throws AxisFault {
078: if (isParameterLocked(param.getName())) {
079: throw new AxisFault(Messages.getMessage(
080: "paramterlockedbyparent", param.getName()));
081: } else {
082: parameterInclude.removeParameter(param);
083: }
084: }
085:
086: public void deserializeParameters(OMElement parameterElement)
087: throws AxisFault {
088: this .parameterInclude.deserializeParameters(parameterElement);
089: }
090:
091: /**
092: * Method getClassName.
093: *
094: * @return Returns String.
095: */
096: public String getClassName() {
097: return className;
098: }
099:
100: /**
101: * @return Returns Handler.
102: */
103: public Handler getHandler() {
104: return handler;
105: }
106:
107: /**
108: * @return Returns QName.
109: */
110: public String getName() {
111: return name;
112: }
113:
114: /**
115: * Get a named Parameter
116: *
117: * @param name name of Parameter to search
118: * @return a Parameter, which may come from us or from some parent up the tree, or null.
119: */
120: public Parameter getParameter(String name) {
121: Parameter parameter = parameterInclude.getParameter(name);
122: if (parameter == null && parent != null) {
123: return parent.getParameter(name);
124: } else {
125: return parameter;
126: }
127: }
128:
129: public ArrayList getParameters() {
130: return parameterInclude.getParameters();
131: }
132:
133: public ParameterInclude getParent() {
134: return parent;
135: }
136:
137: /**
138: * Method getRules.
139: *
140: * @return Returns PhaseRule.
141: */
142: public PhaseRule getRules() {
143: return rules;
144: }
145:
146: // to check whether the parameter is locked at any level
147: public boolean isParameterLocked(String parameterName) {
148: if (parent != null) {
149: if (parent.isParameterLocked(parameterName)) {
150: return true;
151: }
152: }
153:
154: return parameterInclude.isParameterLocked(parameterName);
155: }
156:
157: /**
158: * Method setClassName.
159: *
160: * @param className the class name of the Handler class
161: */
162: public void setClassName(String className) {
163: this .className = className;
164: }
165:
166: /**
167: * Explicitly set the Handler object
168: *
169: * @param handler a Handler instance, which will be deployed wherever this HandlerDescription is
170: */
171: public void setHandler(Handler handler) {
172: this .handler = handler;
173: this .className = handler.getClass().getName();
174: }
175:
176: /**
177: * Set the name
178: *
179: * @param name the desired name
180: */
181: public void setName(String name) {
182: this .name = name;
183: }
184:
185: public void setParent(ParameterInclude parent) {
186: this .parent = parent;
187: }
188:
189: /**
190: * Set the deployment rules for this HandlerDescription
191: *
192: * @param rules a PhaseRule object
193: */
194: public void setRules(PhaseRule rules) {
195: this.rules = rules;
196: }
197: }
|