3
0
Fork 0

[svn r327] done some cleaning, and removed beanutils depencie

This commit is contained in:
willemc 2008-03-01 04:00:34 +01:00
parent 7c57017fff
commit 520ba683db
24 changed files with 100 additions and 377 deletions

View file

@ -4,7 +4,6 @@
<classpathentry kind="src" path="tests"/> <classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/idcanet-x4o-bin.jar"/> <classpathentry kind="lib" path="lib/idcanet-x4o-bin.jar"/>
<classpathentry kind="lib" path="lib/commons-beanutils.jar"/>
<classpathentry kind="lib" path="lib/juel-2.1.0-rc1.jar"/> <classpathentry kind="lib" path="lib/juel-2.1.0-rc1.jar"/>
<classpathentry kind="lib" path="lib/juel-2.1.0-rc1-impl.jar"/> <classpathentry kind="lib" path="lib/juel-2.1.0-rc1-impl.jar"/>
<classpathentry kind="lib" path="lib/jms-api.jar"/> <classpathentry kind="lib" path="lib/jms-api.jar"/>

Binary file not shown.

Binary file not shown.

View file

@ -40,8 +40,8 @@ import com.idcanet.foei.event.IllegalEventPortNameException;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 27, 2005 * @version 1.0 Feb 27, 2005
*/ */
public class EventProxy extends AbstractEventObject public class EventProxy extends AbstractEventObject {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;

View file

@ -48,8 +48,8 @@ import com.idcanet.foei.event.IllegalEventPortNameException;
@SetEventPort(type=EventPortType.output,name=EventPort.PASS), @SetEventPort(type=EventPortType.output,name=EventPort.PASS),
}) })
*/ */
public class Filter extends AbstractEventObjectStepController public class Filter extends AbstractEventObjectStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;

View file

