You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sg...@apache.org on 2005/05/09 19:52:01 UTC
cvs commit: jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service SystemPropertyService.java SystemPropertyServiceImpl.java
sgoeschl 2005/05/09 10:52:01
Added: yaafi/tutorial/temp .cvsignore
yaafi/tutorial/src/java/tutorial/running Application.java
Factory.java
yaafi/tutorial/conf componentConfig.xml componentRoles.xml
containerConfiguration.xml parameters.properties
yaafi/tutorial/src/java/tutorial/service
SystemPropertyService.java
SystemPropertyServiceImpl.java
Log:
Added a simple YAAFI tutorial
Revision Changes Path
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/temp/.cvsignore
Index: .cvsignore
===================================================================
*.properties
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/running/Application.java
Index: Application.java
===================================================================
package tutorial.running;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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.
*/
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.fulcrum.yaafi.cli.Main;
/**
* Test suite for exercising the command line integration.
*
* @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
*/
public class Application implements Runnable
{
/** the YAAFI command line interface */
private Main cli;
public static void main( String[] args )
{
try
{
new Application(args).init().run();
}
catch( Throwable t )
{
String msg = "Execution of the server failed : " + t.getMessage();
System.err.println(msg);
}
}
/**
* Constructor
*
* @param args the command line parameters
*/
public Application(String[] args)
{
this.cli = new Main(args);
}
/**
* Initialize the application
*
* @return the initialized instance
* @throws Exception the initialization failed
*/
protected Application init() throws Exception
{
// 1) initialize the YAAFI Main class
// 1.1) set the temp directory to be used
this.cli.setTempHome( "./tutorial/temp" );
// 1.2) set the container configuration to bootstrap the YAAFI container
this.cli.setContainerConfigValue( "./tutorial/conf/containerConfiguration.xml" );
// 1.3) block the main thread until the JVM is terminated
this.cli.setIsBlocking(true);
// 1.4) install a JVM shutdown hook to dispose the YAAFI container
this.cli.setHasShutdownHook(true);
// 2) initialize the logger
ConsoleLogger consoleLogger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
this.cli.setLogger( consoleLogger );
return this;
}
/**)
* @see java.lang.Runnable#run()
*/
public void run()
{
try
{
this.cli.initialize();
this.cli.getLogger().info( "The application is up and running ..." );
this.cli.onWait();
this.cli.getLogger().info( "The application is terminating ..." );
}
catch (Throwable t)
{
String msg = "Running the server failed due to : " + t.getMessage();
this.cli.getLogger().error(msg,t);
throw new RuntimeException(msg);
}
}
}
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/running/Factory.java
Index: Factory.java
===================================================================
package tutorial.running;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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.
*/
import org.apache.fulcrum.yaafi.framework.container.ServiceContainer;
import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration;
import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory;
/**
* Test suite for exercising the command line integration.
*
* @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
*/
public class Factory
{
public static void main( String[] args )
{
try
{
ServiceContainer container = null;
ServiceContainerConfiguration config = null;
config = new ServiceContainerConfiguration();
config.loadContainerConfiguration( "./tutorial/conf/containerConfiguration.xml" );
container = ServiceContainerFactory.create( config );
container.dispose();
}
catch( Throwable t )
{
String msg = "Execution of the server failed : " + t.getMessage();
System.err.println(msg);
}
}
}
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/conf/componentConfig.xml
Index: componentConfig.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<componentConfig>
<SystemPropertyService>
<property name="FOO">BAR</property>
</SystemPropertyService>
</componentConfig>
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/conf/componentRoles.xml
Index: componentRoles.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<role-list>
<role
name="tutorial.service.SystemPropertyService"
shorthand="SystemPropertyService"
default-class="tutorial.service.SystemPropertyServiceImpl"
/>
</role-list>
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/conf/containerConfiguration.xml
Index: containerConfiguration.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<fulcrum-yaafi>
<componentRoles>
<location>./tutorial/conf/componentRoles.xml</location>
</componentRoles>
<componentConfiguration>
<location>./tutorial/conf/componentConfig.xml</location>
</componentConfiguration>
<parameters>
<location>./tutorial/conf/parameters.properties</location>
</parameters>
</fulcrum-yaafi>
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/conf/parameters.properties
<<Binary file>>
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service/SystemPropertyService.java
Index: SystemPropertyService.java
===================================================================
package tutorial.service;
/*
* Copyright 2004 Apache Software Foundation
* 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.
*/
/**
* Copies the properties into SystemProperties
*
* @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
*/
public interface SystemPropertyService
{
// This interface doesn't exposes any other methods
}
1.1 jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service/SystemPropertyServiceImpl.java
Index: SystemPropertyServiceImpl.java
===================================================================
package tutorial.service;
/*
* Copyright 2004 Apache Software Foundation
* 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.
*/
import java.io.File;
import java.io.FileOutputStream;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Reconfigurable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
* A slightly more complex tuturial example.
*
* @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
*/
public class SystemPropertyServiceImpl
extends AbstractLogEnabled
implements SystemPropertyService, Reconfigurable, Contextualizable, Initializable
{
/** the Avalon temp directory */
private File tempDir;
/**
* @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
*/
public void contextualize(Context context) throws ContextException
{
this.tempDir = (File) context.get("urn:avalon:temp");
}
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException
{
Configuration[] systemProperties = configuration.getChildren("property");
for( int i=0; i<systemProperties.length; i++ )
{
String key = systemProperties[i].getAttribute("name");
String value = systemProperties[i].getValue();
this.getLogger().debug( "Setting the value of " + key + " to " + value );
System.setProperty( key, value );
}
}
/**
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
public void initialize() throws Exception
{
FileOutputStream fos = new FileOutputStream( new File(this.tempDir,"system.properties") );
System.getProperties().store( fos, "system.properties" );
fos.flush();
fos.close();
}
/**
* @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration)
*/
public void reconfigure(Configuration configuration)
throws ConfigurationException
{
this.configure(configuration);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service
SystemPropertyService.java SystemPropertyServiceImpl.java
Posted by Siegfried Goeschl <si...@it20one.at>.
Hi Scott,
thanks for the recommendation - the tutorial will go through a few
iterations anyway since I wrote it yesterday evening ....
Cheers,
Siegfried Goeschl
Scott Eade wrote:
> sgoeschl@apache.org wrote:
>
>> sgoeschl 2005/05/09 10:52:01
>
> ...
>
>> Added a simple YAAFI tutorial
>
> Excellent - it is always great to see documentation being committed.
> ...
>
>> * Copyright 2001-2004 The Apache Software Foundation.
>
> For new files this should be just 2005 - I think you can run into
> problems if you indicate that the copyright commences before the code
> existed :-)
>
> Regards,
>
> Scott
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service
SystemPropertyService.java SystemPropertyServiceImpl.java
Posted by Scott Eade <se...@apache.org>.
sgoeschl@apache.org wrote:
> sgoeschl 2005/05/09 10:52:01
...
> Added a simple YAAFI tutorial
Excellent - it is always great to see documentation being committed.
...
> * Copyright 2001-2004 The Apache Software Foundation.
For new files this should be just 2005 - I think you can run into
problems if you indicate that the copyright commences before the code
existed :-)
Regards,
Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org