KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > utils > ObjectFactory


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.utils;
14
15 import java.io.IOException JavaDoc;
16 import java.net.URL JavaDoc;
17
18 import org.apache.commons.digester.Digester;
19 import org.apache.commons.digester.xmlrules.DigesterLoader;
20 import org.xml.sax.SAXException JavaDoc;
21
22 /**
23  * Creates Object instances via Digester xml rules. For more info
24  * see <a HREF="http://jakarta.apache.org/commons/digester.html">Commons Digester</a>.
25  * @author av
26  */

27 public class ObjectFactory {
28
29   /**
30    * not for external use. Has to be public for the commons digester
31    * to access it.
32    */

33   public static class ObjectHolder {
34     private Object JavaDoc object;
35     public void setObject(Object JavaDoc object) {
36       this.object = object;
37     }
38     public Object JavaDoc getObject() {
39       return object;
40     }
41   }
42
43   private ObjectFactory() {
44   }
45
46   public static Object JavaDoc instance(URL JavaDoc rulesXml, URL JavaDoc configXml) throws SAXException JavaDoc, IOException JavaDoc {
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