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: package org.apache.axis2.util;
020:
021: import org.apache.axis2.description.AxisBinding;
022: import org.apache.axis2.description.AxisBindingMessage;
023: import org.apache.axis2.description.AxisBindingOperation;
024: import org.apache.axis2.description.AxisDescription;
025: import org.apache.axis2.description.AxisEndpoint;
026: import org.apache.axis2.description.AxisMessage;
027: import org.apache.axis2.description.AxisOperation;
028: import org.apache.axis2.description.AxisService;
029: import org.apache.axis2.description.AxisServiceGroup;
030: import org.apache.axis2.description.PolicyInclude;
031: import org.apache.axis2.engine.AxisConfiguration;
032: import org.apache.neethi.Policy;
033: import org.apache.neethi.PolicyRegistry;
034:
035: public class AxisPolicyLocator implements PolicyRegistry {
036:
037: AxisDescription subject = null;
038:
039: private static final short AXIS_BINDING_MESSAGE = 1;
040: private static final short AXIS_MESSAGE = 2;
041: private static final short AXIS_BINDING_OPERATION = 3;
042: private static final short AXIS_OPERATION = 4;
043: private static final short AXIS_BINDING = 5;
044: private static final short AXIS_ENDPOINT = 6;
045: private static final short AXIS_SERVICE = 7;
046: private static final short AXIS_SERVICE_GROUP = 8;
047: private static final short AXIS_CONFIGURATION = 9;
048:
049: public AxisPolicyLocator(AxisDescription subject) {
050: this .subject = subject;
051: }
052:
053: public Policy lookup(String key) {
054: if (subject == null) {
055: return null;
056: }
057:
058: PolicyInclude policyInclude = subject.getPolicyInclude();
059: PolicyRegistry policyRegistry = policyInclude
060: .getPolicyRegistry();
061: Policy policy = policyRegistry.lookup(key);
062:
063: if (policy != null) {
064: return policy;
065: }
066:
067: short type = getType(subject);
068:
069: /*
070: * processing the parallel level
071: */
072: AxisDescription parallelLevel = null;
073:
074: switch (type) {
075: case AXIS_BINDING_MESSAGE:
076: parallelLevel = ((AxisBindingMessage) subject)
077: .getAxisMessage();
078: break;
079: case AXIS_BINDING_OPERATION:
080: parallelLevel = ((AxisBindingOperation) subject)
081: .getAxisOperation();
082: break;
083: default:
084: break;
085: }
086:
087: if (parallelLevel != null) {
088: policy = (new AxisPolicyLocator(parallelLevel)).lookup(key);
089: if (policy != null) {
090: return policy;
091: }
092: }
093:
094: AxisDescription upperLevel = getUpperLevel(type, subject);
095: if (upperLevel != null) {
096: policy = (new AxisPolicyLocator(upperLevel)).lookup(key);
097: return policy;
098: }
099:
100: return null;
101: }
102:
103: public void register(String key, Policy policy) {
104: throw new UnsupportedOperationException();
105: }
106:
107: public void remove(String key) {
108: throw new UnsupportedOperationException();
109: }
110:
111: private AxisDescription getUpperLevel(short type,
112: AxisDescription this Level) {
113:
114: switch (type) {
115: case AXIS_BINDING_MESSAGE:
116: return ((AxisBindingMessage) this Level)
117: .getAxisBindingOperation();
118: case AXIS_BINDING_OPERATION:
119: return ((AxisBindingOperation) this Level).getAxisBinding();
120: case AXIS_BINDING:
121: return ((AxisBinding) this Level).getAxisEndpoint();
122: case AXIS_ENDPOINT:
123: return ((AxisEndpoint) this Level).getAxisService();
124: case AXIS_SERVICE:
125: return ((AxisService) this Level).getAxisServiceGroup();
126: case AXIS_SERVICE_GROUP:
127: return ((AxisServiceGroup) this Level)
128: .getAxisConfiguration();
129: default:
130: return null;
131: }
132: }
133:
134: private short getType(AxisDescription description) {
135:
136: if (description instanceof AxisBindingMessage) {
137: return AXIS_BINDING_MESSAGE;
138: } else if (description instanceof AxisMessage) {
139: return AXIS_MESSAGE;
140: } else if (description instanceof AxisBindingOperation) {
141: return AXIS_BINDING_OPERATION;
142: } else if (description instanceof AxisOperation) {
143: return AXIS_OPERATION;
144: } else if (description instanceof AxisBinding) {
145: return AXIS_BINDING;
146: } else if (description instanceof AxisEndpoint) {
147: return AXIS_ENDPOINT;
148: } else if (description instanceof AxisService) {
149: return AXIS_SERVICE;
150: } else if (description instanceof AxisServiceGroup) {
151: return AXIS_SERVICE_GROUP;
152: } else if (description instanceof AxisConfiguration) {
153: return AXIS_CONFIGURATION;
154: }
155:
156: return -1;
157:
158: }
159: }
|