crafterm 2002/07/10 03:01:09
Added: fortress/examples/bin runextended.sh runswing.bat
runswing.sh
fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended
ExtendedContainer.java ExtendedContainer.roles
ExtendedContainer.xconf ExtendedContainer.xlog
Main.java
fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/components
ExtendedComponent.java ExtendedComponentImpl.java
fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/extensions
Extensions.java SecurityManageable.java
Removed: fortress/examples/bin run.bat run.sh
Log:
Initial commit of a simple example using lifecycle extensions.
Revision Changes Path
1.1 jakarta-avalon-excalibur/fortress/examples/bin/runextended.sh
Index: runextended.sh
===================================================================
#!/bin/bash
#
# Startup script.
#
#
# Determine if JAVA_HOME is set and if so then use it
#
if [ -z "$JAVA_HOME" ] ; then
JAVA=`which java`
if [ -z "$JAVA" ] ; then
echo "Cannot find JAVA. Please set your PATH."
exit 1
fi
JAVA_BINDIR=`dirname $JAVA`
JAVA_HOME=$JAVA_BINDIR/..
fi
if [ "$JAVACMD" = "" ] ; then
# it may be defined in env - including flags!!
JAVACMD=$JAVA_HOME/bin/java
fi
# Main.java has hard coded config values so this script must be run from
# altprofile/bin (any better ideas ?)
EXAMPLE_HOME=..
#
# Build the runtime classpath
#
for i in ${EXAMPLE_HOME}/lib/*.jar ; do
CP=${CP}:$i
done
CP=${CP}:${EXAMPLE_HOME}/build/classes
echo $CP
# Run the example application
$JAVACMD -classpath $CP org.apache.excalibur.fortress.examples.extended.Main $@
1.1 jakarta-avalon-excalibur/fortress/examples/bin/runswing.bat
Index: runswing.bat
===================================================================
@echo off
rem
rem Example start script.
rem
rem Author: Leif Mortenson [[EMAIL PROTECTED]]
rem Author: Berin Loritsch [[EMAIL PROTECTED]]
rem
rem Determine if JAVA_HOME is set and if so then use it
rem
if not "%JAVA_HOME%"=="" goto found_java
set EXAMPLE_JAVACMD=java
goto file_locate
:found_java
set EXAMPLE_JAVACMD=%JAVA_HOME%\bin\java
:file_locate
rem
rem Locate where the example is in filesystem
rem
if not "%OS%"=="Windows_NT" goto start
rem %~dp0 is name of current script under NT
set EXAMPLE_HOME=%~dp0
rem : operator works similar to make : operator
set EXAMPLE_HOME=%EXAMPLE_HOME:\bin\=%
:start
if not "%EXAMPLE_HOME%" == "" goto example_home
echo.
echo Warning: EXAMPLE_HOME environment variable is not set.
echo This needs to be set for Win9x as it's command prompt
echo scripting bites
echo.
goto end
:example_home
rem
rem build the runtime classpath
rem
set CP=%EXAMPLE_HOME%\lib\container.jar
set _LIBJARS=
for %%i in (%EXAMPLE_HOME%\..\lib\*.jar) do call %EXAMPLE_HOME%\bin\cpappend.bat %%i
if not "%_LIBJARS%" == "" goto run
echo Unable to set CLASSPATH dynamically.
goto end
:run
set CP=%CP%%_LIBJARS%
rem Run the example application
%EXAMPLE_JAVACMD% -Djava.compiler="NONE" -classpath "%CP%"
org.apache.excalibur.fortress.examples.simple.Main %1 %2 %3 %4 %5 %6 %7 %8 %9
:end
1.1 jakarta-avalon-excalibur/fortress/examples/bin/runswing.sh
Index: runswing.sh
===================================================================
#!/bin/bash
#
# Startup script.
#
#
# Determine if JAVA_HOME is set and if so then use it
#
if [ -z "$JAVA_HOME" ] ; then
JAVA=`which java`
if [ -z "$JAVA" ] ; then
echo "Cannot find JAVA. Please set your PATH."
exit 1
fi
JAVA_BINDIR=`dirname $JAVA`
JAVA_HOME=$JAVA_BINDIR/..
fi
if [ "$JAVACMD" = "" ] ; then
# it may be defined in env - including flags!!
JAVACMD=$JAVA_HOME/bin/java
fi
# Main.java has hard coded config values so this script must be run from
# altprofile/bin (any better ideas ?)
EXAMPLE_HOME=..
#
# Build the runtime classpath
#
for i in ${EXAMPLE_HOME}/lib/*.jar ; do
CP=${CP}:$i
done
CP=${CP}:${EXAMPLE_HOME}/build/classes
echo $CP
# Run the example application
$JAVACMD -classpath $CP org.apache.excalibur.fortress.examples.swing.Main $@
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/ExtendedContainer.java
Index: ExtendedContainer.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.examples.extended;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.excalibur.fortress.AbstractContainer;
import org.apache.excalibur.fortress.examples.extended.components.ExtendedComponent;
import org.apache.excalibur.fortress.examples.extended.extensions.Extensions;
public final class ExtendedContainer
extends AbstractContainer
{
private ComponentManager m_manager;
public void initialize()
throws Exception
{
super.initialize();
m_extManager.getAccessLifecycleExtensions().add(new Extensions());
// REVISIT(MC): this doesn't belong here
m_manager = getComponentManager();
}
public void doLookups()
throws Exception
{
getLogger().info("Starting lookup of custom component");
for (int i = 0; i < 10; ++i)
{
ExtendedComponent comp = (ExtendedComponent)
m_manager.lookup(ExtendedComponent.ROLE);
m_manager.release(comp);
}
getLogger().info("Finished lookups of custom component");
}
}
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/ExtendedContainer.roles
Index: ExtendedContainer.roles
===================================================================
<test>
<role
name="org.apache.excalibur.fortress.examples.extended.components.ExtendedComponent">
<component shorthand="extended-component"
class="org.apache.excalibur.fortress.examples.extended.components.ExtendedComponentImpl"
handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"/>
</role>
</test>
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/ExtendedContainer.xconf
Index: ExtendedContainer.xconf
===================================================================
<test>
<component id="extended-component"
class="org.apache.excalibur.fortress.examples.extended.components.ExtendedComponentImpl"
role="org.apache.excalibur.fortress.examples.extended.components.ExtendedComponent"
handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"
logger="extended-component">
</component>
</test>
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/ExtendedContainer.xlog
Index: ExtendedContainer.xlog
===================================================================
<logkit>
<factories>
<factory type="file"
class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
</factories>
<targets>
<file id="root">
<filename>fortress-extensions.log</filename>
<format type="extended">
%7.7{priority} %5.5{time} [%8.8{category}] (%{context}):
%{message}\n%{throwable}
</format>
</file>
</targets>
<categories>
<category name="" log-level="DEBUG">
<log-target id-ref="root"/>
</category>
</categories>
</logkit>
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/Main.java
Index: Main.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.examples.extended;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.fortress.ContainerManager;
import org.apache.excalibur.fortress.DefaultContainerManager;
import org.apache.excalibur.fortress.util.ContextBuilder;
import org.apache.excalibur.fortress.util.ContextManager;
/**
* Fortress container example with custom extensions
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version $Id: Main.java,v 1.1 2002/07/10 10:01:08 crafterm Exp $
*/
public final class Main
{
// container reference
private static ExtendedContainer m_container;
/**
* @param args a <code>String[]</code> array of command line arguments
* @exception Exception if an error occurs
*/
public static final void main( String[] args )
throws Exception
{
ContextBuilder contextBuilder = new ContextBuilder();
contextBuilder.setContainerClass(
"org.apache.excalibur.fortress.examples.extended.ExtendedContainer" );
contextBuilder.setContextDirectory( "./" );
contextBuilder.setWorkDirectory( "./" );
contextBuilder.setContainerConfiguration(
"resource://org/apache/excalibur/fortress/examples/extended/ExtendedContainer.xconf" );
contextBuilder.setLoggerManagerConfiguration(
"resource://org/apache/excalibur/fortress/examples/extended/ExtendedContainer.xlog" );
contextBuilder.setRoleManagerConfiguration(
"resource://org/apache/excalibur/fortress/examples/extended/ExtendedContainer.roles" );
ContextManager contextManager = new ContextManager(
contextBuilder.getContext(), null );
contextManager.initialize();
ContainerManager cm = new DefaultContainerManager( contextManager );
cm.initialize();
m_container = ( ExtendedContainer ) cm.getContainer();
m_container.doLookups();
}
}
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/components/ExtendedComponent.java
Index: ExtendedComponent.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.examples.extended.components;
import org.apache.avalon.framework.component.Component;
/**
* Simple <code>TestComponent</code> component for testing custom extensions
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/10 10:01:09 $
*/
public interface ExtendedComponent extends Component
{
/**
* Component <code>ROLE</code>
*/
String ROLE = ExtendedComponent.class.getName();
}
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/components/ExtendedComponentImpl.java
Index: ExtendedComponentImpl.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.examples.extended.components;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.component.Component;
import org.apache.excalibur.fortress.examples.extended.extensions.SecurityManageable;
/**
* <code>TestComponentImpl</code>, demonstrating the use of a custom
* lifecycle stage <code>SecurityManageable</code>. This code does
* a simple access check for several files on the file system and logs
* the results accordingly.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/10 10:01:09 $
*/
public class ExtendedComponentImpl
extends AbstractLogEnabled
implements ExtendedComponent, SecurityManageable
{
/**
* Pass a SecurityManager object to the component
*
* @param manager a <code>SecurityManager</code> value
*/
public void secure( final SecurityManager manager )
throws SecurityException
{
getLogger().debug( "Received SecurityManager instance: " + manager );
final String[] files = { "/tmp", "/vmlinuz", "/usr/lib/libc.a" };
for ( int i = 0; i < files.length; ++i )
{
try
{
manager.checkRead( files[ i ] );
getLogger().info( "Thread can read " + files[ i ] );
}
catch ( SecurityException e )
{
getLogger().info( "Thread can not read " + files[ i ] );
}
}
}
}
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/extensions/Extensions.java
Index: Extensions.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.examples.extended.extensions;
import org.apache.avalon.framework.context.Context;
import org.apache.excalibur.fortress.AbstractContainer;
import org.apache.excalibur.fortress.lifecycle.AbstractLifecycleExtension;
/**
* Some custom extensions for this container's components.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/10 10:01:09 $
*/
public class Extensions
extends AbstractLifecycleExtension
{
/**
* Access, called when the given component is being
* accessed (ie. via lookup() or select()).
*
* @param component a <code>Component</code> instance
* @param context a <code>Context</code> instance
* @exception Exception if an error occurs
*/
public void access( Object component, Context context )
throws Exception
{
if ( component instanceof SecurityManageable )
{
// pass in a simple security manager for testing, a real
// system might want to pass in specialized/custom security managers
( ( SecurityManageable ) component ).secure( new SecurityManager() );
}
}
}
1.1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/extensions/SecurityManageable.java
Index: SecurityManageable.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.examples.extended.extensions;
/**
* Simple custom lifecycle extension interface for supplying a component
* with a security manager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/10 10:01:09 $
*/
public interface SecurityManageable
{
/**
* Pass a SecurityManager object to the component
*
* @param manager a <code>SecurityManager</code> value
*/
void secure( SecurityManager manager )
throws SecurityException;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>