1 13 package com.tonbeller.wcf.utils; 14 15 import java.io.IOException ; 16 import java.net.URL ; 17 18 import org.apache.commons.digester.Digester; 19 import org.apache.commons.digester.xmlrules.DigesterLoader; 20 import org.xml.sax.SAXException ; 21 22 27 public class ObjectFactory { 28 29 33 public static class ObjectHolder { 34 private Object object; 35 public void setObject(Object object) { 36 this.object = object; 37 } 38 public Object getObject() { 39 return object; 40 } 41 } 42 43 private ObjectFactory() { 44 } 45 46 public static Object instance(URL rulesXml, URL configXml) throws SAXException , IOException { 47 48 Digester digester = DigesterLoader.createDigester(rulesXml); 49 digester.setValidating(false); 50 51 ObjectHolder root = new ObjectHolder(); 52 digester.push(root); 53 54 digester.parse(configXml.openStream()); 55 return root.getObject(); 56 } 57 58 } 59 | Popular Tags |