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: */package org.apache.cxf.ws.policy;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.ResourceBundle;
026:
027: import javax.xml.namespace.QName;
028:
029: import org.apache.cxf.common.i18n.BundleUtils;
030: import org.apache.cxf.common.i18n.Message;
031: import org.apache.cxf.helpers.CastUtils;
032: import org.apache.neethi.Assertion;
033: import org.apache.neethi.Policy;
034:
035: /**
036: *
037: */
038: public class AssertionInfoMap extends
039: HashMap<QName, Collection<AssertionInfo>> {
040:
041: private static final ResourceBundle BUNDLE = BundleUtils.getBundle(
042: AssertionInfoMap.class, "APIMessages");
043:
044: public AssertionInfoMap(Collection<Assertion> assertions) {
045: super (assertions.size());
046: for (Assertion a : assertions) {
047: AssertionInfo ai = new AssertionInfo(a);
048: Collection<AssertionInfo> ais = get(a.getName());
049: if (null == ais) {
050: ais = new ArrayList<AssertionInfo>();
051: put(a.getName(), ais);
052: }
053: ais.add(ai);
054: }
055: }
056:
057: public boolean supportsAlternative(Collection<Assertion> alternative) {
058: for (Assertion a : alternative) {
059: boolean asserted = false;
060: Collection<AssertionInfo> ais = get(a.getName());
061: if (null != ais) {
062: for (AssertionInfo ai : ais) {
063: // if (ai.getAssertion() == a && ai.isAsserted()) {
064: if (ai.getAssertion().equal(a) && ai.isAsserted()) {
065: asserted = true;
066: break;
067: }
068: }
069: }
070: if (!asserted) {
071: return false;
072: }
073: }
074:
075: return true;
076: }
077:
078: public void checkEffectivePolicy(Policy policy) {
079: Iterator alternatives = policy.getAlternatives();
080: while (alternatives.hasNext()) {
081: List<Assertion> alternative = CastUtils.cast(
082: (List) alternatives.next(), Assertion.class);
083: if (supportsAlternative(alternative)) {
084: return;
085: }
086: }
087: throw new PolicyException(new Message("NO_ALTERNATIVE_EXC",
088: BUNDLE));
089: }
090:
091: public void check() {
092: for (Collection<AssertionInfo> ais : values()) {
093: for (AssertionInfo ai : ais) {
094: if (!ai.isAsserted()) {
095: throw new PolicyException(
096: new org.apache.cxf.common.i18n.Message(
097: "NOT_ASSERTED_EXC", BUNDLE, ai
098: .getAssertion().getName()));
099: }
100: }
101: }
102: }
103: }
|