View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
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   */
19  
20  package javax.xml.ws.wsaddressing;
21  
22  import javax.xml.bind.JAXBContext;
23  import javax.xml.bind.Marshaller;
24  import javax.xml.bind.Unmarshaller;
25  import javax.xml.bind.annotation.XmlAccessType;
26  import javax.xml.bind.annotation.XmlAccessorType;
27  import javax.xml.bind.annotation.XmlAnyAttribute;
28  import javax.xml.bind.annotation.XmlAnyElement;
29  import javax.xml.bind.annotation.XmlElement;
30  import javax.xml.bind.annotation.XmlRootElement;
31  import javax.xml.bind.annotation.XmlSchemaType;
32  import javax.xml.bind.annotation.XmlType;
33  import javax.xml.bind.annotation.XmlValue;
34  import javax.xml.namespace.QName;
35  import javax.xml.transform.Result;
36  import javax.xml.transform.Source;
37  import javax.xml.ws.EndpointReference;
38  import javax.xml.ws.WebServiceException;
39  import java.util.HashMap;
40  import java.util.List;
41  import java.util.Map;
42  
43  /**
44   * <p>Java class for EndpointReferenceType complex type.
45   * 
46   * <p>The following schema fragment specifies the expected content contained within this class.
47   * 
48   * <pre>
49   * &lt;complexType name="EndpointReferenceType">
50   *   &lt;complexContent>
51   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
52   *       &lt;sequence>
53   *         &lt;element name="Address" type="{http://www.w3.org/2005/08/addressing}AttributedURIType"/>
54   *         &lt;element ref="{http://www.w3.org/2005/08/addressing}ReferenceParameters" minOccurs="0"/>
55   *         &lt;element ref="{http://www.w3.org/2005/08/addressing}Metadata" minOccurs="0"/>
56   *         &lt;any/>
57   *       &lt;/sequence>
58   *     &lt;/restriction>
59   *   &lt;/complexContent>
60   * &lt;/complexType>
61   * </pre>
62   * 
63   * 
64   */
65  @XmlRootElement(name = "EndpointReference", namespace = W3CEndpointReference.NS)
66  @XmlType(name = "EndpointReferenceType", namespace = W3CEndpointReference.NS)
67  public final class W3CEndpointReference extends EndpointReference {
68      protected static final String NS = "http://www.w3.org/2005/08/addressing";
69      private static JAXBContext jaxbContext;
70      
71      @XmlElement(name = "Address", namespace = NS, required = true)
72      private AttributedURIType address;
73      @XmlElement(name = "ReferenceParameters", namespace = NS)
74      private ReferenceParametersType referenceParameters;
75      @XmlElement(name = "Metadata", namespace = NS)
76      private MetadataType metadata;
77      @XmlAnyElement(lax = true)
78      private List<Object> any;
79      @XmlAnyAttribute
80      private Map<QName, String> otherAttributes = new HashMap<QName, String>();
81      
82      static {
83          try { 
84              jaxbContext = JAXBContext.newInstance(W3CEndpointReference.class);
85          }
86          catch (Exception e) {
87              //TODO NLS enable
88              throw new WebServiceException("JAXBContext creation failed.", e);
89          }
90      }
91  
92      protected W3CEndpointReference() {
93      }
94      
95      public W3CEndpointReference(Source eprInfoset) {
96          super();
97          
98          try {
99              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 }