1 19 package org.netbeans.modules.j2ee.dd.impl.common; 20 21 import org.netbeans.modules.j2ee.dd.api.client.AppClient; 22 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 24 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 25 import org.netbeans.modules.j2ee.dd.impl.ejb.EjbJarProxy; 26 import org.netbeans.modules.schema2beans.Schema2BeansRuntimeException; 27 import org.xml.sax.InputSource ; 28 import org.xml.sax.SAXException ; 29 import org.xml.sax.SAXParseException ; 30 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.io.Reader ; 34 35 38 public class DDUtils { 39 public static EjbJarProxy createEjbJarProxy(InputStream inputStream) throws IOException { 40 return createEjbJarProxy(new InputSource (inputStream)); 41 } 42 43 public static EjbJarProxy createEjbJarProxy(Reader reader) throws IOException { 44 return createEjbJarProxy(new InputSource (reader)); 45 } 46 47 public static EjbJarProxy createEjbJarProxy(InputSource inputSource) throws IOException { 48 try { 49 return (EjbJarProxy) DDProvider.getDefault().getDDRoot(inputSource); 50 } catch (SAXException ex) { 51 EjbJar ejbJar = org.netbeans.modules.j2ee.dd.impl.ejb.model_2_0.EjbJar.createGraph(); 53 EjbJarProxy ejbJarProxy = new EjbJarProxy(ejbJar, ejbJar.getVersion().toString()); 54 ejbJarProxy.setStatus(EjbJar.STATE_INVALID_UNPARSABLE); 55 if (ex instanceof SAXParseException ) { 56 ejbJarProxy.setError((SAXParseException ) ex); 57 } else if (ex.getException() instanceof SAXParseException ) { 58 ejbJarProxy.setError((SAXParseException ) ex.getException()); 59 } 60 return ejbJarProxy; 61 } 62 } 63 64 65 public static void merge(EjbJarProxy ejbJarProxy, Reader reader) { 66 try { 67 EjbJarProxy newEjbJarProxy = createEjbJarProxy(reader); 68 if (newEjbJarProxy.getStatus() == EjbJar.STATE_INVALID_UNPARSABLE) { 69 ejbJarProxy.setStatus(EjbJar.STATE_INVALID_UNPARSABLE); 70 ejbJarProxy.setError(newEjbJarProxy.getError()); 71 return; 72 } 73 ejbJarProxy.merge(newEjbJarProxy, EjbJar.MERGE_UPDATE); 74 ejbJarProxy.setStatus(newEjbJarProxy.getStatus()); 75 ejbJarProxy.setError(newEjbJarProxy.getError()); 76 } catch (IOException ex) { 77 ejbJarProxy.setStatus(EjbJar.STATE_INVALID_UNPARSABLE); 78 } catch (Schema2BeansRuntimeException ex2){ ejbJarProxy.setStatus(EjbJar.STATE_INVALID_UNPARSABLE); 87 ejbJarProxy.setError(new SAXParseException (null, null, ex2)); 88 } 89 } 90 91 public static WebApp createWebApp(InputStream is, String version) throws IOException , SAXException { 92 try { 93 if (WebApp.VERSION_2_3.equals(version)) { 94 return org.netbeans.modules.j2ee.dd.impl.web.model_2_3.WebApp.createGraph(is); 95 } else if (WebApp.VERSION_2_4.equals(version)) { 96 return org.netbeans.modules.j2ee.dd.impl.web .model_2_4.WebApp.createGraph(is); 97 } else { 98 return org.netbeans.modules.j2ee.dd.impl.web .model_2_5.WebApp.createGraph(is); 99 } 100 } catch (RuntimeException ex) { 101 throw new SAXException (ex); 102 } 103 } 104 105 public static AppClient createAppClient(InputStream is, String version) throws IOException , SAXException { 106 try { 107 if (AppClient.VERSION_1_3.equals(version)) { 108 return org.netbeans.modules.j2ee.dd.impl.client.model_1_3.ApplicationClient.createGraph(is); 109 } else if (AppClient.VERSION_1_4.equals(version)) { 110 return org.netbeans.modules.j2ee.dd.impl.client.model_1_4.ApplicationClient.createGraph(is); 111 } else if (AppClient.VERSION_5_0.equals(version)) { 112 return org.netbeans.modules.j2ee.dd.impl.client.model_5_0.ApplicationClient.createGraph(is); 113 } 114 } catch (RuntimeException ex) { 115 throw new SAXException (ex); 116 } 117 return null; 118 } 119 } 120 | Popular Tags |