Skip to Content.
Sympa Menu

notify-dpml - r1140 - in trunk: . lab lab/schema lab/schema/examples lab/schema/src lab/schema/src/main lab/schema/src/main/dpmlx lab/schema/src/main/dpmlx/schema lab/schema/src/test lab/schema/src/test/dpmlx lab/schema/src/test/dpmlx/schema lab/schema/src/test/dpmlx/schema/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1140 - in trunk: . lab lab/schema lab/schema/examples lab/schema/src lab/schema/src/main lab/schema/src/main/dpmlx lab/schema/src/main/dpmlx/schema lab/schema/src/test lab/schema/src/test/dpmlx lab/schema/src/test/dpmlx/schema lab/schema/src/test/dpmlx/schema/test
  • Date: Tue, 28 Feb 2006 04:20:40 +0100

Author: mcconnell
Date: 2006-02-28 04:19:46 +0100 (Tue, 28 Feb 2006)
New Revision: 1140

Added:
trunk/lab/
trunk/lab/library.xml
trunk/lab/schema/
trunk/lab/schema/README.TXT
trunk/lab/schema/examples/
trunk/lab/schema/examples/component.xml
trunk/lab/schema/examples/component.xsd
trunk/lab/schema/examples/part.xsd
trunk/lab/schema/examples/plugin.xml
trunk/lab/schema/examples/plugin.xsd
trunk/lab/schema/src/
trunk/lab/schema/src/main/
trunk/lab/schema/src/main/dpmlx/
trunk/lab/schema/src/main/dpmlx/schema/
trunk/lab/schema/src/main/dpmlx/schema/ParserAPIUsage.java
trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java
trunk/lab/schema/src/test/
trunk/lab/schema/src/test/dpmlx/
trunk/lab/schema/src/test/dpmlx/schema/
trunk/lab/schema/src/test/dpmlx/schema/test/
trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
Log:
Add XML schema based validation testcase.

Added: trunk/lab/library.xml
===================================================================
--- trunk/lab/library.xml 2006-02-25 00:17:13 UTC (rev 1139)
+++ trunk/lab/library.xml 2006-02-28 03:19:46 UTC (rev 1140)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE library PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd"; >
+
+<library>
+
+ <imports>
+ <import uri="link:module:ant"/>
+ <import uri="link:module:dpml"/>
+ </imports>
+
+ <modules>
+
+ <module name="dpmlx">
+
+ <project name="dpmlx-schema-test" basedir="schema">
+ <types>
+ <type id="jar"/>
+ <type id="plugin" alias="true">
+ <property name="project.plugin.class"
+ value="dpmlx.schema.StandardBuilder"/>
+ </type>
+ </types>
+ <dependencies scope="test">
+ <include ref="dpml/transit/dpml-transit-main"/>
+ <include ref="ant/ant-junit"/>
+ </dependencies>
+ </project>
+
+ </module>
+
+ </modules>
+
+</library>

Added: trunk/lab/schema/README.TXT
===================================================================
--- trunk/lab/schema/README.TXT 2006-02-25 00:17:13 UTC (rev 1139)
+++ trunk/lab/schema/README.TXT 2006-02-28 03:19:46 UTC (rev 1140)
@@ -0,0 +1,31 @@
+
+Build instructions
+------------------
+
+ $ build clean install
+
+
+Notes
+-----
+
+This project is a tescase for XML-Schema based validation of a generalized
+plugin descriptor that leverages XML-namespaces to allow the declaration of
+a custom plugin handler. Two examles are provided 'plugin.xml' and
+'component.xml'. The plugin.xml file is an example of what a transit plugin
+defintion wouold look like (it contains a transit plugin strategy
declaration).
+The component.xml used the same enclosing structure but defines a component
+deployment strategy.
+
+The purpose of the project is to check that everything works as expected when
+running under any of the following four scenarios:
+
+ 1. JDK 1.4 plain
+ 2. JDK 1.4 with xeces in lib/endorced
+ 3. JDK 1.5 plain
+ 4. JDK 1.5 with xeces in lib/endorced
+
+When running under 1.4 without xerces xml content will not be validated.
+When running under 1.4 + Xerces xml content will be validated using
XML-Schema.
+Test related to 1.5 are pending.
+
+Namespace names and schema resolving strategies are subject to change.

