1 13 package com.tonbeller.jpivot.core; 14 15 import java.io.IOException ; 16 import java.net.URL ; 17 18 import org.apache.commons.digester.Digester; 19 import org.xml.sax.InputSource ; 20 import org.xml.sax.SAXException ; 21 22 23 24 35 36 public class ModelFactory { 37 38 41 private ModelFactory() { 42 } 43 44 48 public static class ModelHolder { 49 private Model model; 50 public void setModel(Model model) { 51 this.model = model; 52 } 53 public Model getModel() { 54 return model; 55 } 56 } 57 58 65 public static Model instance(URL url) throws SAXException , IOException { 66 Digester digester = new Digester(); 67 digester.setValidating(false); 68 69 ModelHolder root = new ModelHolder(); 70 digester.push(root); 71 72 digester.addObjectCreate("model", "missing \"class\" attribute", "class"); 73 digester.addSetProperties("model"); 74 digester.addSetNext("model", "setModel"); 75 76 digester.addObjectCreate("model/extension", "missing \"class\" attribute", "class"); 77 digester.addSetProperties("model/extension"); 78 digester.addSetNext("model/extension", "addExtension"); 79 80 InputSource is = new InputSource (url.toExternalForm()); 81 digester.parse(is); 82 return root.getModel(); 83 } 84 85 86 } 87 | Popular Tags |