001: package com.sun.xml.ws.rm;
002:
003: import com.sun.xml.bind.api.JAXBRIContext;
004:
005: import javax.xml.bind.JAXBException;
006: import javax.xml.bind.Marshaller;
007: import javax.xml.bind.Unmarshaller;
008: import javax.xml.namespace.QName;
009: import java.util.ArrayList;
010: import java.util.Arrays;
011: import java.util.List;
012:
013: /**
014: * This is the class which will determine which RM version we are dealing with
015: * WSRM 1.0 or WSRM 1.1
016: */
017: public enum RMVersion {
018:
019: WSRM10("http://schemas.xmlsoap.org/ws/2005/02/rm",
020: "http://schemas.xmlsoap.org/ws/2005/02/rm/policy",
021: "com.sun.xml.ws.rm.v200502"
022:
023: ) {
024:
025: @Override
026: public String getNamespaceURI() {
027: return namespaceUri;
028: }
029:
030: @Override
031: public String getPolicyNamespaceURI() {
032: return policyNamespaceUri;
033: }
034:
035: @Override
036: public String getPackageName() {
037: return packageName;
038: }
039:
040: @Override
041: public List<Class> getClassesToBeBound() throws RMException {
042: final Class[] classes;
043: final ArrayList<Class> classList;
044: try {
045: classes = new Class[] {
046: Class.forName(getPackageName()
047: + ".AckRequestedElement"),
048: Class.forName(getPackageName()
049: + ".SequenceElement"),
050: Class.forName(getPackageName()
051: + ".SequenceAcknowledgementElement"),
052: Class.forName(getPackageName() + ".Identifier"),
053: Class.forName(getPackageName()
054: + ".CreateSequenceElement"),
055: Class.forName(getPackageName()
056: + ".CreateSequenceResponseElement"),
057: Class.forName(getPackageName()
058: + ".SequenceFaultElement"),
059: Class.forName(getPackageName()
060: + ".TerminateSequenceElement"),
061: Class.forName(getPackageName() + ".AcceptType"),
062: Class.forName(getPackageName() + ".OfferType"),
063: Class.forName(getPackageName() + ".Expires"),
064:
065: };
066: classList = new ArrayList<Class>(Arrays.asList(classes));
067: classList.add(RMConstants.W3C.getAcksToClass());
068:
069: return classList;
070: } catch (ClassNotFoundException e) {
071: throw new RMException(
072: "Cannot bind the following class with JAXBContext"
073: + e);
074: }
075: }
076:
077: },
078: WSRM11("http://docs.oasis-open.org/ws-rx/wsrm/200702",
079: "http://docs.oasis-open.org/ws-rx/wsrmp/200702",
080: "com.sun.xml.ws.rm.v200702") {
081:
082: @Override
083: public String getNamespaceURI() {
084: return namespaceUri;
085: }
086:
087: @Override
088: public String getPolicyNamespaceURI() {
089: return policyNamespaceUri;
090: }
091:
092: @Override
093: public String getPackageName() {
094: return packageName;
095: }
096:
097: public List<Class> getClassesToBeBound() throws RMException {
098: final Class[] classes;
099: final ArrayList<Class> classList;
100: try {
101: classes = new Class[] {
102: Class.forName(getPackageName()
103: + ".AckRequestedElement"),
104: Class.forName(getPackageName()
105: + ".SequenceElement"),
106: Class.forName(getPackageName()
107: + ".SequenceAcknowledgementElement"),
108: Class.forName(getPackageName() + ".Identifier"),
109: Class.forName(getPackageName()
110: + ".CreateSequenceElement"),
111: Class.forName(getPackageName()
112: + ".CreateSequenceResponseElement"),
113: Class.forName(getPackageName()
114: + ".SequenceFaultElement"),
115: Class.forName(getPackageName()
116: + ".TerminateSequenceElement"),
117: Class.forName(getPackageName()
118: + ".TerminateSequenceResponseElement"),
119: Class.forName(getPackageName() + ".AcceptType"),
120: Class.forName(getPackageName() + ".OfferType"),
121: Class.forName(getPackageName() + ".Expires"),
122: Class.forName(getPackageName()
123: + ".CloseSequenceResponseElement"),
124: Class.forName(getPackageName()
125: + ".CloseSequenceElement")
126:
127: };
128: classList = new ArrayList<Class>(Arrays.asList(classes));
129: classList.add(RMConstants.W3C.getAcksToClass());
130:
131: return classList;
132: } catch (ClassNotFoundException e) {
133: throw new RMException(
134: "Cannot bind the following class with JAXBContext"
135: + e);
136: }
137: }
138:
139: };
140:
141: public final String namespaceUri;
142:
143: public final String policyNamespaceUri;
144:
145: public final String packageName;
146:
147: private JAXBRIContext jc;
148:
149: public JAXBRIContext jaxbricontext;
150:
151: private RMVersion(String nsUri, String policynsuri,
152: String packagename) {
153: this .namespaceUri = nsUri;
154: this .policyNamespaceUri = policynsuri;
155: this .packageName = packagename;
156: init();
157:
158: }
159:
160: public abstract String getNamespaceURI();
161:
162: public abstract String getPolicyNamespaceURI();
163:
164: public abstract String getPackageName();
165:
166: public String getCreateSequenceAction() {
167: return namespaceUri + "/CreateSequence";
168: }
169:
170: public String getTerminateSequenceAction() {
171: return namespaceUri + "/TerminateSequence";
172: }
173:
174: public String getAckRequestedAction() {
175: return namespaceUri + "/AckRequested";
176: }
177:
178: public String getCreateSequenceResponseAction() {
179: return namespaceUri + "/CreateSequenceResponse";
180: }
181:
182: public String getSequenceAcknowledgementAction() {
183: return namespaceUri + "/SequenceAcknowledgement";
184: }
185:
186: public String getMakeConnectionAction() {
187: return namespaceUri + "/MakeConnection";
188: }
189:
190: public QName getRMPolicyAssertionQName() {
191: return new QName(getPolicyNamespaceURI(), "RMAssertion");
192: }
193:
194: public QName getInactivityTimeoutAssertionQName() {
195: return new QName(getPolicyNamespaceURI(), "InactivityTimeout");
196: }
197:
198: public QName getSequenceSTRAssertionQName() {
199: return new QName(getPolicyNamespaceURI(), "SequenceSTR");
200: }
201:
202: public QName getSequenceTransportSecurityAssertionQName() {
203: return new QName(getPolicyNamespaceURI(),
204: "SequenceTransportSecurity");
205: }
206:
207: /**
208: * Returns {@link RMVersion} whose {@link #nsUri} equals to
209: * the given string.
210: *
211: *
212: *
213: * @param nsUri
214: * must not be null.
215: * @return always non-null.
216: */
217: public static RMVersion fromNsUri(String nsUri) {
218: if (nsUri.equals(WSRM10.namespaceUri)) {
219: return WSRM10;
220:
221: } else {
222: //return WSRM 1.1 by default
223: return WSRM11;
224: }
225:
226: }
227:
228: private List<Class> getHeaderClassesToBeBound() throws RMException {
229: final Class[] classes;
230: final ArrayList<Class> classList;
231: try {
232: classes = new Class[] {
233: Class.forName(getPackageName()
234: + ".AckRequestedElement"),
235: Class
236: .forName(getPackageName()
237: + ".SequenceElement"),
238: Class.forName(getPackageName()
239: + ".SequenceAcknowledgementElement"),
240: Class.forName(getPackageName() + ".Identifier"),
241:
242: };
243: classList = new ArrayList<Class>(Arrays.asList(classes));
244: classList.add(RMConstants.W3C.getAcksToClass());
245: return classList;
246: } catch (ClassNotFoundException e) {
247: throw new RMException(
248: "Cannot bind the following class with JAXBContext"
249: + e);
250: }
251: }
252:
253: private void init() {
254: try {
255:
256: List<Class> classes = getClassesToBeBound();
257: jc = JAXBRIContext.newInstance(classes
258: .toArray(new Class[0]), null, null, null, false,
259: null);
260:
261: Class[] clazzes = getHeaderClassesToBeBound().toArray(
262: new Class[0]);
263: jaxbricontext = JAXBRIContext.newInstance(clazzes, null,
264: null, null, false, null);
265:
266: } catch (JAXBException e) {
267: throw new Error(e);
268: } catch (RMException e) {
269: throw new Error(e);
270: }
271:
272: }
273:
274: public JAXBRIContext getJAXBContext() {
275: return jc;
276: }
277:
278: public JAXBRIContext getJAXBRIContextHeaders() {
279: return jaxbricontext;
280: }
281:
282: public Marshaller createMarshaller() {
283: try {
284: Marshaller marshaller = jc.createMarshaller();
285: marshaller.setProperty(Marshaller.JAXB_FRAGMENT,
286: Boolean.TRUE);
287: return marshaller;
288: } catch (JAXBException e) {
289: return null;
290: }
291: }
292:
293: public Unmarshaller createUnmarshaller() {
294: try {
295: return jc.createUnmarshaller();
296: } catch (JAXBException e) {
297: return null;
298: }
299: }
300:
301: public QName getMessageNumberRolloverQname() {
302: return new QName(namespaceUri, "MessageNumberRollover");
303:
304: }
305:
306: public QName getUnknownSequenceQname() {
307: return new QName(namespaceUri, "UnknownSequence");
308: }
309:
310: public QName getClosedSequenceQname() {
311: return new QName(namespaceUri, "SequenceClosed");
312: }
313:
314: public QName getCreateSequenceRefusedQname() {
315: return new QName(namespaceUri, "CreateSequenceRefused");
316: }
317:
318: public QName getSequenceTerminatedQname() {
319: return new QName(namespaceUri, "SequenceTerminated");
320:
321: }
322:
323: public QName getSequenceQName() {
324: return new QName(getNamespaceURI(), "Sequence");
325: }
326:
327: public QName getAckRequestedQName() {
328: return new QName(getNamespaceURI(), "AckRequested");
329: }
330:
331: public QName getSequenceAcknowledgementQName() {
332: return new QName(getNamespaceURI(), "SequenceAcknowledgement");
333: }
334:
335: /**
336: * Returns the value of the WS-Addressing Action property stand alone Sequence
337: * messages with Last child.
338: *
339: * @return The Action value (http://schemas.xmlsoap.org/ws/2005/02/rm/Last)
340: */
341: public String getLastAction() {
342: return namespaceUri + "/LastMessage";
343: }
344:
345: public String getCloseSequenceAction() {
346: return namespaceUri + "/CloseSequence";
347: }
348:
349: public String getCloseSequenceResponseAction() {
350: return namespaceUri + "/CloseSequenceResponse";
351: }
352:
353: public String getTerminateSequenceResponseAction() {
354: return namespaceUri + "/TerminateSequenceResponse";
355: }
356:
357: public abstract List<Class> getClassesToBeBound()
358: throws RMException;
359:
360: }
|