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.List;
022: import java.util.Map;
023: import java.util.ResourceBundle;
024: import java.util.logging.Logger;
025:
026: import javax.xml.namespace.QName;
027:
028: import org.w3c.dom.Element;
029:
030: import org.apache.cxf.common.i18n.BundleUtils;
031: import org.apache.cxf.common.i18n.Message;
032: import org.apache.cxf.common.logging.LogUtils;
033: import org.apache.cxf.extension.BusExtension;
034: import org.apache.cxf.extension.RegistryImpl;
035: import org.apache.neethi.Assertion;
036:
037: /**
038: *
039: */
040: public class AssertionBuilderRegistryImpl extends
041: RegistryImpl<QName, AssertionBuilder> implements
042: AssertionBuilderRegistry, BusExtension {
043:
044: private static final ResourceBundle BUNDLE = BundleUtils
045: .getBundle(AssertionBuilderRegistryImpl.class);
046: private static final Logger LOG = LogUtils
047: .getL7dLogger(AssertionBuilderRegistryImpl.class);
048: private static final int IGNORED_CACHE_SIZE = 10;
049: private boolean ignoreUnknownAssertions;
050: private List<QName> ignored = new ArrayList<QName>(
051: IGNORED_CACHE_SIZE);
052:
053: public AssertionBuilderRegistryImpl() {
054: this (null);
055: }
056:
057: public AssertionBuilderRegistryImpl(
058: Map<QName, AssertionBuilder> builders) {
059: super (builders);
060: }
061:
062: public Class<?> getRegistrationType() {
063: return AssertionBuilderRegistry.class;
064: }
065:
066: public boolean isIgnoreUnknownAssertions() {
067: return ignoreUnknownAssertions;
068: }
069:
070: public void setIgnoreUnknownAssertions(boolean ignore) {
071: ignoreUnknownAssertions = ignore;
072: }
073:
074: public Assertion build(Element element) {
075:
076: AssertionBuilder builder;
077:
078: QName qname = new QName(element.getNamespaceURI(), element
079: .getLocalName());
080: builder = get(qname);
081:
082: if (null == builder) {
083: Message m = new Message("NO_ASSERTIONBUILDER_EXC", BUNDLE,
084: qname.toString());
085: if (ignoreUnknownAssertions) {
086: boolean alreadyWarned = ignored.contains(qname);
087: if (alreadyWarned) {
088: ignored.remove(qname);
089: } else if (ignored.size() == IGNORED_CACHE_SIZE) {
090: ignored.remove(IGNORED_CACHE_SIZE - 1);
091: }
092: ignored.add(0, qname);
093: if (!alreadyWarned) {
094: LOG.warning(m.toString());
095: }
096: return null;
097: } else {
098: throw new PolicyException(m);
099: }
100: }
101:
102: return builder.build(element);
103:
104: }
105: }
|