@ -26,13 +26,12 @@
package com.idcanet.foei.components.lang; package com.idcanet.foei.components.lang;
import org.apache.commons.beanutils.BeanUtils;
import com.idcanet.foei.core.FoeiProcessFactory; import com.idcanet.foei.core.FoeiProcessFactory;
import com.idcanet.foei.event.AbstractEventObject; import com.idcanet.foei.event.AbstractEventObject;
import com.idcanet.foei.event.EventInput; import com.idcanet.foei.event.EventInput;
import com.idcanet.foei.event.EventPort; import com.idcanet.foei.event.EventPort;
import com.idcanet.foei.event.IllegalEventPortNameException; import com.idcanet.foei.event.IllegalEventPortNameException;
import com.idcanet.x4o.impl.DefaultElementParameterHelper;
/** /**
* Gets the property of an Bean * Gets the property of an Bean
@ -41,8 +40,8 @@ import com.idcanet.foei.event.IllegalEventPortNameException;
* @version 1.0 Jun 5, 2006 * @version 1.0 Jun 5, 2006
* *
*/ */
public class GetBeanProperty extends AbstractEventObject public class GetBeanProperty extends AbstractEventObject {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** The Property name */ /** The Property name */
@ -51,6 +50,9 @@ public class GetBeanProperty extends AbstractEventObject
private String property = null; private String property = null;
//private Object propertyValue = null; //private Object propertyValue = null;
private DefaultElementParameterHelper helper = null;
/** /**
* Creates an SetBeanProperty * Creates an SetBeanProperty
*/ */
@ -58,6 +60,7 @@ public class GetBeanProperty extends AbstractEventObject
addInputPort(EventPort.INPUT,Object.class); addInputPort(EventPort.INPUT,Object.class);
//addInputPort(PROPERTY,Object.class); //addInputPort(PROPERTY,Object.class);
addOutputPort(EventPort.OUTPUT); addOutputPort(EventPort.OUTPUT);
helper = new DefaultElementParameterHelper();
} }
/** /**
@ -75,7 +78,7 @@ public class GetBeanProperty extends AbstractEventObject
return; return;
} }
try { try {
object = BeanUtils.getProperty(object,property); // todo: fix error this wil only return String !!!!!!!!!!!!!!!!! object = helper.getParameter(object,property); // todo: fix error this wil only return String !!!!!!!!!!!!!!!!!
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return; return;

View file

@ -39,8 +39,8 @@ import com.idcanet.foei.event.IllegalEventPortNameException;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 9, 2006 * @version 1.0 Feb 9, 2006
*/ */
public class SendEvent extends AbstractEventInput public class SendEvent extends AbstractEventInput {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;

View file

@ -26,13 +26,12 @@
package com.idcanet.foei.components.lang; package com.idcanet.foei.components.lang;
import org.apache.commons.beanutils.BeanUtils;
import com.idcanet.foei.core.FoeiProcessFactory; import com.idcanet.foei.core.FoeiProcessFactory;
import com.idcanet.foei.event.AbstractEventObject; import com.idcanet.foei.event.AbstractEventObject;
import com.idcanet.foei.event.EventInput; import com.idcanet.foei.event.EventInput;
import com.idcanet.foei.event.EventPort; import com.idcanet.foei.event.EventPort;
import com.idcanet.foei.event.IllegalEventPortNameException; import com.idcanet.foei.event.IllegalEventPortNameException;
import com.idcanet.x4o.impl.DefaultElementParameterHelper;
/** /**
* Sets an property of an bean which is set on the propery input port. * Sets an property of an bean which is set on the propery input port.
@ -40,8 +39,8 @@ import com.idcanet.foei.event.IllegalEventPortNameException;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 12, 2006 * @version 1.0 Feb 12, 2006
*/ */
public class SetBeanProperty extends AbstractEventObject public class SetBeanProperty extends AbstractEventObject {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** The Property name */ /** The Property name */
@ -50,6 +49,9 @@ public class SetBeanProperty extends AbstractEventObject
private String property = null; private String property = null;
private Object propertyValue = null; private Object propertyValue = null;
private DefaultElementParameterHelper helper = null;
/** /**
* Creates an SetBeanProperty * Creates an SetBeanProperty
*/ */
@ -57,6 +59,7 @@ public class SetBeanProperty extends AbstractEventObject
addInputPort(EventPort.INPUT,Object.class); addInputPort(EventPort.INPUT,Object.class);
addInputPort(PROPERTY,Object.class); addInputPort(PROPERTY,Object.class);
addOutputPort(EventPort.OUTPUT); addOutputPort(EventPort.OUTPUT);
helper = new DefaultElementParameterHelper();
} }
/** /**
@ -74,7 +77,7 @@ public class SetBeanProperty extends AbstractEventObject
return; return;
} }
try { try {
BeanUtils.setProperty(object,property,propertyValue); helper.setParameter(object,property,propertyValue);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return; return;

View file

@ -37,13 +37,12 @@ import java.util.logging.LogRecord;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 25, 2006 * @version 1.0 Jan 25, 2006
*/ */
public class LoggerHandler extends Handler public class LoggerHandler extends Handler {
{
private Logger logger = Logger.getLogger(this.getClass().getName()); private Logger logger = Logger.getLogger(this.getClass().getName());
private LoggerInput loggerInput = null; private LoggerInput loggerInput = null;
public LoggerHandler(LoggerInput loggerInput) public LoggerHandler(LoggerInput loggerInput) {
{
this.loggerInput=loggerInput; this.loggerInput=loggerInput;
logger.addHandler(this); logger.addHandler(this);
} }
@ -51,7 +50,7 @@ public class LoggerHandler extends Handler
// ------------ handler // ------------ handler
public void publish(LogRecord record) { public void publish(LogRecord record) {
HashMap event = new HashMap(); HashMap<String,String> event = new HashMap<String,String>();
event.put("message",record.getMessage()); event.put("message",record.getMessage());
event.put("level",record.getLevel().getName()); event.put("level",record.getLevel().getName());
loggerInput.sendMessage(event); loggerInput.sendMessage(event);

View file

@ -38,8 +38,8 @@ import java.util.Map;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 25, 2006 * @version 1.0 Jan 25, 2006
*/ */
public class LoggerInput extends AbstractEventOutput public class LoggerInput extends AbstractEventOutput {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** */ /** */
@ -59,9 +59,7 @@ public class LoggerInput extends AbstractEventOutput
* *
* @param event * @param event
*/ */
public void sendMessage(Map event) { public void sendMessage(Map<String,String> event) {
FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.OUTPUT),event); FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.OUTPUT),event);
//FoeiInstance foeiInstance = FoeiServer.getFoeiInstance();
//foeiInstance.getObjectBindingsManager().sendEventOutput(getID(),OUTPUT,event);
} }
} }

