3
Fork 0

[svn r115] added the rest of foei

This commit is contained in:
willemc 2006-07-27 14:53:20 +02:00
parent a9ea03e737
commit ed5da52253
75 changed files with 6511 additions and 1 deletions

View file

@ -0,0 +1,40 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.beans;
/**
* Gets ans Set properties of an java bean
*
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2006
*/
public class BeanProperty {
}

View file

@ -0,0 +1,174 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.beans;
import java.lang.Comparable;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.beanutils.BeanUtils;
/**
* Compares a property of a java bean.
* The property should be Comparable.
*
* @author Willem Cazander
* @version 1.0 Jan 11, 2006
*/
public class BeanPropertyComparator<T> implements Comparator {
/** The propery of the bean to compare. */
private String property = null;
/** The logger to log to. */
private Logger logger = null;
/** The ascending */
private boolean ascending = true;
/**
* The constructor inits the logger.
*/
public BeanPropertyComparator() {
logger = Logger.getLogger(BeanPropertyComparator.class.getName());
}
/**
* Creates an BeanPropertyComparator with an property
* @param property
*/
public BeanPropertyComparator(String property) {
this();
setProperty(property);
}
/**
* Creates an BeanPropertyComparator with an property
* @param property
*/
public BeanPropertyComparator(String property,boolean ascending) {
this();
setProperty(property);
setAscending(ascending);
}
/**
* Compares 2 objects by the propery
* @see Comparator#compare(T, T);
* @param o1 Object 1
* @param o2 Object 2
* @return the differce between the objects.
*/
public int compare(Object o1,Object o2) throws ClassCastException {
Comparable c1 = getComparableProperty(o1);
Comparable c2 = getComparableProperty(o2);
if(c1==null && c2==null) {
return 0;
}
if(c1==null) {
if(ascending) {
return 1;
} else {
return -1;
}
}
if(c2==null) {
if(ascending) {
return 1;
} else {
return -1;
}
}
if(ascending) {
return c1.compareTo(c2);
} else {
return c2.compareTo(c1);
}
}
/**
* Returns the Comparable property of the object.
* @param object
* @return
* @throws ClassCastException
*/
private Comparable getComparableProperty(Object object) throws ClassCastException {
if(property==null) {
throw new IllegalStateException("property is not set.");
}
Object result = null;
try {
result = BeanUtils.getProperty(object,property);
} catch (Exception e) {
logger.log(Level.WARNING,"property:"+property+" is not an property of object: "+object.getClass().getName(),e);
}
try {
Comparable c = (Comparable)result;
return c;
} catch (ClassCastException e) {
logger.log(Level.WARNING,"property:"+property+" is not Comparable",e);
throw e;
}
}
/**
* @return Returns the property.
*/
public String getProperty() {
return property;
}
/**
* @param property The property to set.
*/
public void setProperty(String property) {
if(property==null) {
throw new NullPointerException("property may not be null");
}
this.property = property;
logger.finest("property="+property);
}
/**
* @return Returns the ascending.
*/
public boolean isAscending() {
return ascending;
}
/**
* @param ascending The ascending to set.
*/
public void setAscending(boolean ascending) {
this.ascending = ascending;
logger.finest("ascending="+ascending);
}
}

View file

@ -0,0 +1,95 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.beans;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Comparator;
import java.util.Locale;
/**
*
*
* @author Willem Cazander
* @version 1.0 Feb 9, 2006
*/
public class NumberComparator implements Comparator {
private Locale locale = null;
/**
* @return Returns the locale.
*/
public Locale getLocale() {
return locale;
}
/**
* @param locale The locale to set.
*/
public void setLocale(Locale locale) {
this.locale = locale;
}
/**
* Compares two String as number.
* @param o1
* @param o2
* @return
* @see Comparator#compare(T, T)
*/
public int compare(Object o1, Object o2) {
Double d1 = getDoubleValue((String)o1,locale);
Double d2 = getDoubleValue((String)o2,locale);
return d1.compareTo(d2);
}
/**
* Converts an String to an Number wich is converted to a Double
* @param test The String to parse.
* @param locale The locale of the numberFormat.
* @return An Double
*/
static public Double getDoubleValue(String text,Locale locale) {
try {
NumberFormat nf = NumberFormat.getInstance(locale);
Number n = nf.parse(text);
if(n instanceof Double) {
return (Double)n;
}
if(n instanceof Integer) {
return ((Integer)n).doubleValue();
}
if(n instanceof Long) {
return ((Long)n).doubleValue();
}
} catch(ParseException pe) {
} catch (NumberFormatException e) {
}
return 0.0;
}
}

