You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/11/15 23:35:25 UTC

cvs commit: jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety Main.java

leosimons    2002/11/15 14:35:25

  Modified:    tweety   build.xml README.txt
               tweety/src/java/org/apache/avalon/excalibur/tweety Main.java
  Added:       tweety   wiki.txt
  Log:
  - adding a wiki.txt with some jotted-down ideas
  - adding a -d option to Main to allow debugging
  - do something meaningful with the Context by providing work and home dirs. Useful for pointing out a file IO demo. should empty the work dir on exit though.
  
  Revision  Changes    Path
  1.13      +1 -0      jakarta-avalon-excalibur/tweety/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/build.xml,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- build.xml	27 Oct 2002 19:07:52 -0000	1.12
  +++ build.xml	15 Nov 2002 22:35:24 -0000	1.13
  @@ -53,6 +53,7 @@
   
       <java classname="org.apache.avalon.excalibur.tweety.Main" fork="true" dir="." failonerror="true">
          <classpath refid="project.class.path" />
  +       <!-- uncomment to enable debugging <arg value="-d"/>-->
       </java>
   
     </target>
  
  
  
  1.4       +11 -0     jakarta-avalon-excalibur/tweety/README.txt
  
  Index: README.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/README.txt,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- README.txt	3 Jul 2002 20:21:03 -0000	1.3
  +++ README.txt	15 Nov 2002 22:35:24 -0000	1.4
  @@ -80,6 +80,17 @@
   
   Type 'ant' again and your components should run. It is that simple!
   
  +Note about File IO
  +------------------
  +Tweety will create a work directory (aplty called "work) and a permanent
  +storage directory (even more surprising, called "store") if they do not
  +exist yet. Your components can get to these through the Context, in the
  +form of java.io.Files, and then read from and write to them. The idea is
  +that the work directory contains temporary files your application uses,
  +whereas the storage directory is more or less permanent.
  +To get access to these directories, make your component implement
  +Contextualizable, and get() "component.home" and/or "component.work"
  +from the context you get, casting them to java.io.File.
   
   More Documentation
   ------------------
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/wiki.txt
  
  Index: wiki.txt
  ===================================================================
  		Wiki-file
  		---------
  This is a scratchpad with some thoughts on where this is to go. Not using
  bugzilla cuz I hate it, not using a wiki cuz we don't have one.
  
  Tweety-related threads:
  	http://marc.theaimsgroup.com/?t=102448194500001&r=1&w=2
  	http://marc.theaimsgroup.com/?t=102478651200001&r=1&w=2
  	http://marc.theaimsgroup.com/?t=102466687600003&r=1&w=2
  	http://marc.theaimsgroup.com/?t=102572858800005&r=1&w=2
  	http://marc.theaimsgroup.com/?t=102632427100011&r=1&w=2
  	http://marc.theaimsgroup.com/?t=103664349100005&r=1&w=2
  	http://marc.theaimsgroup.com/?t=103734660100001&r=1&w=2
  
  - Many people are 'abusing' Tweety (poor little birdy) by basing some
  actual software or containers on it. Clearly it fills a simplificy
  need. Makes one wonder how to get the rest of avalon fill that need.
  
  - people have suggested making Tweety into some kind of reference
  implementation. I don't think we should do that as it would make
  Tweety so complex the code becomes difficult to read, and it is also
  just about impossible as there is no definition of what a container
  should and should not do and hence you cannot make a reference
  implementation either.
  
  - the getting started docs aren't going the way they should. Instead
  of showing many concepts at one time, we should show them one at a
  time with a class per concept.
  
  
  
  1.5       +65 -22    jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/Main.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Main.java	23 Oct 2002 17:49:24 -0000	1.4
  +++ Main.java	15 Nov 2002 22:35:24 -0000	1.5
  @@ -3,34 +3,34 @@
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
    Copyright (c) 2002 The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"  
  -    must not be used to endorse or promote products derived from this  software 
  -    without  prior written permission. For written permission, please contact 
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,11 +41,11 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the 
  + on  behalf of the Apache Software  Foundation. For more  information on the
    Apache Software Foundation, please see <http://www.apache.org/>.
  - 
  +
   */
   
   
  @@ -99,20 +99,34 @@
   	 * <p><b>Note:</b> we should improve this method to create a sensible context and
   	 * configuration for hosted components.</p>
   	 *
  -	 * @param args the command line arguments. We don't use them.
  +	 * @param args the command line arguments. There is one option: if you provide
  +	 * the option "-d" you will get extra debugging information.
   	 */
   	public static void main( String[] args )
   	{
  -		// create logger
  -		ConsoleLogger logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
  +		// creating logger. We do some very simple commandline parsing here to figure
  +		// out whether we should enable debugging.
  +		ConsoleLogger logger = null;
  +		for(int i = 0; i < args.length; i++)
  +		{
  +			if(args[i].equals("-d"))
  +			{
  +	    		logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
  +				break;
  +			}
  +		}
  +		if(logger == null)
  +			logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
   
   		try
   		{
  -			/** @todo: this is stupid. Figure out what to do about contexts */
   			// create dummy context
  -			Context context = new DefaultContext();
  +			DefaultContext context = new DefaultContext();
   
  -			/** @todo: this is stupid. Figure out what to do about configurations */
  +			/** @todo: this is stupid. It would be a good idea to use a configuration builder
  +			 *  as org.apache.avalon.framework.tools.infobuilder in the info/meta packages.
  +			 *  Until such a thing is standardised, keep things like they are. Don't want to
  +			 *  add a dependency on xerces or alpha code for this. */
   			// create dummy configuration
   			Configuration config = new DefaultConfiguration( "empty config", "nowhere" );
   
  @@ -123,15 +137,39 @@
   			// create parameters from properties
   			Parameters params = Parameters.fromProperties( properties );
   
  -			// debug: show the stuff we feed into tweety
  +		    // add some stuff into the context. This loosely follows
  +			// the context spec part of the info revolution for lack
  +			// of any standard.
  +			// see: http://jakarta.apache.org/avalon/excalibur/info/context.html
  +
  +			// directory for persistent data
  +			File storage = new File("./store");
  +			// directory for non-persistent data
  +			File work = new File("./work");
  +
  +			// make sure those dirs exist
  +			if(!storage.exists())
  +				storage.mkdir();
  +			if(!storage.isDirectory())
  +				throw new Exception("No permanent storage directory available!");
  +			if(!work.exists())
  +				storage.mkdir();
  +			if(!work.isDirectory())
  +				throw new Exception("No working directory available!");
  +
  +			context.put( "component.classloader", Thread.currentThread().getContextClassLoader() );
  +			context.put( "component.home", storage );
  +			context.put( "component.work", work );
   
   			// create tweety instance
   			Tweety tweety = new Tweety();
   
  +			// debug: show the stuff we feed into tweety
  +
   			logger.debug("tweety.Main: Providing tweety with a console logger.");
   			tweety.enableLogging( logger );
   
  -			logger.debug("tweety.Main: Providing tweety with an empty context.");
  +			logger.debug("tweety.Main: Providing tweety with the context.");
   			tweety.contextualize( context );
   
   			logger.debug("tweety.Main: Providing tweety with an empty configuration");
  @@ -168,6 +206,11 @@
   		{
   			logger.error( "tweety.Main: Error starting up.\nProgram Terminated", e );
   			System.exit(-2);
  +		}
  +		finally
  +		{
  +			/** @todo make sure the work directory is empty so that there aren't any file
  +			 *  conflicts during subsequent runs */
   		}
   	}
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>