This project has retired. For details please refer to its
Attic page.
JaxBHelper xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.commons.impl;
20
21 import java.io.OutputStream;
22
23 import javax.xml.bind.JAXBContext;
24 import javax.xml.bind.JAXBElement;
25 import javax.xml.bind.JAXBException;
26 import javax.xml.bind.Marshaller;
27 import javax.xml.bind.Unmarshaller;
28 import javax.xml.bind.annotation.XmlElementDecl;
29 import javax.xml.bind.annotation.XmlRegistry;
30 import javax.xml.namespace.QName;
31 import javax.xml.stream.XMLStreamWriter;
32
33 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
34 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryInfoType;
35 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
36 import org.apache.chemistry.opencmis.commons.impl.jaxb.ObjectFactory;
37
38
39
40
41
42
43
44 public final class JaxBHelper {
45
46 private static final QName CMIS_OBJECT = new QName(Constants.NAMESPACE_RESTATOM, "object");
47 private static final QName CMIS_TYPE_DEFINITION = new QName(Constants.NAMESPACE_RESTATOM, "type");
48 private static final QName CMIS_REPOSITORY_INFO = new QName(Constants.NAMESPACE_RESTATOM, "repositoryInfo");
49
50 public static final ObjectFactory CMIS_OBJECT_FACTORY = new ObjectFactory();
51 public static final CMISExtraObjectFactory CMIS_EXTRA_OBJECT_FACTORY = new CMISExtraObjectFactory();
52 public static final JAXBContext CONTEXT;
53 static {
54 JAXBContext jc = null;
55 try {
56 jc = JAXBContext.newInstance(ObjectFactory.class, CMISExtraObjectFactory.class);
57 } catch (JAXBException e) {
58 e.printStackTrace();
59 }
60 CONTEXT = jc;
61 }
62
63 @XmlRegistry
64 public static class CMISExtraObjectFactory {
65 @XmlElementDecl(namespace = Constants.NAMESPACE_RESTATOM, name = "object")
66 public JAXBElement<CmisObjectType> createObject(CmisObjectType value) {
67 return new JAXBElement<CmisObjectType>(CMIS_OBJECT, CmisObjectType.class, value);
68 }
69
70 @XmlElementDecl(namespace = Constants.NAMESPACE_RESTATOM, name = "type")
71 public JAXBElement<CmisTypeDefinitionType> createTypeDefinition(CmisTypeDefinitionType value) {
72 return new JAXBElement<CmisTypeDefinitionType>(CMIS_TYPE_DEFINITION, CmisTypeDefinitionType.class, value);
73 }
74
75 @XmlElementDecl(namespace = Constants.NAMESPACE_RESTATOM, name = "repositoryInfo")
76 public JAXBElement<CmisRepositoryInfoType> createRepositoryInfo(CmisRepositoryInfoType value) {
77 return new JAXBElement<CmisRepositoryInfoType>(CMIS_REPOSITORY_INFO, CmisRepositoryInfoType.class, value);
78 }
79 }
80
81
82
83
84 private JaxBHelper() {
85 }
86
87
88
89
90 public static Unmarshaller createUnmarshaller() throws JAXBException {
91 return CONTEXT.createUnmarshaller();
92 }
93
94
95
96
97 public static Marshaller createMarshaller() throws JAXBException {
98 return CONTEXT.createMarshaller();
99 }
100
101
102
103
104 public static <T> void marshal(JAXBElement<T> object, OutputStream out, boolean fragment) throws JAXBException {
105 if (object == null) {
106 return;
107 }
108
109 Marshaller m = CONTEXT.createMarshaller();
110 if (fragment) {
111 m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
112 }
113
114 m.marshal(object, out);
115 }
116
117
118
119
120 public static void marshal(Object object, XMLStreamWriter out, boolean fragment) throws JAXBException {
121 if (object == null) {
122 return;
123 }
124
125 Marshaller m = CONTEXT.createMarshaller();
126 if (fragment) {
127 m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
128 }
129
130 m.marshal(object, out);
131 }
132 }