View file

@ -0,0 +1,61 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.00
Copyright 2004-2006 IDCA. 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.
THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
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.
The views and conclusions contained in the software and documentation are those of the authors and
should not be interpreted as representing official policies, either expressed or implied, of IDCA.
-->
</head>
<body bgcolor="white">
Provides some handy classes for working with java beans.<br/>
<h2>Package Specification</h2>
<ul>
<li>Full J2SE 5 compatible</li>
<li>Small package</li>
</ul>
<!--
<ul>
<li><a href="">hgj</a>
</ul>
-->
<h2>Related Documentation</h2>
None.
<!--
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="http://foei.idca.nl/docs/jmx/example1">Example 1</a>
</ul>
-->
<!-- Put @see and @since tags down here. -->
</body>
</html>

View file

@ -0,0 +1,56 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jdbc;
import java.sql.Connection;
/**
* Java code can get a DB connections here.
* Its retreived from the ConnectionProviderManager.
*
* @author Willem Cazander
* @version 1.0
*/
public class ConnectionFactory
{
/**
* Returns a connection by its name
* @param name The name of the connection
* @return Returns the Connection.
*/
static public Connection getConnection(String name) {
return getConnectionProviderManager().getConnection(name);
}
/**
* Gets the instance of the ConnectionProviderManager.
* @return Returns the ConnectionProviderManager.
*/
static public ConnectionProviderManager getConnectionProviderManager() {
return ConnectionProviderManager.getSharedInstance();
}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jdbc;
import java.sql.Connection;
/**
* The ConnectionProvider is an interface which
* lets objects returns a Connection.
*
* We normally registrates an ConnectionProvider to the
* ConnectionProviderManager so objects can use it.
*
* @author Willem Cazander
* @version 1.0 Jan 4, 2006
*/
public interface ConnectionProvider
{
/**
* Gets the connection name for which this
* ConnectionProvider handles connections.
* @return Returns the connection name.
*/
public String getConnectionName();
/**
* Gets an connection of this ConnectionProvider.
* @return Returns an Connection
*/
public Connection getConnection();
}

View file

@ -0,0 +1,115 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jdbc;
import java.sql.Connection;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
/**
* Manages the different ConnectionProviders.
*
* @author Willem Cazander
* @version 1.0 Jan 4, 2006
*/
public class ConnectionProviderManager
{
/** The logger to log to */
private Logger logger = null;
/** The map with all connection providers */
private Map<String,ConnectionProvider> connectionProviders = null;
/** The ConnectionProviderManager instance */
static private ConnectionProviderManager connectionProviderManager = null;
static {
try {
connectionProviderManager = new ConnectionProviderManager();
} catch (Exception e) {
throw new RuntimeException("Error while creating ConnectionProviderManager",e);
}
}
/**
* Creates an private ConnectionProviderManager
*
*/
private ConnectionProviderManager() {
logger = Logger.getLogger(ConnectionProviderManager.class.getName());
logger.fine("Creating an ConnectionProviderManager");
connectionProviders = new HashMap<String,ConnectionProvider>(3);
}
/**
* Returns the singleton object of the ConnectionProviderManager.
* @return
*/
static public ConnectionProviderManager getSharedInstance() {
return connectionProviderManager;
}
// ============ END SINGLETON
/**
* Gets an Connection by its connectionName
* @param connectionName The connection name.
* @return Returns the Connection
*/
public Connection getConnection(String connectionName) {
return getConnectionProvider(connectionName).getConnection();
}
/**
* Adds an ConnectionProvider
* @param connectionProvider The ConnectionProvider to add.
*/
public void addConnectionProvider(ConnectionProvider connectionProvider) {
if(connectionProvider==null) {
throw new NullPointerException("connectionProvider may not be null.");
}
logger.fine("Adding ConnnectionProvider for connection: "+connectionProvider.getConnectionName());
connectionProviders.put(connectionProvider.getConnectionName(),connectionProvider);
}
/**
* Gets an ConnectionProvider by its connectionName
* @param connectionName The connection name
* @return Returns the ConnectionProvider for this connectionName.
*/
public ConnectionProvider getConnectionProvider(String connectionName) {
return connectionProviders.get(connectionName);
}
/**
* Gets all ConnectionProviders
* @return Returns all ConnectionProviders.
*/
public Collection<ConnectionProvider> getConnectionProviders() {
return connectionProviders.values();
}
}

View file

@ -0,0 +1,163 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jdbc;
import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
/**
* The JndiDataSourceProvider is an ConnectionProvider which gets its connection
* from a jndi context.
* @author Willem Cazander
* @version 1.0 Jan 4, 2006
*/
public class JndiDataSourceProvider implements ConnectionProvider
{
/** The context in which database datasources are found. */
private static final String DATASOURCE_CONTEXT = "java:comp/env/jdbc/";
/** The connectionName for this Provider */
private String connectionName = null;
/** The jndi context to search for the dataSource. */
private String dataSourceContext = null;
/** The logger to log to. */
private Logger logger = null;
/**
* Creates an JndiDataSourceProvider and inits the Logger
*/
public JndiDataSourceProvider() {
logger = Logger.getLogger(JndiDataSourceProvider.class.getName());
}
/**
* Creates JndiDataSourceProvider and sets its connectionName.
* @param connectionName
*/
public JndiDataSourceProvider(String connectionName) {
this();
setConnectionName(connectionName);
}
/**
* Creates an JndiDataSourceProvider and inits the Logger
* @param connectionName The connection name which this provider handles
* @param dataSourceContext The JNDI datasource prefix for getting the DataSource
*/
public JndiDataSourceProvider(String connectionName,String dataSourceContext) {
this(connectionName);
setDataSourceContext(dataSourceContext);
}
/**
* Gets an DataSource out of the jndi context.
* @param name The name of the datasource in the jndi context.
* @return The datasource.
*/
static public DataSource getDataSource(String name) {
try {
Context initialContext = new InitialContext();
if(initialContext == null) {
throw new RuntimeException("Init: Cannot get Initial Context");
}
DataSource datasource = (DataSource) initialContext.lookup(name);
if(datasource == null) {
throw new RuntimeException("Init: Cannot lookup datasource: '"+name+"'");
}
return datasource;
} catch (NamingException ex) {
throw new RuntimeException("Init: Cannot get connection " + ex);
}
}
//========= ConnectionProvider
/**
* Gets the connection name for which this
* ConnectionProvider handles connections.
* @return Returns the connection name.
* @see ConnectionProvider#getConnectionName()
*/
public String getConnectionName() {
return connectionName;
}
/**
* Gets an connection of this ConnectionProvider.
* @return Returns an Connection
* @see ConnectionProvider#getConnection()
*/
public Connection getConnection() {
try {
if(dataSourceContext==null) {
dataSourceContext=DATASOURCE_CONTEXT;
}
logger.finest("Trying retreiving DataSource of connectionName="+connectionName);
return getDataSource(dataSourceContext+connectionName).getConnection();
} catch (Exception e) {
logger.log(Level.WARNING,"Error while getting DataSource",e);
throw new NullPointerException("No datasource");
}
}
// ==== set/getter
/**
* Sets the connectionName.
* @param connectionName The connectionName to set.
*/
public void setConnectionName(String connectionName) {
if(connectionName==null) {
throw new NullPointerException("connectionName may not be null.");
}
logger.finest("setting connectionName="+connectionName);
this.connectionName=connectionName;
}
/**
* @return Returns the dataSourceContext.
*/
public String getDataSourceContext() {
return dataSourceContext;
}
/**
* When set to null(default) then
* DATASOURCE_CONTEXT is used. ("java:comp/env/jdbc/")
* @param dataSourceContext The dataSourceContext to set.
*/
public void setDataSourceContext(String dataSourceContext) {
logger.finest("setting dataSourceContext="+dataSourceContext);
this.dataSourceContext = dataSourceContext;
}
}

View file

@ -0,0 +1,61 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.00
Copyright 2004-2006 IDCA. 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.
THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
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.
The views and conclusions contained in the software and documentation are those of the authors and
should not be interpreted as representing official policies, either expressed or implied, of IDCA.
-->
</head>
<body bgcolor="white">
An generic ConnectionProvider with default jndi support.<br/>
<h2>Package Specification</h2>
<ul>
<li>Full J2SE 5 compatible</li>
<li>Small package</li>
</ul>
<!--
<ul>
<li><a href="">hgj</a>
</ul>
-->
<h2>Related Documentation</h2>
None.
<!--
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="http://foei.idca.nl/docs/jmx/example1">Example 1</a>
</ul>
-->
<!-- Put @see and @since tags down here. -->
</body>
</html>

View file

@ -0,0 +1,70 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jndi;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import java.io.PrintStream;
/**
* A util recursive method which prints the jndi tree.
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2006
*/
public class ContextListWriter
{
/**
* writes an context tree to the printstream out.
* @param out The printstream to which the text line are printed.
* @param ctx The context to list.
* @param indent The intext text for sub contexts.
*/
public static void writeContextTree(PrintStream out,Context ctx, String indent) {
if(out==null | ctx==null | indent==null) {
return;
}
try {
NamingEnumeration list = ctx.listBindings("");
while (list.hasMore()) {
Binding item = (Binding)list.next();
String className = item.getClassName();
String name = item.getName();
out.println(indent+" class: "+className+" name="+name);
Object o = item.getObject();
if (o instanceof javax.naming.Context) {
writeContextTree(out,(Context)o,indent+indent);
}
}
} catch (NamingException ne) {
out.println("Nameing Exception: "+ne.getMessage());
}
}
}

View file

@ -0,0 +1,669 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jndi;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.NoSuchElementException;
import javax.naming.Binding;
import javax.naming.CompositeName;
import javax.naming.Context;
import javax.naming.InvalidNameException;
import javax.naming.Name;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NotContextException;
import javax.naming.OperationNotSupportedException;
import javax.naming.spi.NamingManager;
/**
* A sample service provider that implements a hierarchical namespace in memory.
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2006
*/
public class MemoryContext implements Context
{
protected Hashtable myEnv;
protected Hashtable bindings = new Hashtable(11);
protected final static NameParser myParser = new MemoryContextNameParser();
protected MemoryContext parent = null;
protected String myAtomicName = null;
/**
* Creates an new FoeiContext without an everment
* note:
* This should be done via an Factrory
* but then the server loader can not easaly load this class
*/
public MemoryContext()
{
//super()FoeiContext(null);
}
MemoryContext(Hashtable inEnv)
{
myEnv = (inEnv != null)
? (Hashtable)(inEnv.clone())
: null;
}
protected MemoryContext(MemoryContext parent, String name, Hashtable inEnv,Hashtable bindings)
{
this(inEnv);
this.parent = parent;
myAtomicName = name;
this.bindings = (Hashtable)bindings.clone();
}
protected Context createFoeiContext(MemoryContext parent, String name, Hashtable inEnv)
{
return new MemoryContext(parent, name, inEnv, new Hashtable(11));
}
protected Context cloneCtx()
{
return new MemoryContext(parent, myAtomicName, myEnv, bindings);
}
/**
* Utility method for processing composite/compound name.
* @param name The non-null composite or compound name to process.
* @return The non-null string name in this namespace to be processed.
*/
protected Name getMyComponents(Name name) throws NamingException
{
if (name instanceof CompositeName)
{
if (name.size() > 1)
{
throw new InvalidNameException(name.toString()+" has more components than namespace can handle");
}
// Turn component that belongs to us into compound name
return myParser.parse(name.get(0));
}
// Already parsed
return name;
}
public Object lookup(String name) throws NamingException
{
return lookup(new CompositeName(name));
}
public Object lookup(Name name) throws NamingException
{
if (name.isEmpty())
{
return cloneCtx();
}
// Extract components that belong to this namespace
Name nm = getMyComponents(name);
String atom = nm.get(0);
Object inter = bindings.get(atom);
if (nm.size() == 1)
{
// Atomic name: Find object in internal data structure
if (inter == null)
{
throw new NameNotFoundException(name + " not found");
}
// Call getObjectInstance for using any object factories
try
{
return NamingManager.getObjectInstance(inter,new CompositeName().add(atom),this, myEnv);
}
catch (Exception e)
{
NamingException ne = new NamingException("getObjectInstance failed");
ne.setRootCause(e);
throw ne;
}
}
// else
// {
// Intermediate name: Consume name in this context and continue
if (!(inter instanceof Context))
{
throw new NotContextException(atom+" does not name a context");
}
return ((Context)inter).lookup(nm.getSuffix(1));
// }
}
public void bind(String name, Object obj) throws NamingException
{
bind(new CompositeName(name), obj);
}
public void bind(Name name, Object obj) throws NamingException
{
if (name.isEmpty())
{
throw new InvalidNameException("Cannot bind empty name");
}
Name nm = getMyComponents(name);
String atom = nm.get(0);
Object inter = bindings.get(atom);
if (nm.size() == 1)
{
// Atomic name: Find object in internal data structure
if (inter != null)
{
throw new NameAlreadyBoundException("Use rebind to override");
}
// Call getStateToBind for using any state factories
obj = NamingManager.getStateToBind(obj,new CompositeName().add(atom),this, myEnv);
// Add object to internal data structure
bindings.put(atom, obj);
}
else
{
// Intermediate name: Consume name in this context and continue
if(inter==null)
{
// auto create sub context.
inter = createSubcontext(atom);
}
if (!(inter instanceof Context))
{
throw new NotContextException(atom+" does not name a context");
}
((Context)inter).bind(nm.getSuffix(1), obj);
}
}
public void rebind(String name, Object obj) throws NamingException
{
rebind(new CompositeName(name), obj);
}
public void rebind(Name name, Object obj) throws NamingException
{
if (name.isEmpty())
{
throw new InvalidNameException("Cannot bind empty name");
}
// Extract components that belong to this namespace
Name nm = getMyComponents(name);
String atom = nm.get(0);
if (nm.size() == 1)
{
// Atomic name
// Call getStateToBind for using any state factories
obj = NamingManager.getStateToBind(obj,new CompositeName().add(atom),this, myEnv);
// Add object to internal data structure
bindings.put(atom, obj);
}
else
{
// Intermediate name: Consume name in this context and continue
Object inter = bindings.get(atom);
if(inter==null)
{
// auto create sub context.
inter = createSubcontext(atom);
}
if (!(inter instanceof Context))
{
throw new NotContextException(atom+" does not name a context");
}
((Context)inter).rebind(nm.getSuffix(1), obj);
}
}
public void unbind(String name) throws NamingException
{
unbind(new CompositeName(name));
}
public void unbind(Name name) throws NamingException
{
if (name.isEmpty())
{
throw new InvalidNameException("Cannot unbind empty name");
}
// Extract components that belong to this namespace
Name nm = getMyComponents(name);
String atom = nm.get(0);
// Remove object from internal data structure
if (nm.size() == 1)
{
// Atomic name: Find object in internal data structure
bindings.remove(atom);
}
else
{
// Intermediate name: Consume name in this context and continue
Object inter = bindings.get(atom);
if (!(inter instanceof Context))
{
throw new NotContextException(atom+" does not name a context");
}
((Context)inter).unbind(nm.getSuffix(1));
}
}
public void rename(String oldName, String newName) throws NamingException
{
rename(new CompositeName(oldName), new CompositeName(newName));
}
public void rename(Name oldname, Name newname) throws NamingException
{
if (oldname.isEmpty() || newname.isEmpty())
{
throw new InvalidNameException("Cannot rename empty name");
}
Name oldnm = getMyComponents(oldname);
Name newnm = getMyComponents(newname);
// Simplistic implementation: support only rename within same context
if (oldnm.size() != newnm.size())
{
throw new OperationNotSupportedException("Do not support rename across different contexts");
}
String oldatom = oldnm.get(0);
String newatom = newnm.get(0);
if (oldnm.size() == 1)
{
if (bindings.get(newatom) != null)
{
throw new NameAlreadyBoundException(newname.toString()+" is already bound");
}
// Check if old name is bound
Object oldBinding = bindings.remove(oldatom);
if (oldBinding == null)
{
throw new NameNotFoundException(oldname.toString() + " not bound");
}
bindings.put(newatom, oldBinding);
}
else
{
if (!oldatom.equals(newatom))
{
throw new OperationNotSupportedException("Do not support rename across different contexts");
}
// Intermediate name: Consume name in this context and continue
Object inter = bindings.get(oldatom);
if (!(inter instanceof Context))
{
throw new NotContextException(oldatom+" does not name a context");
}
((Context)inter).rename(oldnm.getSuffix(1), newnm.getSuffix(1));
}
}
public NamingEnumeration list(String name) throws NamingException
{
return list(new CompositeName(name));
}
public NamingEnumeration list(Name name) throws NamingException
{
if (name.isEmpty())
{
// listing this context
return new ListOfNames(bindings.keys());
}
// Perhaps 'name' names a context
Object target = lookup(name);
if (target instanceof Context)
{
return ((Context)target).list("");
}
throw new NotContextException(name + " cannot be listed");
}
public NamingEnumeration listBindings(String name) throws NamingException
{
return listBindings(new CompositeName(name));
}
public NamingEnumeration listBindings(Name name) throws NamingException
{
//System.err.println("FoeiContext list bindings is called "+this+" map size:"+bindings.size());
if (name.isEmpty()) {
// listing this context
return new ListOfBindings(bindings.keys());
}
// Perhaps 'name' names a context
Object target = lookup(name);
if (target instanceof Context) {
return ((Context)target).listBindings("");
}
throw new NotContextException(name + " cannot be listed");
}
public void destroySubcontext(String name) throws NamingException {
destroySubcontext(new CompositeName(name));
}
public void destroySubcontext(Name name) throws NamingException
{
if (name.isEmpty())
{
throw new InvalidNameException("Cannot destroy context using empty name");
}
// Simplistic implementation: not checking for nonempty context first
// Use same implementation as unbind
unbind(name);
}
public Context createSubcontext(String name) throws NamingException
{
return createSubcontext(new CompositeName(name));
}
public Context createSubcontext(Name name) throws NamingException
{
if (name.isEmpty())
{
throw new InvalidNameException("Cannot bind empty name");
}
// Extract components that belong to this namespace
Name nm = getMyComponents(name);
String atom = nm.get(0);
Object inter = bindings.get(atom);
if (nm.size() == 1)
{
// Atomic name: Find object in internal data structure
if (inter != null)
{
throw new NameAlreadyBoundException("Use rebind to override");
}
// Create child
Context child = createFoeiContext(this, atom, myEnv);
// Add child to internal data structure
bindings.put(atom, child);
return child;
}
else
{
// Intermediate name: Consume name in this context and continue
if (!(inter instanceof Context))
{
throw new NotContextException(atom+" does not name a context");
}
return ((Context)inter).createSubcontext(nm.getSuffix(1));
}
}
public Object lookupLink(String name) throws NamingException
{
return lookupLink(new CompositeName(name));
}
public Object lookupLink(Name name) throws NamingException
{
return lookup(name);
}
public NameParser getNameParser(String name) throws NamingException
{
return getNameParser(new CompositeName(name));
}
public NameParser getNameParser(Name name) throws NamingException
{
// Do lookup to verify name exists
Object obj = lookup(name);
if (obj instanceof Context)
{
((Context)obj).close();
}
return myParser;
}
public String composeName(String name, String prefix) throws NamingException
{
Name result = composeName(new CompositeName(name),new CompositeName(prefix));
return result.toString();
}
public Name composeName(Name name, Name prefix) throws NamingException
{
Name result;
// Both are compound names, compose using compound name rules
if (!(name instanceof CompositeName) && !(prefix instanceof CompositeName))
{
result = (Name)(prefix.clone());
result.addAll(name);
return new CompositeName().add(result.toString());
}
// Simplistic implementation: do not support federation
throw new OperationNotSupportedException("Do not support composing composite names");
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException
{
if (myEnv == null)
{
myEnv = new Hashtable(5, 0.75f);
}
return myEnv.put(propName, propVal);
}
public Object removeFromEnvironment(String propName) throws NamingException
{
if (myEnv == null)
{
return null;
}
return myEnv.remove(propName);
}
public Hashtable getEnvironment() throws NamingException
{
if (myEnv == null)
{
return new Hashtable(3, 0.75f);
}
else
{
return (Hashtable)myEnv.clone();
}
}
public String getNameInNamespace() throws NamingException
{
MemoryContext ancestor = parent;
// No ancestor
if (ancestor == null)
{
return "";
}
Name name = myParser.parse("");
name.add(myAtomicName);
// Get parent's names
while (ancestor != null && ancestor.myAtomicName != null)
{
name.add(0, ancestor.myAtomicName);
ancestor = ancestor.parent;
}
return name.toString();
}
public String toString()
{
if (myAtomicName != null)
{
return myAtomicName;
}
else
{
return "ROOT CONTEXT";
}
}
public void close() throws NamingException
{
}
// Class for enumerating name/class pairs
class ListOfNames implements NamingEnumeration {
protected Enumeration names;
ListOfNames (Enumeration names) {
this.names = names;
}
public boolean hasMoreElements() {
try {
return hasMore();
} catch (NamingException e) {
return false;
}
}
public boolean hasMore() throws NamingException {
return names.hasMoreElements();
}
public Object next() throws NamingException {
String name = (String)names.nextElement();
String className = bindings.get(name).getClass().getName();
return new NameClassPair(name, className);
}
public Object nextElement() {
try {
return next();
} catch (NamingException e) {
throw new NoSuchElementException(e.toString());
}
}
public void close() {
}
}
// Class for enumerating bindings
class ListOfBindings extends ListOfNames {
ListOfBindings(Enumeration names) {
super(names);
}
public Object next() throws NamingException {
String name = (String)names.nextElement();
Object obj = bindings.get(name);
try {
obj = NamingManager.getObjectInstance(obj,
new CompositeName().add(name), MemoryContext.this,
MemoryContext.this.myEnv);
} catch (Exception e) {
NamingException ne = new NamingException(
"getObjectInstance failed");
ne.setRootCause(e);
throw ne;
}
return new Binding(name, obj);
}
}
/*
static FoeiContext testRoot;
static {
try {
testRoot = new FoeiContext(null);
Context a = testRoot.createSubcontext("a");
Context b = a.createSubcontext("b");
Context c = b.createSubcontext("c");
testRoot.createSubcontext("x");
testRoot.createSubcontext("y");
} catch (NamingException e) {
}
}
public static Context getStaticNamespace(Hashtable env) {
return testRoot;
}
public static void main(String[] args) {
try {
Context ctx = new FoeiContext(null);
Context a = ctx.createSubcontext("a");
Context b = a.createSubcontext("b");
Context c = b.createSubcontext("c");
System.out.println(c.getNameInNamespace());
System.out.println(ctx.lookup(""));
System.out.println(ctx.lookup("a"));
System.out.println(ctx.lookup("b.a"));
System.out.println(a.lookup("c.b"));
} catch (NamingException e) {
e.printStackTrace();
}
}
*/
}

View file

@ -0,0 +1,61 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jndi;
import java.util.Hashtable;
import javax.naming.spi.InitialContextFactory;
import javax.naming.Context;
import javax.naming.NamingException;
/**
* Creates an new MemoryContext
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2006
*
*/
public class MemoryContextFactory implements InitialContextFactory
{
/** Stores the jvm wide instance of the FoeiContext */
static private Context context = null;
/**
* Returns the FoeiContext
* @param environment
* @return
* @throws NamingException
*/
public Context getInitialContext(Hashtable environment) throws NamingException {
if(context!=null) {
return context;
}
context = new MemoryContext(environment);
return context;
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright 2004-2006 IDCA. 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.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
* 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.foei.utils.jndi;
import java.util.Properties;
import javax.naming.NameParser;
import javax.naming.Name;
import javax.naming.CompoundName;
import javax.naming.NamingException;
/**
* A jndi name parser
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2006
*/
class MemoryContextNameParser implements NameParser {
/** The syntax to use. */
private static Properties syntax = null;
static {
try {
syntax = new Properties();
syntax.put("jndi.syntax.direction", "left_to_right");
syntax.put("jndi.syntax.separator", ".");
syntax.put("jndi.syntax.ignorecase", "false");
syntax.put("jndi.syntax.escape", "\\");
syntax.put("jndi.syntax.beginquote", "'");
} catch (Exception e) {
throw new RuntimeException("Error while creating FoeiNameParser",e);
}
}
/**
* Parses the String name into an Jndi name.
* @see NameParser#parse(java.lang.String)
*/
public Name parse(String name) throws NamingException {
return new CompoundName(name, syntax);
}
}

View file

@ -0,0 +1,61 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.00
Copyright 2004-2006 IDCA. 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.
THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 IDCA OR
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.
The views and conclusions contained in the software and documentation are those of the authors and
should not be interpreted as representing official policies, either expressed or implied, of IDCA.
-->
</head>
<body bgcolor="white">
Defines an MemoryContext for storing object in a jndi tree.<br/>
<h2>Package Specification</h2>
<ul>
<li>Full J2SE 5 compatible</li>
<li>Small package</li>
</ul>
<!--
<ul>
<li><a href="">hgj</a>
</ul>
-->
<h2>Related Documentation</h2>
None.
<!--
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="http://foei.idca.nl/docs/jmx/example1">Example 1</a>
</ul>
-->
<!-- Put @see and @since tags down here. -->
</body>
</html>