avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial BirdSong1.java BirdSongImpl.java BirdSong.java BirdSongRunner.java CartoonBird.java CartoonCage.java CartoonCat.java Cartoon.java
Date Sun, 27 Oct 2002 19:07:52 GMT
leosimons    2002/10/27 11:07:52

  Modified:    tweety   build.xml default.properties
               tweety/src/xdocs avalon-for-beginners.xml
  Added:       tweety/examples/tutorial/src/java/avalon/tutorial
                        BirdSong1.java BirdSongImpl.java BirdSong.java
                        BirdSongRunner.java CartoonBird.java
                        CartoonCage.java CartoonCat.java Cartoon.java
  Log:
  some work on the "avalon for beginners" paper. Code examples currently not working yet.
  
  Revision  Changes    Path
  1.12      +31 -0     jakarta-avalon-excalibur/tweety/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	10 Aug 2002 21:14:36 -0000	1.11
  +++ build.xml	27 Oct 2002 19:07:52 -0000	1.12
  @@ -115,6 +115,37 @@
   
       </target>
   
  +    <!-- Compiles the example source code -->
  +    <target name="compile-examples" depends="compile" description="Compiles the source
code">
  +        <mkdir dir="${build.examplesrc}"/>
  +
  +        <!-- Copy over all of the tests applying test filters -->
  +        <copy todir="${build.examplesrc}">
  +            <fileset dir="${example.dir}/tutorial/src/java"/>
  +        </copy>
  +
  +        <mkdir dir="${build.exampleclasses}"/>
  +
  +        <!-- Compile all test classes. -->
  +        <javac srcdir="${build.examplesrc}"
  +            destdir="${build.exampleclasses}"
  +            debug="${build.debug}"
  +            optimize="${build.optimize}"
  +            deprecation="${build.deprecation}"
  +            target="1.2">
  +            <classpath refid="test.class.path" />
  +            <include name="**/*.java"/>
  +        </javac>
  +
  +        <copy todir="${build.exampleclasses}">
  +            <fileset dir="${example.dir}">
  +                <exclude name="**/*.java"/>
  +                <exclude name="**/package.html"/>
  +            </fileset>
  +        </copy>
  +
  +    </target>
  +
       <!-- Copies and filters the manifest and license. Used by jar and dist -->
       <target name="prepare-conf">
           <mkdir dir="${build.conf}"/>
  
  
  
  1.6       +3 -0      jakarta-avalon-excalibur/tweety/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/default.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- default.properties	14 Aug 2002 22:51:14 -0000	1.5
  +++ default.properties	27 Oct 2002 19:07:52 -0000	1.6
  @@ -34,6 +34,8 @@
   build.dir = build
   build.testsrc = ${build.dir}/testsrc
   build.testclasses = ${build.dir}/testclasses
  +build.examplesrc = ${build.dir}/examplesrc
  +build.exampleclasses = ${build.dir}/exampleclasses
   build.lib = ${build.dir}/lib
   build.conf = ${build.dir}/conf
   build.classes = ${build.dir}/classes
  @@ -47,6 +49,7 @@
   java.dir = ${src.dir}/java
   conf.dir = ${src.dir}/conf
   test.dir = ${src.dir}/test
  +example.dir = examples
   
   #  Set the properties for distribution directories
   dist.dir = dist
  
  
  
  1.5       +35 -34    jakarta-avalon-excalibur/tweety/src/xdocs/avalon-for-beginners.xml
  
  Index: avalon-for-beginners.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/src/xdocs/avalon-for-beginners.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- avalon-for-beginners.xml	14 Jul 2002 10:41:29 -0000	1.4
  +++ avalon-for-beginners.xml	27 Oct 2002 19:07:52 -0000	1.5
  @@ -71,14 +71,14 @@
   	private String m_chilpMessage;
   	private String m_chilpSeparator;
   
  -	public void BirdSong1( int numberOfChilps, chilpMessage, chilpSeparator )
  +	public BirdSong1( int numberOfChilps, String chilpMessage, String chilpSeparator )
   	{
   		m_numberOfChilps = numberOfChilps;
   		m_chilpMessage = chilpMessage;
   		m_chilpSeparator = chilpSeparator;
   	}
   
  -	public sing()
  +	public void sing()
   	{
   		for( int i = 0; i != m_numberOfChilps; i++ )
   		{
  @@ -89,12 +89,12 @@
   		}
   	}
   
  -	public static void main(String args[])
  +	public static void main( String args[] )
   	{
   		BirdSong1 birdSong = new BirdSong1( new Integer( args[0] ).intValue(),
   				args[1], args[2] );
   
  -		BirdSong.sing();
  +		birdSong.sing();
   	}
   }
   		</source>
  @@ -124,10 +124,11 @@
   
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.logger.LogEnabled;
   
  -public interface BirdSong extends Parameterizable, Startable, LogEnabled;
  +public interface BirdSong extends Parameterizable, Startable, LogEnabled
   {
   	public static final String PARAM_NUMBER_OF_CHILPS = "numberOfChilps";
   	public static final String PARAM_CHILP_MESSAGE = "chilpMessage";
  @@ -135,15 +136,15 @@
   
   	/**
   	* Provide us with the parameters it needs to work. Required are:
  -	* &gt;ul&lt;
  -	* &gt;li&lt;numberOfChilps&gt;/li&lt;
  -	* &gt;li&lt;chilpMessage&gt;/li&lt;
  -	* &gt;li&lt;chilpSeparator&gt;/li&lt;
  -	* &gt;/ul&lt;
  -	* &gt;/pre&lt;
  +	* <ul>
  +	* <li>numberOfChilps</li>
  +	* <li>chilpMessage</li>
  +	* <li>chilpSeparator</li>
  +	* </ul>
  +	* </pre>
   	*
   	*/
  -	public void parameterize( Parameters parameters );
  +	void parameterize( Parameters parameters ) throws ParameterException;
   }
   		</source>
   		</s4>
  @@ -154,12 +155,12 @@
   
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.parameters.ParameterException;
  -import org.apache.avalon.logger.AbstractLoggable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
   
   import avalon.tutorial.BirdSong;
   import avalon.tutorial.BirdSongRunner;
   
  -public class BirdSongImpl extends AbstractLoggable implements BirdSong
  +public class BirdSongImpl extends AbstractLogEnabled implements BirdSong
   {
   	private int m_numberOfChilps;
   	private String m_chilpMessage;
  @@ -167,8 +168,7 @@
   
   	private Thread m_runnerThread;
   
  -
  -	public void BirdSongImpl()
  +	public BirdSongImpl()
   	{
   	}
   
  @@ -176,15 +176,15 @@
   	{
   		getLogger().debug( "got parameters" );
   
  -		m_numberOfChilps = m_parameters.getParameterAsInteger( PARAM_NUMBER_OF_CHILPS );
  -		m_chilpMessage = m_parameters.getParameter( PARAM_CHILP_MESSAGE );
  -		m_chilpSeparator = m_parameters.getParameter( PARAM_CHILP_SEPARATOR );
  +		m_numberOfChilps = parameters.getParameterAsInteger( PARAM_NUMBER_OF_CHILPS );
  +		m_chilpMessage = parameters.getParameter( PARAM_CHILP_MESSAGE );
  +		m_chilpSeparator = parameters.getParameter( PARAM_CHILP_SEPARATOR );
   	}
   	public void start()
   	{
   		getLogger().debug( "starting" );
   
  -		Runnable runnable = new BirdSongImplRunner( this );
  +		Runnable runnable = new BirdSongRunner( this );
   
   		m_runnerThread = new Thread( runnable );
   		m_runnerThread.setDaemon( true );
  @@ -197,15 +197,15 @@
   		m_runnerThread.notify();
   	}
   
  -	int getNumberOfChilps()
  +	public int getNumberOfChilps()
   	{
   		return m_numberOfChilps;
   	}
  -	String getChilpMessage()
  +	public String getChilpMessage()
   	{
   		return m_chilpMessage;
   	}
  -	String getChilpSeperator()
  +	public String getChilpSeperator()
   	{
   		return m_chilpSeparator;
   	}
  @@ -213,7 +213,7 @@
   		</source>
   		</s4>
   
  -		<s4>
  +		<s4 title="BirdSongRunner.java">
   		<source>
   package avalon.tutorial;
   
  @@ -223,21 +223,21 @@
   {
   	BirdSongImpl m_bs;
   
  -	public void BirdSongRunner( BirdSongImpl bs )
  +	public BirdSongRunner( BirdSongImpl bs )
   	{
   		m_bs = bs;
   	}
   
   	public void run()
   	{
  -		int max = bs.getNumberOfChilps();
  -		String msg = bs.getChilpMessage();
  -		String separator = bs.getSeparator();
  +		int max = m_bs.getNumberOfChilps();
  +		String msg = m_bs.getChilpMessage();
  +		String seperator = m_bs.getChilpSeperator();
   
   		for( int i = 0; i != max; i++ )
   		{
  -			if( i != 0 &amp;&amp; i != (max-1) )
  -				System.out.print( separator );
  +			if( i != 0 && i != (max-1) )
  +				System.out.print( seperator );
   
   			System.out.print(msg );
   		}
  @@ -275,9 +275,10 @@
   			<p>Based on the name of the container (a vital piece in all avalon software)
   			we'll be using (it's called "Tweety"), the idea to do something with cartoons
   			immediately sprang to mind. At first we thought it'd be cool to have a
  -			CartoonDistributionService or something cool and serverside (which is where
  -			avalon is probably used most), we're going to keep it even more simple and
  -			do a commandline input-output thing.</p>
  +			CartoonDistributionService or something more complex and serverside (which is where
  +			avalon is probably used most), but we're going to keep it even more simple and
  +			do a commandline input-output thing. If you want more complex examples,
  +			avalon's got plenty :)</p>
   
   			<p>Our application will be configurable with a <strong>bird</strong>,
a
   			<strong>cat</strong>, and a <strong>cage</strong>. In addition
to these, we're
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/BirdSong1.java
  
  Index: BirdSong1.java
  ===================================================================
  package avalon.tutorial;
  
  public class BirdSong1
  {
  	private int m_numberOfChilps;
  	private String m_chilpMessage;
  	private String m_chilpSeparator;
  
  	public BirdSong1( int numberOfChilps, String chilpMessage, String chilpSeparator )
  	{
  		m_numberOfChilps = numberOfChilps;
  		m_chilpMessage = chilpMessage;
  		m_chilpSeparator = chilpSeparator;
  	}
  
  	public void sing()
  	{
  		for( int i = 0; i != m_numberOfChilps; i++ )
  		{
  			if( i != 0 && i != (m_numberOfChilps-1) )
  				System.out.print( m_chilpSeparator );
  
  			System.out.print( m_chilpMessage );
  		}
  	}
  
  	public static void main( String args[] )
  	{
  		BirdSong1 birdSong = new BirdSong1( new Integer( args[0] ).intValue(),
  				args[1], args[2] );
  
  		birdSong.sing();
  	}
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/BirdSongImpl.java
  
  Index: BirdSongImpl.java
  ===================================================================
  package avalon.tutorial;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  import avalon.tutorial.BirdSong;
  import avalon.tutorial.BirdSongRunner;
  
  public class BirdSongImpl extends AbstractLogEnabled implements BirdSong
  {
  	private int m_numberOfChilps;
  	private String m_chilpMessage;
  	private String m_chilpSeparator;
  
  	private Thread m_runnerThread;
  
  	public BirdSongImpl()
  	{
  	}
  
  	public void parameterize( Parameters parameters ) throws ParameterException
  	{
  		getLogger().debug( "got parameters" );
  
  		m_numberOfChilps = parameters.getParameterAsInteger( PARAM_NUMBER_OF_CHILPS );
  		m_chilpMessage = parameters.getParameter( PARAM_CHILP_MESSAGE );
  		m_chilpSeparator = parameters.getParameter( PARAM_CHILP_SEPARATOR );
  	}
  	public void start()
  	{
  		getLogger().debug( "starting" );
  
  		Runnable runnable = new BirdSongRunner( this );
  
  		m_runnerThread = new Thread( runnable );
  		m_runnerThread.setDaemon( true );
  		m_runnerThread.run();
  	}
  	public void stop()
  	{
  		getLogger().debug( "stopping" );
  
  		m_runnerThread.notify();
  	}
  
  	public int getNumberOfChilps()
  	{
  		return m_numberOfChilps;
  	}
  	public String getChilpMessage()
  	{
  		return m_chilpMessage;
  	}
  	public String getChilpSeperator()
  	{
  		return m_chilpSeparator;
  	}
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/BirdSong.java
  
  Index: BirdSong.java
  ===================================================================
  package avalon.tutorial;
  
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.logger.LogEnabled;
  
  public interface BirdSong extends Parameterizable, Startable, LogEnabled
  {
  	public static final String PARAM_NUMBER_OF_CHILPS = "numberOfChilps";
  	public static final String PARAM_CHILP_MESSAGE = "chilpMessage";
  	public static final String PARAM_CHILP_SEPARATOR = "chilpSeparator";
  
  	/**
  	* Provide us with the parameters it needs to work. Required are:
  	* <ul>
  	* <li>numberOfChilps</li>
  	* <li>chilpMessage</li>
  	* <li>chilpSeparator</li>
  	* </ul>
  	* </pre>
  	*
  	*/
  	void parameterize( Parameters parameters ) throws ParameterException;
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/BirdSongRunner.java
  
  Index: BirdSongRunner.java
  ===================================================================
  package avalon.tutorial;
  
  import avalon.tutorial.BirdSongImpl;
  
  public class BirdSongRunner implements Runnable
  {
  	BirdSongImpl m_bs;
  
  	public BirdSongRunner( BirdSongImpl bs )
  	{
  		m_bs = bs;
  	}
  
  	public void run()
  	{
  		int max = m_bs.getNumberOfChilps();
  		String msg = m_bs.getChilpMessage();
  		String seperator = m_bs.getChilpSeperator();
  
  		for( int i = 0; i != max; i++ )
  		{
  			if( i != 0 && i != (max-1) )
  				System.out.print( seperator );
  
  			System.out.print(msg );
  		}
  	}
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/CartoonBird.java
  
  Index: CartoonBird.java
  ===================================================================
  package avalon.tutorial;
  
  public class CartoonBird
  {
  	private String m_name;
  	private String m_quote;
  	
  	public CartoonBird( String name, String quote )
  	{
  		m_name = name;
  		m_quote = quote;
  	}
  	
  	public void setName( String name )
  	{
  		m_name = name;
  	}
  	public String getName()
  	{
  		return m_name;
  	}
  	public void setQuote( String quote )
  	{
  		m_quote = quote;
  	}
  	public String getQuote()
  	{
  		return m_quote;
  	}
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/CartoonCage.java
  
  Index: CartoonCage.java
  ===================================================================
  package avalon.tutorial;
  
  import java.util.ArrayList;
  import java.util.Collections;
  
  public class CartoonCage
  {
  	private String m_name;
  	private String m_description;
  	
  	private ArrayList m_contents;
  	
  	public CartoonCage( String name, String description )
  	{
  		m_name = name;
  		m_description = description;
  		
  		m_contents = new ArrayList();
  	}
  	
  	public void setName( String name )
  	{
  		m_name = name;
  	}
  	public String getName()
  	{
  		return m_name;
  	}
  	public void setDescription( String description )
  	{
  		m_description = description;
  	}
  	public String getDescription()
  	{
  		return m_description;
  	}
  	
  	public void addBird( CartoonBird bird )
  	{
  		m_contents.add( bird );
  	}
  	public void removeBird( CartoonBird bird )
  	{
  		int index = m_contents.indexOf(bird);
  		if(index != -1)
  			m_contents.remove( index );
  	}
  	public Iterator getBirds()
  	{
  		return (Collections.unmodifiableList(m_contents)).iterator();
  	}
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/CartoonCat.java
  
  Index: CartoonCat.java
  ===================================================================
  package avalon.tutorial;
  
  public class CartoonCat
  {
  	private String m_name;
  	private String m_quote;
  	
  	public CartoonCat( String name, String quote )
  	{
  		m_name = name;
  		m_quote = quote;
  	}
  	
  	public void setName( String name )
  	{
  		m_name = name;
  	}
  	public String getName()
  	{
  		return m_name;
  	}
  	public void setQuote( String quote )
  	{
  		m_quote = quote;
  	}
  	public String getQuote()
  	{
  		return m_quote;
  	}
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/tweety/examples/tutorial/src/java/avalon/tutorial/Cartoon.java
  
  Index: Cartoon.java
  ===================================================================
  package avalon.tutorial;
  
  import java.util.ArrayList;
  
  public class Cartoon
  {
  	private String m_name;
  	
  	private ArrayList m_birds;
  	private ArrayList m_cats;
  	private ArrayList m_cages;
  	
  	public CartoonBird( String name )
  	{
  		m_name = name;
  		
  		m_birds = new ArrayList();
  		m_cats = new ArrayList();
  		m_cages = new ArrayList();
  	}
  	
  	public static void main( String[] args )
  	{
  		Cartoon c = new Cartoon( "AvalonBirdie vs StupidCat" );
  		CartoonBird ab = new CartoonBird( "AvalonBirdie", "I thawt I saw a Stupid Cat!" );
  		CartoonBird ob = new CartoonBird( "OtherBirdie", "I like the mountains, I like the rolling
hills. I like the ..." );
  		CartoonCat sc = new CartoonBird( "StupidCat", "EJBs to the victory!" );
  		
  		CartoonCage gc = new CartoonCage( "GoldenCage", "A shiney golden cage" );
  		
  		c.addBird( ab );
  		c.addBird( ob );
  		c.addCat( sc );
  		c.addCage( gc );
  		
  	}
  	
  	public static void printIntro( Object o )
  	{
  		if( o instanceof Cartoon )
  		{
  			Cartoon c = (Cartoon)o;
  			System.out.println( "Starting cartoon :" + c.getName() );
  			return;
  		}
  		if( o instanceof CartoonBird )
  		{
  			CartoonBird c = (CartoonBird)b;
  			System.out.println( "   Starring the really cool bird :" + c.getName() );
  			return;
  		}
  		if( o instanceof CartoonCat )
  		{
  			CartoonCat c = (CartoonBird)c;
  			System.out.println( "   Starring the really mean cat :" + c.getName() );
  			return;
  		}
  		
  		// got ourselves something else
  		System.out.println( "   Containing the really interesting object :" + c.getName() );
  	}
  	
  	public void setName( String name )
  	{
  		m_name = name;
  	}
  	public String getName()
  	{
  		return m_name;
  	}
  	
  	public void addBird( CartoonBird bird )
  	{
  		m_birds.add( bird );
  	}
  	public void removeBird( CartoonBird bird )
  	{
  		int index = m_birds.indexOf(bird);
  		if(index != -1)
  			m_birds.remove( index );
  	}
  	public Iterator getBirds()
  	{
  		return (Collections.unmodifiableList(m_birds)).iterator();
  	}
  
  	public void addCat( CartoonCat cat )
  	{
  		m_cats.add( cat );
  	}
  	public void removeCat( CartoonCat cat )
  	{
  		int index = m_cats.indexOf(cat);
  		if(index != -1)
  			m_cats.remove( index );
  	}
  	public Iterator getCats()
  	{
  		return (Collections.unmodifiableList(m_cats)).iterator();
  	}
  
  
  	public void addCage( CartoonCage cage )
  	{
  		m_cages.add( cage );
  	}
  	public void removeCage( CartoonCage cage )
  	{
  		int index = m_cages.indexOf(cage);
  		if(index != -1)
  			m_cages.remove( index );
  	}
  	public Iterator getCages()
  	{
  		return (Collections.unmodifiableList(m_cages)).iterator();
  	}
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message