1 22 package org.jboss.test.messagedriven.mock; 23 24 import java.io.InputStream ; 25 26 import javax.xml.parsers.DocumentBuilder ; 27 import javax.xml.parsers.DocumentBuilderFactory ; 28 29 import org.w3c.dom.Document ; 30 import org.xml.sax.InputSource ; 31 32 38 public class JmsMockObjectHelper 39 { 40 41 42 public static DocumentBuilder getDocumentBuilder(){ 43 44 try 45 { 46 final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 47 return builder; 48 } 49 catch (Exception e) 50 { 51 throw new JmsMockObjectException(e.getMessage()); 52 53 } 54 55 } 56 57 public static Document getDocument(String xml){ 58 59 Document doc = null; 60 61 try 62 { 63 DocumentBuilder builder = getDocumentBuilder(); 64 InputSource is = getInputSource(xml); 65 return builder.parse(is); 66 } 67 catch (Exception e) 68 { 69 throw new JmsMockObjectException(e.getMessage()); 70 71 } 72 73 } 74 75 private static InputSource getInputSource(String xml){ 76 77 InputStream is = null; 78 79 try 80 { 81 is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xml); 82 return new InputSource (is); 83 84 }finally{ 85 86 try 87 { 88 if (is != null) 89 { 90 } 92 } 93 catch (Exception e) 94 { 95 } 97 } 98 99 100 101 } 102 103 public static void main(String [] args) 104 { 105 String fileName = "org/jboss/test/messagedriven/mock/mock-provider-adapter.xml"; 106 Document doc = getDocument(fileName); 107 108 } 109 110 111 } 112 | Popular Tags |