Added: trunk/lab/schema/examples/component.xml
===================================================================
--- trunk/lab/schema/examples/component.xml 2006-02-25 00:17:13 UTC (rev
1139)
+++ trunk/lab/schema/examples/component.xml 2006-02-28 03:19:46 UTC (rev
1140)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<part xmlns="link:xsd:dpml/transit/dpml-transit-part"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xmlns:metro="link:xsd:dpml/metro/dpml-metro-component"
+ xsi:schemaLocation="link:xsd:dpml/transit/dpml-transit-part part.xsd
+ link:xsd:dpml/metro/dpml-metro-component
component.xsd" >
+
+ <info title="Demo Part">
+ <description>
+ Plugin descriptor using XMLSchema.
+ </description>
+ </info>
+
+ <strategy uri="link:plugin:dpml/metro/dpml-metro-runtime">
+ <metro:component type="org.acme.Widget">
+ <metro:context>
+ <metro:entry key="foo" value="abc"/>
+ <metro:entry key="bar">
+ <metro:value class="int" value="2"/>
+ </metro:entry>
+ </metro:context>
+ </metro:component>
+ </strategy>
+
+ <classpath>
+ <public>
+ <uri>link:jar:fred/blogs"</uri>
+ <uri>link:jar:peter/rabbit"</uri>
+ </public>
+ </classpath>
+
+</part>

Added: trunk/lab/schema/examples/component.xsd
===================================================================
--- trunk/lab/schema/examples/component.xsd 2006-02-25 00:17:13 UTC (rev
1139)
+++ trunk/lab/schema/examples/component.xsd 2006-02-28 03:19:46 UTC (rev
1140)
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+
+<!--
+http://download.dpml.net/component
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+ targetNamespace="link:xsd:dpml/metro/dpml-metro-component"
+ xmlns="link:xsd:dpml/metro/dpml-metro-component"
+ elementFormDefault="qualified">
+
+ <xsd:element name="component" type="ComponentType"/>
+
+ <xsd:complexType name="ComponentType">
+ <xsd:sequence>
+ <xsd:element name="context" type="ContextType" minOccurs="0"
maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="type" type="xsd:string"/>
+ <xsd:attribute name="lifestyle" type="xsd:string"/>
+ <xsd:attribute name="collection" type="xsd:string"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="ContextType">
+ <xsd:sequence>
+ <xsd:element name="entry" type="EntryType" minOccurs="0"
maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="EntryType">
+ <xsd:sequence>
+ <xsd:element name="value" type="ValueType" minOccurs="0"
maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <xsd:attribute name="key" type="xsd:string"/>
+ <xsd:attribute name="value" type="xsd:string"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="ValueType">
+ <xsd:sequence>
+ <xsd:element name="value" type="ValueType" minOccurs="0"
maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <xsd:attribute name="class" type="xsd:string"/>
+ <xsd:attribute name="value" type="xsd:string"/>
+ </xsd:complexType>
+
+</xsd:schema>

Added: trunk/lab/schema/examples/part.xsd
===================================================================
--- trunk/lab/schema/examples/part.xsd 2006-02-25 00:17:13 UTC (rev 1139)
+++ trunk/lab/schema/examples/part.xsd 2006-02-28 03:19:46 UTC (rev 1140)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+ targetNamespace="link:xsd:dpml/transit/dpml-transit-part"
+ xmlns="link:xsd:dpml/transit/dpml-transit-part"
+ elementFormDefault="qualified">
+
+ <xsd:element name="part" type="PartType"/>
+
+ <xsd:complexType name="PartType">
+ <xsd:sequence>
+ <xsd:element name="info" type="InfoType"/>
+ <xsd:element name="strategy" type="StrategyType"/>
+ <xsd:element name="classpath" type="ClassPathType"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="StrategyType">
+ <xsd:sequence>
+ <xsd:any minOccurs="0"/>
+ </xsd:sequence>
+ <xsd:attribute name="uri" type="xsd:anyURI"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="ClassPathType">
+ <xsd:sequence>
+ <xsd:element name="system" type="ClassLoaderType" minOccurs="0"
maxOccurs="1"/>
+ <xsd:element name="public" type="ClassLoaderType" minOccurs="0"
maxOccurs="1"/>
+ <xsd:element name="protected" type="ClassLoaderType" minOccurs="0"
maxOccurs="1"/>
+ <xsd:element name="private" type="ClassLoaderType" minOccurs="0"
maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="ClassLoaderType">
+ <xsd:sequence>
+ <xsd:element name="uri" type="URIType" minOccurs="0"
maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="InfoType">
+ <xsd:sequence>
+ <xsd:element name="description" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="title" type="xsd:string"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="URIType">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:anyURI"/>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+</xsd:schema>

