01: /*
02: * The contents of this file are subject to the terms
03: * of the Common Development and Distribution License
04: * (the License). You may not use this file except in
05: * compliance with the License.
06: *
07: * You can obtain a copy of the license at
08: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
09: * See the License for the specific language governing
10: * permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL
13: * Header Notice in each file and include the License file
14: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
15: * If applicable, add the following below the CDDL Header,
16: * with the fields enclosed by brackets [] replaced by
17: * you own identifying information:
18: * "Portions Copyrighted [year] [name of copyright owner]"
19: *
20: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
21: */
22:
23: /*
24: * JAXBUtil.java
25: *
26: * Created on July 20, 2006, 3:19 PM
27: *
28: * To change this template, choose Tools | Template Manager
29: * and open the template in the editor.
30: */
31:
32: package com.sun.xml.ws.security.opt.impl.util;
33:
34: import com.sun.xml.ws.api.SOAPVersion;
35: import javax.xml.bind.JAXBContext;
36: import javax.xml.bind.JAXBException;
37: import javax.xml.bind.Marshaller;
38: import javax.xml.ws.WebServiceException;
39:
40: /**
41: *
42: * @author K.Venugopal@sun.com
43: */
44: public class JAXBUtil {
45: public static final WSSNamespacePrefixMapper prefixMapper11 = new WSSNamespacePrefixMapper();
46: public static final WSSNamespacePrefixMapper prefixMapper12 = new WSSNamespacePrefixMapper(
47: true);
48:
49: private static final JAXBContext jaxbContext;
50: static {
51: try {
52: jaxbContext = JAXBContext
53: .newInstance("com.sun.xml.ws.security.opt.crypto.dsig:com.sun.xml.ws.security.opt.crypto.dsig.keyinfo:com.sun.xml.security.core.dsig:com.sun.xml.security.core.xenc:"
54: + "com.sun.xml.ws.security.opt.impl.keyinfo:com.sun.xml.ws.security.opt.impl.reference:"
55: + "com.sun.xml.ws.security.secext10:com.sun.xml.ws.security.wsu10:com.sun.xml.ws.security.secext11:"
56: + "com.sun.xml.ws.security.secconv.impl.bindings");
57: } catch (JAXBException je) {
58: throw new WebServiceException(je);
59: }
60: }
61:
62: public static JAXBContext getJAXBContext() {
63: return jaxbContext;
64: }
65:
66: public static Marshaller createMarshaller(SOAPVersion soapVersion)
67: throws JAXBException {
68: try {
69: Marshaller marshaller = jaxbContext.createMarshaller();
70: if (SOAPVersion.SOAP_11 == soapVersion) {
71: marshaller.setProperty(
72: "com.sun.xml.bind.namespacePrefixMapper",
73: prefixMapper11);
74: } else {
75: marshaller.setProperty(
76: "com.sun.xml.bind.namespacePrefixMapper",
77: prefixMapper12);
78: }
79: marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
80: marshaller.setProperty("com.sun.xml.bind.xmlDeclaration",
81: false);
82: return marshaller;
83: } catch (javax.xml.bind.PropertyException pe) {
84: throw new JAXBException(
85: "Error occurred while setting security marshaller properties",
86: pe);
87: }
88:
89: }
90:
91: }
|