1 17 package org.apache.geronimo.webservices; 18 19 import java.io.InputStream ; 20 import java.net.URL ; 21 22 import org.apache.geronimo.common.DeploymentException; 23 import org.exolab.castor.mapping.Mapping; 24 import org.exolab.castor.xml.Unmarshaller; 25 import org.exolab.castor.xml.Marshaller; 26 import org.xml.sax.InputSource ; 27 28 public class WebServicesFactory { 29 30 private static WebServicesFactory webServicesFactory; 31 32 private final Mapping mapping; 33 private final Unmarshaller unmarshaller; 34 35 private WebServicesFactory() { 36 ClassLoader classLoader = WebServicesFactory.class.getClassLoader(); 37 URL mappingUrl = classLoader.getResource("org/apache/geronimo/webservices/webservices_1_1.xml"); 38 39 try { 40 mapping = new Mapping(classLoader); 41 mapping.loadMapping(mappingUrl); 42 unmarshaller = new Unmarshaller(mapping); 43 } catch (Exception e) { 44 throw (IllegalStateException )new IllegalStateException ("Unable to initialize xml unmarshaller").initCause(e); 45 } 46 } 47 48 public static WebServicesFactory getInstance() { 49 if (webServicesFactory == null){ 50 webServicesFactory = new WebServicesFactory(); 51 } 52 return webServicesFactory; 53 } 54 55 public WebServices readXML(URL webservicesURL) throws DeploymentException { 56 InputStream in = null; 57 WebServices webservice = null; 58 try { 59 in = webservicesURL.openStream(); 60 webservice = (WebServices) unmarshaller.unmarshal(new InputSource (in)); 61 } catch (Exception e) { 62 throw new DeploymentException(e); 63 } finally { 64 if (in != null) { 65 try { 66 in.close(); 67 } catch(Exception ignored) { 68 } 70 } 71 } 72 return webservice; 73 } 74 75 } 76 | Popular Tags |