Added: trunk/lab/schema/examples/plugin.xml
===================================================================
--- trunk/lab/schema/examples/plugin.xml 2006-02-25 00:17:13 UTC (rev
1139)
+++ trunk/lab/schema/examples/plugin.xml 2006-02-28 03:19:46 UTC (rev
1140)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<part xmlns="link:xsd:dpml/transit/dpml-transit-part"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xmlns:transit="link:xsd:dpml/transit/dpml-transit-main"
+ xsi:schemaLocation="link:xsd:dpml/transit/dpml-transit-part part.xsd
+ link:xsd:dpml/transit/dpml-transit-main plugin.xsd
+ link:xsd:dpml/metro/dpml-metro-component
component.xsd" >
+
+ <info title="Demo Plugin">
+ <description>
+ Plugin descriptor using XMLSchema.
+ </description>
+ </info>
+
+ <strategy>
+ <transit:plugin>
+ <transit:properties>
+ <transit:property name="project.plugin.class" value="Widget"/>
+ </transit:properties>
+ </transit:plugin>
+ </strategy>
+
+ <classpath>
+ <public>
+ <uri>link:jar:fred/blogs"</uri>
+ <uri>link:jar:peter/rabbit"</uri>
+ </public>
+ </classpath>
+
+</part>

Added: trunk/lab/schema/examples/plugin.xsd
===================================================================
--- trunk/lab/schema/examples/plugin.xsd 2006-02-25 00:17:13 UTC (rev
1139)
+++ trunk/lab/schema/examples/plugin.xsd 2006-02-28 03:19:46 UTC (rev
1140)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+ targetNamespace="link:xsd:dpml/transit/dpml-transit-main"
+ xmlns="link:xsd:dpml/transit/dpml-transit-main"
+ elementFormDefault="qualified">
+
+ <xsd:element name="plugin" type="PluginType"/>
+
+ <xsd:complexType name="PluginType">
+ <xsd:sequence>
+ <xsd:element name="properties" type="PropertiesType" minOccurs="0"
maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="PropertiesType">
+ <xsd:sequence>
+ <xsd:element name="property" type="PropertyType" minOccurs="0"
maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="PropertyType">
+ <xsd:attribute name="name" type="xsd:string"/>
+ <xsd:attribute name="value" type="xsd:string"/>
+ </xsd:complexType>
+
+</xsd:schema>

Added: trunk/lab/schema/src/main/dpmlx/schema/ParserAPIUsage.java
===================================================================
--- trunk/lab/schema/src/main/dpmlx/schema/ParserAPIUsage.java 2006-02-25
00:17:13 UTC (rev 1139)
+++ trunk/lab/schema/src/main/dpmlx/schema/ParserAPIUsage.java 2006-02-28
03:19:46 UTC (rev 1140)
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.schema;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * <p>A sample which demonstrates usage of the JAXP 1.3 Parser API.</p>
+ *
+ * @author Michael Glavassevich, IBM
+ * @author Ankit Pasricha, IBM
+ *
+ * @version $Id: ParserAPIUsage.java,v 1.2 2005/06/10 03:43:46 mrglavas Exp $
+ */
+public class ParserAPIUsage extends DefaultHandler {
+
+ /** Default constructor. */
+ public ParserAPIUsage() {
+ } // <init>()
+
+ //
+ // ErrorHandler methods
+ //
+
+ /** Warning. */
+ public void warning(SAXParseException ex) throws SAXException {
+ printError("Warning", ex);
+ } // warning(SAXParseException)
+
+ /** Error. */
+ public void error(SAXParseException ex) throws SAXException {
+ printError("Error", ex);
+ } // error(SAXParseException)
+
+ /** Fatal error. */
+ public void fatalError(SAXParseException ex) throws SAXException {
+ printError("Fatal Error", ex);
+ throw ex;
+ } // fatalError(SAXParseException)
+
+ //
+ // Protected methods
+ //
+
+ /** Prints the error message. */
+ protected void printError(String type, SAXParseException ex) {
+
+ System.err.print("[");
+ System.err.print(type);
+ System.err.print("] ");
+ String systemId = ex.getSystemId();
+ if (systemId != null) {
+ int index = systemId.lastIndexOf('/');
+ if (index != -1)
+ systemId = systemId.substring(index + 1);
+ System.err.print(systemId);
+ }
+ System.err.print(':');
+ System.err.print(ex.getLineNumber());
+ System.err.print(':');
+ System.err.print(ex.getColumnNumber());
+ System.err.print(": ");
+ System.err.print(ex.getMessage());
+ System.err.println();
+ System.err.flush();
+
+ } // printError(String,SAXParseException)
+
+} // ParserAPIUsage

