geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command CommandContainerTest.java CommandFactoryTest.java
Date Wed, 27 Aug 2003 12:00:00 GMT
jdillon     2003/08/27 05:00:00

  Modified:    modules/core/src/conf/twiddle geronimo.conf
               modules/twiddle project.xml
               modules/twiddle/src/conf classworlds.conf twiddle.conf
               modules/twiddle/src/etc twiddle-configuration-binding.xml
               modules/twiddle/src/java/org/apache/geronimo/twiddle
                        Twiddle.java
               modules/twiddle/src/java/org/apache/geronimo/twiddle/command
                        Command.java CommandFactory.java CommandInfo.java
               modules/twiddle/src/java/org/apache/geronimo/twiddle/config
                        Configurator.java
               modules/twiddle/src/schema twiddle-configuration.xsd
               modules/twiddle/src/test/org/apache/geronimo/twiddle/command
                        CommandContainerTest.java CommandFactoryTest.java
  Log:
   o Hooked up Classworlds to load command classes
  
  Revision  Changes    Path
  1.2       +13 -2     incubator-geronimo/modules/core/src/conf/twiddle/geronimo.conf
  
  Index: geronimo.conf
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/conf/twiddle/geronimo.conf,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- geronimo.conf	24 Aug 2003 11:23:14 -0000	1.1
  +++ geronimo.conf	27 Aug 2003 11:59:59 -0000	1.2
  @@ -4,9 +4,20 @@
   
   <configuration xmlns="http://geronimo.apache.org/xml/schema/Twiddle/Configuration">
     
  +  <class-worlds>
  +    <class-realm name="twiddle.geronimo">
  +      <!-- FIXME: Only load the required jars -->
  +      <load>${twiddle.home}/lib/*.jar</load>
  +      <import realm="twiddle.default">org.apache.geronimo.twiddle</import>
  +      <import realm="twiddle.default">org.apache.commons</import>
  +    </class-realm>
  +  </class-worlds>
  +  
     <!-- Command sets are not implemented yet so simulate them with command name -->
     <commands>
  -    <command name="geronimo/start" code="org.apache.geronimo.command.StartCommand"/>
  +    <command name="geronimo/start"
  +             code="org.apache.geronimo.command.StartCommand"
  +             realm="twiddle.geronimo"/>
     </commands>
   
   </configuration>
  
  
  
  1.10      +4 -6      incubator-geronimo/modules/twiddle/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/project.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.xml	25 Aug 2003 15:44:54 -0000	1.9
  +++ project.xml	27 Aug 2003 11:59:59 -0000	1.10
  @@ -41,12 +41,10 @@
       
       <!-- Thirdparty Dependencies -->
       
  -    <!-- this does not work because the artifact on ibiblio does not contain version
info
  +    <!-- Will need this for the expression parser generation
       <dependency>
  -      <groupId>javacc</groupId>
  -      <artifactId>JavaCC</artifactId>
  -      <type>zip</type>
  -      <version></version>
  +      <id>javacc</id>
  +      <jar>JavaCC.zip</jar>
         <properties>
           <runtime>false</runtime>
         </properties>
  
  
  
  1.3       +10 -11    incubator-geronimo/modules/twiddle/src/conf/classworlds.conf
  
  Index: classworlds.conf
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/conf/classworlds.conf,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- classworlds.conf	25 Aug 2003 17:05:42 -0000	1.2
  +++ classworlds.conf	27 Aug 2003 11:59:59 -0000	1.3
  @@ -9,16 +9,12 @@
   ##
   
   # The main entry-point
  -main is org.apache.geronimo.twiddle.cli.Main from twiddle 
  -
  -#
  -# TODO: Fix me, so that the class realm only contains the basic
  -#       libraries, but for now this works
  -#
  +main is org.apache.geronimo.twiddle.cli.Main from twiddle
   
  +# The core Twiddle class-realm
   [twiddle]
       # Allow access to resources
  -    load ${twiddle.home}/etc/
  +    load ${twiddle.home}/etc
       
       # Load required libraries
       load ${twiddle.home}/lib/xerces-*.jar
  @@ -33,6 +29,9 @@
       
       # Logging adapter is currently in here
       load ${twiddle.home}/lib/geronimo-core-*.jar
  -    
  -    # Required to boot Geronimo since it does not do any bootstrap classloading
  -    load ${twiddle.home}/lib/*.jar
  +
  +# The default class-realm for commands
  +[twiddle.default]
  +    import org.apache.geronimo.twiddle from twiddle
  +    import org.apache.commons from twiddle
  +
  
  
  
  1.5       +1 -20     incubator-geronimo/modules/twiddle/src/conf/twiddle.conf
  
  Index: twiddle.conf
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/conf/twiddle.conf,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- twiddle.conf	25 Aug 2003 17:06:31 -0000	1.4
  +++ twiddle.conf	27 Aug 2003 11:59:59 -0000	1.5
  @@ -8,27 +8,8 @@
       <include>${twiddle.home}/etc/twiddle/*.conf</include>
     </includes>
     
  -  <!--
  -  <classworlds>
  -    <realm name="whatever">
  -      <load>${twiddle.home}/lib/whatever.jar</load>
  -    </realm>
  -    
  -    <realm name="otherstuff">
  -      <load>${twiddle.home}/lib/otherstuff.jar</load>
  -      <import realm="whatever">org.apache.whatever</import>
  -    </realm>
  -  </classworlds>
  -  -->
  -  
     <commands>
       <command name="exit" code="org.apache.geronimo.twiddle.commands.ExitCommand"/>
  -    
  -    <!--
  -    <command name="whatever" 
  -             code="org.apache.geronimo.twiddle.commands.WhateverCommand"
  -             realm="whatever"/>
  -    -->
     </commands>
   
   </configuration>
  
  
  
  1.5       +29 -13    incubator-geronimo/modules/twiddle/src/etc/twiddle-configuration-binding.xml
  
  Index: twiddle-configuration-binding.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/etc/twiddle-configuration-binding.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- twiddle-configuration-binding.xml	16 Aug 2003 15:14:12 -0000	1.4
  +++ twiddle-configuration-binding.xml	27 Aug 2003 11:59:59 -0000	1.5
  @@ -32,43 +32,59 @@
     
     <!-- Custom element binding -->
     
  -  <elementBinding name="properties">
  +  <elementBinding name="/properties">
       <java-class name="PropertiesConfig"/>
     </elementBinding>
     
  -  <elementBinding name="property">
  +  <elementBinding name="/property">
       <java-class name="PropertyConfig"/>
     </elementBinding>
     
  -  <elementBinding name="includes">
  +  <elementBinding name="/includes">
       <java-class name="IncludesConfig"/>
     </elementBinding>
     
  -  <elementBinding name="libraries">
  -    <java-class name="LibrariesConfig"/>
  +  <elementBinding name="/class-worlds">
  +    <java-class
  +      name="ClassWorldsConfig"
  +      package="org.apache.geronimo.twiddle.config.classworlds"/>
     </elementBinding>
     
  -  <elementBinding name="library">
  -    <java-class name="LibraryConfig"/>
  +  <elementBinding name="/class-realm">
  +    <java-class
  +      name="ClassRealmConfig"
  +      package="org.apache.geronimo.twiddle.config.classworlds"/>
     </elementBinding>
     
  -  <elementBinding name="search-path">
  +  <elementBinding name="/class-realm/load">
  +    <java-class
  +      name="LoadURLConfig"
  +      package="org.apache.geronimo.twiddle.config.classworlds"/>
  +  </elementBinding>
  +  
  +  <elementBinding name="/class-realm/import">
  +    <java-class
  +      name="ImportPackageConfig"
  +      package="org.apache.geronimo.twiddle.config.classworlds"/>
  +  </elementBinding>
  +  
  +  <elementBinding name="/search-path">
       <java-class name="SearchPathConfig"/>
     </elementBinding>
     
  -  <elementBinding name="environment">
  +  <elementBinding name="/environment">
       <java-class name="EnvironmentConfig"/>
     </elementBinding>
     
  -  <elementBinding name="commands">
  +  <elementBinding name="/commands">
       <java-class name="CommandsConfig"/>
     </elementBinding>
     
  -  <elementBinding name="command">
  +  <elementBinding name="/command">
       <java-class name="CommandConfig"/>
     </elementBinding>
     
  -  <elementBinding name="command-set">
  +  <elementBinding name="/command-set">
       <java-class name="CommandSetConfig"/>
     </elementBinding>
     
  
  
  
  1.11      +16 -1     incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/Twiddle.java
  
  Index: Twiddle.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/Twiddle.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Twiddle.java	25 Aug 2003 18:44:06 -0000	1.10
  +++ Twiddle.java	27 Aug 2003 11:59:59 -0000	1.11
  @@ -66,6 +66,7 @@
   import java.io.PrintWriter;
   
   import com.werken.classworlds.ClassWorld;
  +import com.werken.classworlds.DuplicateRealmException;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -125,6 +126,16 @@
           this.world = world;
           this.container = new CommandContainer();
           this.executor = new CommandExecutor(container);
  +        
  +        // Make sure the default realm is there
  +        try {
  +            world.newRealm(Command.DEFAULT_CLASS_REALM);
  +            log.debug("Created new default class-realm");
  +        }
  +        catch (DuplicateRealmException ignore) {
  +            // default realm already exists
  +            log.debug("Default class-realm already exists, using it");
  +        }
       }
       
       /**
  @@ -199,8 +210,12 @@
        */
       public void configure(final Configuration config) throws CommandException
       {
  +        log.debug("Configuring...");
  +        
           Configurator c = new Configurator(this);
           c.configure(config);
  +        
  +        log.debug("Configured");
       }
       
       
  
  
  
  1.5       +4 -1      incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/Command.java
  
  Index: Command.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/Command.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Command.java	16 Aug 2003 15:14:12 -0000	1.4
  +++ Command.java	27 Aug 2003 12:00:00 -0000	1.5
  @@ -67,6 +67,9 @@
   public interface Command
       extends Cloneable
   {
  +    /** The default class-realm id. */
  +    String DEFAULT_CLASS_REALM = "twiddle.default";
  +    
       /** Standard command success status code. */
       int SUCCESS = 0;
       
  
  
  
  1.7       +63 -35    incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/CommandFactory.java
  
  Index: CommandFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/CommandFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CommandFactory.java	16 Aug 2003 15:14:12 -0000	1.6
  +++ CommandFactory.java	27 Aug 2003 12:00:00 -0000	1.7
  @@ -59,11 +59,17 @@
   import java.io.IOException;
   
   import java.beans.Beans;
  -import java.beans.BeanInfo;
  -import java.beans.Introspector;
  -import java.beans.PropertyDescriptor;
   
  -import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
  +
  +import com.werken.classworlds.ClassWorld;
  +import com.werken.classworlds.ClassRealm;
  +import com.werken.classworlds.NoSuchRealmException;
  +
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
  +import org.apache.commons.beanutils.BeanUtils;
   
   import org.apache.geronimo.common.NullArgumentException;
   
  @@ -78,15 +84,22 @@
    */
   public class CommandFactory
   {
  +    private static final Log log = LogFactory.getLog(CommandFactory.class);
  +    
       protected CommandConfig config;
  +    protected ClassWorld world;
       
  -    public CommandFactory(final CommandConfig config)
  +    public CommandFactory(final CommandConfig config, final ClassWorld world)
       {
           if (config == null) {
               throw new NullArgumentException("config");
           }
  +        if (world == null) {
  +            throw new NullArgumentException("world");
  +        }
           
           this.config = config;
  +        this.world = world;
       }
       
       public CommandConfig getConfig()
  @@ -94,41 +107,56 @@
           return config;
       }
       
  -    protected Command doCreate() throws Exception
  +    public ClassWorld getClassWorld()
  +    {
  +        return world;
  +    }
  +    
  +    protected ClassRealm getClassRealm()
  +        throws NoSuchRealmException
       {
  +        String name = config.getRealm();
  +        if (name == null) {
  +            name = Command.DEFAULT_CLASS_REALM;
  +        }
  +        
  +        if (log.isTraceEnabled()) {
  +            log.trace("Loading command from class-realm: " + name);
  +        }
  +        
  +        return getClassWorld().getRealm(name);
  +    }
  +    
  +    protected Command doCreate()
  +        throws ClassNotFoundException, IllegalAccessException,
  +               InvocationTargetException, NoSuchRealmException,
  +               IOException
  +    {
  +        // Get a handle on the class realm to load the class from
  +        ClassRealm realm = getClassRealm();
  +        ClassLoader cl = realm.getClassLoader();
  +        
           // Load the command instance
  -        ClassLoader cl = Thread.currentThread().getContextClassLoader();
           Command command = (Command)Beans.instantiate(cl, config.getCode());
           
  -        //
  -        // TODO: Use Commons BeanUtils
  -        //
  -        
  -        // Apply attributes
  -        BeanInfo info = Introspector.getBeanInfo(command.getClass());
  -        Attribute[] attrs = config.getAttribute();
  -        if (attrs != null) {
  -            PropertyDescriptor[] descs = info.getPropertyDescriptors();
  -            
  -            for (int i=0; i<attrs.length; i++) {
  -                String name = attrs[i].getName();
  -                
  -                for (int j=0; j<descs.length; j++) {
  -                    //
  -                    // TODO: Handle attribute types, for now they are all strings
  -                    //
  -                    
  -                    if (name.equals(descs[j].getName())) {
  -                        Object value = attrs[i].getContent();
  -                        Method method = descs[j].getWriteMethod();
  -                        method.invoke(command, new Object[] { value });
  -                        break;
  -                    }
  -                }
  -            }
  -        }
  +        // Configure the command attributes
  +        configureAttributes(command, config.getAttribute());
           
           return command;
  +    }
  +    
  +    protected void configureAttributes(final Command command, final Attribute[] attrs)
  +        throws IllegalAccessException, InvocationTargetException
  +    {
  +        assert command != null;
  +        
  +        if (attrs == null) return;
  +        
  +        for (int i=0; i<attrs.length; i++) {
  +            String name = attrs[i].getName();
  +            Object value = attrs[i].getContent();
  +            BeanUtils.setProperty(command, name, value);
  +        }
       }
       
       public Command create() throws CommandException
  
  
  
  1.5       +23 -3     incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/CommandInfo.java
  
  Index: CommandInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/command/CommandInfo.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CommandInfo.java	16 Aug 2003 15:14:12 -0000	1.4
  +++ CommandInfo.java	27 Aug 2003 12:00:00 -0000	1.5
  @@ -56,6 +56,8 @@
   
   package org.apache.geronimo.twiddle.command;
   
  +import com.werken.classworlds.ClassWorld;
  +
   import org.apache.geronimo.common.NullArgumentException;
   
   import org.apache.geronimo.twiddle.config.CommandConfig;
  @@ -70,6 +72,9 @@
       /** The command configuration. */
       protected CommandConfig config;
       
  +    /** The classworld to load the command class from. */
  +    protected ClassWorld world;
  +    
       /** The command prototype. */
       protected Command prototype;
       
  @@ -77,14 +82,19 @@
        * Construct a <code>CommandInfo</code> from the given config.
        *
        * @param config    The command configuration.
  +     * @param world     The classworld to load the command class from.
        */
  -    public CommandInfo(final CommandConfig config)
  +    public CommandInfo(final CommandConfig config, final ClassWorld world)
       {
           if (config == null) {
               throw new NullArgumentException("config");
           }
  +        if (world == null) {
  +            throw new NullArgumentException("world");
  +        }
           
           this.config = config;
  +        this.world = world;
       }
       
       /**
  @@ -98,6 +108,16 @@
       }
       
       /**
  +     * Get classworld to load the command class from.
  +     *
  +     * @return The classworld to load the command class from.
  +     */
  +    public ClassWorld getClassWorld()
  +    {
  +        return world;
  +    }
  +    
  +    /**
        * Create the command prototype.
        *
        * @return The command prototype.
  @@ -106,7 +126,7 @@
        */
       protected Command createPrototype() throws CommandException
       {
  -        CommandFactory factory = new CommandFactory(config);
  +        CommandFactory factory = new CommandFactory(config, world);
           Command command = factory.create();
           command.setCommandInfo(this);
           
  
  
  
  1.10      +132 -29   incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/config/Configurator.java
  
  Index: Configurator.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/config/Configurator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Configurator.java	26 Aug 2003 08:23:07 -0000	1.9
  +++ Configurator.java	27 Aug 2003 12:00:00 -0000	1.10
  @@ -65,6 +65,11 @@
   import java.util.List;
   import java.util.LinkedList;
   
  +import com.werken.classworlds.ClassWorld;
  +import com.werken.classworlds.ClassRealm;
  +import com.werken.classworlds.NoSuchRealmException;
  +import com.werken.classworlds.ClassWorldException;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -77,6 +82,11 @@
   import org.apache.geronimo.twiddle.command.CommandContainer;
   import org.apache.geronimo.twiddle.command.CommandInfo;
   import org.apache.geronimo.twiddle.command.CommandException;
  +import org.apache.geronimo.twiddle.command.Command;
  +
  +import org.apache.geronimo.twiddle.config.classworlds.ClassWorldsConfig;
  +import org.apache.geronimo.twiddle.config.classworlds.ClassRealmConfig;
  +import org.apache.geronimo.twiddle.config.classworlds.ImportPackageConfig;
   
   /**
    * Handles the details of Twiddle configuration.
  @@ -111,9 +121,15 @@
               throw new NullArgumentException("config");
           }
           
  -        configureProperties(config.getPropertiesConfig());
  -        configureIncludes(config.getIncludesConfig());
  -        configureCommands(config.getCommandsConfig());
  +        try {
  +            configureProperties(config.getPropertiesConfig());
  +            configureClassWorlds(config.getClassWorldsConfig());
  +            configureIncludes(config.getIncludesConfig());
  +            configureCommands(config.getCommandsConfig());
  +        }
  +        catch (Exception e) {
  +            throw new CommandException("Failed to configure", e);
  +        }
       }
       
       protected void configureProperties(final PropertiesConfig config)
  @@ -133,30 +149,116 @@
           }
       }
       
  -    protected void configureIncludes(final IncludesConfig config) throws CommandException
  +    protected void configureClassWorlds(final ClassWorldsConfig config) 
  +        throws ClassWorldException, MalformedURLException
       {
           if (config == null) return;
           
  -        String[] includes = config.getInclude();
  -        if (includes != null && includes.length != 0) {
  -            ConfigurationReader reader = new ConfigurationReader();
  +        ClassRealmConfig[] realms = config.getClassRealmConfig();
  +        for (int i=0; i<realms.length; i++) {
  +            if (realms[i] == null) {
  +                throw new NullArgumentException("ClassRealmConfig", i);
  +            }
               
  -            for (int i=0; i<includes.length; i++) {
  -                if (includes[i] == null) {
  -                    throw new NullArgumentException("Includes", i);
  -                }
  +            String name = realms[i].getName();
  +            if (name == null) {
  +                name = Command.DEFAULT_CLASS_REALM;
  +            }
  +            else {
  +                name = valueParser.parse(name);
  +            }
  +            
  +            configureClassWorldClassRealm(name, realms[i]);
  +        }
  +    }
  +    
  +    protected void configureClassWorldClassRealm(final String name, final ClassRealmConfig
config)
  +        throws ClassWorldException, MalformedURLException
  +    {
  +        assert name != null;
  +        assert config != null;
  +        
  +        boolean trace = log.isTraceEnabled();
  +        if (trace) {
  +            log.trace("Processing classworld realm: " + name);
  +        }
  +        
  +        // Get or create a new realm for this name
  +        ClassWorld world = getTwiddle().getClassWorld();
  +        ClassRealm realm = null;
  +        try {
  +            realm = world.getRealm(name);
  +        }
  +        catch (NoSuchRealmException e) {
  +            realm = world.newRealm(name);
  +        }
  +        
  +        String[] constituents = config.getLoadURLConfig();
  +        if (constituents != null) {
  +            log.trace("Processing constituents...");
  +            
  +            for (int i=0; i<constituents.length; i++) {
  +                assert constituents[i] != null;
                   
  -                try {
  -                    String value = valueParser.parse(includes[i]);
  -                    URL[] urls = parseGlobURLs(value);
  -                    for (int j=0; j<urls.length; j++) {
  -                        Configuration iconfig = reader.read(urls[j]);
  -                        this.configure(iconfig);
  +                String urlspec = valueParser.parse(constituents[i], true);
  +                URL[] urls = parseGlobURLs(urlspec);
  +                for (int j=0; j<urls.length; j++) {
  +                    if (trace) {
  +                        log.trace("Adding constituent: " + urls[j]);
                       }
  +                    realm.addConstituent(urls[j]);
                   }
  -                catch (Exception e) {
  -                    throw new ConfigurationException("Failed to process include: " + includes[i],
e);
  +            }
  +        }
  +        
  +        ImportPackageConfig[] imports = config.getImportPackageConfig();
  +        if (imports != null) {
  +            log.trace("Processing imports...");
  +            
  +            for (int i=0; i<imports.length; i++) {
  +                assert imports[i] != null;
  +                assert imports[i].getRealm() != null;
  +                assert imports[i].getContent() != null;
  +                
  +                String from = valueParser.parse(imports[i].getRealm(), true);
  +                String pkg = valueParser.parse(imports[i].getContent(), true);
  +                if (trace) {
  +                    log.trace("Importing " + pkg + " from realm " + from);
                   }
  +                realm.importFrom(from, pkg);
  +            }
  +        }
  +    }
  +    
  +    protected void configureIncludes(final IncludesConfig config) throws CommandException
  +    {
  +        if (config == null) return;
  +        
  +        String[] includes = config.getInclude();
  +        if (includes == null || includes.length == 0) return;
  +        
  +        boolean trace = log.isTraceEnabled();
  +        
  +        ConfigurationReader reader = new ConfigurationReader();
  +        
  +        for (int i=0; i<includes.length; i++) {
  +            if (includes[i] == null) {
  +                throw new NullArgumentException("Includes", i);
  +            }
  +            if (trace) {
  +                log.trace("Processing include: " + includes[i]);
  +            }
  +        
  +            try {
  +                String value = valueParser.parse(includes[i]);
  +                URL[] urls = parseGlobURLs(value);
  +                for (int j=0; j<urls.length; j++) {
  +                    Configuration iconfig = reader.read(urls[j]);
  +                    this.configure(iconfig);
  +                }
  +            }
  +            catch (Exception e) {
  +                throw new ConfigurationException("Failed to process include: " + includes[i],
e);
               }
           }
       }
  @@ -238,17 +340,18 @@
           if (config == null) return;
           
           CommandConfig[] commands = config.getCommandConfig();
  -        if (commands != null) {
  -            CommandContainer container = twiddle.getCommandContainer();
  -            
  -            for (int i=0; i<commands.length; i++) {
  -                if (commands[i] == null) {
  -                    throw new NullArgumentException("CommandConfig", i);
  -                }
  -                
  -                CommandInfo info = new CommandInfo(commands[i]);
  -                container.addCommandInfo(info);
  +        if (commands == null) return;
  +        
  +        CommandContainer container = twiddle.getCommandContainer();
  +        ClassWorld world = getTwiddle().getClassWorld();
  +        
  +        for (int i=0; i<commands.length; i++) {
  +            if (commands[i] == null) {
  +                throw new NullArgumentException("CommandConfig", i);
               }
  +            
  +            CommandInfo info = new CommandInfo(commands[i], world);
  +            container.addCommandInfo(info);
           }
       }
   }
  
  
  
  1.5       +21 -17    incubator-geronimo/modules/twiddle/src/schema/twiddle-configuration.xsd
  
  Index: twiddle-configuration.xsd
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/schema/twiddle-configuration.xsd,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- twiddle-configuration.xsd	16 Aug 2003 15:14:12 -0000	1.4
  +++ twiddle-configuration.xsd	27 Aug 2003 12:00:00 -0000	1.5
  @@ -23,7 +23,7 @@
       <xsd:complexType>
         <xsd:sequence>
           <xsd:element ref="properties" minOccurs="0" maxOccurs="1"/>
  -        <!-- <xsd:element ref="libraries" minOccurs="0" maxOccurs="1"/> -->
  +        <xsd:element ref="class-worlds" minOccurs="0" maxOccurs="1"/>
           <xsd:element ref="includes" minOccurs="0" maxOccurs="1"/>
           <xsd:element ref="environment" minOccurs="0" maxOccurs="1"/>
           <!-- <xsd:element ref="search-path" minOccurs="0" maxOccurs="1"/> -->
  @@ -32,40 +32,44 @@
       </xsd:complexType>
     </xsd:element>
     
  -  <!--
  -  
  -  <xsd:element name="libraries">
  +  <xsd:element name="class-worlds">
       <xsd:annotation>
         <xsd:documentation>
  -        Definitions of additional libraries to load.
  +        Definitions of classworlds.
         </xsd:documentation>
       </xsd:annotation>
       
       <xsd:complexType>
         <xsd:sequence>
  -        <xsd:element ref="library" minOccurs="0" maxOccurs="unbounded"/>
  +        <xsd:element ref="class-realm" minOccurs="0" maxOccurs="unbounded"/>
         </xsd:sequence>
       </xsd:complexType>
     </xsd:element>
     
  -  <xsd:element name="library">
  +  <xsd:element name="class-realm">
       <xsd:annotation>
         <xsd:documentation>
  -        Definition of a single library.
  +        Definition of a classworld class-realm.
         </xsd:documentation>
       </xsd:annotation>
       
       <xsd:complexType>
  -      <xsd:simpleContent>
  -        <xsd:extension base="xsd:string">
  -          <xsd:attribute name="id" type="xsd:string"/>
  -        </xsd:extension>
  -      </xsd:simpleContent>
  +      <xsd:sequence>
  +        <xsd:element name="load" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
  +        <xsd:element name="import" minOccurs="0" maxOccurs="unbounded">
  +          <xsd:complexType>
  +            <xsd:simpleContent>
  +              <xsd:extension base="xsd:string">
  +                <xsd:attribute name="realm" use="required" type="xsd:string"/>
  +              </xsd:extension>
  +            </xsd:simpleContent>
  +          </xsd:complexType>
  +        </xsd:element>
  +      </xsd:sequence>
  +      <xsd:attribute name="name" use="optional" type="xsd:string"/>
       </xsd:complexType>
     </xsd:element>
     
  -  -->
  -  
     <xsd:element name="properties">
       <xsd:annotation>
         <xsd:documentation>
  @@ -251,7 +255,7 @@
         
         <xsd:attribute name="name" use="required" type="xsd:string"/>
         <xsd:attribute name="code" use="required" type="xsd:string"/>
  -      <!-- <xsd:attribute name="libid" type="xsd:string"/> -->
  +      <xsd:attribute name="realm" type="xsd:string"/>
       </xsd:complexType>
     </xsd:element>
     
  
  
  
  1.2       +9 -3      incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/CommandContainerTest.java
  
  Index: CommandContainerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/CommandContainerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CommandContainerTest.java	24 Aug 2003 17:10:36 -0000	1.1
  +++ CommandContainerTest.java	27 Aug 2003 12:00:00 -0000	1.2
  @@ -61,6 +61,8 @@
   
   import junit.framework.TestCase;
   
  +import com.werken.classworlds.ClassWorld;
  +
   import org.apache.geronimo.common.NullArgumentException;
   import org.apache.geronimo.twiddle.config.CommandConfig;
   
  @@ -71,24 +73,28 @@
    */
   public class CommandContainerTest extends TestCase {
   
  +    ClassWorld world;
       CommandContainer commandContainer;
       CommandInfo commandInfoOne;
       CommandInfo commandInfoTwo;
   
       protected void setUp() throws Exception {
  +        world = new ClassWorld();
  +        world.newRealm(Command.DEFAULT_CLASS_REALM);
  +        
           commandContainer = new CommandContainer();
   
           CommandConfig config = new CommandConfig();
           config.setName("Uno");
           config.setDescription("First Command");
           config.setCode("org.apache.geronimo.twiddle.command.TestCommand");
  -        commandInfoOne = new CommandInfo(config);
  +        commandInfoOne = new CommandInfo(config, world);
   
           config = new CommandConfig();
           config.setName("Due");
           config.setDescription("Second Command");
           config.setCode("org.apache.geronimo.twiddle.command.TestCommand");
  -        commandInfoTwo = new CommandInfo(config);
  +        commandInfoTwo = new CommandInfo(config, world);
   
           super.setUp();
       }
  
  
  
  1.8       +17 -9     incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/CommandFactoryTest.java
  
  Index: CommandFactoryTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/CommandFactoryTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CommandFactoryTest.java	24 Aug 2003 19:40:48 -0000	1.7
  +++ CommandFactoryTest.java	27 Aug 2003 12:00:00 -0000	1.8
  @@ -58,8 +58,11 @@
   
   import junit.framework.TestCase;
   
  +import com.werken.classworlds.ClassWorld;
  +
   import org.apache.geronimo.twiddle.config.CommandConfig;
   import org.apache.geronimo.twiddle.config.Attribute;
  +
   import org.apache.geronimo.common.NullArgumentException;
   
   /**
  @@ -70,11 +73,15 @@
   public class CommandFactoryTest
       extends TestCase
   {
  +    protected ClassWorld world;
  +    
       /**
        * Set up instance variables required by this test case.
        */
  -    protected void setUp()
  +    protected void setUp() throws Exception
       {
  +        world = new ClassWorld();
  +        world.newRealm(Command.DEFAULT_CLASS_REALM);
       }
   
       /**
  @@ -82,6 +89,7 @@
        */
       protected void tearDown()
       {
  +        world = null;
       }
   
   
  @@ -99,13 +107,13 @@
           config.setDescription(desc);
           config.setCode(type);
   
  -        CommandInfo protoInfo = new CommandInfo(config);
  +        CommandInfo protoInfo = new CommandInfo(config, world);
           assertEquals(config,protoInfo.getConfig());
           assertTrue(protoInfo.hasDescription());
           Command command = protoInfo.getPrototype();
   
           try {
  -            new CommandInfo(null);
  +            new CommandInfo(null, null);
               fail("Expected NullArgumentException");
           } catch (NullArgumentException ignore) {
           }
  @@ -134,7 +142,7 @@
           attr.setContent(text);
           config.addAttribute(attr);
   
  -        CommandInfo protoInfo = new CommandInfo(config);
  +        CommandInfo protoInfo = new CommandInfo(config, world);
           Command command = protoInfo.getPrototype();
   
           // Verify that the text attribute was set correctly
  @@ -147,7 +155,7 @@
           CommandFactory commandFactory;
   
           try {
  -            new CommandFactory(null);
  +            new CommandFactory(null, null);
               fail("Expected NullArgumentException");
           } catch (NullArgumentException ignore) {
           }
  @@ -160,16 +168,16 @@
           config.setDescription(desc);
           config.setCode(type);
   
  -        commandFactory = new CommandFactory(config);
  +        commandFactory = new CommandFactory(config, world);
           assertEquals(config,commandFactory.getConfig());
           try {
               commandFactory.create();
           } catch (CommandException e) {
  -            fail("Unexpected CommandException"+e);
  +            fail("Unexpected CommandException: " + e);
           }
   
           try {
  -            new CommandFactory(new CommandConfig()).create();
  +            new CommandFactory(new CommandConfig(), world).create();
               fail("Expected CommandException");
           } catch (CommandException ignore) {
           }
  
  
  

Mime
View raw message