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    
020    package javax.xml.ws.wsaddressing;
021    
022    import javax.xml.bind.JAXBContext;
023    import javax.xml.bind.Marshaller;
024    import javax.xml.bind.Unmarshaller;
025    import javax.xml.bind.annotation.XmlAccessType;
026    import javax.xml.bind.annotation.XmlAccessorType;
027    import javax.xml.bind.annotation.XmlAnyAttribute;
028    import javax.xml.bind.annotation.XmlAnyElement;
029    import javax.xml.bind.annotation.XmlElement;
030    import javax.xml.bind.annotation.XmlRootElement;
031    import javax.xml.bind.annotation.XmlSchemaType;
032    import javax.xml.bind.annotation.XmlType;
033    import javax.xml.bind.annotation.XmlValue;
034    import javax.xml.namespace.QName;
035    import javax.xml.transform.Result;
036    import javax.xml.transform.Source;
037    import javax.xml.ws.EndpointReference;
038    import javax.xml.ws.WebServiceException;
039    import java.util.HashMap;
040    import java.util.List;
041    import java.util.Map;
042    
043    /**
044     * <p>Java class for EndpointReferenceType complex type.
045     * 
046     * <p>The following schema fragment specifies the expected content contained within this class.
047     * 
048     * <pre>
049     * &lt;complexType name="EndpointReferenceType">
050     *   &lt;complexContent>
051     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
052     *       &lt;sequence>
053     *         &lt;element name="Address" type="{http://www.w3.org/2005/08/addressing}AttributedURIType"/>
054     *         &lt;element ref="{http://www.w3.org/2005/08/addressing}ReferenceParameters" minOccurs="0"/>
055     *         &lt;element ref="{http://www.w3.org/2005/08/addressing}Metadata" minOccurs="0"/>
056     *         &lt;any/>
057     *       &lt;/sequence>
058     *     &lt;/restriction>
059     *   &lt;/complexContent>
060     * &lt;/complexType>
061     * </pre>
062     * 
063     * 
064     */
065    @XmlRootElement(name = "EndpointReference", namespace = W3CEndpointReference.NS)
066    @XmlType(name = "EndpointReferenceType", namespace = W3CEndpointReference.NS)
067    public final class W3CEndpointReference extends EndpointReference {
068        protected static final String NS = "http://www.w3.org/2005/08/addressing";
069        private static JAXBContext jaxbContext;
070        
071        @XmlElement(name = "Address", namespace = NS, required = true)
072        private AttributedURIType address;
073        @XmlElement(name = "ReferenceParameters", namespace = NS)
074        private ReferenceParametersType referenceParameters;
075        @XmlElement(name = "Metadata", namespace = NS)
076        private MetadataType metadata;
077        @XmlAnyElement(lax = true)
078        private List<Object> any;
079        @XmlAnyAttribute
080        private Map<QName, String> otherAttributes = new HashMap<QName, String>();
081        
082        static {
083            try { 
084                jaxbContext = JAXBContext.newInstance(W3CEndpointReference.class);
085            }
086            catch (Exception e) {
087                //TODO NLS enable
088                throw new WebServiceException("JAXBContext creation failed.", e);
089            }
090        }
091    
092        protected W3CEndpointReference() {
093        }
094        
095        public W3CEndpointReference(Source eprInfoset) {
096            super();
097            
098            try {
099                Unmarshaller um = jaxbContext.createUnmarshaller();
100                W3CEndpointReference w3cEPR = (W3CEndpointReference) um.unmarshal(eprInfoset);
101                
102                address = w3cEPR.address;
103                referenceParameters = w3cEPR.referenceParameters;
104                metadata = w3cEPR.metadata;
105                any = w3cEPR.any;
106                otherAttributes.putAll(w3cEPR.otherAttributes);
107            }
108            catch (Exception e) {
109                //TODO NLS enable.
110                throw new WebServiceException("Unable to create W3C endpoint reference.", e);
111            }
112        }
113        
114        @Override
115        public void writeTo(Result result) {
116            if (result == null) {
117                //TODO NLS enable
118                throw new IllegalArgumentException("Null is not allowed.");
119            }
120            
121            try {
122                Marshaller m = jaxbContext.createMarshaller();
123                m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
124                m.marshal(this, result);
125            }
126            catch (Exception e) {
127                //TODO NLS enable
128                throw new WebServiceException("writeTo failure.", e);
129            }
130        }
131    
132        /**
133         * <p>Java class for AttributedURIType complex type.
134         * 
135         * <p>The following schema fragment specifies the expected content contained within this class.
136         * 
137         * <pre>
138         * &lt;complexType name="AttributedURIType">
139         *   &lt;simpleContent>
140         *     &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>anyURI">
141         *     &lt;/extension>
142         *   &lt;/simpleContent>
143         * &lt;/complexType>
144         * </pre>
145         * 
146         * 
147         */
148        @XmlAccessorType(XmlAccessType.FIELD)
149        @XmlType(name = "AttributedURIType", propOrder = {
150            "value"
151        })
152        private static class AttributedURIType {
153    
154            @XmlValue
155            @XmlSchemaType(name = "anyURI")
156            protected String value;
157            @XmlAnyAttribute
158            private Map<QName, String> otherAttributes = new HashMap<QName, String>();
159            
160            public AttributedURIType() {
161            }
162        }
163    
164        /**
165         * <p>Java class for ReferenceParametersType complex type.
166         * 
167         * <p>The following schema fragment specifies the expected content contained within this class.
168         * 
169         * <pre>
170         * &lt;complexType name="ReferenceParametersType">
171         *   &lt;complexContent>
172         *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
173         *       &lt;sequence>
174         *         &lt;any/>
175         *       &lt;/sequence>
176         *     &lt;/restriction>
177         *   &lt;/complexContent>
178         * &lt;/complexType>
179         * </pre>
180         * 
181         * 
182         */
183        @XmlAccessorType(XmlAccessType.FIELD)
184        @XmlType(name = "ReferenceParametersType", propOrder = {
185            "any"
186        })
187        private static class ReferenceParametersType {
188    
189            @XmlAnyElement(lax = true)
190            protected List<Object> any;
191            @XmlAnyAttribute
192            private Map<QName, String> otherAttributes = new HashMap<QName, String>();
193            
194            public ReferenceParametersType() {
195            }
196        }
197    
198        /**
199         * <p>Java class for MetadataType complex type.
200         * 
201         * <p>The following schema fragment specifies the expected content contained within this class.
202         * 
203         * <pre>
204         * &lt;complexType name="MetadataType">
205         *   &lt;complexContent>
206         *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
207         *       &lt;sequence>
208         *         &lt;any/>
209         *       &lt;/sequence>
210         *     &lt;/restriction>
211         *   &lt;/complexContent>
212         * &lt;/complexType>
213         * </pre>
214         * 
215         * 
216         */
217        @XmlAccessorType(XmlAccessType.FIELD)
218        @XmlType(name = "MetadataType", propOrder = {
219            "any"
220        })
221        private static class MetadataType {
222    
223            @XmlAnyElement(lax = true)
224            protected List<Object> any;
225            @XmlAnyAttribute
226            private Map<QName, String> otherAttributes = new HashMap<QName, String>();
227            
228            public MetadataType() {
229            }
230        }
231    }