Added: trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java
===================================================================
--- trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java 2006-02-25
00:17:13 UTC (rev 1139)
+++ trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java 2006-02-28
03:19:46 UTC (rev 1140)
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.schema;
+
+import java.lang.reflect.Method;
+
+//import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.stream.StreamSource;
+//import javax.xml.validation.Schema;
+//import javax.xml.validation.SchemaFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.w3c.dom.Document;
+
+public class StandardBuilder extends DefaultHandler
+{
+ static final String PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
+
+ protected static final String DEFAULT_API_TO_USE = "sax";
+
+ protected static final boolean DEFAULT_XINCLUDE = false;
+
+ protected static final boolean DEFAULT_SECURE_PROCESSING = false;
+
+ private static final String FEATURE_SECURE_PROCESSING =
+ "http://javax.xml.XMLConstants/feature/secure-processing";;
+
+ private static final String W3C_XML_SCHEMA_NS_URI =
+ "http://www.w3.org/2001/XMLSchema";;
+
+ //
+ // Constructors
+ //
+
+ public StandardBuilder( String[] args ) throws Exception
+ {
+ if (args.length == 1)
+ {
+ try
+ {
+ String source = args[0];
+ parse( source );
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public Document parse( String source ) throws Exception
+ {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware( true );
+ setupBuilderForSchemaValidation( dbf );
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ db.setErrorHandler( new ParserAPIUsage() );
+ return db.parse( source );
+ }
+
+ private boolean isSchemaCapable()
+ {
+ try
+ {
+ ClassLoader classloader = StandardBuilder.class.getClassLoader();
+ classloader.loadClass( "javax.xml.XMLConstants" );
+ return true;
+ }
+ catch( ClassNotFoundException e )
+ {
+ return false;
+ }
+ }
+
+ private void setupBuilderForSchemaValidation( DocumentBuilderFactory dbf
) throws Exception
+ {
+ if( !isSchemaCapable() )
+ {
+ return;
+ }
+ else
+ {
+ //dbf.setFeature( FEATURE_SECURE_PROCESSING, false );
+
+ Class schemaFactoryClass =
getClass().getClassLoader().loadClass( "javax.xml.validation.SchemaFactory" );
+ Method newInstanceMethod = schemaFactoryClass.getMethod(
"newInstance", new Class[]{ String.class } );
+ Object schemaFactory = newInstanceMethod.invoke( null, new
Object[]{ W3C_XML_SCHEMA_NS_URI } );
+ Method newSchemaMethod = schemaFactory.getClass().getMethod(
"newSchema", new Class[0] );
+ Object schemaObject = newSchemaMethod.invoke( schemaFactory, new
Object[0] );
+ Class schemaClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.Schema" );
+ Method setSchemaMethod = DocumentBuilderFactory.class.getMethod(
"setSchema", new Class[]{ schemaClass } );
+ setSchemaMethod.invoke( dbf, new Object[]{ schemaObject } );
+
+ //SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI );
+ //Schema schema = factory.newSchema();
+ //dbf.setXIncludeAware( false );
+ //dbf.setSchema( schema );
+ }
+ }
+
+ /*
+ public String process( String xmlFileURL ) throws Exception
+ {
+ StandardHandler builder = new StandardHandler();
+ XMLReader parser = XMLReaderFactory.createXMLReader( PARSER_NAME );
+ parser.setContentHandler( builder );
+ parser.setErrorHandler( builder );
+ parser.setFeature( "http://xml.org/sax/features/validation";, true );
+ parser.setFeature(
"http://apache.org/xml/features/validation/schema";, true );
+ parser.setFeature(
"http://apache.org/xml/features/validation/schema-full-checking";, true );
+ parser.parse( xmlFileURL );
+ String result = builder.getResult();
+ return result;
+ }
+
+ public class StandardHandler extends DefaultHandler
+ {
+ StringBuffer m_result = new StringBuffer( "" );
+
+ public void warning( SAXParseException ex )
+ {
+ m_result.append( "\n[WARN] " +
+ getLocationString( ex ) + ": " +
+ ex.getMessage() + " " );
+ }
+
+ public void error( SAXParseException ex )
+ {
+ m_result.append("\n[ERROR] " +
+ getLocationString( ex ) + ": " +
+ ex.getMessage() + " " );
+ }
+
+ public void fatalError( SAXParseException ex ) throws SAXException
+ {
+ m_result.append("\n[FATAL] "+
+ getLocationString( ex ) + ": "+
+ ex.getMessage() + " " );
+ }
+
+ public String getResult()
+ {
+ return m_result.toString();
+ }
+
+ private String getLocationString( SAXParseException ex )
+ {
+ StringBuffer str = new StringBuffer();
+ String systemId = ex.getSystemId();
+ if( systemId != null )
+ {
+ int index = systemId.lastIndexOf( '/' );
+ if( index != -1 )
+ {
+ systemId = systemId.substring( index + 1 );
+ }
+ str.append( systemId );
+ }
+ str.append( ':' );
+ str.append( ex.getLineNumber() );
+ str.append( ':' );
+ str.append( ex.getColumnNumber() );
+ return str.toString();
+ }
+ }
+ */
+}

Added: trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-02-25 00:17:13 UTC (rev 1139)
+++ trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-02-28 03:19:46 UTC (rev 1140)
@@ -0,0 +1,79 @@
+
+package dpmlx.schema.test;
+
+import java.io.File;
+import java.net.URI;
+
+import dpmlx.schema.StandardBuilder;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ElementHelper;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.DocumentType;
+
+/**
+ * Test the demo class..
+ */
+public class SchemaTestCase extends TestCase
+{
+ StandardBuilder m_builder;
+
+ /**
+ * Test the demo class.
+ */
+ public void setUp() throws Exception
+ {
+ ClassLoader classloader = Transit.class.getClassLoader();
+ File file = new File(
"target/deliverables/plugins/dpmlx-schema-test-SNAPSHOT.plugin" );
+ URI uri = file.toURI();
+ Object[] args = new Object[0];
+ m_builder =
+ (StandardBuilder) Transit.getInstance().getRepository().getPlugin(
+ classloader, uri, args );
+ }
+
+ /**
+ * Test the demo class.
+ */
+ public void testPlugin() throws Exception
+ {
+ Document doc = m_builder.parse( "examples/plugin.xml" );
+ final Element root = doc.getDocumentElement();
+ final String uri = root.getNamespaceURI();
+ //System.out.println( "NS: [" + uri + "]" );
+ //System.out.println( "ROOT: [" + root + "]" );
+ Element strategy = ElementHelper.getChild( root, "strategy" );
+ String handlerUri = ElementHelper.getAttribute( strategy, "uri" );
+ if( null == handlerUri )
+ {
+ System.out.println( "DEFAULT STRATEGY" );
+ }
+ else
+ {
+ System.out.println( "CUSTOM STRATEGY: " + handlerUri );
+ }
+ }
+
+ public void testComponent() throws Exception
+ {
+ Document doc = m_builder.parse( "examples/component.xml" );
+ final Element root = doc.getDocumentElement();
+ final String uri = root.getNamespaceURI();
+ //System.out.println( "NS: [" + uri + "]" );
+ //System.out.println( "ROOT: [" + root + "]" );
+ Element strategy = ElementHelper.getChild( root, "strategy" );
+ String handlerUri = ElementHelper.getAttribute( strategy, "uri" );
+ if( null == handlerUri )
+ {
+ System.out.println( "DEFAULT STRATEGY" );
+ }
+ else
+ {
+ System.out.println( "CUSTOM STRATEGY: " + handlerUri );
+ }
+ }
+}




  • r1140 - in trunk: . lab lab/schema lab/schema/examples lab/schema/src lab/schema/src/main lab/schema/src/main/dpmlx lab/schema/src/main/dpmlx/schema lab/schema/src/test lab/schema/src/test/dpmlx lab/schema/src/test/dpmlx/schema lab/schema/src/test/dpmlx/schema/test, mcconnell at BerliOS, 02/27/2006

Archive powered by MHonArc 2.6.24.

Top of Page