notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1148 - in trunk/lab/schema/src: main/dpmlx/schema test/dpmlx/schema/test
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1148 - in trunk/lab/schema/src: main/dpmlx/schema test/dpmlx/schema/test
- Date: Tue, 28 Feb 2006 13:19:18 +0100
Author: mcconnell
Date: 2006-02-28 13:18:46 +0100 (Tue, 28 Feb 2006)
New Revision: 1148
Added:
trunk/lab/schema/src/main/dpmlx/schema/UnresolvableHandlerException.java
Modified:
trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java
trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
Log:
add evaluation of exact plugin version with fallback to an equivalent
non-versioned link
Modified: trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java
===================================================================
--- trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java 2006-02-28
11:07:57 UTC (rev 1147)
+++ trunk/lab/schema/src/main/dpmlx/schema/StandardBuilder.java 2006-02-28
12:18:46 UTC (rev 1148)
@@ -116,71 +116,4 @@
return false;
}
}
-
- /*
- 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/main/dpmlx/schema/UnresolvableHandlerException.java
===================================================================
--- trunk/lab/schema/src/main/dpmlx/schema/UnresolvableHandlerException.java
2006-02-28 11:07:57 UTC (rev 1147)
+++ trunk/lab/schema/src/main/dpmlx/schema/UnresolvableHandlerException.java
2006-02-28 12:18:46 UTC (rev 1148)
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2006 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.net.URI;
+
+import net.dpml.transit.artifact.ArtifactNotFoundException;
+
+public class UnresolvableHandlerException extends ArtifactNotFoundException
+{
+ public UnresolvableHandlerException( String message, URI uri )
+ {
+ super( message, uri );
+ }
+}
Modified: trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-02-28 11:07:57 UTC (rev 1147)
+++ trunk/lab/schema/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-02-28 12:18:46 UTC (rev 1148)
@@ -3,10 +3,13 @@
import java.io.File;
import java.net.URI;
+import java.net.URL;
import dpmlx.schema.StandardBuilder;
+import dpmlx.schema.UnresolvableHandlerException;
import net.dpml.transit.Artifact;
+import net.dpml.transit.artifact.ArtifactNotFoundException;
import net.dpml.transit.Transit;
import net.dpml.transit.util.ElementHelper;
@@ -42,18 +45,25 @@
*/
public void testPlugin() throws Exception
{
- Document doc = m_builder.parse( "target/test/plugin.xml" );
- evaluateDocument( doc );
+ evaluateDocument( "target/test/plugin.xml" );
}
public void testComponent() throws Exception
{
- Document doc = m_builder.parse( "target/test/component.xml" );
- evaluateDocument( doc );
+ try
+ {
+ evaluateDocument( "target/test/component.xml" );
+ }
+ catch( UnresolvableHandlerException e )
+ {
+ // expected
+ }
}
- private void evaluateDocument( Document doc ) throws Exception
+ private void evaluateDocument( String path ) throws Exception
{
+ System.out.println( "source: " + path );
+ Document doc = m_builder.parse( path );
final Element root = doc.getDocumentElement();
final String namespace = root.getNamespaceURI();
@@ -65,7 +75,7 @@
// a concern private to the transit implementation to
// resolve the plugin strategy
- System.out.println( "PLUGIN STRATEGY: " + namespace );
+ System.out.println( "plugin (namespace): " + namespace );
}
else
{
@@ -75,9 +85,9 @@
Element strategy = ElementHelper.getChild( root, "strategy" );
Element implementation = getSingleNestedElement( strategy );
String urn = implementation.getNamespaceURI();
- System.out.println( "CUSTOM STRATEGY: " + urn );
+ System.out.println( "strategy (namespace): " + urn );
URI uri = getImplementationHandler( urn );
- System.out.println( "HANDLER: " + uri );
+ System.out.println( "handler: " + uri );
}
}
@@ -117,7 +127,35 @@
String version = artifact.getVersion();
Artifact result = Artifact.createArtifact( group, name, version,
"plugin" );
- return result.toURI();
+ try
+ {
+ System.out.println( " checking: " + result );
+ URL url = result.toURL();
+ url.getContent( new Class[]{File.class} );
+ return result.toURI();
+ }
+ catch( ArtifactNotFoundException e )
+ {
+ String path = "link:plugin:" + group + "/" + name;
+ Artifact link = Artifact.createArtifact( path );
+ System.out.println( " checking: " + link );
+ URI linkUri = link.toURI();
+ try
+ {
+ URL linkUrl = link.toURL();
+ linkUrl.getContent( new Class[]{File.class} );
+ return link.toURI();
+ }
+ catch( ArtifactNotFoundException anfe )
+ {
+ System.out.println( " unresolved" );
+ final String error =
+ "Unable to resolve a strategy handler for the urn ["
+ + urn
+ + "].";
+ throw new UnresolvableHandlerException( error, linkUri );
+ }
+ }
}
else
{
- r1148 - in trunk/lab/schema/src: main/dpmlx/schema test/dpmlx/schema/test, mcconnell at BerliOS, 02/28/2006
Archive powered by MHonArc 2.6.24.