Skip to Content.
Sympa Menu

notify-dpml - r1142 - in trunk/lab: component component/src component/src/main component/src/main/dpmlx schema/src/main/dpmlx/schema 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: r1142 - in trunk/lab: component component/src component/src/main component/src/main/dpmlx schema/src/main/dpmlx/schema schema/src/test/dpmlx/schema/test
  • Date: Tue, 28 Feb 2006 11:57:02 +0100

Author: mcconnell
Date: 2006-02-28 11:57:01 +0100 (Tue, 28 Feb 2006)
New Revision: 1142

Added:
trunk/lab/component/src/
trunk/lab/component/src/main/
trunk/lab/component/src/main/dpmlx/
trunk/lab/component/src/main/dpmlx/component/
Modified:
trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java
trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
Log:
namespace management (continued)

Modified: trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java
===================================================================
--- trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java 2006-02-28
09:37:45 UTC (rev 1141)
+++ trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java 2006-02-28
10:57:01 UTC (rev 1142)
@@ -20,14 +20,11 @@

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;
@@ -55,6 +52,8 @@

private static final String W3C_XML_SCHEMA_NS_URI =
"http://www.w3.org/2001/XMLSchema";;
+
+ private static boolean VALIDATING = isSchemaCapable();

//
// Constructors
@@ -80,57 +79,44 @@
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware( true );
- setupBuilderForSchemaValidation( dbf );
+ if( VALIDATING )
+ {
+ setupBuilderForSchemaValidation( dbf );
+ }
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler( new ParserAPIUsage() );
return db.parse( source );
}

- private boolean isSchemaCapable()
+ private void setupBuilderForSchemaValidation( DocumentBuilderFactory dbf
) throws Exception
{
+ Class schemaFactoryClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.SchemaFactory" );
+ Class schemaClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.Schema" );
+
+ Method newInstanceMethod = schemaFactoryClass.getMethod(
"newInstance", new Class[]{ String.class } );
+ Object schemaFactory = newInstanceMethod.invoke( null, new Object[]{
W3C_XML_SCHEMA_NS_URI } );
+ Method newSchemaMethod = schemaFactoryClass.getMethod( "newSchema",
new Class[0] );
+ Object schemaObject = newSchemaMethod.invoke( schemaFactory, new
Object[0] );
+ Method setSchemaMethod = DocumentBuilderFactory.class.getMethod(
"setSchema", new Class[]{ schemaClass } );
+ setSchemaMethod.invoke( dbf, new Object[]{ schemaObject } );
+ }
+
+ private static boolean isSchemaCapable()
+ {
try
{
ClassLoader classloader = StandardBuilder.class.getClassLoader();
classloader.loadClass( "javax.xml.XMLConstants" );
+ System.out.println( "validating" );
return true;
}
catch( ClassNotFoundException e )
{
+ System.out.println( "validation disabled" );
return false;
}
}

- private void setupBuilderForSchemaValidation( DocumentBuilderFactory dbf
) throws Exception
- {
- if( !isSchemaCapable() )
- {
- return;
- }
- else
- {
- System.out.println( "VALIDATING" );
-
- Class schemaFactoryClass =
getClass().getClassLoader().loadClass( "javax.xml.validation.SchemaFactory" );
- Class schemaClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.Schema" );
-
- Method newInstanceMethod = schemaFactoryClass.getMethod(
"newInstance", new Class[]{ String.class } );
- Object schemaFactory = newInstanceMethod.invoke( null, new
Object[]{ W3C_XML_SCHEMA_NS_URI } );
- Method newSchemaMethod = schemaFactoryClass.getMethod(
"newSchema", new Class[0] );
- Object schemaObject = newSchemaMethod.invoke( schemaFactory, new
Object[0] );
- Method setSchemaMethod = DocumentBuilderFactory.class.getMethod(
"setSchema", new Class[]{ schemaClass } );
- setSchemaMethod.invoke( dbf, new Object[]{ schemaObject } );
-
-
- //Class validatorClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.Validator" );
- //Method newValidatorMethod = schemaClass.getMethod(
"newValidator", new Class[0] );
-
- //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
{

Modified: trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-02-28 09:37:45 UTC (rev 1141)
+++ trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-02-28 10:57:01 UTC (rev 1142)
@@ -6,6 +6,7 @@

import dpmlx.schema.StandardBuilder;

+import net.dpml.transit.Artifact;
import net.dpml.transit.Transit;
import net.dpml.transit.util.ElementHelper;

@@ -55,7 +56,6 @@
{
final Element root = doc.getDocumentElement();
final String namespace = root.getNamespaceURI();
- //assertEquals( "namespace", "dpml:transit/part", namespace );

Element plugin = ElementHelper.getChild( root, "plugin" );
if( null != plugin )
@@ -65,7 +65,7 @@
// a concern private to the transit implementation to
// resolve the plugin strategy

- System.out.println( "PLUGIN STRATEGY " + namespace );
+ System.out.println( "PLUGIN STRATEGY: " + namespace );
}
else
{
@@ -73,17 +73,59 @@
// a <strategy> element

Element strategy = ElementHelper.getChild( root, "strategy" );
- Element[] children = ElementHelper.getChildren( strategy );
+ Element implementation = getSingleNestedElement( strategy );
+ String urn = implementation.getNamespaceURI();
+ System.out.println( "CUSTOM STRATEGY: " + urn );
+ URI uri = getImplementationHandler( urn );
+ System.out.println( "HANDLER: " + uri );
+ }
+ }
+
+ private Element getSingleNestedElement( Element parent ) throws Exception
+ {
+ if( null == parent )
+ {
+ throw new NullPointerException( "parent" );
+ }
+ else
+ {
+ Element[] children = ElementHelper.getChildren( parent );
if( children.length == 1 )
{
- Element thing = children[0];
- System.out.println( "CUSTOM STRATEGY " +
thing.getNamespaceURI() );
+ return children[0];
}
else
{
- fail( "Strategy must contain a single element." );
+ final String error =
+ "Parent element does not contain a single child.";
+ throw new IllegalArgumentException( error );
}
}
+
}

+ private URI getImplementationHandler( String urn ) throws Exception
+ {
+ URI raw = new URI( urn );
+ if( Artifact.isRecognized( raw ) )
+ {
+ Artifact artifact = Artifact.createArtifact( raw );
+ String scheme = artifact.getScheme();
+ String group = artifact.getGroup();
+ String name = artifact.getName();
+ String type = artifact.getType();
+ String version = artifact.getVersion();
+
+ Artifact result = Artifact.createArtifact( group, name, version,
"plugin" );
+ return result.toURI();
+ }
+ else
+ {
+ final String error =
+ "Namespace urn ["
+ + urn
+ + "] is not a recognized artifact protocol.";
+ throw new IllegalArgumentException( error );
+ }
+ }
}




  • r1142 - in trunk/lab: component component/src component/src/main component/src/main/dpmlx schema/src/main/dpmlx/schema schema/src/test/dpmlx/schema/test, mcconnell at BerliOS, 02/28/2006

Archive powered by MHonArc 2.6.24.

Top of Page