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.attachment.external;
019:
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.ResourceBundle;
023:
024: import javax.xml.bind.JAXBContext;
025: import javax.xml.bind.JAXBElement;
026: import javax.xml.bind.JAXBException;
027: import javax.xml.bind.Unmarshaller;
028: import javax.xml.namespace.QName;
029:
030: import org.w3c.dom.Element;
031:
032: import org.apache.cxf.common.i18n.BundleUtils;
033: import org.apache.cxf.common.i18n.Message;
034: import org.apache.cxf.ws.addressing.EndpointReferenceType;
035: import org.apache.cxf.ws.policy.PolicyException;
036:
037: /**
038: *
039: */
040: public class EndpointReferenceDomainExpressionBuilder implements
041: DomainExpressionBuilder {
042:
043: private static final ResourceBundle BUNDLE = BundleUtils
044: .getBundle(EndpointReferenceDomainExpressionBuilder.class);
045:
046: private static final Collection<QName> SUPPORTED_TYPES = Collections
047: .singletonList(new QName(
048: "http://www.w3.org/2005/08/addressing",
049: "EndpointReference"));
050:
051: private Unmarshaller unmarshaller;
052:
053: EndpointReferenceDomainExpressionBuilder() {
054:
055: }
056:
057: public Collection<QName> getDomainExpressionTypes() {
058: return SUPPORTED_TYPES;
059: }
060:
061: public DomainExpression build(Element e) {
062: Object obj = null;
063: try {
064: obj = getUnmarshaller().unmarshal(e);
065: } catch (JAXBException ex) {
066: throw new PolicyException(new Message(
067: "EPR_DOMAIN_EXPRESSION_BUILD_EXC", BUNDLE,
068: (Object[]) null), ex);
069: }
070: if (obj instanceof JAXBElement<?>) {
071: JAXBElement<?> el = (JAXBElement<?>) obj;
072: obj = el.getValue();
073: }
074:
075: EndpointReferenceDomainExpression eprde = new EndpointReferenceDomainExpression();
076: eprde.setEndpointReference((EndpointReferenceType) obj);
077: return eprde;
078: }
079:
080: protected Unmarshaller getUnmarshaller() {
081: if (unmarshaller == null) {
082: createUnmarshaller();
083: }
084:
085: return unmarshaller;
086: }
087:
088: protected synchronized void createUnmarshaller() {
089: if (unmarshaller != null) {
090: return;
091: }
092:
093: try {
094: JAXBContext context = JAXBContext
095: .newInstance(EndpointReferenceType.class
096: .getPackage().getName());
097: unmarshaller = context.createUnmarshaller();
098: } catch (JAXBException ex) {
099: throw new PolicyException(new Message(
100: "EPR_DOMAIN_EXPRESSION_BUILDER_INIT_EXC", BUNDLE,
101: (Object[]) null), ex);
102: }
103: }
104: }
|