git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269110 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -9,10 +9,12 @@ package org.apache.myrmidon.components.builder; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import javax.xml.parsers.SAXParser; | |||||
| import javax.xml.parsers.SAXParserFactory; | |||||
| import org.apache.avalon.framework.ExceptionUtil; | import org.apache.avalon.framework.ExceptionUtil; | ||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; | |||||
| import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | |||||
| import org.apache.avalon.framework.logger.AbstractLoggable; | import org.apache.avalon.framework.logger.AbstractLoggable; | ||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| @@ -21,8 +23,8 @@ import org.apache.myrmidon.components.model.DefaultProject; | |||||
| import org.apache.myrmidon.components.model.DefaultTarget; | import org.apache.myrmidon.components.model.DefaultTarget; | ||||
| import org.apache.myrmidon.components.model.Project; | import org.apache.myrmidon.components.model.Project; | ||||
| import org.apache.myrmidon.components.model.Target; | import org.apache.myrmidon.components.model.Target; | ||||
| import org.xml.sax.InputSource; | |||||
| import org.xml.sax.SAXException; | import org.xml.sax.SAXException; | ||||
| import org.xml.sax.XMLReader; | |||||
| /** | /** | ||||
| * Default implementation to construct project from a build file. | * Default implementation to construct project from a build file. | ||||
| @@ -33,13 +35,6 @@ public class DefaultProjectBuilder | |||||
| extends AbstractLoggable | extends AbstractLoggable | ||||
| implements ProjectBuilder | implements ProjectBuilder | ||||
| { | { | ||||
| protected DefaultConfigurationBuilder m_builder; | |||||
| public DefaultProjectBuilder() | |||||
| { | |||||
| m_builder = new DefaultConfigurationBuilder(); | |||||
| } | |||||
| /** | /** | ||||
| * build a project from file. | * build a project from file. | ||||
| * | * | ||||
| @@ -51,10 +46,35 @@ public class DefaultProjectBuilder | |||||
| public Project build( final File projectFile ) | public Project build( final File projectFile ) | ||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| final String location = projectFile.getCanonicalFile().toString(); | |||||
| final Configuration configuration = (Configuration)m_builder.buildFromFile( location ); | |||||
| return build( projectFile, configuration ); | |||||
| final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); | |||||
| final SAXParser saxParser = saxParserFactory.newSAXParser(); | |||||
| final XMLReader parser = saxParser.getXMLReader(); | |||||
| parser.setFeature( "http://xml.org/sax/features/namespace-prefixes", false ); | |||||
| parser.setFeature( "http://xml.org/sax/features/namespaces", false ); | |||||
| //parser.setFeature( "http://xml.org/sax/features/validation", false ); | |||||
| final SAXConfigurationHandler handler = new SAXConfigurationHandler(); | |||||
| parser.setContentHandler( handler ); | |||||
| parser.setErrorHandler( handler ); | |||||
| final String location = projectFile.toURL().toString(); | |||||
| parser.parse( location ); | |||||
| return build( projectFile, handler.getConfiguration() ); | |||||
| } | |||||
| /* | |||||
| private final void dump( final Configuration configuration ) | |||||
| throws Exception | |||||
| { | |||||
| System.out.println( "Configuration: "+ configuration.getName() + "/" + configuration.getLocation() ); | |||||
| final Configuration[] children = configuration.getChildren(); | |||||
| for( int i = 0; i < children.length; i++ ) | |||||
| { | |||||
| dump( children[ i ] ); | |||||
| } | |||||
| } | } | ||||
| */ | |||||
| /** | /** | ||||
| * build project from configuration. | * build project from configuration. | ||||
| @@ -66,7 +86,7 @@ public class DefaultProjectBuilder | |||||
| * @exception Exception if an error occurs | * @exception Exception if an error occurs | ||||
| * @exception ConfigurationException if an error occurs | * @exception ConfigurationException if an error occurs | ||||
| */ | */ | ||||
| protected Project build( final File file, final Configuration configuration ) | |||||
| protected final Project build( final File file, final Configuration configuration ) | |||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| if( !configuration.getName().equals("project") ) | if( !configuration.getName().equals("project") ) | ||||
| @@ -10,11 +10,14 @@ package org.apache.myrmidon.components.deployer; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.util.Enumeration; | import java.util.Enumeration; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import javax.xml.parsers.SAXParser; | |||||
| import javax.xml.parsers.SAXParserFactory; | |||||
| import org.apache.avalon.framework.activity.Initializable; | import org.apache.avalon.framework.activity.Initializable; | ||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; | |||||
| import org.xml.sax.InputSource; | |||||
| import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | |||||
| import org.xml.sax.SAXException; | |||||
| import org.xml.sax.XMLReader; | |||||
| /** | /** | ||||
| * Interface to manage roles and mapping to names. | * Interface to manage roles and mapping to names. | ||||
| @@ -64,14 +67,21 @@ public class DefaultRoleManager | |||||
| public void initialize() | public void initialize() | ||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); | |||||
| final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); | |||||
| final SAXParser saxParser = saxParserFactory.newSAXParser(); | |||||
| final XMLReader parser = saxParser.getXMLReader(); | |||||
| //parser.setFeature( "http://xml.org/sax/features/namespace-prefixes", false ); | |||||
| final SAXConfigurationHandler handler = new SAXConfigurationHandler(); | |||||
| parser.setContentHandler( handler ); | |||||
| parser.setErrorHandler( handler ); | |||||
| final Enumeration enum = getClass().getClassLoader().getResources( ROLE_DESCRIPTOR ); | final Enumeration enum = getClass().getClassLoader().getResources( ROLE_DESCRIPTOR ); | ||||
| while( enum.hasMoreElements() ) | while( enum.hasMoreElements() ) | ||||
| { | { | ||||
| final URL url = (URL)enum.nextElement(); | final URL url = (URL)enum.nextElement(); | ||||
| final Configuration descriptor = builder.build( new InputSource( url.toString() ) ); | |||||
| handleDescriptor( descriptor ); | |||||
| parser.parse( url.toString() ); | |||||
| handleDescriptor( handler.getConfiguration() ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -11,11 +11,14 @@ import java.io.File; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import javax.xml.parsers.SAXParser; | |||||
| import javax.xml.parsers.SAXParserFactory; | |||||
| import javax.xml.parsers.ParserConfigurationException; | |||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; | |||||
| import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | |||||
| import org.xml.sax.SAXException; | import org.xml.sax.SAXException; | ||||
| import org.xml.sax.InputSource; | |||||
| import org.xml.sax.XMLReader; | |||||
| /** | /** | ||||
| * This class deploys a .tsk file into a registry. | * This class deploys a .tsk file into a registry. | ||||
| @@ -61,19 +64,27 @@ public class Deployment | |||||
| { | { | ||||
| final String systemID = "jar:" + getURL() + "!/" + TSKDEF_FILE; | final String systemID = "jar:" + getURL() + "!/" + TSKDEF_FILE; | ||||
| final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); | |||||
| try | try | ||||
| { | { | ||||
| return builder.build( new InputSource( systemID ) ); | |||||
| final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); | |||||
| final SAXParser saxParser = saxParserFactory.newSAXParser(); | |||||
| final XMLReader parser = saxParser.getXMLReader(); | |||||
| //parser.setFeature( "http://xml.org/sax/features/namespace-prefixes", false ); | |||||
| final SAXConfigurationHandler handler = new SAXConfigurationHandler(); | |||||
| parser.setContentHandler( handler ); | |||||
| parser.setErrorHandler( handler ); | |||||
| parser.parse( systemID ); | |||||
| return handler.getConfiguration(); | |||||
| } | } | ||||
| catch( final SAXException se ) | catch( final SAXException se ) | ||||
| { | { | ||||
| throw new DeploymentException( "Malformed configuration data", se ); | throw new DeploymentException( "Malformed configuration data", se ); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | |||||
| catch( final ParserConfigurationException pce ) | |||||
| { | { | ||||
| throw new DeploymentException( "Error building configuration", ce ); | |||||
| throw new DeploymentException( "Error configuring parser", pce ); | |||||
| } | } | ||||
| catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
| { | { | ||||