You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2004/02/13 15:24:27 UTC
cvs commit: jakarta-turbine-fulcrum/naming/src/test/org/apache/fulcrum/naming NamingServiceTest.java
epugh 2004/02/13 06:24:27
Added: naming project.properties project.xml LICENSE.txt
.cvsignore
naming/xdocs navigation.xml index.xml changes.xml
naming/src/java/org/apache/fulcrum/naming NamingService.java
DefaultNamingService.java
naming/src/test TestRoleConfig.xml TestComponentConfig.xml
naming/src/test/org/apache/fulcrum/naming
NamingServiceTest.java
Log:
Conversion to Avalon Component
Revision Changes Path
1.1 jakarta-turbine-fulcrum/naming/project.properties
Index: project.properties
===================================================================
1.1 jakarta-turbine-fulcrum/naming/project.xml
Index: project.xml
===================================================================
<?xml version="1.0"?>
<project>
<extend>${basedir}/../project.xml</extend>
<id>fulcrum-naming</id>
<name>Fulcrum Naming Component</name>
<currentVersion>1.0-alpha-1</currentVersion>
<dependencies>
<!-- Needed only for testing -->
<dependency>
<groupId>fulcrum</groupId>
<artifactId>fulcrum-testcontainer</artifactId>
<version>1.0-alpha-2</version>
</dependency>
<dependency>
<id>xerces:xercesImpl</id>
<version>2.0.2</version>
<url>http://xml.apache.org/xerces2-j/</url>
</dependency>
<dependency>
<id>xerces:xmlParserAPIs</id>
<version>2.0.2</version>
<url>http://xml.apache.org/xerces2-j/</url>
</dependency>
</dependencies>
</project>
1.1 jakarta-turbine-fulcrum/naming/LICENSE.txt
Index: LICENSE.txt
===================================================================
/* ----------------------------------------------------------------------------
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Plexus", 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 names without prior written
* permission of the Apache Group.
*
* 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON 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 Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ----------------------------------------------------------------------------
*/
1.1 jakarta-turbine-fulcrum/naming/.cvsignore
Index: .cvsignore
===================================================================
target
.classpath
.project
*.ser
*.log
1.1 jakarta-turbine-fulcrum/naming/xdocs/navigation.xml
Index: navigation.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project
name="cache"
href="http://jakarta.apache.org/turbine/fulcrum/cache/">
<body>
<links>
<item name="Turbine"
href="http://jakarta.apache.org/turbine/"/>
<item name="Fulcrum"
href="http://jakarta.apache.org/turbine/fulcrum/"/>
</links>
<menu name="Overview">
<item name="Main" href="/index.html"/>
</menu>
</body>
</project>
1.1 jakarta-turbine-fulcrum/naming/xdocs/index.xml
Index: index.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Naming Component</title>
<author email="epugh@opensourceconnections.com">Eric Pugh</author>
</properties>
<body>
<section name="Overview">
<p>
This Service functions as a Naming component.
</p>
<p>
It is written
for use in Turbine but it can be used in any container compatible
with Avalon's ECM container.
</p>
</section>
<section name="Configuration">
<p>
First, here is the role configuration.
</p>
<source>
<![CDATA[
<role
name="org.apache.fulcrum.naming.NamingService"
shorthand="cache"
default-class="org.apache.fulcrum.naming.DefaultNamingService"/>
]]>
</source>
<p>
And here is the configuration:
</p>
<source>
<![CDATA[
<cache cacheInitialSize="20" cacheCheckFrequency="5"/>
]]>
</source>
</section>
<section name="Usage">
<source><![CDATA[
GlobalCacheService gs = null;
try
{
/*
* Look for the item in the cache.
* If it doesn't exist or the item is stale,
* the cache will throw an exception.
*/
gs = (GlobalCacheService)avalonComponentService.lookup(GlobalCacheService.ROLE)
CachedObject obj = gs.getObject("cached_object");
data.setMessage( data.getScreen() + " Got " +
obj.getContents().toString() + " from global cache!" );
}
catch(ObjectExpiredException gone)
{
/*
* Add the item to the cache.
*/
gs.addObject("cached_object",
new CachedObject("in_the_cache",5000));
data.setMessage( data.getScreen() +
" Refreshed/or added new item to" +
" the cache! Expires in 5 seconds" );
}
]]></source>
<p>
You can also place an expiration time on your objects so the Service will
automatically remove them when they expire. If you don't specify an expiration
time, the Service uses 5 seconds. To see an example, look at the
test case <a href="xref-test/org/apache/fulcrum/cache/CacheTest.html">CacheTest</a>
</p>
</section>
</body>
</document>
1.1 jakarta-turbine-fulcrum/naming/xdocs/changes.xml
Index: changes.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Fulcrum BSF</title>
<author email="epugh@opensourceconnections.com">Eric Pugh</author>
</properties>
<body>
<release version="1.0-alpha-2" date="in CVS">
<action dev="epugh" type="add">
Initial conversion to Avalon component.
</action>
</release>
</body>
</document>
1.1 jakarta-turbine-fulcrum/naming/src/java/org/apache/fulcrum/naming/NamingService.java
Index: NamingService.java
===================================================================
package org.apache.fulcrum.naming;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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 "Apache" and "Apache Software Foundation" and
* "Apache Turbine" 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",
* "Apache Turbine", 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON 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 Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import javax.naming.Context;
/**
* Implementations of the NamingService interface provide JNDI naming
* contexts.
*
* @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
* @version $Id: NamingService.java,v 1.1 2004/02/13 14:24:27 epugh Exp $
*/
public interface NamingService
{
/** Avalon role - used to id the component within the manager */
String ROLE = NamingService.class.getName();
/**
* Return the Context with the specified name.
*
* @param name The name of the context.
* @return The context with the specified name, or null if no context
* exists with that name.
*/
public Context getContext(String name);
}
1.1 jakarta-turbine-fulcrum/naming/src/java/org/apache/fulcrum/naming/DefaultNamingService.java
Index: DefaultNamingService.java
===================================================================
package org.apache.fulcrum.naming;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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 "Apache" and "Apache Software Foundation" and
* "Apache Turbine" 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",
* "Apache Turbine", 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON 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 Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
/**
* This class is the default implementation of NamingService, which
* provides JNDI naming contexts.
*
* @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
* @author <a href="mailto:colin.chalmers@maxware.nl">Colin Chalmers</a>
* @version $Id: DefaultNamingService.java,v 1.1 2004/02/13 14:24:27 epugh Exp $
*/
public class DefaultNamingService
extends AbstractLogEnabled
implements NamingService, Configurable, Initializable, ThreadSafe
{
/**
* A global HashTable of Property objects which are initialised using
* parameters from the ResourcesFile
*/
private static Hashtable contextPropsList = null;
private Hashtable initialContexts = new Hashtable();
/**
* Return the Context with the specified name.
*
* @param name The name of the context.
* @return The context with the specified name, or null if no
* context exists with that name.
*/
public Context getContext(String contextName)
{
// Get just the properties for the context with the specified
// name.
Properties contextProps = null;
if (contextPropsList.containsKey(contextName))
{
contextProps = (Properties) contextPropsList.get(contextName);
}
else
{
contextProps = new Properties();
}
// Construct a new context with the properties.
try
{
return new InitialContext(contextProps);
}
catch (Exception e)
{
return null;
}
}
// ---------------- Avalon Lifecycle Methods ---------------------
/**
* Avalon component lifecycle method
*/
public void configure(Configuration conf) throws ConfigurationException
{
Configuration[] keys = conf.getChildren();
if (keys != null)
{
for (int i = 0; i < keys.length; i++)
{
String contextName = keys[i].getName();
Properties contextProps =
toProperties(Parameters.fromConfiguration(keys[i]));
contextPropsList.put(contextName, contextProps);
}
}
}
/**
* Note: this is copied from avalon's Parameter class, which does not
* appear to have the method in the version I'm compiling against.
* Creates a <code>java.util.Properties</code> object from an Avalon
* Parameters object.
*
* @param params a <code>Parameters</code> instance
* @return a <code>Properties</code> instance
*/
private static Properties toProperties(final Parameters params)
{
final Properties properties = new Properties();
final String[] names = params.getNames();
for (int i = 0; i < names.length; ++i)
{
// "" is the default value, since getNames() proves it will exist
properties.setProperty(names[i], params.getParameter(names[i], ""));
}
return properties;
}
/**
* Avalon component lifecycle method
*/
public void initialize() throws Exception
{
try
{
Enumeration contextPropsKeys = contextPropsList.keys();
while (contextPropsKeys.hasMoreElements())
{
String key = (String) contextPropsKeys.nextElement();
Properties contextProps =
(Properties) contextPropsList.get(key);
InitialContext context = new InitialContext(contextProps);
initialContexts.put(key, context);
}
}
catch (Exception e)
{
getLogger().error("Failed to initialize JDNI contexts!", e);
throw new Exception("Failed to initialize JDNI contexts!");
}
}
}
1.1 jakarta-turbine-fulcrum/naming/src/test/TestRoleConfig.xml
Index: TestRoleConfig.xml
===================================================================
<!-- This configuration file for Avalon components is used for testing the TestComponent -->
<role-list>
<role
name="org.apache.fulcrum.naming.NamingService"
shorthand="naming"
default-class="org.apache.fulcrum.naming.DefaultNamingService"/>
</role-list>
1.1 jakarta-turbine-fulcrum/naming/src/test/TestComponentConfig.xml
Index: TestComponentConfig.xml
===================================================================
<componentConfig>
<naming/>
</componentConfig>
1.1 jakarta-turbine-fulcrum/naming/src/test/org/apache/fulcrum/naming/NamingServiceTest.java
Index: NamingServiceTest.java
===================================================================
package org.apache.fulcrum.naming;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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 "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" 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" or
* "Apache Jetspeed", 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON 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 Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.fulcrum.testcontainer.BaseUnitTest;
/**
* NamingServiceTest
*
* @author <a href="epugh@opensourceconnections.com">Eric Pugh</a>
* @version $Id: NamingServiceTest.java,v 1.1 2004/02/13 14:24:27 epugh Exp $
*/
public class NamingServiceTest extends BaseUnitTest
{
private NamingService namingService = null;
/**
* Defines the testcase name for JUnit.
*
* @param name the testcase's name.
*/
public NamingServiceTest(String name)
{
super(name);
}
/**
* Simple test that adds, retrieves, and deletes 2 object.
*
* @throws Exception
*/
public void testGettingNamingService() throws Exception
{
NamingService ns = (NamingService) this.lookup(NamingService.ROLE);
assertNotNull(ns);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org