Changeset 10
- Timestamp:
- 07/01/05 11:24:56 (4 years ago)
- Files:
-
- trunk/src/net/schst/XJConf/AttributeDefinition.java (modified) (2 diffs)
- trunk/src/net/schst/XJConf/Examples/Example1.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Examples/Example2.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Examples/Example3.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Examples/ExampleCollection.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Examples/ExampleHashMap.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Examples/ExampleInclude.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Extension.java (modified) (2 diffs)
- trunk/src/net/schst/XJConf/TagDefinition.java (modified) (5 diffs)
- trunk/src/net/schst/XJConf/UnknownExtensionException.java (added)
- trunk/src/net/schst/XJConf/UnknownNamespaceException.java (modified) (2 diffs)
- trunk/src/net/schst/XJConf/UnknownTagException.java (modified) (2 diffs)
- trunk/src/net/schst/XJConf/ValueConversionException.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/XJConfException.java (added)
- trunk/src/net/schst/XJConf/XmlReader.java (modified) (6 diffs)
- trunk/src/net/schst/XJConf/ext/XInclude.java (modified) (5 diffs)
- trunk/src/net/schst/XJConf/ext/XIncludeException.java (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/net/schst/XJConf/AttributeDefinition.java
r1 r10 123 123 * @param val value to convert 124 124 * @return converted value 125 * @throws ValueConversionException 125 126 */ 126 public Object convertValue(Object val) {127 public Object convertValue(Object val) throws ValueConversionException { 127 128 String value = (String)val; 128 129 Object instance = null; … … 134 135 String params[] = {value}; 135 136 instance = co.newInstance(params); 136 } catch ( Throwablet) {137 } catch (Exception t) { 137 138 throw new ValueConversionException("Could not create attribute " + this.name + " of type " + this.type, t); 138 139 } trunk/src/net/schst/XJConf/Examples/Example1.java
r2 r10 31 31 32 32 XmlReader conf = new XmlReader(); 33 conf.setTagDefinitions(defs); 34 35 conf.parse("xml/test.xml"); 33 try { 34 conf.setTagDefinitions(defs); 35 36 conf.parse("xml/test.xml"); 37 } catch (Exception e) { 38 e.printStackTrace(); 39 System.exit(0); 40 } 36 41 37 42 String foo = (String)conf.getConfigValue("foo"); trunk/src/net/schst/XJConf/Examples/Example2.java
r2 r10 25 25 conf.setTagDefinitions(defs); 26 26 27 conf.parse("xml/test2.xml"); 27 try { 28 conf.parse("xml/test2.xml"); 29 } catch (Exception e) { 30 e.printStackTrace(); 31 System.exit(0); 32 } 28 33 29 34 Integer one = (Integer)conf.getConfigValue("one"); trunk/src/net/schst/XJConf/Examples/Example3.java
r2 r10 29 29 conf.setTagDefinitions(defs); 30 30 31 conf.parse("xml/test3.xml"); 31 try { 32 conf.parse("xml/test3.xml"); 33 } catch (Exception e) { 34 e.printStackTrace(); 35 System.exit(0); 36 } 32 37 33 38 Integer zahl = (Integer)conf.getConfigValue("zahl"); trunk/src/net/schst/XJConf/Examples/ExampleCollection.java
r5 r10 19 19 conf.setTagDefinitions(defs); 20 20 21 conf.parse("xml/test-collection.xml"); 21 try { 22 conf.parse("xml/test-collection.xml"); 23 } catch (Exception e) { 24 e.printStackTrace(); 25 System.exit(0); 26 } 22 27 23 28 ArrayList list = (ArrayList)conf.getConfigValue("list"); trunk/src/net/schst/XJConf/Examples/ExampleHashMap.java
r5 r10 20 20 conf.setTagDefinitions(defs); 21 21 22 conf.parse("xml/test-hashmap.xml"); 22 try { 23 conf.parse("xml/test-hashmap.xml"); 24 } catch (Exception e) { 25 e.printStackTrace(); 26 System.exit(0); 27 } 23 28 24 29 HashMap map = (HashMap)conf.getConfigValue("map"); trunk/src/net/schst/XJConf/Examples/ExampleInclude.java
r8 r10 23 23 conf.addExtension("http://www.w3.org/2001/XInclude", xinc); 24 24 25 conf.parse("xml/test-xinclude.xml"); 25 try { 26 conf.parse("xml/test-xinclude.xml"); 27 } catch (Exception e) { 28 e.printStackTrace(); 29 System.exit(0); 30 } 26 31 27 32 HashMap map = (HashMap)conf.getConfigValue("map"); trunk/src/net/schst/XJConf/Extension.java
r9 r10 1 1 package net.schst.XJConf; 2 2 3 import org.xml.sax.SAXException;4 3 5 4 /** … … 11 10 12 11 public void startElement(XmlReader reader, Tag tag) 13 throws SAXException;12 throws XJConfException; 14 13 15 public void endElement(XmlReader reader, Tag tag); 14 public void endElement(XmlReader reader, Tag tag) 15 throws XJConfException; 16 16 17 17 } trunk/src/net/schst/XJConf/TagDefinition.java
r8 r10 140 140 * @param v value to convert 141 141 * @return converted value 142 */ 143 public Object convertValue(Object v) { 142 * @throws ValueConversionException 143 */ 144 public Object convertValue(Object v) throws ValueConversionException { 144 145 Tag tag = (Tag)v; 145 146 … … 157 158 // get the class object 158 159 cl = Class.forName(this.type); 159 } catch ( Throwablee) {160 } catch (Exception e) { 160 161 throw new ValueConversionException("Class " + this.type + " does not exist", e); 161 162 } … … 175 176 try { 176 177 instance = cl.newInstance(); 177 } catch ( Throwablet) {178 } catch (Exception t) { 178 179 throw new ValueConversionException("Could not create instance of " + this.type, t); 179 180 } … … 209 210 me.invoke(instance, meParams); 210 211 211 } catch ( Throwablet) {212 } catch (Exception t) { 212 213 throw new ValueConversionException("Could not set attribute " + attName + " of " + this.type, t); 213 214 } … … 257 258 childMethod.invoke(instance, childParams); 258 259 } 259 } catch ( Throwablet) {260 } catch (Exception t) { 260 261 throw new ValueConversionException("Could not add child " + child.getKey() + " to " + this.getType() + " using "+methodName+"().", t); 261 262 } trunk/src/net/schst/XJConf/UnknownNamespaceException.java
r1 r10 1 1 package net.schst.XJConf; 2 2 3 3 4 /** … … 6 7 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 7 8 */ 8 public class UnknownNamespaceException extends RuntimeException {9 public class UnknownNamespaceException extends XJConfException { 9 10 public UnknownNamespaceException(String message) { 10 11 super(message); trunk/src/net/schst/XJConf/UnknownTagException.java
r1 r10 1 1 package net.schst.XJConf; 2 2 3 3 4 /** … … 6 7 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 7 8 */ 8 public class UnknownTagException extends RuntimeException {9 public class UnknownTagException extends XJConfException { 9 10 public UnknownTagException(String message) { 10 11 super(message); 11 12 } 13 12 14 public UnknownTagException(String message, Exception cause) { 13 15 super(message, (Exception) cause); trunk/src/net/schst/XJConf/ValueConversionException.java
r1 r10 6 6 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 7 7 */ 8 public class ValueConversionException extends RuntimeException { 9 public ValueConversionException(String message, Throwable cause) { 10 super(message, cause); 8 public class ValueConversionException extends XJConfException { 9 10 /** 11 * @param e 12 */ 13 public ValueConversionException(Exception e) { 14 super(e); 15 } 16 17 /** 18 * @param message 19 */ 20 public ValueConversionException(String message) { 21 super(message); 22 } 23 24 /** 25 * @param message 26 * @param e 27 */ 28 public ValueConversionException(String message, Exception e) { 29 super(message, e); 11 30 } 12 31 } trunk/src/net/schst/XJConf/XmlReader.java
r9 r10 2 2 3 3 import java.io.File; 4 import java.io.IOException; 4 5 import java.util.HashMap; 5 6 import java.util.Stack; … … 63 64 private Stack openFiles = new Stack(); 64 65 66 /** 67 * The factory for all parsers 68 */ 65 69 private SAXParserFactory parserFactory = null; 66 70 … … 91 95 } 92 96 93 public void addExtension(String name) { 97 /** 98 * Add a new extension 99 * 100 * @param name full-qualified class name 101 * @throws UnknownExtensionException 102 */ 103 public void addExtension(String name) throws UnknownExtensionException { 104 Extension ext; 94 105 try { 95 106 Class c = Class.forName(name); 96 Extension ext = (Extension)c.newInstance(); 97 String ns = ext.getNamespace(); 98 99 this.addExtension(ns, ext); 100 107 ext = (Extension)c.newInstance(); 101 108 } catch (Exception e) { 102 e.printStackTrace(); 103 } 109 throw new UnknownExtensionException("The extension " + name + " could not be loaded."); 110 } 111 String ns = ext.getNamespace(); 112 this.addExtension(ns, ext); 104 113 } 105 114 … … 109 118 * 110 119 * @param file File object to parse 111 */ 112 public void parse(File file) { 120 * @throws XJConfException 121 * @throws IOException 122 */ 123 public void parse(File file) throws XJConfException, IOException { 113 124 if (this.parserFactory == null) { 114 125 this.parserFactory = SAXParserFactory.newInstance(); … … 122 133 saxParser = this.parserFactory.newSAXParser(); 123 134 saxParser.parse(file, this); 124 } catch (Throwable t) { 125 t.printStackTrace(); 135 } catch (XJConfException e) { 136 throw e; 137 } catch (ParserConfigurationException e) { 138 throw new InternalError("Could not configure the parser correctly."); 139 } catch (SAXException e) { 140 throw new XJConfException(e.getMessage()); 141 } catch (IOException e) { 142 throw e; 126 143 } 127 144 this.openFiles.pop(); … … 141 158 * 142 159 * @param filename filename of the configuration file 160 * @throws IOException 161 * @throws XJConfException 143 162 */ 144 public void parse(String filename) {163 public void parse(String filename) throws XJConfException, IOException { 145 164 File file = new File(filename); 146 165 this.parse(file); trunk/src/net/schst/XJConf/ext/XInclude.java
r9 r10 7 7 import net.schst.XJConf.XmlReader; 8 8 9 import org.xml.sax.SAXException;10 11 9 /** 12 10 * Very basic xInclude mechanism … … 16 14 public class XInclude implements Extension { 17 15 16 /** 17 * Namespace of the extension 18 */ 18 19 private String namespace = "http://www.w3.org/2001/XInclude"; 19 20 … … 25 26 * @see net.schst.XJConf.Extension#endElement(java.lang.String, java.lang.String) 26 27 */ 27 public void endElement(XmlReader reader, Tag tag) {28 public void endElement(XmlReader reader, Tag tag) throws XIncludeException { 28 29 String href = tag.getAttribute("href"); 29 30 if (href == null) { … … 35 36 href = current.getParent() + "/" + href; 36 37 } 37 reader.parse(href); 38 try { 39 reader.parse(href); 40 } catch (Exception e) { 41 throw new XIncludeException("Could not xInclude " + href, e); 42 } 38 43 } 39 44 … … 41 46 * @see net.schst.XJConf.Extension#startElement(java.lang.String, org.xml.sax.Attributes) 42 47 */ 43 public void startElement(XmlReader reader, Tag tag) throws SAXException{48 public void startElement(XmlReader reader, Tag tag) { 44 49 } 45 50 }
