Changeset 57

Show
Ignore:
Timestamp:
04/04/06 22:26:47 (3 years ago)
Author:
schst
Message:

Added InvalidNamespaceDefinitionException?, added several test cases (17% code coverage reached)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/.classpath

    r56 r57  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<classpath> 
     3    <classpathentry exported="true" kind="var" path="CLOVER_RUNTIME"/> 
    34    <classpathentry kind="src" path="src/main/java"/> 
    4     <classpathentry kind="src" path="src/test/java"/> 
     5    <classpathentry kind="src" path="src/main/resources"/> 
     6    <classpathentry output="target/test-classes" kind="src" path="src/test/java"/> 
     7    <classpathentry output="target/test-classes" kind="src" path="src/test/resources"/> 
    58    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 
    6     <classpathentry sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/> 
    7     <classpathentry kind="output" path="build"/> 
     9    <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/> 
     10    <classpathentry kind="output" path="target/classes"/> 
    811</classpath> 
  • trunk/.project

    r18 r57  
    1111            </arguments> 
    1212        </buildCommand> 
     13        <buildCommand> 
     14            <name>com.cenqua.clover.eclipse.cloverjavabuilder</name> 
     15            <arguments> 
     16            </arguments> 
     17        </buildCommand> 
    1318    </buildSpec> 
    1419    <natures> 
  • trunk/src/main/java/net/schst/XJConf/AttributeDefinition.java

    r39 r57  
    1919 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 
    2020 */ 
    21 public class AttributeDefinition implements Definition
     21public class AttributeDefinition implements Definition
    2222     
    2323    /** 
  • trunk/src/main/java/net/schst/XJConf/DefinitionParser.java

    r48 r57  
    1 /* 
    2  * Created on 24.05.2005 
    3  */ 
    41package net.schst.XJConf; 
    52 
     
    118import javax.xml.parsers.SAXParserFactory; 
    129 
     10import net.schst.XJConf.exceptions.InvalidNamespaceDefinitionException; 
    1311import net.schst.XJConf.exceptions.InvalidTagDefinitionException; 
    1412import net.schst.XJConf.exceptions.XJConfException; 
     
    3129     
    3230    /** 
     31     * Constant for the default namespace 
     32     */ 
     33    public final static String DEFAULT_NAMESPACE = "__default"; 
     34     
     35    /** 
    3336     * The current namespace 
    3437     */ 
    35     private String currentNamespace = "__default"
     38    private String currentNamespace = DefinitionParser.DEFAULT_NAMESPACE
    3639     
    3740    /** 
     
    6467            SAXParser saxParser = factory.newSAXParser(); 
    6568            saxParser.parse(file, this); 
    66         }  catch (Exception e) { 
     69        }  catch (XJConfException e) { 
     70            throw e; 
     71        } catch (Exception e) { 
    6772            throw new XJConfException("Could not read definition file.", e); 
    6873        } 
     
    8287            SAXParser saxParser = factory.newSAXParser(); 
    8388            saxParser.parse(inputStream, this); 
    84         }  catch (Exception e) { 
    85             throw new XJConfException("Could not read definition file.", e); 
    86         } 
     89        }  catch (XJConfException e) { 
     90            throw e; 
     91        } catch (Exception e) { 
     92            throw new XJConfException("Could not read definition file.", e); 
     93        } 
    8794        return this.defs; 
    8895    } 
     
    102109            String uri = atts.getValue("uri"); 
    103110            if (uri == null) { 
    104                 throw new InvalidTagDefinitionException("The <namespace> tag is missing the uri attribute."); 
     111                throw new InvalidNamespaceDefinitionException("The <namespace> tag is missing the uri attribute."); 
    105112            } 
    106113            this.currentNamespace = uri; 
     
    227234 
    228235        if (qName.equals("namespace")) { 
    229             this.currentNamespace = "__default"
     236            this.currentNamespace = DefinitionParser.DEFAULT_NAMESPACE
    230237        } 
    231238 
     
    266273            TagDefinition def = (TagDefinition)this.defStack.pop(); 
    267274             
    268             if (!this.defs.namespaceExists(this.currentNamespace)) { 
     275            if (!this.defs.isNamespaceDefined(this.currentNamespace)) { 
    269276                this.defs.addNamespaceDefinition(this.currentNamespace, new NamespaceDefinition(this.currentNamespace)); 
    270277            } 
  • trunk/src/main/java/net/schst/XJConf/NamespaceDefinitions.java

    r34 r57  
    112112        } 
    113113    } 
    114      
    115     public boolean namespaceExists(String namespaceURI) { 
    116         return this.namespaces.containsKey(namespaceURI); 
    117     } 
    118114} 
  • trunk/src/test/java/net/schst/XJConf/tests/DefinitionParserParseTestCase.java

    r56 r57  
    4444        defParser.parse(stream); 
    4545    } 
     46 
     47    /* 
     48     * Test method for parse with an invalid file name 
     49     */ 
     50    public void testParseExceptionString() { 
     51        DefinitionParser defParser = new DefinitionParser(); 
     52        try { 
     53            defParser.parse("invalid-file.xml"); 
     54        } catch (XJConfException e){ 
     55            return; 
     56        } 
     57        TestCase.fail("Expected XJConf exception because of invalid file."); 
     58    } 
     59 
    4660}