This project has retired. For details please refer to its
Attic page.
EntityCreator xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.apache.juddi.jaxb;
16
17
18
19
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.StringReader;
25 import java.net.URL;
26
27 import javax.xml.bind.JAXBContext;
28 import javax.xml.bind.JAXBElement;
29 import javax.xml.bind.JAXBException;
30 import javax.xml.bind.Marshaller;
31 import javax.xml.bind.Unmarshaller;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36
37
38
39
40
41
42 public class EntityCreator {
43
44 public static final String UDDIv3_Package="org.uddi.api_v3";
45 public static final String JUDDIv3_Package="org.apache.juddi.api_v3";
46
47 private static Log logger = LogFactory.getLog(EntityCreator.class);
48
49
50
51
52
53
54
55
56
57 @SuppressWarnings("rawtypes")
58 public static Object buildFromDoc(String fileName, String thePackage) throws JAXBException, IOException {
59 Object obj = null;
60 File f = new File(fileName);
61 URL url=null;
62 if (f.exists()){
63 url = f.toURI().toURL();
64 }
65 if (url==null) {
66 url = Thread.currentThread().getContextClassLoader().getResource(fileName);
67 }
68 if (url==null) {
69 logger.error("Could not find resource: " + fileName);
70 } else {
71 InputStream resourceStream =url.openStream();
72
73 JAXBContext jc = JAXBContext.newInstance(thePackage);
74 Unmarshaller unmarshaller = jc.createUnmarshaller();
75 obj = ((JAXBElement)unmarshaller.unmarshal(resourceStream)).getValue();
76 }
77 return obj;
78 }
79
80
81
82
83
84
85
86
87
88 @SuppressWarnings("rawtypes")
89 public static Object buildFromString(String source, String thePackage) throws JAXBException, IOException {
90 Object obj = null;
91 JAXBContext jc = JAXBContext.newInstance(thePackage);
92 Unmarshaller unmarshaller = jc.createUnmarshaller();
93 obj = ((JAXBElement)unmarshaller.unmarshal(new StringReader(source)));
94 return obj;
95 }
96
97
98
99
100
101
102
103
104 @Deprecated
105 public static void outputEntity(Object obj, String thePackage) throws JAXBException {
106 JAXBContext jc = JAXBContext.newInstance(thePackage);
107 Marshaller marshaller = jc.createMarshaller();
108 marshaller.marshal( new JAXBElement<Object>(new javax.xml.namespace.QName("uri","local"), Object.class, obj), System.out);
109
110 }
111
112 }