View file

@ -34,8 +34,8 @@ import com.idcanet.foei.event.AbstractEventStepController;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 26/01/2005 * @version 1.0 26/01/2005
*/ */
public class ClassFilter extends AbstractEventStepController public class ClassFilter extends AbstractEventStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** The class name to match */ /** The class name to match */
@ -45,8 +45,7 @@ public class ClassFilter extends AbstractEventStepController
* Sets the className which the filtered object has to have. * Sets the className which the filtered object has to have.
* @param className The className. * @param className The className.
*/ */
public void setClassName(String className) public void setClassName(String className) {
{
this.className=className; this.className=className;
} }
@ -54,8 +53,7 @@ public class ClassFilter extends AbstractEventStepController
* Returns the className on which this filter filters. * Returns the className on which this filter filters.
* @return The className. * @return The className.
*/ */
public String getClassName() public String getClassName() {
{
return className; return className;
} }
@ -64,21 +62,14 @@ public class ClassFilter extends AbstractEventStepController
* This checks if the objects class equals that of the className. * This checks if the objects class equals that of the className.
* @return The object or null is not succesfull. * @return The object or null is not succesfull.
*/ */
public Object processObject(Object object) public Object processObject(Object object) {
{ if(object==null) {
if(object==null)
{
return null; return null;
} }
Class[] classes = object.getClass().getClasses(); Class<?>[] classes = object.getClass().getClasses();
System.out.println("ClassFilter filter: "+object+" on "+className+" classes: "+classes.length); for(int i=0;i<classes.length;i++) {
for(int i=0;i<classes.length;i++) if(classes[i].getName().equals(className)) {
{
System.err.println("test:"+classes[i].getName());
if(classes[i].getName().equals(className))
{
Object object2 = processEventSteps(object); Object object2 = processEventSteps(object);
System.err.println("ClassFilter filter: "+object+" childFilter: "+object2);
return object2; return object2;
} }
} }

View file

@ -36,41 +36,30 @@ import java.util.Date;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 26/01/2005 * @version 1.0 26/01/2005
*/ */
public class DateFilter extends AbstractEventStepController public class DateFilter extends AbstractEventStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
private Date minDate=null; private Date minDate=null;
private Date maxDate=null; private Date maxDate=null;
/** public void setMinDate(Date minDate) {
* Emty constuctor.
*
*/
public DateFilter()
{
}
public void setMinDate(Date minDate)
{
this.minDate=minDate; this.minDate=minDate;
} }
public Date getMinDate()
{ public Date getMinDate() {
return minDate; return minDate;
} }
public void setMaxDate(Date maxDate)
{ public void setMaxDate(Date maxDate) {
this.maxDate=maxDate; this.maxDate=maxDate;
} }
public Date getMaxDate()
{ public Date getMaxDate() {
return maxDate; return maxDate;
} }
public Object processObject(Object object) public Object processObject(Object object) {
{
processEventSteps(object); processEventSteps(object);
return object; return object;
} }

View file

@ -24,7 +24,7 @@
* should not be interpreted as representing official policies, either expressed or implied, of IDCA. * should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/ */
package com.idcanet.foei.utils.beans; package com.idcanet.foei.components.steps.filters;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParseException; import java.text.ParseException;
@ -37,6 +37,7 @@ import java.util.Locale;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 9, 2006 * @version 1.0 Feb 9, 2006
*/ */
@SuppressWarnings("unchecked")
public class NumberComparator implements Comparator { public class NumberComparator implements Comparator {
private Locale locale = null; private Locale locale = null;

View file

@ -27,7 +27,6 @@
package com.idcanet.foei.components.steps.filters; package com.idcanet.foei.components.steps.filters;
import com.idcanet.foei.event.AbstractEventStepController; import com.idcanet.foei.event.AbstractEventStepController;
import com.idcanet.foei.utils.beans.NumberComparator;
import java.util.Locale; import java.util.Locale;
@ -37,8 +36,8 @@ import java.util.Locale;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 9, 2006 * @version 1.0 Feb 9, 2006
*/ */
public class NumberFilter extends AbstractEventStepController public class NumberFilter extends AbstractEventStepController {
{
/** */ /** */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** */ /** */

View file

@ -28,7 +28,6 @@ package com.idcanet.foei.components.steps.filters;
import com.idcanet.foei.event.AbstractEventStepController; import com.idcanet.foei.event.AbstractEventStepController;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -38,21 +37,14 @@ import java.util.regex.Pattern;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 26/01/2005 * @version 1.0 26/01/2005
*/ */
public class StringFilter extends AbstractEventStepController public class StringFilter extends AbstractEventStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
private int minLength=0; private int minLength=0;
private int maxLength=0; private int maxLength=0;
private Logger logger = Logger.getLogger(this.getClass().getName());
private Pattern pattern = null; private Pattern pattern = null;
/**
* Emty constuctor.
*/
public StringFilter() {
}
// -------------- (bean)properties. // -------------- (bean)properties.
/** /**

View file

@ -27,8 +27,7 @@
package com.idcanet.foei.components.steps.lang; package com.idcanet.foei.components.steps.lang;
import com.idcanet.foei.event.AbstractEventStepController; import com.idcanet.foei.event.AbstractEventStepController;
import com.idcanet.x4o.impl.DefaultElementParameterHelper;
import org.apache.commons.beanutils.BeanUtils;
/** /**
* Gets the property of an java bean. * Gets the property of an java bean.
@ -36,13 +35,18 @@ import org.apache.commons.beanutils.BeanUtils;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 9, 2006 * @version 1.0 Feb 9, 2006
*/ */
public class GetBeanPropertyStep extends AbstractEventStepController public class GetBeanPropertyStep extends AbstractEventStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** Holds the key which contains the object in the map. */ /** Holds the key which contains the object in the map. */
private String property = null; private String property = null;
private DefaultElementParameterHelper helper = null;
public GetBeanPropertyStep() {
helper = new DefaultElementParameterHelper();
}
//----------- get/set functions //----------- get/set functions
@ -66,7 +70,7 @@ public class GetBeanPropertyStep extends AbstractEventStepController
} }
Object result = null; Object result = null;
try { try {
result = BeanUtils.getProperty(object,property); result = helper.getParameter(object,property);
} catch (Exception e) { } catch (Exception e) {
//logger.log(Level.WARNING,"property:"+property+" is not an property of object: "+object.getClass().getName(),e); //logger.log(Level.WARNING,"property:"+property+" is not an property of object: "+object.getClass().getName(),e);
e.printStackTrace(); e.printStackTrace();

View file

@ -36,8 +36,8 @@ import java.util.List;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Feb 9, 2006 * @version 1.0 Feb 9, 2006
*/ */
public class ListValue extends AbstractEventStepController public class ListValue extends AbstractEventStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** Holds the index which contains the object in the map. */ /** Holds the index which contains the object in the map. */
@ -51,9 +51,12 @@ public class ListValue extends AbstractEventStepController
public void setIndex(String index) { public void setIndex(String index) {
this.index=index; this.index=index;
} }
public String getIndex() { public String getIndex() {
return index; return index;
} }
@SuppressWarnings("unchecked")
public Object processObject(Object object) { public Object processObject(Object object) {
if(!(object instanceof List)) { if(!(object instanceof List)) {

View file

@ -38,8 +38,8 @@ import java.util.Map;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 28/03/2004 * @version 1.0 28/03/2004
*/ */
public class MapValue extends AbstractEventStepController public class MapValue extends AbstractEventStepController {
{
/** v1.0 */ /** v1.0 */
static final long serialVersionUID = 10l; static final long serialVersionUID = 10l;
/** Holds the key which contains the object in the map. */ /** Holds the key which contains the object in the map. */
@ -76,6 +76,7 @@ public class MapValue extends AbstractEventStepController
* by the last EventStep in the List.<br> * by the last EventStep in the List.<br>
* *
*/ */
@SuppressWarnings("unchecked")
public Object processObject(Object object) { public Object processObject(Object object) {
if(key==null) { if(key==null) {
return null; return null;

View file

@ -121,7 +121,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
if(className==null) { if(className==null) {
return new ObjectBindingsManagerImpl(); return new ObjectBindingsManagerImpl();
} }
return (ObjectBindingsManager)Class.forName(className).newInstance(); return (ObjectBindingsManager)loadClass(className).newInstance();
} }
/** /**
@ -138,7 +138,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
if(className==null) { if(className==null) {
return new MemoryContextFactory().getInitialContext(new Hashtable<String,String>(properties)); return new MemoryContextFactory().getInitialContext(new Hashtable<String,String>(properties));
} }
return ((InitialContextFactory)Class.forName(className).newInstance()).getInitialContext(new Hashtable<String,String>(properties)); return ((InitialContextFactory)loadClass(className).newInstance()).getInitialContext(new Hashtable<String,String>(properties));
} }
/** /**
@ -154,7 +154,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
if(className==null) { if(className==null) {
return new EventExecutorManagerImpl(); return new EventExecutorManagerImpl();
} }
return (EventExecutorManager)Class.forName(className).newInstance(); return (EventExecutorManager)loadClass(className).newInstance();
} }
/** /**
@ -171,7 +171,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
} }
for(String className:classNames.split(",")) { for(String className:classNames.split(",")) {
logger.finest("Loading class: "+className); logger.finest("Loading class: "+className);
EventThreadListener eventThreadListener = (EventThreadListener)Class.forName(className).newInstance(); EventThreadListener eventThreadListener = (EventThreadListener)loadClass(className).newInstance();
eventExecutorManager.addEventThreadListener(eventThreadListener); eventExecutorManager.addEventThreadListener(eventThreadListener);
} }
} }
@ -229,7 +229,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
if(className==null) { if(className==null) {
return EventExecutorImpl.class; return EventExecutorImpl.class;
} }
return Class.forName(className); return loadClass(className);
} }
/** /**
@ -258,7 +258,22 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
if(className==null) { if(className==null) {
return new FoeiProcessManagerImpl(); return new FoeiProcessManagerImpl();
} }
return (FoeiProcessManager)Class.forName(className).newInstance(); return (FoeiProcessManager)loadClass(className).newInstance();
} }
/**
* Loads a Class from the ContextClassLoader and if that is not set, then
* uses the class of the String parameters
* @param className The class name to load
* @return The loaded class
* @throws Exception throws exception if class not loaded.
*/
static public Class<?> loadClass(String className) throws ClassNotFoundException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = className.getClass().getClassLoader(); // fallback
}
return cl.loadClass(className);
}
} }

View file

@ -1,40 +0,0 @@
/*
* 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

@ -1,174 +0,0 @@
/*
* 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

@ -1,61 +0,0 @@
<!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

@ -52,8 +52,9 @@ import javax.naming.spi.NamingManager;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 18, 2006 * @version 1.0 Jan 18, 2006
*/ */
public class MemoryContext implements Context @SuppressWarnings("unchecked")
{ public class MemoryContext implements Context {
protected Hashtable myEnv; protected Hashtable myEnv;
protected Hashtable bindings = new Hashtable(11); protected Hashtable bindings = new Hashtable(11);
protected final static NameParser myParser = new MemoryContextNameParser(); protected final static NameParser myParser = new MemoryContextNameParser();

View file

@ -39,8 +39,8 @@ import javax.naming.NamingException;
* @version 1.0 Jan 18, 2006 * @version 1.0 Jan 18, 2006
* *
*/ */
public class MemoryContextFactory implements InitialContextFactory public class MemoryContextFactory implements InitialContextFactory {
{
/** Stores the jvm wide instance of the FoeiContext */ /** Stores the jvm wide instance of the FoeiContext */
static private Context context = null; static private Context context = null;
@ -50,8 +50,8 @@ public class MemoryContextFactory implements InitialContextFactory
* @return * @return
* @throws NamingException * @throws NamingException
*/ */
@SuppressWarnings("unchecked")
public Context getInitialContext(Hashtable environment) throws NamingException { public Context getInitialContext(Hashtable environment) throws NamingException {
if (context!=null) { if (context!=null) {
return context; return context;
} }