You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hl...@apache.org on 2004/02/28 01:34:38 UTC
cvs commit: jakarta-commons-sandbox/hivemind/library project.xml
hlship 2004/02/27 16:34:38
Modified: hivemind/framework/src/java/org/apache/hivemind/schema/rules
LongTranslator.java ConfigurationTranslator.java
InvokeParentRule.java ClassTranslator.java
BooleanTranslator.java ServiceTranslator.java
IntTranslator.java RuleUtils.java
EnumerationTranslator.java ResourceTranslator.java
DoubleTranslator.java
hivemind/framework project.xml
hivemind/framework/src/java/org/apache/hivemind/util
LocalizedNameGenerator.java
hivemind/framework/src/test/hivemind/test/services
TestServices.java
hivemind/framework/src/test/hivemind/test
TestHiveMindFindLocation.java TestMisc.java
hivemind/framework/src/java/org/apache/hivemind/parse
DescriptorParser.java
hivemind/framework/src/java/org/apache/hivemind
HiveMind.java HiveMindMessages.properties
hivemind/framework/src/java/org/apache/hivemind/impl
RegistryAssemblyImpl.java ProxyUtils.java
RegistryAssembly.java
CreateClassServiceConstructor.java
hivemind/framework/src/test/hivemind/test/config
ToUpperCaseTranslator.java
hivemind/framework/src/test/hivemind/test/rules
TestInvokeParentRule.java TestObjectTranslator.java
hivemind/framework/src/test/hivemind/test/impl
TestRegistryAssemblyImpl.java
hivemind/framework/src/java/org/apache/hivemind/service/impl
BuilderParameter.java BuilderFactory.java
BuilderFacet.java EventLinkerImpl.java
hivemind .classpath
hivemind/library project.xml
Added: hivemind/framework/src/java/org/apache/hivemind/util
PropertyUtils.java PropertyAdaptor.java
ClassAdaptor.java ConstructorUtils.java
hivemind/framework/src/test/hivemind/test/util
TestPropertyUtils.java
Log:
Remove dependency on commons-beanutils (and commons-collections, by extension).
Revision Changes Path
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/LongTranslator.java
Index: LongTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/LongTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LongTranslator.java 26 Feb 2004 23:07:42 -0000 1.1
+++ LongTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -16,7 +16,6 @@
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -81,7 +80,7 @@
*/
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return new Long(_defaultValue);
long value;
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ConfigurationTranslator.java
Index: ConfigurationTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ConfigurationTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationTranslator.java 26 Feb 2004 23:07:42 -0000 1.1
+++ ConfigurationTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -14,7 +14,6 @@
package org.apache.hivemind.schema.rules;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -37,7 +36,7 @@
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return null;
Module module = processor.getContributingModule();
1.2 +38 -6 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/InvokeParentRule.java
Index: InvokeParentRule.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/InvokeParentRule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvokeParentRule.java 26 Feb 2004 23:07:42 -0000 1.1
+++ InvokeParentRule.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -14,7 +14,8 @@
package org.apache.hivemind.schema.rules;
-import org.apache.commons.beanutils.MethodUtils;
+import java.lang.reflect.Method;
+
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Element;
import org.apache.hivemind.HiveMind;
@@ -45,7 +46,9 @@
try
{
- MethodUtils.invokeMethod(parent, _methodName, child);
+ Method m = findMethod(parent, _methodName, child.getClass());
+
+ m.invoke(parent, new Object[] { child });
}
catch (Exception ex)
{
@@ -68,12 +71,41 @@
_methodName = string;
}
- /**
- * Sets the depth of the parent object. The default is 1.
- */
+ /**
+ * Sets the depth of the parent object. The default is 1.
+ */
public void setDepth(int i)
{
_depth = i;
+ }
+
+ /**
+ * Searches for the *first* public method the has the right name, and takes a
+ * single parameter that is compatible with the parameter type.
+ *
+ * @throws NoSuchMethodException if a method can't be found
+ */
+ private Method findMethod(Object target, String name, Class parameterType)
+ throws NoSuchMethodException
+ {
+ Method[] methods = target.getClass().getMethods();
+
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method m = methods[i];
+
+ if (m.getParameterTypes().length != 1)
+ continue;
+
+ if (!m.getName().equals(name))
+ continue;
+
+ if (m.getParameterTypes()[0].isAssignableFrom(parameterType))
+ return m;
+
+ }
+
+ throw new NoSuchMethodException(name);
}
}
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ClassTranslator.java
Index: ClassTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ClassTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClassTranslator.java 26 Feb 2004 23:07:43 -0000 1.1
+++ ClassTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -14,7 +14,6 @@
package org.apache.hivemind.schema.rules;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ClassResolver;
@@ -44,7 +43,7 @@
*/
protected Class extractClass(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return null;
try
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/BooleanTranslator.java
Index: BooleanTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/BooleanTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BooleanTranslator.java 26 Feb 2004 23:07:43 -0000 1.1
+++ BooleanTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -16,7 +16,6 @@
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -59,7 +58,7 @@
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return _defaultValue;
if (inputValue.equals("true"))
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ServiceTranslator.java
Index: ServiceTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ServiceTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceTranslator.java 26 Feb 2004 23:07:42 -0000 1.1
+++ ServiceTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -14,7 +14,6 @@
package org.apache.hivemind.schema.rules;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -40,7 +39,7 @@
*/
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return null;
Module module = processor.getContributingModule();
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/IntTranslator.java
Index: IntTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/IntTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IntTranslator.java 26 Feb 2004 23:07:42 -0000 1.1
+++ IntTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -16,7 +16,6 @@
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -81,7 +80,7 @@
*/
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return new Integer(_defaultValue);
int value;
1.2 +5 -15 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/RuleUtils.java
Index: RuleUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/RuleUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RuleUtils.java 26 Feb 2004 23:07:42 -0000 1.1
+++ RuleUtils.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -18,8 +18,6 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
@@ -27,6 +25,7 @@
import org.apache.hivemind.HiveMind;
import org.apache.hivemind.Registry;
import org.apache.hivemind.schema.SchemaProcessor;
+import org.apache.hivemind.util.PropertyUtils;
/**
* Static methods useful to {@link org.apache.hivemind.schema.Rule}s and
@@ -47,7 +46,7 @@
*/
public static Map convertInitializer(String initializer)
{
- if (StringUtils.isBlank(initializer))
+ if (HiveMind.isBlank(initializer))
return Collections.EMPTY_MAP;
Map result = new HashMap();
@@ -127,23 +126,14 @@
{
try
{
- PropertyUtils.setProperty(target, propertyName, value);
+ PropertyUtils.write(target, propertyName, value, element);
}
catch (Exception ex)
{
// Have to decide if we need to display the location of the rule
// or the element.
- LOG.error(
- HiveMind.format(
- "BaseRule.set-property-error",
- new Object[] {
- propertyName,
- target,
- value,
- processor.getElementPath(),
- element.getLocation(),
- ex.getMessage()}));
+ LOG.error(ex.getMessage());
}
}
}
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/EnumerationTranslator.java
Index: EnumerationTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/EnumerationTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EnumerationTranslator.java 26 Feb 2004 23:07:43 -0000 1.1
+++ EnumerationTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -17,7 +17,6 @@
import java.lang.reflect.Field;
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -66,7 +65,7 @@
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return null;
Class c = getClass(processor);
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ResourceTranslator.java
Index: ResourceTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/ResourceTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourceTranslator.java 26 Feb 2004 23:07:42 -0000 1.1
+++ ResourceTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -16,7 +16,6 @@
import java.util.Locale;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -45,7 +44,7 @@
*/
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return null;
Module module = processor.getContributingModule();
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/DoubleTranslator.java
Index: DoubleTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/schema/rules/DoubleTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DoubleTranslator.java 26 Feb 2004 23:07:43 -0000 1.1
+++ DoubleTranslator.java 28 Feb 2004 00:34:36 -0000 1.2
@@ -16,7 +16,6 @@
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.Element;
@@ -81,7 +80,7 @@
*/
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return new Double(_defaultValue);
double value;
1.12 +1 -14 jakarta-commons-sandbox/hivemind/framework/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/project.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- project.xml 26 Feb 2004 23:07:59 -0000 1.11
+++ project.xml 28 Feb 2004 00:34:37 -0000 1.12
@@ -60,12 +60,6 @@
<version>2.0</version>
<url>http://jakarta.apache.org/jakarta-commons/lang.html</url>
</dependency>
-
- <dependency>
- <id>commons-beanutils</id>
- <version>1.6.1</version>
- <url>http://jakarta.apache.org/jakarta-commons/beanutils.html</url>
- </dependency>
<dependency>
<groupId>jboss</groupId>
@@ -99,13 +93,6 @@
<id>xerces</id>
<version>2.2.1</version>
<url>http://xml.apache.org/xerces/</url>
- </dependency>
-
-
- <dependency>
- <id>commons-collections</id>
- <version>2.1</version>
- <url>http://jakarta.apache.org/jakarta-commons/collections.html</url>
</dependency>
<!-- Needed by test suite classes, but not the framework itself. -->
1.2 +6 -6 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/util/LocalizedNameGenerator.java
Index: LocalizedNameGenerator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/util/LocalizedNameGenerator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LocalizedNameGenerator.java 26 Feb 2004 23:07:54 -0000 1.1
+++ LocalizedNameGenerator.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -17,7 +17,7 @@
import java.util.Locale;
import java.util.NoSuchElementException;
-import org.apache.commons.lang.StringUtils;
+import org.apache.hivemind.HiveMind;
/**
* Used in a wide variety of resource searches. Generates
@@ -82,14 +82,14 @@
{
case LCV :
- if (StringUtils.isBlank(_variant))
+ if (HiveMind.isBlank(_variant))
continue;
return;
case LC :
- if (StringUtils.isBlank(_country))
+ if (HiveMind.isBlank(_country))
continue;
return;
@@ -99,14 +99,14 @@
// If _country is null, then we've already generated this string
// as state LCV and we can continue directly to state L
- if (StringUtils.isBlank(_variant) || StringUtils.isBlank(_country))
+ if (HiveMind.isBlank(_variant) || HiveMind.isBlank(_country))
continue;
return;
case L :
- if (StringUtils.isBlank(_language))
+ if (HiveMind.isBlank(_language))
continue;
return;
1.1 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/util/PropertyUtils.java
Index: PropertyUtils.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.util;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.util.HashMap;
import java.util.Map;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.HiveMind;
/**
* A collection of static methods used to perform property-level access on arbitrary objects.
*
* @author Howard Lewis Ship
* @version $Id: PropertyUtils.java,v 1.1 2004/02/28 00:34:37 hlship Exp $
*/
public class PropertyUtils
{
private static final Map _classAdaptors = new HashMap();
// Prevent instantiation
private PropertyUtils()
{
}
/**
* Updates the property of the target object.
*
* @param target the object to update
* @param propertyName the name of the property to be updated
* @param value the value to be stored into the target object property
* @param location an object used to "locate" any errors, it will be passed to
* {@link HiveMind#getLocationString(Object)} as part of any errors
*/
public static void write(Object target, String propertyName, Object value, Object location)
{
ClassAdaptor a = getAdaptor(target, location);
a.write(target, propertyName, value, location);
}
/**
* Updates the property of the target object.
*
* @param target the object to update
* @param propertyName the name of a property toread
* @param location an object used to "locate" any errors, it will be passed to
* {@link HiveMind#getLocationString(Object)} as part of any errors
* @return the value for the named property
*/
public static Object read(Object target, String propertyName, Object location)
{
ClassAdaptor a = getAdaptor(target, location);
return a.read(target, propertyName, location);
}
private static synchronized ClassAdaptor getAdaptor(Object target, Object location)
{
if (target == null)
throw new ApplicationRuntimeException(
HiveMind.format("PropertyUtils.null-object", HiveMind.getLocationString(location)),
null,
HiveMind.getLocation(location),
null);
Class targetClass = target.getClass();
ClassAdaptor result = (ClassAdaptor) _classAdaptors.get(targetClass);
if (result == null)
{
result = buildClassAdaptor(target, targetClass, location);
_classAdaptors.put(targetClass, result);
}
return result;
}
private static ClassAdaptor buildClassAdaptor(
Object target,
Class targetClass,
Object location)
{
try
{
BeanInfo info = Introspector.getBeanInfo(targetClass);
return new ClassAdaptor(info.getPropertyDescriptors());
}
catch (Exception ex)
{
throw new ApplicationRuntimeException(
HiveMind.format(
"PropertyUtils.unable-to-introspect",
targetClass.getName(),
HiveMind.getLocationString(location),
ex.getMessage()),
target,
HiveMind.getLocation(location),
ex);
}
}
}
1.1 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/util/PropertyAdaptor.java
Index: PropertyAdaptor.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.util;
import java.lang.reflect.Method;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.HiveMind;
/**
* Used to manage dynamic access to a property of a specific class.
*
* @author Howard Lewis Ship
* @version $Id: PropertyAdaptor.java,v 1.1 2004/02/28 00:34:37 hlship Exp $
*/
class PropertyAdaptor
{
private String _propertyName;
private Method _readMethod;
private Method _writeMethod;
PropertyAdaptor(String propertyName, Method readMethod, Method writeMethod)
{
_propertyName = propertyName;
_readMethod = readMethod;
_writeMethod = writeMethod;
}
/**
* Updates the property of the target object.
*
* @param target the object to update
* @param value the value to be stored into the target object property
* @param location an object used to "locate" any errors, it will be passed to
* {@link HiveMind#getLocationString(Object)} as part of any errors
*/
public void write(Object target, Object value, Object location)
{
if (_writeMethod == null)
throw new ApplicationRuntimeException(
HiveMind.format(
"PropertyAdaptor.no-writer",
_propertyName,
target,
HiveMind.getLocationString(location)),
target,
HiveMind.getLocation(location),
null);
try
{
_writeMethod.invoke(target, new Object[] { value });
}
catch (Exception ex)
{
throw new ApplicationRuntimeException(
HiveMind.format(
"PropertyAdaptor.write-failure",
new Object[] {
_propertyName,
target,
HiveMind.getLocationString(location),
ex.getMessage()}),
target,
HiveMind.getLocation(location),
ex);
}
}
/**
* Reads the property of the target object.
*
* @param target the object to read a property from
* @param location an object used to "locate" any errors, it will be passed to
* {@link HiveMind#getLocationString(Object)} as part of any errors
* @return the value of the property
*/
public Object read(Object target, Object location)
{
if (_readMethod == null)
throw new ApplicationRuntimeException(
HiveMind.format(
"PropertyAdaptor.no-reader",
_propertyName,
target,
HiveMind.getLocationString(location)),
target,
HiveMind.getLocation(location),
null);
try
{
return _readMethod.invoke(target, null);
}
catch (Exception ex)
{
throw new ApplicationRuntimeException(
HiveMind.format(
"PropertyAdaptor.read-failure",
new Object[] {
_propertyName,
target,
HiveMind.getLocationString(location),
ex.getMessage()}),
target,
HiveMind.getLocation(location),
ex);
}
}
}
1.1 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/util/ClassAdaptor.java
Index: ClassAdaptor.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.util;
import java.beans.PropertyDescriptor;
import java.util.HashMap;
import java.util.Map;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.HiveMind;
/**
* Provides access to an object (of a particular class) as a set of individual property
* that may be read or updated.
*
* @author Howard Lewis Ship
* @version $Id: ClassAdaptor.java,v 1.1 2004/02/28 00:34:37 hlship Exp $
*/
class ClassAdaptor
{
private final Map _propertyAdaptorMap = new HashMap();
public ClassAdaptor(PropertyDescriptor[] properties)
{
for (int i = 0; i < properties.length; i++)
{
PropertyDescriptor d = properties[i];
String name = d.getName();
_propertyAdaptorMap.put(
name,
new PropertyAdaptor(name, d.getReadMethod(), d.getWriteMethod()));
}
}
/**
* Updates the property of the target object.
*
* @param target the object to update
* @param value the value to be stored into the target object property
* @param location an object used to "locate" any errors, it will be passed to
* {@link HiveMind#getLocationString(Object)} as part of any errors
*/
public void write(Object target, String propertyName, Object value, Object location)
{
PropertyAdaptor a = getAdaptor(target, propertyName, location);
a.write(target, value, location);
}
/**
* Reads the property of the target object.
*
* @param target the object to read
* @param propertyName the name of the property to read
* @param location an object used to "locate" any errors, it will be passed to
* {@link HiveMind#getLocationString(Object)} as part of any errors
* @return the value for the named property
*/
public Object read(Object target, String propertyName, Object location)
{
PropertyAdaptor a = getAdaptor(target, propertyName, location);
return a.read(target, location);
}
private PropertyAdaptor getAdaptor(Object target, String propertyName, Object location)
{
PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
if (result == null)
throw new ApplicationRuntimeException(
HiveMind.format(
"ClassAdaptor.no-such-property",
target.getClass().getName(),
propertyName,
HiveMind.getLocationString(location)),
target,
HiveMind.getLocation(location),
null);
return result;
}
}
1.1 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java
Index: ConstructorUtils.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.util;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.HiveMind;
/**
* Static methods for invoking constructors.
*
* @author Howard Lewis Ship
* @version $Id: ConstructorUtils.java,v 1.1 2004/02/28 00:34:37 hlship Exp $
*/
public class ConstructorUtils
{
/**
* Map from primitive type to wrapper type.
*/
private static final Map _primitiveMap = new HashMap();
static {
_primitiveMap.put(boolean.class, Boolean.class);
_primitiveMap.put(byte.class, Byte.class);
_primitiveMap.put(char.class, Character.class);
_primitiveMap.put(short.class, Short.class);
_primitiveMap.put(int.class, Integer.class);
_primitiveMap.put(long.class, Long.class);
_primitiveMap.put(float.class, Float.class);
_primitiveMap.put(double.class, Double.class);
}
// Prevent instantiation
private ConstructorUtils()
{
}
/**
* Searches for a constructor matching against the provided arguments.
*
* @param targetClass the class to be instantiated
* @param parameters the parameters to pass to the constructor (may be null or empty)
* @param location the location to use in any reported errors (this will be passed
* to {@link HiveMind#getLocationString(Object)})
* @return the new instance
* @throws ApplicationRuntimeException on any failure
*
*/
public static Object invokeConstructor(Class targetClass, Object[] parameters, Object location)
{
if (parameters == null)
parameters = new Object[0];
Class[] parameterTypes = new Class[parameters.length];
for (int i = 0; i < parameters.length; i++)
parameterTypes[i] = parameters[i] == null ? null : parameters[i].getClass();
return invokeMatchingConstructor(targetClass, parameterTypes, parameters, location);
}
private static Object invokeMatchingConstructor(
Class targetClass,
Class[] parameterTypes,
Object[] parameters,
Object location)
{
Constructor[] constructors = targetClass.getConstructors();
for (int i = 0; i < constructors.length; i++)
{
Constructor c = constructors[i];
if (isMatch(c, parameterTypes))
return invoke(c, parameters, location);
}
throw new ApplicationRuntimeException(
HiveMind.format(
"ConstructorUtils.no-matching-constructor",
targetClass.getName(),
HiveMind.getLocationString(location)),
HiveMind.getLocation(location),
null);
}
private static boolean isMatch(Constructor c, Class[] types)
{
Class[] actualTypes = c.getParameterTypes();
if (actualTypes.length != types.length)
return false;
for (int i = 0; i < types.length; i++)
{
if (types[i] == null && actualTypes[i].isPrimitive())
continue;
if (!isCompatible(actualTypes[i], types[i]))
return false;
}
return true;
}
private static boolean isCompatible(Class actualType, Class parameterType)
{
if (actualType.isAssignableFrom(parameterType))
return true;
// Reflection fudges the assignment of a wrapper class to a primitive
// type ... we check for that the hard way.
if (actualType.isPrimitive())
{
Class wrapperClass = (Class) _primitiveMap.get(actualType);
return wrapperClass.isAssignableFrom(parameterType);
}
return false;
}
private static Object invoke(Constructor c, Object[] parameters, Object location)
{
try
{
return c.newInstance(parameters);
}
catch (Exception ex)
{
throw new ApplicationRuntimeException(
HiveMind.format(
"ConstructorUtils.invoke-failed",
c.getDeclaringClass().getName(),
HiveMind.getLocationString(location),
ex.getMessage()),
HiveMind.getLocation(location),
ex);
}
}
}
1.9 +4 -2 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/services/TestServices.java
Index: TestServices.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/services/TestServices.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TestServices.java 26 Feb 2004 23:07:35 -0000 1.8
+++ TestServices.java 28 Feb 2004 00:34:37 -0000 1.9
@@ -258,7 +258,9 @@
s.getExtensionPointId();
- assertLoggedMessagePattern("Unable to set property EVIL of hivemind\\.test\\.services\\.impl\\.BuilderAccessImpl@.*: Unknown property 'EVIL'");
+ assertLoggedMessagePattern(
+ "Class hivemind\\.test\\.services\\.impl\\.BuilderAccessImpl "
+ + "does not contain a property named 'EVIL' \\(at .*\\)\\.");
}
public void testConstructorFactory() throws Exception
1.5 +6 -1 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/TestHiveMindFindLocation.java
Index: TestHiveMindFindLocation.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/TestHiveMindFindLocation.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestHiveMindFindLocation.java 26 Feb 2004 23:08:01 -0000 1.4
+++ TestHiveMindFindLocation.java 28 Feb 2004 00:34:37 -0000 1.5
@@ -86,4 +86,9 @@
assertSame(l1, HiveMind.findLocation(new Object[] { this, "Hello", l1, "Goodbye" }));
}
+ public void testToLocationStringNull()
+ {
+ assertEquals("unknown location", HiveMind.getLocationString(null));
+ }
+
}
1.10 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/TestMisc.java
Index: TestMisc.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/TestMisc.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestMisc.java 26 Feb 2004 23:08:01 -0000 1.9
+++ TestMisc.java 28 Feb 2004 00:34:37 -0000 1.10
@@ -190,8 +190,7 @@
{
assertExceptionSubstring(
ex,
- "Unable to create an instance of class hivemind.test.PrivateBean: "
- + "Class org.apache.hivemind.impl.CreateClassServiceConstructor can not access a member of class hivemind.test.PrivateBean with modifiers \"private\"");
+ "Unable to find a constructor for class hivemind.test.PrivateBean.");
}
}
1.2 +3 -13 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
Index: DescriptorParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DescriptorParser.java 26 Feb 2004 23:07:44 -0000 1.1
+++ DescriptorParser.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -27,7 +27,6 @@
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
@@ -66,6 +65,7 @@
import org.apache.hivemind.schema.rules.ServiceTranslator;
import org.apache.hivemind.schema.rules.SetModuleRule;
import org.apache.hivemind.schema.rules.SetParentRule;
+import org.apache.hivemind.util.PropertyUtils;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
@@ -135,17 +135,7 @@
_referenceLocation));
}
- try
- {
- PropertyUtils.setProperty(_container, _propertyName, s);
- }
- catch (Exception ex)
- {
- // Uncharacteristically sloppy ... because this should never
- // happen.
- LOG.error(ex.getMessage(), ex);
- }
-
+ PropertyUtils.write(_container, _propertyName, s, _referenceLocation);
}
}
1.1 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/util/TestPropertyUtils.java
Index: TestPropertyUtils.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hivemind.test.util;
import java.awt.Image;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.LocationImpl;
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.hivemind.util.ClasspathResource;
import org.apache.hivemind.util.PropertyUtils;
/**
* Tests for the {@link org.apache.hivemind.util.PropertyUtils} class.
*
* @author Howard Lewis Ship
* @version $Id: TestPropertyUtils.java,v 1.1 2004/02/28 00:34:37 hlship Exp $
*/
public class TestPropertyUtils extends HiveMindTestCase
{
private Location makeLocation(int line)
{
Resource r = new ClasspathResource(new DefaultClassResolver(), "/foo/bar");
return new LocationImpl(r, line);
}
public static class Bean
{
private int _value;
public int getValue()
{
return _value;
}
public void setValue(int value)
{
_value = value;
}
public String toString()
{
return "PropertyUtilsTestBean";
}
public void setWriteOnly(boolean b)
{
}
}
public static class ExceptionBean
{
public boolean getFailure()
{
throw new RuntimeException("getFailure");
}
public void setFailure(boolean b)
{
throw new RuntimeException("setFailure");
}
public String toString()
{
return "PropertyUtilsExceptionBean";
}
}
public static class UglyBean
{
}
public static class UglyBeanBeanInfo implements BeanInfo
{
public BeanInfo[] getAdditionalBeanInfo()
{
return null;
}
public BeanDescriptor getBeanDescriptor()
{
return null;
}
public int getDefaultEventIndex()
{
return 0;
}
public int getDefaultPropertyIndex()
{
return 0;
}
public EventSetDescriptor[] getEventSetDescriptors()
{
return null;
}
public Image getIcon(int iconKind)
{
return null;
}
public MethodDescriptor[] getMethodDescriptors()
{
return null;
}
public PropertyDescriptor[] getPropertyDescriptors()
{
throw new RuntimeException("This is the UglyBean.");
}
}
public void testRead()
{
Bean b = new Bean();
b.setValue(37);
assertEquals(new Integer(37), PropertyUtils.read(b, "value", null));
}
public void testWrite()
{
Bean b = new Bean();
PropertyUtils.write(b, "value", new Integer(412), null);
assertEquals(412, b.getValue());
}
public void testMissingProperty()
{
Location l = makeLocation(19);
Bean b = new Bean();
try
{
PropertyUtils.read(b, "zaphod", l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"Class hivemind.test.util.TestPropertyUtils$Bean does not "
+ "contain a property named 'zaphod' (at classpath:/foo/bar, line 19).",
ex.getMessage());
assertEquals(b, ex.getComponent());
assertEquals(l, ex.getLocation());
}
}
public void testReadOnly()
{
Location l = makeLocation(27);
Bean b = new Bean();
try
{
PropertyUtils.write(b, "class", null, l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"Property class of object PropertyUtilsTestBean is "
+ "read-only (at classpath:/foo/bar, line 27).",
ex.getMessage());
assertEquals(b, ex.getComponent());
assertEquals(l, ex.getLocation());
}
}
public void testWriteOnly()
{
Location l = makeLocation(35);
Bean b = new Bean();
try
{
PropertyUtils.read(b, "writeOnly", l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"Property writeOnly of object PropertyUtilsTestBean is write-only (at classpath:/foo/bar, line 35).",
ex.getMessage());
assertEquals(b, ex.getComponent());
assertEquals(l, ex.getLocation());
}
}
public void testReadFailure()
{
Location l = makeLocation(17);
ExceptionBean b = new ExceptionBean();
try
{
PropertyUtils.read(b, "failure", l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"Unable to read property failure of object PropertyUtilsExceptionBean "
+ "(at classpath:/foo/bar, line 17): null",
ex.getMessage());
assertEquals(b, ex.getComponent());
assertEquals(l, ex.getLocation());
}
}
public void testWriteFailure()
{
Location l = makeLocation(17);
ExceptionBean b = new ExceptionBean();
try
{
PropertyUtils.write(b, "failure", Boolean.FALSE, l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"Unable to update property failure of object PropertyUtilsExceptionBean "
+ "(at classpath:/foo/bar, line 17): null",
ex.getMessage());
assertEquals(b, ex.getComponent());
assertEquals(l, ex.getLocation());
}
}
public void testIntrospectFailure()
{
Location l = makeLocation(212);
UglyBean b = new UglyBean();
try
{
PropertyUtils.read(b, "google", l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"Unable to introspect properties of class "
+ "hivemind.test.util.TestPropertyUtils$UglyBean "
+ "(at classpath:/foo/bar, line 212): null",
ex.getMessage());
assertEquals(b, ex.getComponent());
assertEquals(l, ex.getLocation());
}
}
public void testNull()
{
Location l = makeLocation(63);
try
{
PropertyUtils.read(null, "fred", l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals("Attempt to read or update properties of null (at classpath:/foo/bar, line 63).", ex.getMessage());
assertEquals(l, ex.getLocation());
}
}
}
1.2 +73 -18 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/HiveMind.java
Index: HiveMind.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/HiveMind.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMind.java 26 Feb 2004 23:07:56 -0000 1.1
+++ HiveMind.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -41,11 +41,11 @@
_bundle = ResourceBundle.getBundle(HiveMind.class.getName() + "Messages");
}
- /**
- * The full id of the {@link org.apache.hivemind.service.ThreadEventNotifier}
- * service.
- */
- public static final String THREAD_EVENT_NOTIFIER_SERVICE = "hivemind.ThreadEventNotifier";
+ /**
+ * The full id of the {@link org.apache.hivemind.service.ThreadEventNotifier}
+ * service.
+ */
+ public static final String THREAD_EVENT_NOTIFIER_SERVICE = "hivemind.ThreadEventNotifier";
private HiveMind()
{
@@ -198,23 +198,78 @@
{
Object location = locations[i];
- if (location == null)
- continue;
+ Location result = getLocation(location);
+
+ if (result != null)
+ return result;
+
+ }
+
+ return null;
+ }
+
+ /**
+ * Extracts a location from an object, checking to see if it
+ * implement {@link Location} or {@link Locatable}.
+ *
+ * @returns the Location, or null if it can't be found
+ */
+ public static Location getLocation(Object object)
+ {
+ if (object == null)
+ return null;
- if (location instanceof Location)
- return (Location) location;
+ if (object instanceof Location)
+ return (Location) object;
- if (location instanceof Locatable)
- {
- Locatable locatable = (Locatable) location;
- Location result = locatable.getLocation();
-
- if (result != null)
- return result;
- }
+ if (object instanceof Locatable)
+ {
+ Locatable locatable = (Locatable) object;
+
+ return locatable.getLocation();
}
return null;
}
+ /**
+ * Invokes {@link #getLocation(Object)}, then translate the result
+ * to a string value, or "unknown location" if null.
+ *
+ */
+ public static String getLocationString(Object object)
+ {
+ Location l = getLocation(object);
+
+ if (l != null)
+ return l.toString();
+
+ return getMessage("unknown-location");
+ }
+
+ /**
+ * Returns true if the string is null, empty, or contains only whitespace.
+ *
+ * <p>
+ * The commons-lang library provides a version of this, but the naming and behavior
+ * changed between 1.0 and 2.0, which causes some dependency issues.
+ */
+ public static boolean isBlank(String string)
+ {
+ if (string == null || string.length() == 0)
+ return true;
+
+ if (string.trim().length() == 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * As with {@link #isBlank(String)}, but inverts the response.
+ */
+ public static boolean isNonBlank(String string)
+ {
+ return ! isBlank(string);
+ }
}
1.2 +17 -4 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties
Index: HiveMindMessages.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMindMessages.properties 26 Feb 2004 23:07:56 -0000 1.1
+++ HiveMindMessages.properties 28 Feb 2004 00:34:37 -0000 1.2
@@ -18,7 +18,8 @@
unable-to-instantiate-class=Unable to create an instance of class {0}: {1}
no-such-service-extension-id=Service extension point {0} does not exist.
no-such-service=Service {0} (implementing interface {1}) does not exist.
-unable-to-set-property=Unable to set property {0} of {1} to {2}: {3}
+
+unknown-location=unknown location
wrong-factory-parameter-count=Service implementation factory {0} expects {1,choice,0#no parameters|1#one parameter|1<{1,number,integer} parameters} but received {2,choice,0#none|1#one|1<{2,number,integer}}.
@@ -117,8 +118,6 @@
InvokeParentRule.error-invoking-method=Error invoking method {0} on {1} (at {2}): {3}
-BaseRule.set-property-error=Unable to set property {0} of {1} to {2} (at {3}): {4}
-
CreateObjectRule.error-creating-object=Error creating instance of class {0} (at {1}): {2}
ClassTranslator.bad-class-name=''{0}'' is not a valid class name (at {1}): {2}
@@ -168,3 +167,17 @@
HiveMindFilter.init=Constructing HiveMind Registry.
HiveMindFilter.cleanup-error=Unable to cleanup current thread: {0}
+# util package
+
+PropertyAdaptor.no-writer=Property {0} of object {1} is read-only (at {2}).
+PropertyAdaptor.write-failure=Unable to update property {0} of object {1} (at {2}): {3}
+PropertyAdaptor.no-reader=Property {0} of object {1} is write-only (at {2}).
+PropertyAdaptor.read-failure=Unable to read property {0} of object {1} (at {2}): {3}
+
+ClassAdaptor.no-such-property=Class {0} does not contain a property named ''{1}'' (at {2}).
+
+PropertyUtils.null-object=Attempt to read or update properties of null (at {0}).
+PropertyUtils.unable-to-introspect=Unable to introspect properties of class {0} (at {1}): {2}
+
+ConstructorUtils.no-matching-constructor=Unable to find a constructor for class {0}.
+ConstructorUtils.invoke-failed=Failure invoking constructor for class {0} (at {1}): {2}
1.2 +15 -1 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssemblyImpl.java
Index: RegistryAssemblyImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssemblyImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RegistryAssemblyImpl.java 26 Feb 2004 23:07:40 -0000 1.1
+++ RegistryAssemblyImpl.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -1,3 +1,17 @@
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package org.apache.hivemind.impl;
import java.util.ArrayList;
1.2 +8 -9 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
Index: ProxyUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProxyUtils.java 26 Feb 2004 23:07:40 -0000 1.1
+++ ProxyUtils.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -14,15 +14,15 @@
package org.apache.hivemind.impl;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
-import org.apache.commons.beanutils.ConstructorUtils;
-import org.apache.hivemind.service.BodyBuilder;
-import org.apache.hivemind.service.ClassFab;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.RegistryShutdownListener;
import org.apache.hivemind.ServiceExtensionPoint;
import org.apache.hivemind.ServiceModel;
+import org.apache.hivemind.service.BodyBuilder;
+import org.apache.hivemind.service.ClassFab;
/**
* Contains some common code used to create proxies that defer to a service model method
@@ -64,13 +64,13 @@
builder.addServiceMethods(SERVICE_ACCESSOR_METHOD_NAME + "()");
Class proxyClass = classFab.createClass();
+
try
{
+ Constructor c = proxyClass.getConstructor(new Class[] { serviceModel.getClass() });
RegistryShutdownListener result =
- (RegistryShutdownListener) ConstructorUtils.invokeConstructor(
- proxyClass,
- serviceModel);
+ (RegistryShutdownListener) c.newInstance(new Object[] { serviceModel });
shutdownCoordinator.addRegistryShutdownListener(result);
@@ -118,8 +118,7 @@
builder.begin();
builder.addln("if (_shutdown)");
- builder.addln(
- " throw org.apache.hivemind.HiveMind#createRegistryShutdownException();");
+ builder.addln(" throw org.apache.hivemind.HiveMind#createRegistryShutdownException();");
builder.add("return (");
builder.add(serviceInterface.getName());
1.2 +15 -1 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssembly.java
Index: RegistryAssembly.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssembly.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RegistryAssembly.java 26 Feb 2004 23:07:40 -0000 1.1
+++ RegistryAssembly.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -1,3 +1,17 @@
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package org.apache.hivemind.impl;
import org.apache.hivemind.schema.Schema;
1.2 +3 -21 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/CreateClassServiceConstructor.java
Index: CreateClassServiceConstructor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/impl/CreateClassServiceConstructor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CreateClassServiceConstructor.java 26 Feb 2004 23:07:40 -0000 1.1
+++ CreateClassServiceConstructor.java 28 Feb 2004 00:34:37 -0000 1.2
@@ -14,11 +14,10 @@
package org.apache.hivemind.impl;
-import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
-import org.apache.hivemind.HiveMind;
import org.apache.hivemind.Module;
import org.apache.hivemind.ServiceImplementationConstructor;
+import org.apache.hivemind.util.ConstructorUtils;
/**
* Constructs a service by instantiating a class.
@@ -37,25 +36,8 @@
public Object constructCoreServiceImplementation()
{
Class instanceClass = getInstanceClass();
- Object result = null;
- try
- {
- result = instanceClass.newInstance();
- }
- catch (Exception ex)
- {
- throw new ApplicationRuntimeException(
- HiveMind.format(
- "unable-to-instantiate-class",
- instanceClass.getName(),
- ex.getMessage()),
- getLocation(),
- ex);
-
- }
-
- return result;
+ return ConstructorUtils.invokeConstructor(instanceClass, null, this);
}
private synchronized Class getInstanceClass()
1.4 +3 -3 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/config/ToUpperCaseTranslator.java
Index: ToUpperCaseTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/config/ToUpperCaseTranslator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ToUpperCaseTranslator.java 26 Feb 2004 23:07:55 -0000 1.3
+++ ToUpperCaseTranslator.java 28 Feb 2004 00:34:37 -0000 1.4
@@ -14,8 +14,8 @@
package hivemind.test.config;
-import org.apache.commons.lang.StringUtils;
import org.apache.hivemind.Element;
+import org.apache.hivemind.HiveMind;
import org.apache.hivemind.schema.SchemaProcessor;
import org.apache.hivemind.schema.Translator;
@@ -30,7 +30,7 @@
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
- if (StringUtils.isBlank(inputValue))
+ if (HiveMind.isBlank(inputValue))
return null;
return inputValue.toUpperCase();
1.6 +1 -3 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/TestInvokeParentRule.java
Index: TestInvokeParentRule.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/TestInvokeParentRule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestInvokeParentRule.java 26 Feb 2004 23:07:53 -0000 1.5
+++ TestInvokeParentRule.java 28 Feb 2004 00:34:37 -0000 1.6
@@ -44,9 +44,7 @@
"Unable to construct configuration hivemind.test.rules.InvokeFailure: Error invoking method failure on org.apache.hivemind.impl.SchemaProcessorImpl");
Throwable inner = findNestedException(ex);
- assertExceptionSubstring(
- inner,
- "No such accessible method: failure() on object: org.apache.hivemind.impl.SchemaProcessorImpl");
+ assertExceptionSubstring(inner, "failure");
}
}
1.5 +2 -2 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/TestObjectTranslator.java
Index: TestObjectTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/TestObjectTranslator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestObjectTranslator.java 26 Feb 2004 23:07:53 -0000 1.4
+++ TestObjectTranslator.java 28 Feb 2004 00:34:37 -0000 1.5
@@ -117,7 +117,7 @@
l.size();
- assertLoggedMessagePattern("Unable to set property value of hivemind\\.test\\.config\\.impl\\.Datum@.* to {} \\(at datum/value\\): ");
+ assertLoggedMessagePattern("Unable to update property value of object hivemind\\.test\\.config\\.impl\\.Datum@");
}
public void testClassTranslator() throws Exception
1.2 +15 -1 jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/impl/TestRegistryAssemblyImpl.java
Index: TestRegistryAssemblyImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/impl/TestRegistryAssemblyImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRegistryAssemblyImpl.java 26 Feb 2004 23:08:04 -0000 1.1
+++ TestRegistryAssemblyImpl.java 28 Feb 2004 00:34:38 -0000 1.2
@@ -1,3 +1,17 @@
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package hivemind.test.impl;
import java.util.List;
1.2 +4 -2 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java
Index: BuilderParameter.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BuilderParameter.java 26 Feb 2004 23:07:45 -0000 1.1
+++ BuilderParameter.java 28 Feb 2004 00:34:38 -0000 1.2
@@ -17,13 +17,15 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.hivemind.impl.BaseLocatable;
+
/**
* Parameter object used with {@link org.apache.hivemind.service.impl.BuilderFactory}.
*
* @author Howard Lewis Ship
* @version $Id$
*/
-public class BuilderParameter
+public class BuilderParameter extends BaseLocatable
{
private String _className;
private List _properties = new ArrayList();
1.2 +16 -39 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactory.java
Index: BuilderFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BuilderFactory.java 26 Feb 2004 23:07:45 -0000 1.1
+++ BuilderFactory.java 28 Feb 2004 00:34:38 -0000 1.2
@@ -16,17 +16,16 @@
import java.util.List;
-import org.apache.commons.beanutils.ConstructorUtils;
-import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.HiveMind;
import org.apache.hivemind.Module;
import org.apache.hivemind.ServiceExtensionPoint;
import org.apache.hivemind.ServiceImplementationFactory;
import org.apache.hivemind.service.EventLinker;
+import org.apache.hivemind.util.ConstructorUtils;
+import org.apache.hivemind.util.PropertyUtils;
/**
* Implementation of {@link org.apache.hivemind.ServiceImplementationFactory}
@@ -119,7 +118,14 @@
Object value = facet.getFacetValue(point, invokingModule);
- set(result, propertyName, value);
+ try
+ {
+ PropertyUtils.write(result, propertyName, value, facet);
+ }
+ catch (Exception ex)
+ {
+ LOG.error(ex.getMessage());
+ }
}
}
@@ -128,27 +134,14 @@
Module invokingModule,
BuilderParameter parameter)
{
- try
- {
- ClassResolver resolver = invokingModule.getClassResolver();
- Class serviceClass = resolver.findClass(parameter.getClassName());
- Object[] constructorParameters =
- buildConstructorParameters(parameter, invokingModule, point);
+ ClassResolver resolver = invokingModule.getClassResolver();
+ Class serviceClass = resolver.findClass(parameter.getClassName());
- return ConstructorUtils.invokeConstructor(serviceClass, constructorParameters);
- }
- catch (Exception ex)
- {
- throw new ApplicationRuntimeException(
- HiveMind.format(
- "unable-to-instantiate-class",
- parameter.getClassName(),
- ex.getMessage()),
- null,
- ex);
- }
+ Object[] constructorParameters =
+ buildConstructorParameters(parameter, invokingModule, point);
+ return ConstructorUtils.invokeConstructor(serviceClass, constructorParameters, parameter);
}
private Object[] buildConstructorParameters(
@@ -172,21 +165,5 @@
}
return result;
- }
-
- private void set(Object serviceImplementation, String propertyName, Object value)
- {
- try
- {
- PropertyUtils.setProperty(serviceImplementation, propertyName, value);
- }
- catch (Exception ex)
- {
- LOG.error(
- HiveMind.format(
- "unable-to-set-property",
- new Object[] { propertyName, serviceImplementation, value, ex.getMessage()}),
- ex);
- }
}
}
1.2 +3 -2 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java
Index: BuilderFacet.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BuilderFacet.java 26 Feb 2004 23:07:45 -0000 1.1
+++ BuilderFacet.java 28 Feb 2004 00:34:38 -0000 1.2
@@ -16,6 +16,7 @@
import org.apache.hivemind.Module;
import org.apache.hivemind.ServiceExtensionPoint;
+import org.apache.hivemind.impl.BaseLocatable;
/**
* Represents one facet of constructing a service implementation instance.
@@ -27,7 +28,7 @@
* @author Howard Lewis Ship
* @version $Id$
*/
-public abstract class BuilderFacet
+public abstract class BuilderFacet extends BaseLocatable
{
private String _propertyName;
1.2 +2 -3 jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/EventLinkerImpl.java
Index: EventLinkerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/hivemind/service/impl/EventLinkerImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventLinkerImpl.java 26 Feb 2004 23:07:45 -0000 1.1
+++ EventLinkerImpl.java 28 Feb 2004 00:34:38 -0000 1.2
@@ -22,7 +22,6 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.HiveMind;
@@ -54,7 +53,7 @@
Location location)
{
EventSetDescriptor[] sets = getEventSets(producer);
- boolean nameMatch = !StringUtils.isBlank(eventSetName);
+ boolean nameMatch = HiveMind.isNonBlank(eventSetName);
Class consumerClass = consumer.getClass();
int count = 0;
1.22 +0 -2 jakarta-commons-sandbox/hivemind/.classpath
Index: .classpath
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/.classpath,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- .classpath 26 Feb 2004 23:07:56 -0000 1.21
+++ .classpath 28 Feb 2004 00:34:38 -0000 1.22
@@ -10,8 +10,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.7.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-beanutils/jars/commons-beanutils-1.6.1.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-2.1.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/commons-logging/jars/commons-logging-1.0.3.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-2.0.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/xerces/jars/xerces-2.2.1.jar"/>
1.5 +1 -13 jakarta-commons-sandbox/hivemind/library/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/library/project.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- project.xml 26 Feb 2004 23:08:03 -0000 1.4
+++ project.xml 28 Feb 2004 00:34:38 -0000 1.5
@@ -66,12 +66,6 @@
<version>2.0</version>
<url>http://jakarta.apache.org/jakarta-commons/lang.html</url>
</dependency>
-
- <dependency>
- <id>commons-beanutils</id>
- <version>1.6.1</version>
- <url>http://jakarta.apache.org/jakarta-commons/beanutils.html</url>
- </dependency>
<dependency>
@@ -94,12 +88,6 @@
<version>1.0.b2</version>
<url>http://xml.apache.org/xerces/</url>
</dependency>
-
- <dependency>
- <id>commons-collections</id>
- <version>2.1</version>
- <url>http://jakarta.apache.org/jakarta-commons/collections.html</url>
- </dependency>
<!-- Needed by test suite classes, but not the framework itself. -->
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org