01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.webservices;
17:
18: import java.io.InputStream;
19: import java.net.URL;
20:
21: import org.apache.geronimo.common.DeploymentException;
22: import org.exolab.castor.mapping.Mapping;
23: import org.exolab.castor.xml.Unmarshaller;
24: import org.exolab.castor.xml.Marshaller;
25: import org.xml.sax.InputSource;
26:
27: public class WebServicesFactory {
28:
29: private static WebServicesFactory webServicesFactory;
30:
31: private final Mapping mapping;
32: private final Unmarshaller unmarshaller;
33:
34: private WebServicesFactory() {
35: ClassLoader classLoader = WebServicesFactory.class
36: .getClassLoader();
37: URL mappingUrl = classLoader
38: .getResource("org/apache/geronimo/webservices/webservices_1_1.xml");
39:
40: try {
41: mapping = new Mapping(classLoader);
42: mapping.loadMapping(mappingUrl);
43: unmarshaller = new Unmarshaller(mapping);
44: } catch (Exception e) {
45: throw (IllegalStateException) new IllegalStateException(
46: "Unable to initialize xml unmarshaller")
47: .initCause(e);
48: }
49: }
50:
51: public static WebServicesFactory getInstance() {
52: if (webServicesFactory == null) {
53: webServicesFactory = new WebServicesFactory();
54: }
55: return webServicesFactory;
56: }
57:
58: public WebServices readXML(URL webservicesURL)
59: throws DeploymentException {
60: InputStream in = null;
61: WebServices webservice = null;
62: try {
63: in = webservicesURL.openStream();
64: webservice = (WebServices) unmarshaller
65: .unmarshal(new InputSource(in));
66: } catch (Exception e) {
67: throw new DeploymentException(e);
68: } finally {
69: if (in != null) {
70: try {
71: in.close();
72: } catch (Exception ignored) {
73: // Don't care
74: }
75: }
76: }
77: return webservice;
78: }
79:
80: }
|