01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.ws.policy.attachment;
19:
20: import java.util.ResourceBundle;
21:
22: import javax.annotation.PostConstruct;
23:
24: import org.apache.cxf.Bus;
25: import org.apache.cxf.common.i18n.BundleUtils;
26: import org.apache.cxf.common.i18n.Message;
27: import org.apache.cxf.ws.policy.PolicyBuilder;
28: import org.apache.cxf.ws.policy.PolicyConstants;
29: import org.apache.cxf.ws.policy.PolicyEngine;
30: import org.apache.cxf.ws.policy.PolicyException;
31: import org.apache.cxf.ws.policy.PolicyProvider;
32: import org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver;
33: import org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver;
34: import org.apache.neethi.Policy;
35: import org.apache.neethi.PolicyReference;
36: import org.apache.neethi.PolicyRegistry;
37:
38: /**
39: *
40: */
41: public abstract class AbstractPolicyProvider implements PolicyProvider {
42:
43: private static final ResourceBundle BUNDLE = BundleUtils
44: .getBundle(AbstractPolicyProvider.class);
45:
46: protected PolicyBuilder builder;
47: protected PolicyRegistry registry;
48: protected Bus bus;
49:
50: protected AbstractPolicyProvider() {
51: this (null);
52: }
53:
54: protected AbstractPolicyProvider(Bus b) {
55: bus = b;
56: }
57:
58: public void setBuilder(PolicyBuilder b) {
59: builder = b;
60: }
61:
62: public void setRegistry(PolicyRegistry r) {
63: registry = r;
64: }
65:
66: @PostConstruct
67: public void init() {
68: if (null != bus) {
69: setBuilder(bus.getExtension(PolicyBuilder.class));
70: PolicyEngine pe = (PolicyEngine) bus
71: .getExtension(PolicyEngine.class);
72: setRegistry(pe.getRegistry());
73: }
74: }
75:
76: protected Policy resolveExternal(PolicyReference ref, String baseURI) {
77: ReferenceResolver resolver = new RemoteReferenceResolver(
78: baseURI, builder, bus
79: .getExtension(PolicyConstants.class));
80: Policy resolved = registry.lookup(ref.getURI());
81: if (null != resolved) {
82: return resolved;
83: }
84: return resolver.resolveReference(ref.getURI());
85: }
86:
87: protected boolean isExternal(PolicyReference ref) {
88: return !ref.getURI().startsWith("#");
89: }
90:
91: protected void checkResolved(PolicyReference ref, Policy p) {
92: if (null == p) {
93: throw new PolicyException(new Message(
94: "UNRESOLVED_POLICY_REEFERENCE_EXC", BUNDLE, ref
95: .getURI()));
96: }
97: }
98: }
|