You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dm...@apache.org on 2003/01/20 19:29:46 UTC
cvs commit: jakarta-commons-sandbox/clazz/xdocs overview.xml
dmitri 2003/01/20 10:29:46
Modified: clazz/src/java/org/apache/commons/clazz Clazz.java
ClazzAccessException.java ClazzElement.java
ClazzLoader.java ClazzModifiers.java
ClazzNotFoundException.java ClazzProperty.java
ModelClazzLoader.java
clazz/src/java/org/apache/commons/clazz/bean BasicBean.java
Bean.java BeanClazz.java
BeanClazzConfigurationException.java
BeanClazzConstructorInstanceFactory.java
BeanClazzInstanceFactory.java BeanClazzLoader.java
BeanClazzOperation.java BeanClazzProperty.java
BeanGroupClazzLoader.java
clazz/src/java/org/apache/commons/clazz/common
ClazzElementSupport.java ClazzFeatureSupport.java
ClazzLoaderFactorySupport.java
ExtendedClazzLoaderFactory.java
GroupClazzLoader.java
StandardClazzLoaderFactory.java
clazz/src/java/org/apache/commons/clazz/reflect
ReflectedClazz.java ReflectedClazzLoader.java
ReflectedGroupClazzLoader.java
ReflectedInstanceFactoryIntrospector.java
ReflectedOperationIntrospector.java
ReflectedProperty.java
ReflectedPropertyIntrospector.java
clazz/src/java/org/apache/commons/clazz/reflect/common
AccessorMethodParser.java
ReflectedAccessorPairProperty.java
ReflectedConstructorInstanceFactory.java
ReflectedConstructorInstanceFactoryIntrospector.java
ReflectedList.java ReflectedListProperty.java
ReflectedListPropertyIntrospectorSupport.java
ReflectedListPropertyParseResults.java
ReflectedMethodFeatureSupport.java
ReflectedMethodInstanceFactoryIntrospector.java
ReflectedMethodOperationIntrospector.java
ReflectedPropertyIntrospectorSupport.java
ReflectedPropertyParseResults.java
ReflectedScalarProperty.java
ReflectedScalarPropertyIntrospector.java
ReflectedScalarPropertyParseResults.java
clazz/src/java/org/apache/commons/clazz/reflect/extended
ExtendedReflectedListPropertyIntrospector.java
ReflectedMap.java ReflectedMappedProperty.java
ReflectedMappedPropertyIntrospector.java
ReflectedMappedPropertyParseResults.java
clazz/src/java/org/apache/commons/clazz/reflect/standard
StandardReflectedClazzLoader.java
StandardReflectedListPropertyIntrospector.java
clazz/src/test/org/apache/commons/clazz/bean
BeanClazzLoaderTest.java BeanClazzTest.java
clazz/src/test/org/apache/commons/clazz/reflect
ReflectableInstance.java
ReflectedClazzTestCommon.java
ReflectedClazzTestSupport.java
ReflectedInstanceFactoryTestCommon.java
ReflectedListPropertyTestCommon.java
ReflectedOperationCommon.java
ReflectedSuperclazzInstance.java
clazz/src/test/org/apache/commons/clazz/reflect/extended
CustomBean1ExtendedClazz.java
CustomBean1ExtendedClazzTest.java CustomClazz.java
CustomClazzLoaderTest.java
CustomPropertyIntrospector.java
ExtendedReflectedClazzTest.java
ExtendedReflectedInstanceFactoryTest.java
ExtendedReflectedListPropertyTest.java
ExtendedReflectedOperationTest.java
ReflectedMappedPropertyTest.java
clazz/src/test/org/apache/commons/clazz/reflect/standard
StandardReflectedClazzTest.java
StandardReflectedInstanceFactoryTest.java
StandardReflectedListPropertyTest.java
StandardReflectedOperationTest.java
clazz/xdocs overview.xml
Added: clazz/src/java/org/apache/commons/clazz ClazzAttribute.java
clazz/src/test/org/apache/commons/clazz/reflect/extended
CustomBean3.java CustomBean3BeanInfo.java
CustomBean3BeanInfoTest.java
Log:
Checkstyle issues, beaninfo support
Revision Changes Path
1.9 +41 -41 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/Clazz.java
Index: Clazz.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/Clazz.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Clazz.java 9 Jan 2003 03:23:59 -0000 1.8
+++ Clazz.java 20 Jan 2003 18:29:40 -0000 1.9
@@ -184,7 +184,7 @@
* Uses the default clazz loader to obtain the Clazz for the supplied
* object.
*/
- public static Clazz getClazz(Object instance){
+ public static Clazz getClazz(Object instance) {
return getClazz(instance, getDefaultClazzModel());
}
@@ -193,7 +193,7 @@
* be created by the ClazzLoaders only.
*
* @param loader is the owning model clazz loader
* @param name must be unique within the model
*/
- protected Clazz(ClazzLoader modelClazzLoader, String name){
+ protected Clazz(ClazzLoader modelClazzLoader, String name) {
this.loader = modelClazzLoader;
this.name = name;
}
@@ -202,7 +202,7 @@
* Every Clazz belongs to one and only one ClazzLoader. Its name is unique
* within that loader.
*/
- public ClazzLoader getClazzLoader(){
+ public ClazzLoader getClazzLoader() {
return loader;
}
@@ -210,7 +210,7 @@
* Returns the name of the Clazz. It is ok for the same name to be present
* in different ClazzLoaders, except CachingClazzLoaders.
*/
- public String getName(){
+ public String getName() {
return name;
}
@@ -219,12 +219,12 @@
*
* @return the package name
*/
- public String getPackageName(){
- if (name == null){
+ public String getPackageName() {
+ if (name == null) {
return null;
}
int index = name.lastIndexOf('.');
- if (index == -1){
+ if (index == -1) {
return "";
}
@@ -236,12 +236,12 @@
*
* @return the class name (without the package)
*/
- public String getShortClassName(){
- if (name == null){
+ public String getShortClassName() {
+ if (name == null) {
return null;
}
int index = name.lastIndexOf('.');
- if (index == -1){
+ if (index == -1) {
return name;
}
@@ -263,7 +263,7 @@
* Returns true if the supplied clazz is either the same or a subclazz of
* this clazz.
*/
- public boolean isAssignableFrom(Clazz clazz){
+ public boolean isAssignableFrom(Clazz clazz) {
if (clazz == this) {
return true;
}
@@ -337,7 +337,7 @@
* Creates a new instance of this Clazz using the InstanceFactory that takes
* no parameters.
*/
- public Object newInstance(){
+ public Object newInstance() {
ClazzInstanceFactory factory = getInstanceFactory("()");
if (factory == null) {
// @todo: define exception
@@ -351,7 +351,7 @@
* Creates a new instance of this Clazz using the InstanceFactory
* with the specified signature.
*/
- public Object newInstance(String signature, Object[] parameters){
+ public Object newInstance(String signature, Object[] parameters) {
ClazzInstanceFactory factory = getInstanceFactory(signature);
if (factory == null) {
// @todo: define exception
@@ -366,8 +366,8 @@
//--- Notification mechanism - verbose, but what are you gonna do?
- public void addClazzChangeListener(ClazzChangeListener listener){
- if (listeners == null){
+ public void addClazzChangeListener(ClazzChangeListener listener) {
+ if (listeners == null) {
listeners = new ArrayList();
}
@@ -377,13 +377,13 @@
listeners.add(reference);
}
- public void removeClazzChangeListener(ClazzChangeListener listener){
- if (listeners == null){
+ public void removeClazzChangeListener(ClazzChangeListener listener) {
+ if (listeners == null) {
return;
}
for (Iterator iter = listeners.iterator(); iter.hasNext();) {
WeakReference reference = (WeakReference) iter.next();
- if (reference.get() == listener){
+ if (reference.get() == listener) {
iter.remove();
break;
}
@@ -393,7 +393,7 @@
private static final WeakReference[] CLAZZ_CHANGE_LISTENER_ARRAY =
new WeakReference[0];
- private static abstract class Notifier {
+ private abstract static class Notifier {
void fire(Clazz clazz, Object parameter) {
if (clazz.listeners != null && clazz.listeners.size() != 0) {
WeakReference listenerArray[] =
@@ -412,48 +412,48 @@
Clazz clazz, ClazzChangeListener listener, Object parameter);
}
- private static Notifier PROPERTY_ADDED_NOTIFIER = new Notifier() {
+ private static final Notifier PROPERTY_ADDED_NOTIFIER = new Notifier() {
void fire(Clazz clazz, ClazzChangeListener listener, Object parameter) {
listener.propertyAdded(clazz, (ClazzProperty) parameter);
}
};
- protected void firePropertyAdded(ClazzProperty property){
+ protected void firePropertyAdded(ClazzProperty property) {
PROPERTY_ADDED_NOTIFIER.fire(this, property);
}
- private static Notifier PROPERTY_REMOVED_NOTIFIER = new Notifier() {
+ private static final Notifier PROPERTY_REMOVED_NOTIFIER = new Notifier() {
void fire(Clazz clazz, ClazzChangeListener listener, Object parameter) {
listener.propertyRemoved(clazz, (ClazzProperty) parameter);
}
};
- protected void firePropertyRemoved(ClazzProperty property){
+ protected void firePropertyRemoved(ClazzProperty property) {
PROPERTY_REMOVED_NOTIFIER.fire(this, property);
}
- private static Notifier OPERATION_ADDED_NOTIFIER = new Notifier() {
+ private static final Notifier OPERATION_ADDED_NOTIFIER = new Notifier() {
void fire(Clazz clazz, ClazzChangeListener listener, Object parameter) {
listener.operationAdded(clazz, (ClazzOperation) parameter);
}
};
- protected void fireOperationAdded(ClazzOperation operation){
+ protected void fireOperationAdded(ClazzOperation operation) {
OPERATION_ADDED_NOTIFIER.fire(this, operation);
}
- private static Notifier OPERATION_REMOVED_NOTIFIER = new Notifier() {
+ private static final Notifier OPERATION_REMOVED_NOTIFIER = new Notifier() {
void fire(Clazz clazz, ClazzChangeListener listener, Object parameter) {
listener.operationRemoved(clazz, (ClazzOperation) parameter);
}
};
- protected void fireOperationRemoved(ClazzOperation operation){
+ protected void fireOperationRemoved(ClazzOperation operation) {
OPERATION_REMOVED_NOTIFIER.fire(this, operation);
}
- private static Notifier FACTORY_ADDED_NOTIFIER = new Notifier() {
+ private static final Notifier FACTORY_ADDED_NOTIFIER = new Notifier() {
void fire(Clazz clazz, ClazzChangeListener listener, Object parameter) {
listener.instanceFactoryAdded(
clazz,
@@ -461,11 +461,11 @@
}
};
- protected void fireInstanceFactoryAdded(ClazzInstanceFactory factory){
+ protected void fireInstanceFactoryAdded(ClazzInstanceFactory factory) {
FACTORY_ADDED_NOTIFIER.fire(this, factory);
}
- private static Notifier FACTORY_REMOVED_NOTIFIER = new Notifier() {
+ private static final Notifier FACTORY_REMOVED_NOTIFIER = new Notifier() {
void fire(Clazz clazz, ClazzChangeListener listener, Object parameter) {
listener.instanceFactoryRemoved(
clazz,
@@ -473,7 +473,7 @@
}
};
- protected void fireInstanceFactoryRemoved(ClazzInstanceFactory factory){
+ protected void fireInstanceFactoryRemoved(ClazzInstanceFactory factory) {
FACTORY_REMOVED_NOTIFIER.fire(this, factory);
}
@@ -486,13 +486,13 @@
*/
public static String constructSignature(String name, Class[] arguments) {
StringBuffer buffer = new StringBuffer();
- if (name != null){
+ if (name != null) {
buffer.append(name);
}
buffer.append('(');
- if (arguments != null){
+ if (arguments != null) {
for (int i = 0; i < arguments.length; i++) {
- if (i != 0){
+ if (i != 0) {
buffer.append(',');
}
buffer.append(getCanonicalClassName(arguments[i]));
@@ -508,13 +508,13 @@
*/
public static String constructSignature(String name, Clazz[] arguments) {
StringBuffer buffer = new StringBuffer();
- if (name != null){
+ if (name != null) {
buffer.append(name);
}
buffer.append('(');
- if (arguments != null){
+ if (arguments != null) {
for (int i = 0; i < arguments.length; i++) {
- if (i != 0){
+ if (i != 0) {
buffer.append(',');
}
buffer.append(arguments[i].getName());
@@ -533,10 +533,10 @@
* This is basically a remake of java.lang.reflect.Field.getTypeName
* (Class), which cannot be used directly as it is declared with the
* default scope.
- */
- if (javaClass.isArray()){
+ */
+ if (javaClass.isArray()) {
return getCanonicalClassName(javaClass.getComponentType()) + "[]";
}
return javaClass.getName();
- }
+ }
}
1.2 +5 -5 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzAccessException.java
Index: ClazzAccessException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzAccessException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClazzAccessException.java 14 Dec 2002 02:38:41 -0000 1.1
+++ ClazzAccessException.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -87,14 +87,14 @@
this.cause = cause;
}
- public String getMessage(){
- if (cause == null){
+ public String getMessage() {
+ if (cause == null) {
return super.getMessage();
}
- return super.getMessage()+ "; " + cause.getMessage();
+ return super.getMessage() + "; " + cause.getMessage();
}
- public Throwable getCause(){
+ public Throwable getCause() {
return cause;
}
}
1.2 +10 -3 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzElement.java
Index: ClazzElement.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzElement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClazzElement.java 16 Dec 2002 23:17:41 -0000 1.1
+++ ClazzElement.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -60,7 +60,14 @@
* @version $Id$
*/
public interface ClazzElement {
- // @todo: attribute API goes here
- Object getAttribute(String attribute);
+ /**
+ * Returns the attribute for the specified (qualified) name
+ */
+ ClazzAttribute getAttribute(String attribute);
+
+ /**
+ * Returns all attribute for this element.
+ */
+ ClazzAttribute[] getAttributes();
}
1.5 +16 -18 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzLoader.java
Index: ClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzLoader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.4
+++ ClazzLoader.java 20 Jan 2003 18:29:41 -0000 1.5
@@ -60,31 +60,30 @@
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ClazzLoader
-{
+public abstract class ClazzLoader {
private ModelClazzLoader modelClazzLoader;
-
+
/**
* ClazzLoaders are grouped into models.
*/
public ClazzLoader(ModelClazzLoader modelClazzLoader) {
this.modelClazzLoader = modelClazzLoader;
}
-
+
/**
* Returns the model clazz loader for this clazz loader.
*/
- public ModelClazzLoader getModelClazzLoader(){
+ public ModelClazzLoader getModelClazzLoader() {
return modelClazzLoader;
}
-
+
/**
* Returns the name of the model this clazz loader belongs to.
*/
- public String getModel(){
+ public String getModel() {
return getModelClazzLoader().getModel();
}
-
+
/**
* Given a Clazz name, returns the corresponding Clazz. Does not
* cache clazzes, that's the job of CachingGroupClazzLoader. Return null if
@@ -105,13 +104,13 @@
* Returns the Clazz for the supplied instance. Returns <code>null</code>
* if it cannot produce such a Clazz.
*/
- public Clazz getClazz(Object instance){
- if (instance == null){
+ public Clazz getClazz(Object instance) {
+ if (instance == null) {
return null;
}
-
+
String name = getClazzName(instance);
- if (name == null){
+ if (name == null) {
return null;
}
return getClazzForName(name);
@@ -122,7 +121,7 @@
* <code>null</code> if it cannot produce a clazz name for the instance.
*/
public abstract String getClazzName(Object instance);
-
+
/**
* Defines a new Clazz with the supplied name. If it cannot define a
* clazz of the supplied type or if it cannot define clazzes at all, returns
@@ -141,19 +140,18 @@
String name,
Class clazzClass,
Class instanceClass);
-
private HashSet loggingEnabledClasses = new HashSet();
/**
* Enable diagnistic logging for the specified class.
*/
- public void enableLogging(String className){
+ public void enableLogging(String className) {
loggingEnabledClasses.add(className);
}
- public boolean isLoggingEnabled(String className){
+ public boolean isLoggingEnabled(String className) {
return loggingEnabledClasses.contains(className);
}
-
+
}
1.4 +53 -25 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzModifiers.java
Index: ClazzModifiers.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzModifiers.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClazzModifiers.java 6 Dec 2002 01:12:48 -0000 1.3
+++ ClazzModifiers.java 20 Jan 2003 18:29:41 -0000 1.4
@@ -157,7 +157,8 @@
public ClazzModifiers(ClazzModifiers modifiers) {
super();
if (modifiers == null) {
- throw new IllegalArgumentException("The modifiers must not be null");
+ throw new IllegalArgumentException(
+ "The modifiers must not be null");
}
setFlags(modifiers.getFlags());
}
@@ -165,7 +166,8 @@
//--------------------------------------------------------------------------
/**
- * Gets the modifier flags, which can be accessed via java.lang.reflect.Modifier.
+ * Gets the modifier flags, which can be accessed via java.lang.reflect.
+ * Modifier.
*
* @return the modifier flags
*/
@@ -197,7 +199,11 @@
* Set the object to be public scope.
*/
public void setPublicScope() {
- setFlags(getFlags() & ~Modifier.PRIVATE & ~Modifier.PROTECTED & Modifier.PUBLIC);
+ setFlags(
+ getFlags()
+ & ~Modifier.PRIVATE
+ & ~Modifier.PROTECTED
+ & Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
@@ -215,7 +221,11 @@
* Set the object to be protected scope.
*/
public void setProtectedScope() {
- setFlags(getFlags() & ~Modifier.PRIVATE & Modifier.PROTECTED & ~Modifier.PUBLIC);
+ setFlags(
+ getFlags()
+ & ~Modifier.PRIVATE
+ & Modifier.PROTECTED
+ & ~Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
@@ -226,16 +236,21 @@
* @return true if package scope
*/
public boolean isPackageScope() {
- return ((isPublicScope() == false) &&
- (isProtectedScope() == false) &&
- (isPrivateScope() == false));
+ return (
+ (isPublicScope() == false)
+ && (isProtectedScope() == false)
+ && (isPrivateScope() == false));
}
/**
* Set the object to be package scope.
*/
public void setPackageScope() {
- setFlags(getFlags() & ~Modifier.PRIVATE & ~Modifier.PROTECTED & ~Modifier.PUBLIC);
+ setFlags(
+ getFlags()
+ & ~Modifier.PRIVATE
+ & ~Modifier.PROTECTED
+ & ~Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
@@ -253,7 +268,11 @@
* Set the object to be private scope.
*/
public void setPrivateScope() {
- setFlags(getFlags() & Modifier.PRIVATE & ~Modifier.PROTECTED & ~Modifier.PUBLIC);
+ setFlags(
+ getFlags()
+ & Modifier.PRIVATE
+ & ~Modifier.PROTECTED
+ & ~Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
@@ -275,7 +294,8 @@
public void setStatic(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.STATIC);
- } else {
+ }
+ else {
setFlags(getFlags() & ~Modifier.STATIC);
}
}
@@ -299,7 +319,8 @@
public void setFinal(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.FINAL);
- } else {
+ }
+ else {
setFlags(getFlags() & ~Modifier.FINAL);
}
}
@@ -323,7 +344,8 @@
public void setSynchronized(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.SYNCHRONIZED);
- } else {
+ }
+ else {
setFlags(getFlags() & ~Modifier.SYNCHRONIZED);
}
}
@@ -347,7 +369,8 @@
public void setVolatile(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.VOLATILE);
- } else {
+ }
+ else {
setFlags(getFlags() & ~Modifier.VOLATILE);
}
}
@@ -371,7 +394,8 @@
public void setTransient(boolean state) {
if (state) {
setFlags(getFlags() & TRANSIENT);
- } else {
+ }
+ else {
setFlags(getFlags() & ~TRANSIENT);
}
}
@@ -395,7 +419,8 @@
public void setNative(boolean state) {
if (state) {
setFlags(getFlags() & NATIVE);
- } else {
+ }
+ else {
setFlags(getFlags() & ~NATIVE);
}
}
@@ -419,7 +444,8 @@
public void setAbstract(boolean state) {
if (state) {
setFlags(getFlags() & ABSTRACT);
- } else {
+ }
+ else {
setFlags(getFlags() & ~ABSTRACT);
}
}
@@ -443,7 +469,8 @@
public void setStrictFP(boolean state) {
if (state) {
setFlags(getFlags() & STRICT);
- } else {
+ }
+ else {
setFlags(getFlags() & ~STRICT);
}
}
@@ -464,7 +491,7 @@
*/
public String toString() {
StringBuffer sb = new StringBuffer("Modifiers[");
-
+
if (isPublicScope()) {
sb.append("public ");
}
@@ -474,7 +501,7 @@
if (isProtectedScope()) {
sb.append("protected ");
}
-
+
// Canonical order
if (isAbstract()) {
sb.append("abstract ");
@@ -497,16 +524,17 @@
if (isSynchronized()) {
sb.append("synchronized ");
}
-// if (isInterface()) {
-// sb.append("interface ");
-// }
+ // if (isInterface()) {
+ // sb.append("interface ");
+ // }
if (isStrictFP()) {
sb.append("strictfp ");
}
-
+
if (sb.charAt(sb.length() - 1) == ' ') {
sb.setCharAt(sb.length() - 1, ']');
- } else {
+ }
+ else {
sb.append(']');
}
return sb.toString();
1.4 +3 -3 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzNotFoundException.java
Index: ClazzNotFoundException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzNotFoundException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClazzNotFoundException.java 14 Dec 2002 02:38:41 -0000 1.3
+++ ClazzNotFoundException.java 20 Jan 2003 18:29:41 -0000 1.4
@@ -62,11 +62,11 @@
private String className;
- public ClazzNotFoundException(String className){
+ public ClazzNotFoundException(String className) {
this.className = className;
}
- public String getMessage(){
+ public String getMessage() {
return "Clazz not found: " + className;
}
}
1.4 +18 -15 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzProperty.java
Index: ClazzProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzProperty.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClazzProperty.java 6 Dec 2002 01:12:48 -0000 1.3
+++ ClazzProperty.java 20 Jan 2003 18:29:41 -0000 1.4
@@ -59,23 +59,24 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @author <a href="mailto:scolebourne@apache.org">Stephen Colebourne</a>
* @version $Id$
*/
-public interface ClazzProperty extends ClazzFeature
-{
+public interface ClazzProperty extends ClazzFeature {
/**
* Returns the name of the property.
- *
* @return String
*/
+ *
+ * @return String
+ */
String getName();
/**
* Returns the property type.
*/
Clazz getClazz();
-
+
/**
* Returns true if the property is a collection.
*/
boolean isCollection();
-
+
/**
* Returns true if the property is a map.
*/
@@ -87,25 +88,27 @@
*
* @return the type of the item
*/
- public Clazz getContentClazz();
-
+ Clazz getContentClazz();
+
/**
* Gets the type of the key if the property <code>isMap()</code>.
*
* @return the type of the key
*/
- public Clazz getKeyClazz();
-
+ Clazz getKeyClazz();
+
/**
- * @return true if the property can not be changed
*/
- public boolean isReadOnly();
-
+ * @return true if the property can not be changed
+ */
+ boolean isReadOnly();
+
/**
* @todo
*/
Object get(Object instance);
-
+
/**
- * @todo
*/
+ * @todo
+ */
void set(Object instance, Object value);
}
1.2 +6 -6 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ModelClazzLoader.java
Index: ModelClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ModelClazzLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ModelClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.1
+++ ModelClazzLoader.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -69,12 +69,12 @@
private String model;
private HashMap clazzMap = new HashMap();
- public ModelClazzLoader(String model){
+ public ModelClazzLoader(String model) {
super(null);
this.model = model;
}
- public String getModel(){
+ public String getModel() {
return model;
}
@@ -82,10 +82,10 @@
* @see ClazzLoader#getClazzForName(String)
*/
public Clazz getClazzForName(String name) {
- Clazz clazz = (Clazz)clazzMap.get(name);
- if (clazz == null){
+ Clazz clazz = (Clazz) clazzMap.get(name);
+ if (clazz == null) {
clazz = super.getClazzForName(name);
- if (clazz != null){
+ if (clazz != null) {
clazzMap.put(name, clazz);
}
}
1.1 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzAttribute.java
Index: ClazzAttribute.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
/**
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: ClazzAttribute.java,v 1.1 2003/01/20 18:29:41 dmitri Exp $
*/
public interface ClazzAttribute {
/**
* An attribute has a name, perhaps qualified. For example,
* if you have an attribute like @javabean.property name="foo", the
* attribute name will be "javabean.property.name"
*/
String getName();
/**
* Returns the attribute value.
*/
Object getValue();
}
1.3 +3 -4 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BasicBean.java
Index: BasicBean.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BasicBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BasicBean.java 14 Dec 2002 02:38:41 -0000 1.2
+++ BasicBean.java 20 Jan 2003 18:29:41 -0000 1.3
@@ -84,8 +84,7 @@
this(clazz);
for (Iterator iter = initialPropertyValues.entrySet().iterator();
iter.hasNext();
- )
- {
+ ) {
Map.Entry element = (Map.Entry) iter.next();
set((String) element.getKey(), element.getValue());
}
@@ -109,7 +108,7 @@
}
/**
- * @see org.apache.commons.clazz.bean.Bean#set(java.lang.String, java.lang.Object)
+ * @see Bean#set(String, Object)
*/
public void set(String propertyName, Object value) {
// @todo validate property name and value type using the clazz
1.2 +4 -4 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/Bean.java
Index: Bean.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/Bean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Bean.java 6 Dec 2002 01:12:48 -0000 1.1
+++ Bean.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -69,11 +69,11 @@
*
* @return the meta bean for the bean
*/
- public Clazz getClazz();
+ Clazz getClazz();
- public Object get(String propertyName);
+ Object get(String propertyName);
- public void set(String propertyName, Object value);
+ void set(String propertyName, Object value);
}
1.3 +77 -75 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazz.java
Index: BeanClazz.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazz.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BeanClazz.java 14 Dec 2002 02:38:41 -0000 1.2
+++ BeanClazz.java 20 Jan 2003 18:29:41 -0000 1.3
@@ -79,8 +79,7 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class BeanClazz extends Clazz
-{
+public class BeanClazz extends Clazz {
private Clazz superClazz;
private List declaredProperties = new ArrayList();
private List properties = new ArrayList();
@@ -92,7 +91,7 @@
private Map instanceFactoryMap = new HashMap();
private Class instanceClass;
private List subclasses = new ArrayList();
-
+
/**
* Constructor for BeanClazz.
* @param loader
@@ -103,19 +102,19 @@
super(loader, name);
this.instanceClass = instanceClass;
}
-
- public Class getInstanceClass(){
- if (instanceClass != null){
+
+ public Class getInstanceClass() {
+ if (instanceClass != null) {
return instanceClass;
}
-
- if (superClazz instanceof BeanClazz){
- return ((BeanClazz)superClazz).getInstanceClass();
+
+ if (superClazz instanceof BeanClazz) {
+ return ((BeanClazz) superClazz).getInstanceClass();
}
-
+
return BasicBean.class;
}
-
+
/**
* @see org.apache.commons.clazz.Clazz#getSuperclazz()
*/
@@ -124,25 +123,25 @@
}
public void setSuperclazz(Clazz clazz) {
- if (superClazz != null){
- superClazz.removeClazzChangeListener(listener);
+ if (superClazz != null) {
+ superClazz.removeClazzChangeListener(listener);
}
superClazz = clazz;
- if (clazz != null){
+ if (clazz != null) {
superClazz.addClazzChangeListener(listener);
}
refreshAllCaches();
}
- protected void refreshAllCaches(){
+ protected void refreshAllCaches() {
refreshPropertyCache();
refreshOperationCache();
}
- protected void refreshPropertyCache(){
+ protected void refreshPropertyCache() {
properties = new ArrayList();
propertyMap = new HashMap();
-
+
Set propertyNames = new HashSet();
if (superClazz != null) {
List superProperties = superClazz.getProperties();
@@ -160,14 +159,14 @@
properties.add(property);
}
}
-
+
for (Iterator iter = properties.iterator(); iter.hasNext();) {
ClazzProperty property = (ClazzProperty) iter.next();
propertyMap.put(property.getName(), property);
}
}
-
- protected void refreshOperationCache(){
+
+ protected void refreshOperationCache() {
List operations = new ArrayList();
Set signatures = new HashSet();
if (superClazz != null) {
@@ -188,45 +187,45 @@
}
}
}
-
+
/**
* @see org.apache.commons.clazz.Clazz#getDeclaredProperties()
*/
public List getDeclaredProperties() {
return Collections.unmodifiableList(declaredProperties);
}
-
- public void addDeclaredProperty(ClazzProperty property){
+
+ public void addDeclaredProperty(ClazzProperty property) {
if (property.getDeclaringClazz() != this) {
throw new BeanClazzConfigurationException(
"Property belongs to a different clazz: "
+ property.getDeclaringClazz().getName());
}
-
+
ClazzProperty oldProperty =
(ClazzProperty) propertyMap.get(property.getName());
if (oldProperty != null) {
removeDeclaredProperty(oldProperty);
}
-
+
declaredProperties.add(property);
addProperty(property);
}
-
+
/**
* Called indirectly when declared properties are manipulated.
*/
- protected void addProperty(ClazzProperty property){
+ protected void addProperty(ClazzProperty property) {
properties.add(property);
propertyMap.put(property.getName(), property);
firePropertyAdded(property);
}
-
- public void removeDeclaredProperty(ClazzProperty property){
+
+ public void removeDeclaredProperty(ClazzProperty property) {
String name = property.getName();
- property = (ClazzProperty)propertyMap.get(name);
- if (property != null){
+ property = (ClazzProperty) propertyMap.get(name);
+ if (property != null) {
declaredProperties.remove(property);
removeProperty(property);
}
@@ -234,20 +233,20 @@
/**
* Called indirectly when declared properties are manipulated.
- */
- protected void removeProperty(ClazzProperty property){
+ */
+ protected void removeProperty(ClazzProperty property) {
String name = property.getName();
properties.remove(property);
propertyMap.remove(name);
firePropertyRemoved(property);
-
+
// By deleting this declared property, we may have exposed
// an inherited one
- if (superClazz != null){
+ if (superClazz != null) {
property = superClazz.getProperty(name);
- if (property != null){
+ if (property != null) {
addProperty(property);
- }
+ }
}
}
@@ -262,7 +261,7 @@
* @see org.apache.commons.clazz.Clazz#getProperty(java.lang.String)
*/
public ClazzProperty getProperty(String name) {
- return (ClazzProperty)propertyMap.get(name);
+ return (ClazzProperty) propertyMap.get(name);
}
/**
@@ -272,13 +271,13 @@
return Collections.unmodifiableList(declaredOperations);
}
- public void addDeclaredOperation(ClazzOperation operation){
+ public void addDeclaredOperation(ClazzOperation operation) {
if (operation.getDeclaringClazz() != this) {
throw new BeanClazzConfigurationException(
"Operation belongs to a different clazz: "
+ operation.getDeclaringClazz().getName());
}
-
+
ClazzOperation oldOperation =
(ClazzOperation) operationMap.get(operation.getSignature());
if (oldOperation != null) {
@@ -293,16 +292,16 @@
/**
* Called indirectly when declared operations are manipulated.
*/
- protected void addOperation(ClazzOperation operation){
+ protected void addOperation(ClazzOperation operation) {
operations.add(operation);
operationMap.put(operation.getSignature(), operation);
fireOperationAdded(operation);
}
- public void removeDeclaredOperation(ClazzOperation operation){
+ public void removeDeclaredOperation(ClazzOperation operation) {
String signature = operation.getSignature();
- operation = (ClazzOperation)operationMap.get(signature);
- if (operation != null){
+ operation = (ClazzOperation) operationMap.get(signature);
+ if (operation != null) {
declaredOperations.remove(operation);
removeOperation(operation);
}
@@ -311,7 +310,7 @@
/**
* Called indirectly when declared operations are manipulated.
*/
- protected void removeOperation(ClazzOperation operation){
+ protected void removeOperation(ClazzOperation operation) {
String signature = operation.getSignature();
operations.remove(operation);
operationMap.remove(signature);
@@ -319,9 +318,9 @@
// By deleting this declared operation, we may have exposed
// an inherited one
- if (superClazz != null){
+ if (superClazz != null) {
operation = superClazz.getOperation(signature);
- if (operation != null){
+ if (operation != null) {
addOperation(operation);
}
}
@@ -338,14 +337,14 @@
* @see org.apache.commons.clazz.Clazz#getOperation(java.lang.String)
*/
public ClazzOperation getOperation(String signature) {
- return (ClazzOperation)operationMap.get(signature);
+ return (ClazzOperation) operationMap.get(signature);
}
/**
* @see org.apache.commons.clazz.Clazz#getInstanceFactories()
*/
public List getInstanceFactories() {
- if (instanceFactories == null){
+ if (instanceFactories == null) {
introspectInstanceFactories();
}
return Collections.unmodifiableList(instanceFactories);
@@ -355,36 +354,36 @@
* @see org.apache.commons.clazz.Clazz#getInstanceFactory(java.lang.String)
*/
public ClazzInstanceFactory getInstanceFactory(String signature) {
- if (instanceFactories == null){
+ if (instanceFactories == null) {
introspectInstanceFactories();
}
- return (ClazzInstanceFactory)instanceFactoryMap.get(signature);
+ return (ClazzInstanceFactory) instanceFactoryMap.get(signature);
}
- public void addInstanceFactory(ClazzInstanceFactory factory){
+ public void addInstanceFactory(ClazzInstanceFactory factory) {
if (factory.getDeclaringClazz() != this) {
throw new BeanClazzConfigurationException(
"Instance factory belongs to a different clazz: "
+ factory.getDeclaringClazz().getName());
}
- if (instanceFactories == null){
+ if (instanceFactories == null) {
introspectInstanceFactories();
}
ClazzInstanceFactory oldFactory =
(ClazzInstanceFactory) instanceFactoryMap.get(
factory.getSignature());
- if (oldFactory != null){
+ if (oldFactory != null) {
removeInstanceFactory(oldFactory);
}
instanceFactories.add(factory);
- instanceFactoryMap.put(factory.getSignature(), factory);
+ instanceFactoryMap.put(factory.getSignature(), factory);
fireInstanceFactoryAdded(factory);
}
-
- public void removeInstanceFactory(ClazzInstanceFactory factory){
- if (instanceFactories.remove(factory)){
+
+ public void removeInstanceFactory(ClazzInstanceFactory factory) {
+ if (instanceFactories.remove(factory)) {
instanceFactoryMap.remove(factory.getSignature());
fireInstanceFactoryRemoved(factory);
}
@@ -405,8 +404,8 @@
for (int i = 0; i < constructors.length; i++) {
Class[] parameterTypes = constructors[i].getParameterTypes();
if (parameterTypes != null
- && parameterTypes.length >= 1
- && Clazz.class.isAssignableFrom(parameterTypes[0])) {
+ && parameterTypes.length >= 1
+ && Clazz.class.isAssignableFrom(parameterTypes[0])) {
addInstanceFactory(
new BeanClazzConstructorInstanceFactory(
this,
@@ -414,44 +413,47 @@
}
}
}
-
- private ClazzChangeListener listener = new ClazzChangeListener()
- {
+
+ private ClazzChangeListener listener = new ClazzChangeListener() {
public void propertyAdded(Clazz clazz, ClazzProperty property) {
- if (propertyMap.get(property.getName()) == null){
+ if (propertyMap.get(property.getName()) == null) {
addProperty(property);
}
}
-
+
public void propertyRemoved(Clazz clazz, ClazzProperty property) {
ClazzProperty declared =
(ClazzProperty) propertyMap.get(property.getName());
- if (declared != null && declared.equals(property)){
+ if (declared != null && declared.equals(property)) {
removeProperty(property);
}
}
-
+
public void operationAdded(Clazz clazz, ClazzOperation operation) {
- if (operationMap.get(operation.getSignature()) == null){
+ if (operationMap.get(operation.getSignature()) == null) {
addOperation(operation);
}
}
-
+
public void operationRemoved(Clazz clazz, ClazzOperation operation) {
ClazzOperation declared =
(ClazzOperation) operationMap.get(operation.getSignature());
- if (declared != null && declared.equals(operation)){
+ if (declared != null && declared.equals(operation)) {
removeOperation(operation);
}
}
-
+
public void instanceFactoryAdded(
- Clazz clazz, ClazzInstanceFactory property) {
+ Clazz clazz,
+ ClazzInstanceFactory property)
+ {
// Ignore - factories are not inherited
}
-
+
public void instanceFactoryRemoved(
- Clazz clazz, ClazzInstanceFactory property) {
+ Clazz clazz,
+ ClazzInstanceFactory property)
+ {
// Ignore - factories are not inherited
}
};
1.2 +4 -4 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzConfigurationException.java
Index: BeanClazzConfigurationException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzConfigurationException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanClazzConfigurationException.java 14 Dec 2002 02:38:41 -0000 1.1
+++ BeanClazzConfigurationException.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -86,14 +86,14 @@
this.cause = cause;
}
- public String getMessage(){
- if (cause == null){
+ public String getMessage() {
+ if (cause == null) {
return super.getMessage();
}
return super.getMessage() + "; " + cause.getMessage();
}
- public Throwable getCause(){
+ public Throwable getCause() {
return cause;
}
}
1.2 +8 -8 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzConstructorInstanceFactory.java
Index: BeanClazzConstructorInstanceFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzConstructorInstanceFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanClazzConstructorInstanceFactory.java 14 Dec 2002 02:38:41 -0000 1.1
+++ BeanClazzConstructorInstanceFactory.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -93,11 +93,11 @@
this.constructor = constructor;
}
- public Constructor getConstructor(){
+ public Constructor getConstructor() {
return constructor;
}
- public String getName(){
+ public String getName() {
return null;
}
@@ -116,11 +116,11 @@
* @see org.apache.commons.clazz.ClazzOperation#getParameterClazzes()
*/
public Clazz[] getParameterClazzes() {
- if (parameterClazzes == null){
+ if (parameterClazzes == null) {
Class paramClasses[] = getVisibleParameterTypes();
parameterClazzes = new Clazz[paramClasses.length];
ClazzLoader loader = getDeclaringClazz().getClazzLoader();
- for (int i = 0; i < paramClasses.length; i++){
+ for (int i = 0; i < paramClasses.length; i++) {
String name = Clazz.getCanonicalClassName(paramClasses[i]);
parameterClazzes[i] = loader.getClazzForName(name);
}
@@ -141,10 +141,10 @@
try {
// Insert the declaring clazz as the invisible first parameter
int length = (parameters == null ? 0 : parameters.length);
- Object allParameters[] = new Object[length+1];
+ Object allParameters[] = new Object[length + 1];
allParameters[0] = getDeclaringClazz();
for (int i = 0; i < length; i++) {
- allParameters[i+1] = parameters[i];
+ allParameters[i + 1] = parameters[i];
}
return constructor.newInstance(allParameters);
}
@@ -155,7 +155,7 @@
}
}
- public String toString(){
+ public String toString() {
return getSignature();
}
}
1.2 +3 -3 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzInstanceFactory.java
Index: BeanClazzInstanceFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzInstanceFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanClazzInstanceFactory.java 14 Dec 2002 02:38:41 -0000 1.1
+++ BeanClazzInstanceFactory.java 20 Jan 2003 18:29:41 -0000 1.2
@@ -68,7 +68,7 @@
implements ClazzInstanceFactory
{
private String name;
- private final String[] EMPTY_STRING_ARRAY = new String[0];
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
private String[] parameterClazzNames;
private Clazz[] parameterClazzes;
private String signature;
@@ -115,7 +115,7 @@
for (int i = 0; i < parameterClazzes.length; i++) {
parameterClazzes[i] =
loader.getClazzForName(parameterClazzNames[i]);
- if (parameterClazzes[i] == null){
+ if (parameterClazzes[i] == null) {
throw new BeanClazzConfigurationException(
"Invalid argument type: "
+ parameterClazzNames[i]
1.4 +5 -5 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzLoader.java
Index: BeanClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BeanClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.3
+++ BeanClazzLoader.java 20 Jan 2003 18:29:41 -0000 1.4
@@ -66,7 +66,7 @@
*/
public class BeanClazzLoader extends ClazzLoader {
- public BeanClazzLoader(ModelClazzLoader modelClazzLoader){
+ public BeanClazzLoader(ModelClazzLoader modelClazzLoader) {
super(modelClazzLoader);
}
@@ -78,18 +78,18 @@
}
public String getClazzName(Object instance) {
- if (!isMember(instance)){
+ if (!isMember(instance)) {
return null;
}
- return ((Bean)instance).getClazz().getName();
+ return ((Bean) instance).getClazz().getName();
}
/**
* BeanClazzLoader does not cache clazzes, its parent, BeanGroupClazzLoader,
* is responsible for caching
*/
- public Clazz getClazzForName(String clazzName){
+ public Clazz getClazzForName(String clazzName) {
return null;
}
1.3 +5 -5 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzOperation.java
Index: BeanClazzOperation.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzOperation.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BeanClazzOperation.java 9 Jan 2003 03:23:59 -0000 1.2
+++ BeanClazzOperation.java 20 Jan 2003 18:29:41 -0000 1.3
@@ -70,7 +70,7 @@
private String returnClazzName;
private Clazz returnClazz;
private String name;
- private final String[] EMPTY_STRING_ARRAY = new String[0];
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
private String[] parameterClazzNames;
private Clazz[] parameterClazzes;
private String signature;
@@ -105,7 +105,7 @@
*/
public String getSignature() {
if (signature == null) {
- signature = Clazz.constructSignature(name, getParameterClazzes());
+ signature = Clazz.constructSignature(name, getParameterClazzes());
}
return signature;
@@ -128,7 +128,7 @@
for (int i = 0; i < parameterClazzes.length; i++) {
parameterClazzes[i] =
loader.getClazzForName(parameterClazzNames[i]);
- if (parameterClazzes[i] == null){
+ if (parameterClazzes[i] == null) {
throw new BeanClazzConfigurationException(
"Invalid argument type: "
+ parameterClazzNames[i]
@@ -144,7 +144,7 @@
* @see ClazzOperation#getReturnClazz()
*/
public Clazz getReturnClazz() {
- if (returnClazzName == null){
+ if (returnClazzName == null) {
return null;
}
1.3 +13 -12 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzProperty.java
Index: BeanClazzProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzProperty.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BeanClazzProperty.java 14 Dec 2002 02:38:41 -0000 1.2
+++ BeanClazzProperty.java 20 Jan 2003 18:29:41 -0000 1.3
@@ -63,30 +63,31 @@
* @version $Id$
*/
public class BeanClazzProperty extends ClazzFeatureSupport
- implements ClazzProperty {
+ implements ClazzProperty
+{
private String name;
private String clazzName;
private String type;
private Clazz clazz;
-
+
public BeanClazzProperty(Clazz declaringClazz, String name) {
this(declaringClazz, name, Object.class.getName());
}
-
+
public BeanClazzProperty(Clazz declaringClazz, String name, String type) {
super(declaringClazz);
this.name = name;
this.clazzName = type;
}
-
+
/**
* @see org.apache.commons.clazz.ClazzProperty#getName()
*/
public String getName() {
return name;
}
-
+
/**
* @see org.apache.commons.clazz.ClazzProperty#getClazz()
*/
@@ -101,17 +102,17 @@
/**
* Returns true if the property is a collection.
*/
- public boolean isCollection(){
+ public boolean isCollection() {
return false;
}
/**
* Returns true if the property is a map.
*/
- public boolean isMap(){
+ public boolean isMap() {
return false;
}
-
+
/**
* @see org.apache.commons.clazz.ClazzProperty#getContentClazz()
*/
@@ -137,14 +138,14 @@
* @see org.apache.commons.clazz.ClazzProperty#get(java.lang.Object)
*/
public Object get(Object instance) {
- return ((Bean)instance).get(getName());
+ return ((Bean) instance).get(getName());
}
/**
- * @see org.apache.commons.clazz.ClazzProperty#set(java.lang.Object, java.lang.Object)
+ * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object)
*/
public void set(Object instance, Object value) {
- ((Bean)instance).set(getName(), value);
+ ((Bean) instance).set(getName(), value);
}
}
1.4 +4 -4 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanGroupClazzLoader.java
Index: BeanGroupClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanGroupClazzLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BeanGroupClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.3
+++ BeanGroupClazzLoader.java 20 Jan 2003 18:29:41 -0000 1.4
@@ -64,11 +64,11 @@
*/
public class BeanGroupClazzLoader extends GroupClazzLoader {
- public BeanGroupClazzLoader(ModelClazzLoader modelClazzLoader){
+ public BeanGroupClazzLoader(ModelClazzLoader modelClazzLoader) {
super(modelClazzLoader);
}
- public boolean canAddClazzLoader(ClazzLoader loader){
+ public boolean canAddClazzLoader(ClazzLoader loader) {
return loader instanceof BeanClazzLoader;
}
@@ -84,7 +84,7 @@
public String getClazzName(Object instance) {
// This is just an optimization - the Group can answer for all
// of its members without checking with each one individually
- if (!isMember(instance)){
+ if (!isMember(instance)) {
return null;
}
return super.getClazzName(instance);
1.2 +6 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzElementSupport.java
Index: ClazzElementSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzElementSupport.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClazzElementSupport.java 16 Dec 2002 23:17:41 -0000 1.1
+++ ClazzElementSupport.java 20 Jan 2003 18:29:42 -0000 1.2
@@ -53,6 +53,7 @@
*/
package org.apache.commons.clazz.common;
+import org.apache.commons.clazz.ClazzAttribute;
import org.apache.commons.clazz.ClazzElement;
/**
@@ -65,9 +66,12 @@
/**
* @see org.apache.commons.clazz.ClazzElement#getAttribute(java.lang.String)
*/
- public Object getAttribute(String attribute) {
+ public ClazzAttribute getAttribute(String attribute) {
throw new UnsupportedOperationException(
"No such attribute: " + attribute);
}
+ public ClazzAttribute[] getAttributes() {
+ return new ClazzAttribute[0];
+ }
}
1.3 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzFeatureSupport.java
Index: ClazzFeatureSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzFeatureSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ClazzFeatureSupport.java 16 Dec 2002 23:17:41 -0000 1.2
+++ ClazzFeatureSupport.java 20 Jan 2003 18:29:42 -0000 1.3
@@ -73,7 +73,7 @@
* Constructor for ClazzFeature.
*/
public ClazzFeatureSupport(Clazz declaringClazz) {
- if (declaringClazz == null){
+ if (declaringClazz == null) {
throw new NullPointerException("Declaring Clazz cannot be null");
}
this.declaringClazz = declaringClazz;
1.3 +12 -12 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzLoaderFactorySupport.java
Index: ClazzLoaderFactorySupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzLoaderFactorySupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ClazzLoaderFactorySupport.java 9 Jan 2003 03:23:59 -0000 1.2
+++ ClazzLoaderFactorySupport.java 20 Jan 2003 18:29:42 -0000 1.3
@@ -57,10 +57,10 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.clazz.*;
import org.apache.commons.clazz.ClazzAccessException;
import org.apache.commons.clazz.ClazzLoader;
import org.apache.commons.clazz.ClazzLoaderFactory;
+import org.apache.commons.clazz.ModelClazzLoader;
import org.apache.commons.collections.ReferenceMap;
/**
@@ -71,12 +71,12 @@
public abstract class ClazzLoaderFactorySupport implements ClazzLoaderFactory {
private List clazzLoaderClasses = new ArrayList();
-
+
private ClazzLoader defaultClazzLoader;
-
+
private ReferenceMap clazzLoaders =
new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD);
-
+
/**
* Constructor for ClazzLoaderFactorySupport.
*/
@@ -84,7 +84,7 @@
}
/**
- * @see org.apache.commons.clazz.ClazzLoaderFactory#getClazzLoader(java.lang.ClassLoader)
+ * @see ClazzLoaderFactory#getClazzLoader(ClassLoader)
*/
public synchronized ClazzLoader getClazzLoader(
ClassLoader contextClassLoader)
@@ -105,10 +105,8 @@
return loader;
}
}
-
- protected ClazzLoader createClazzLoader(
- ClassLoader contextClassLoader)
- {
+
+ protected ClazzLoader createClazzLoader(ClassLoader contextClassLoader) {
ModelClazzLoader modelClazzLoader =
new ModelClazzLoader(getClazzModel());
@@ -124,7 +122,7 @@
return modelClazzLoader;
}
-
+
protected ClazzLoader allocateClazzLoader(
ModelClazzLoader modelClazzLoader,
Class javaClass,
@@ -140,6 +138,7 @@
ClassLoader.class });
}
catch (NoSuchMethodException e) {
+ // Won't happen
}
if (constructor != null) {
return (ClazzLoader) constructor.newInstance(
@@ -152,6 +151,7 @@
new Class[] { ModelClazzLoader.class });
}
catch (NoSuchMethodException e) {
+ // Won't happen
}
if (constructor != null) {
return (ClazzLoader) constructor.newInstance(
@@ -165,7 +165,7 @@
e);
}
}
-
+
public void addClazzLoaderClass(Class clazzLoaderClass) {
clazzLoaderClasses.add(clazzLoaderClass);
}
1.4 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ExtendedClazzLoaderFactory.java
Index: ExtendedClazzLoaderFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ExtendedClazzLoaderFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ExtendedClazzLoaderFactory.java 9 Jan 2003 03:23:59 -0000 1.3
+++ ExtendedClazzLoaderFactory.java 20 Jan 2003 18:29:42 -0000 1.4
@@ -81,7 +81,7 @@
addClazzLoaderClass(BeanClazzLoader.class);
}
- public String getClazzModel(){
+ public String getClazzModel() {
return MODEL;
}
}
1.4 +31 -57 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/GroupClazzLoader.java
Index: GroupClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/GroupClazzLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GroupClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.3
+++ GroupClazzLoader.java 20 Jan 2003 18:29:42 -0000 1.4
@@ -68,38 +68,37 @@
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class GroupClazzLoader extends ClazzLoader
-{
+public class GroupClazzLoader extends ClazzLoader {
/**
* List of member loaders. Note that the list is always iterated in the
* reverse direction, so the loaded add last is the one invoked first.
*/
protected ArrayList loaders = new ArrayList();
- public GroupClazzLoader(ModelClazzLoader modelClazzLoader){
+ public GroupClazzLoader(ModelClazzLoader modelClazzLoader) {
super(modelClazzLoader);
}
-
+
/**
* Returns true if the supplied loader "belongs" in the group and can be
* added to it. The default implementation returns true.
*/
- public boolean canAddClazzLoader(ClazzLoader loader){
+ public boolean canAddClazzLoader(ClazzLoader loader) {
return true;
}
-
+
/**
* Adds a ClazzLoader to the group. ClazzLoaders added last are invoked
* first. Before the group adds the loader to itself, it checks if any
* of its members are groups themselves and, if so, tries to add the new
* loader to those subgroups.
*/
- public void addClazzLoader(ClazzLoader loader){
- for (int i = loaders.size(); --i >= 0; ){
- ClazzLoader member = (ClazzLoader)loaders.get(i);
- if (member instanceof GroupClazzLoader){
- GroupClazzLoader group = (GroupClazzLoader)member;
- if (group.canAddClazzLoader(loader)){
+ public void addClazzLoader(ClazzLoader loader) {
+ for (int i = loaders.size(); --i >= 0;) {
+ ClazzLoader member = (ClazzLoader) loaders.get(i);
+ if (member instanceof GroupClazzLoader) {
+ GroupClazzLoader group = (GroupClazzLoader) member;
+ if (group.canAddClazzLoader(loader)) {
group.addClazzLoader(loader);
return;
}
@@ -107,16 +106,16 @@
}
loaders.add(loader);
}
-
+
/**
* Returns true iff this group has a member loader that has or can construct
* a Clazz for the supplied instance.
*/
- public boolean isMember(Object instance){
+ public boolean isMember(Object instance) {
// Note the reverse order
- for (int i = loaders.size(); --i >= 0; ){
- ClazzLoader loader = (ClazzLoader)loaders.get(i);
- if (loader.isMember(instance)){
+ for (int i = loaders.size(); --i >= 0;) {
+ ClazzLoader loader = (ClazzLoader) loaders.get(i);
+ if (loader.isMember(instance)) {
return true;
}
}
@@ -125,10 +124,10 @@
public String getClazzName(Object instance) {
// Note the reverse order
- for (int i = loaders.size(); --i >= 0; ){
- ClazzLoader loader = (ClazzLoader)loaders.get(i);
+ for (int i = loaders.size(); --i >= 0;) {
+ ClazzLoader loader = (ClazzLoader) loaders.get(i);
String name = loader.getClazzName(instance);
- if (name != null){
+ if (name != null) {
return name;
}
}
@@ -142,23 +141,23 @@
public Clazz getClazzForName(String name) {
Clazz clazz = null;
// Note the reverse order
- for (int i = loaders.size(); --i >= 0; ){
- ClazzLoader loader = (ClazzLoader)loaders.get(i);
+ for (int i = loaders.size(); --i >= 0;) {
+ ClazzLoader loader = (ClazzLoader) loaders.get(i);
clazz = loader.getClazzForName(name);
- if (clazz != null){
+ if (clazz != null) {
break;
}
}
return clazz;
}
-
+
/**
* @see ClazzLoader#defineClazz(String, Class, Class)
*/
public Clazz defineClazz(
- String name,
- Class clazzClass,
- Class instanceClass)
+ String name,
+ Class clazzClass,
+ Class instanceClass)
{
Clazz clazz = null;
// Note the reverse order
@@ -173,41 +172,16 @@
}
/**
- * Adds a ClazzLoader to the group. The added clazz loader will be
- * invoked before the one supplied as the second argument.
- */
-/*
- public void addClazzLoader(ClazzLoader loader, ClazzLoader invokeBefore){
- if (invokeBefore == null){
- addClazzLoader(loader);
- return;
- }
-
- int index = loaders.indexOf(invokeBefore);
- if (index == -1){
- throw new IllegalArgumentException(
- "ClazzLoader "
- + invokeBefore.getClass().getName()
- + " is not a member of the group");
- }
-
- // In order to be invoked before, the clazz loader needs to be
- // inserted after the parameter.
- loaders.add(index + 1, loader);
- }
-*/
-
- /**
* Returns all clazz loaders registered with this group,
* in the order of priority
- */
- public List getClazzLoaders(){
+ */
+ public List getClazzLoaders() {
return Collections.unmodifiableList(loaders);
}
/**
* Returns clazzloaders matching the supplied Predicate
- */
-// public List getClazzLoaders(Predicate predicate){
+ */
+// public List getClazzLoaders(Predicate predicate) {
// }
}
1.4 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/StandardClazzLoaderFactory.java
Index: StandardClazzLoaderFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/StandardClazzLoaderFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StandardClazzLoaderFactory.java 9 Jan 2003 03:23:59 -0000 1.3
+++ StandardClazzLoaderFactory.java 20 Jan 2003 18:29:42 -0000 1.4
@@ -81,7 +81,7 @@
addClazzLoaderClass(BeanClazzLoader.class);
}
- public String getClazzModel(){
+ public String getClazzModel() {
return MODEL;
}
}
1.6 +219 -90 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedClazz.java
Index: ReflectedClazz.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedClazz.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ReflectedClazz.java 9 Jan 2003 03:23:59 -0000 1.5
+++ ReflectedClazz.java 20 Jan 2003 18:29:42 -0000 1.6
@@ -53,9 +53,24 @@
*/
package org.apache.commons.clazz.reflect;
-import java.util.*;
-
-import org.apache.commons.clazz.*;
+import java.beans.BeanInfo;
+import java.beans.IndexedPropertyDescriptor;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.clazz.Clazz;
+import org.apache.commons.clazz.ClazzInstanceFactory;
+import org.apache.commons.clazz.ClazzLoader;
+import org.apache.commons.clazz.ClazzOperation;
+import org.apache.commons.clazz.ClazzProperty;
+import org.apache.commons.clazz.reflect.common.ReflectedListProperty;
+import org.apache.commons.clazz.reflect.common.ReflectedScalarProperty;
/**
* This implementation of Clazz is based on Java reflection.
@@ -68,44 +83,44 @@
private Class instanceClass;
private boolean superClazzKnown;
private Clazz superClazz;
-
+
/**
* This map includes all properties, declared and inherited
*/
private Map propertyMap;
private List propertyList;
private List declaredPropertyList;
-
+
/**
* This map includes all operations, declared and inherited
*/
private Map operationMap;
private List operationList;
private List declaredOperationList;
-
+
/**
* This map includes all factories
*/
private Map factoryMap;
private List factoryList;
+
+ private boolean hasLookedForBeanInfo = false;
+ private BeanInfo beanInfo;
/**
*
* @param loader
* @param instanceClass
*/
- public ReflectedClazz(
- ClazzLoader loader,
- Class instanceClass)
- {
+ public ReflectedClazz(ClazzLoader loader, Class instanceClass) {
super(loader, getCanonicalClassName(instanceClass));
this.instanceClass = instanceClass;
}
-
- public Class getInstanceClass(){
+
+ public Class getInstanceClass() {
return instanceClass;
}
-
+
/**
* The order of introspectors is significant, they are invoked sequencially.
* Once a property has been recoginzed by an introspector, it will not be
@@ -125,32 +140,35 @@
*/
protected abstract ReflectedInstanceFactoryIntrospector[]
getInstanceFactoryIntrospectors();
-
+
/**
- * Returns true if diagnostic is enabled for this clazz
*/
- public boolean isLoggingEnabled(){
+ * Returns true if diagnostic is enabled for this clazz
+ */
+ public boolean isLoggingEnabled() {
return getClazzLoader().isLoggingEnabled(getName());
}
-
+
/**
- * Returns the class this ReflectedClazz is based upon.
* @return Class
*/
- public Class getReflectedClass(){
+ * Returns the class this ReflectedClazz is based upon.
+ * @return Class
+ */
+ public Class getReflectedClass() {
return instanceClass;
}
-
+
/**
* @see Clazz#getSuperclazz()
*/
public Clazz getSuperclazz() {
- if (!superClazzKnown){
+ if (!superClazzKnown) {
superClazzKnown = true;
Class superclass = instanceClass.getSuperclass();
- if (superclass == null){
+ if (superclass == null) {
superClazz = null;
}
else {
- superClazz = getClazzLoader().
- getClazzForName(superclass.getName());
+ superClazz =
+ getClazzLoader().getClazzForName(superclass.getName());
}
}
return superClazz;
@@ -166,32 +184,32 @@
* and then subtract the latter from the former.
*/
public List getDeclaredProperties() {
- if (declaredPropertyList == null){
- if (instanceClass.getSuperclass() == null){
+ if (declaredPropertyList == null) {
+ if (instanceClass.getSuperclass() == null) {
declaredPropertyList = getProperties();
}
else {
List superProperties = getSuperclazz().getProperties();
- if (superProperties.size() == 0){
+ if (superProperties.size() == 0) {
declaredPropertyList = getProperties();
}
else {
HashSet superNames = new HashSet();
- for (int i = 0; i < superProperties.size(); i++){
- ClazzProperty property =
- (ClazzProperty)superProperties.get(i);
+ for (int i = 0; i < superProperties.size(); i++) {
+ ClazzProperty property =
+ (ClazzProperty) superProperties.get(i);
superNames.add(property.getName());
- }
-
+ }
+
List properties = getProperties();
- declaredPropertyList = new ArrayList();
- for (int i = 0; i < properties.size(); i++){
+ declaredPropertyList = new ArrayList();
+ for (int i = 0; i < properties.size(); i++) {
ClazzProperty property =
(ClazzProperty) properties.get(i);
String name = property.getName();
- if (!superNames.contains(name)){
+ if (!superNames.contains(name)) {
declaredPropertyList.add(property);
- }
+ }
}
}
}
@@ -202,7 +220,7 @@
/**
*/
public List getProperties() {
- if (propertyList == null){
+ if (propertyList == null) {
introspectProperties();
if (isLoggingEnabled()) {
logPropertyParseResults();
@@ -214,30 +232,30 @@
/**
*/
public ClazzProperty getProperty(String name) {
- if (propertyMap == null){
+ if (propertyMap == null) {
introspectProperties();
if (isLoggingEnabled()) {
logPropertyParseResults();
}
}
- return (ClazzProperty)propertyMap.get(name);
+ return (ClazzProperty) propertyMap.get(name);
}
- protected void addProperty(ClazzProperty property){
+ protected void addProperty(ClazzProperty property) {
propertyMap.put(property.getName(), property);
- if (property instanceof ReflectedProperty){
- String[] aliases = ((ReflectedProperty)property).getAliases();
+ if (property instanceof ReflectedProperty) {
+ String[] aliases = ((ReflectedProperty) property).getAliases();
for (int i = 0; i < aliases.length; i++) {
propertyMap.put(aliases[i], property);
}
}
propertyList.add(property);
}
-
+
/**
*/
public List getOperations() {
- if (operationList == null){
+ if (operationList == null) {
introspectOperations();
// if (isLoggingEnabled()) {
// logOperationParseResults();
@@ -247,10 +265,10 @@
}
/**
- * @see org.apache.commons.clazz.Clazz#getDeclaredOperations()
+ * @see Clazz#getDeclaredOperations()
*/
public List getDeclaredOperations() {
- if (declaredOperationList == null){
+ if (declaredOperationList == null) {
introspectOperations();
// if (isLoggingEnabled()) {
// logOperationParseResults();
@@ -260,19 +278,19 @@
}
/**
- * @see org.apache.commons.clazz.Clazz#getOperation(java.lang.String)
+ * @see Clazz#getOperation(java.lang.String)
*/
public ClazzOperation getOperation(String signature) {
- if (operationMap == null){
+ if (operationMap == null) {
introspectOperations();
// if (isLoggingEnabled()) {
// logOperationParseResults();
// }
}
- return (ClazzOperation)operationMap.get(signature);
+ return (ClazzOperation) operationMap.get(signature);
}
- protected void addOperation(ClazzOperation operation){
+ protected void addOperation(ClazzOperation operation) {
operationMap.put(operation.getSignature(), operation);
declaredOperationList.add(operation);
}
@@ -280,8 +298,8 @@
/**
* Returns all InstanceFactories for this clazz.
*/
- public List getInstanceFactories(){
- if (factoryList == null){
+ public List getInstanceFactories() {
+ if (factoryList == null) {
introspectInstanceFactories();
// if (isLoggingEnabled()) {
// logInstanceFactoryParseResults();
@@ -293,13 +311,13 @@
/**
* Returns the InstanceFactories that match the Predicate.
*/
-// public List getInstanceFactories(Predicate predicate);
+ // public List getInstanceFactories(Predicate predicate);
/**
* @see org.apache.commons.clazz.Clazz#getInstanceFactory(java.lang.String)
*/
- public ClazzInstanceFactory getInstanceFactory(String signature){
- if (factoryMap == null){
+ public ClazzInstanceFactory getInstanceFactory(String signature) {
+ if (factoryMap == null) {
introspectInstanceFactories();
// if (isLoggingEnabled()) {
// logInstanceFactoryParseResults();
@@ -308,10 +326,10 @@
if (signature == null) {
signature = "()";
}
- return (ClazzInstanceFactory)factoryMap.get(signature);
+ return (ClazzInstanceFactory) factoryMap.get(signature);
}
- protected void addInstanceFactory(ClazzInstanceFactory factory){
+ protected void addInstanceFactory(ClazzInstanceFactory factory) {
factoryMap.put(factory.getSignature(), factory);
factoryList.add(factory);
}
@@ -321,7 +339,7 @@
* also a ReflectedClazz and if so invokes isAssignableFrom on the
* corresponding java classes.
*/
- public boolean isAssignableFrom(Clazz clazz){
+ public boolean isAssignableFrom(Clazz clazz) {
if (clazz == this) {
return true;
}
@@ -335,37 +353,147 @@
/**
* Override this method to provide an alternate way of mapping
* fields and methods to properties.
- */
- protected void introspectProperties()
- {
+ */
+ protected void introspectProperties() {
propertyList = new ArrayList();
propertyMap = new HashMap();
- ReflectedPropertyIntrospector introspectors[] =
- getPropertyIntrospectors();
-
- if (introspectors != null){
- for (int i = 0; i < introspectors.length; i++) {
- List properties =
- introspectors[i].introspectProperties(this, instanceClass);
- for (int j = 0; j < properties.size(); j++) {
- ClazzProperty property = (ClazzProperty) properties.get(j);
- addProperty(property);
+ BeanInfo beanInfo = getBeanInfo();
+
+ if (beanInfo != null) {
+ PropertyDescriptor pds[] = beanInfo.getPropertyDescriptors();
+ if (pds != null) {
+ for (int i = 0; i < pds.length; i++) {
+ PropertyDescriptor pd = pds[i];
+ if (pd instanceof IndexedPropertyDescriptor) {
+ IndexedPropertyDescriptor ipd =
+ (IndexedPropertyDescriptor) pd;
+ ReflectedListProperty prop =
+ new ReflectedListProperty(this, ipd.getName());
+ prop.setType(ipd.getPropertyType());
+ prop.setContentType(ipd.getIndexedPropertyType());
+ prop.setReadMethod(ipd.getReadMethod());
+ prop.setWriteMethod(ipd.getWriteMethod());
+ prop.setGetMethod(ipd.getIndexedReadMethod());
+ prop.setSetMethod(ipd.getIndexedWriteMethod());
+ addProperty(prop);
+ }
+ else {
+ ReflectedScalarProperty prop =
+ new ReflectedScalarProperty(this, pd.getName());
+ prop.setType(pd.getPropertyType());
+ prop.setReadMethod(pd.getReadMethod());
+ prop.setWriteMethod(pd.getWriteMethod());
+ addProperty(prop);
+ }
+ }
+ }
+ }
+ else {
+ ReflectedPropertyIntrospector introspectors[] =
+ getPropertyIntrospectors();
+
+ if (introspectors != null) {
+ for (int i = 0; i < introspectors.length; i++) {
+ List properties =
+ introspectors[i].introspectProperties(
+ this,
+ instanceClass);
+ for (int j = 0; j < properties.size(); j++) {
+ ClazzProperty property =
+ (ClazzProperty) properties.get(j);
+ addProperty(property);
+ }
}
}
}
}
/**
+ * Performs BeanInfo lookup in the same manner as the standard
+ * java.beans.Introspector.
+ */
+ protected BeanInfo getBeanInfo() {
+ if (!hasLookedForBeanInfo) {
+ hasLookedForBeanInfo = true;
+ beanInfo = lookupBeanInfo();
+ }
+ return beanInfo;
+ }
+
+ /**
+ * Search for a custom implementation of BeanInfo according to
+ * the JavaBeans standard definition.
+ */
+ private BeanInfo lookupBeanInfo() {
+ ClassLoader classLoader = instanceClass.getClassLoader();
+
+ String name = instanceClass.getName() + "BeanInfo";
+ try {
+ return (BeanInfo) instantiate(classLoader, name);
+ }
+ catch (Exception ex) {
+ // Just drop through
+ }
+
+ // Now try checking if the bean is its own BeanInfo.
+ try {
+ if (BeanInfo.class.isAssignableFrom(instanceClass)) {
+ return (BeanInfo) instanceClass.newInstance();
+ }
+ }
+ catch (Exception ex) {
+ // Just drop through
+ }
+
+ // Now try looking for <searchPath>.fooBeanInfo
+ while (name.indexOf('.') > 0) {
+ name = name.substring(name.indexOf('.') + 1);
+ }
+
+ String[] searchPath = Introspector.getBeanInfoSearchPath();
+ for (int i = 0; i < searchPath.length; i++) {
+ try {
+ String fullName = searchPath[i] + "." + name;
+ return (BeanInfo) instantiate(classLoader, fullName);
+ }
+ catch (Exception ex) {
+ // Silently ignore any errors.
+ }
+ }
+ return null;
+ }
+
+ static Object instantiate(ClassLoader classLoader, String className)
+ throws
+ InstantiationException,
+ IllegalAccessException,
+ ClassNotFoundException
+ {
+ if (classLoader != null) {
+ try {
+ Class cls = classLoader.loadClass(className);
+ return cls.newInstance();
+ }
+ catch (Exception ex) {
+ // Just drop through and try the system classloader.
+ }
+ }
+
+ // Now try the default classloader.
+ Class cls = Class.forName(className);
+ return cls.newInstance();
+ }
+
+ /**
* Override this method to provide an alternate way of mapping
* methods (and possibly fields) to Operations.
*/
- protected void introspectOperations()
- {
+ protected void introspectOperations() {
declaredOperationList = new ArrayList();
operationMap = new HashMap();
operationList = new ArrayList();
-
+
Clazz superClazz = getSuperclazz();
if (superClazz != null) {
List superOps = superClazz.getOperations();
@@ -378,32 +506,32 @@
ReflectedOperationIntrospector introspectors[] =
getOperationIntrospectors();
- if (introspectors != null){
+ if (introspectors != null) {
for (int i = 0; i < introspectors.length; i++) {
List operations =
introspectors[i].introspectOperations(this, instanceClass);
for (int j = 0; j < operations.size(); j++) {
- ClazzOperation operation = (ClazzOperation) operations.get(j);
+ ClazzOperation operation =
+ (ClazzOperation) operations.get(j);
addOperation(operation);
}
}
}
operationList.addAll(operationMap.values());
}
-
+
/**
* Override this method to provide an alternate way of mapping
* constructors, methods (and possibly fields) to InstanceFactories.
*/
- protected void introspectInstanceFactories()
- {
+ protected void introspectInstanceFactories() {
factoryMap = new HashMap();
factoryList = new ArrayList();
ReflectedInstanceFactoryIntrospector introspectors[] =
getInstanceFactoryIntrospectors();
- if (introspectors != null){
+ if (introspectors != null) {
for (int i = 0; i < introspectors.length; i++) {
List factories =
introspectors[i].introspectInstanceFactories(
@@ -419,7 +547,7 @@
}
private List propertyParseResults;
-
+
/**
* Called by ReflectedPropertyIntrospector's to log results of
* introspection, successful or not.
@@ -430,21 +558,22 @@
}
propertyParseResults.add(parseResults);
}
-
+
/**
- * Prints diagnostics of property introspection.
*/
- protected void logPropertyParseResults(){
- if (propertyParseResults == null){
+ * Prints diagnostics of property introspection.
+ */
+ protected void logPropertyParseResults() {
+ if (propertyParseResults == null) {
return;
}
-
+
// PropertyParseResults are supposed to implement Comparable
Collections.sort(propertyParseResults);
-
+
// @todo: use a logger
System.err.println("[Clazz: " + getName());
- for (int i = 0; i < propertyParseResults.size(); i++){
- System.err.println(propertyParseResults.get(i));
+ for (int i = 0; i < propertyParseResults.size(); i++) {
+ System.err.println(propertyParseResults.get(i));
}
System.err.println("]");
}
1.5 +18 -15 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedClazzLoader.java
Index: ReflectedClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedClazzLoader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ReflectedClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.4
+++ ReflectedClazzLoader.java 20 Jan 2003 18:29:42 -0000 1.5
@@ -78,46 +78,48 @@
}
public String getClazzName(Object instance) {
- if (instance == null){
+ if (instance == null) {
return null;
}
return Clazz.getCanonicalClassName(instance.getClass());
}
- public Clazz getClazzForName(String name){
+ public Clazz getClazzForName(String name) {
Class javaClass = null;
try {
- if (classLoader != null){
+ if (classLoader != null) {
javaClass = classLoader.loadClass(name);
}
else {
javaClass = Class.forName(name);
}
}
- catch (ClassNotFoundException ex){
+ catch (ClassNotFoundException ex) {
+ // Won't happen
}
- if (javaClass == null){
+ if (javaClass == null) {
try {
javaClass = getClazzForCanonicalName(classLoader, name);
}
- catch (ClassNotFoundException ex){
+ catch (ClassNotFoundException ex) {
+ // Won't happen
}
}
- if (javaClass == null){
+ if (javaClass == null) {
return null;
}
- if (javaClass.isArray()){
+ if (javaClass.isArray()) {
// TBD: automatically produce clazzes for arrays
}
else {
Clazz clazz = lookupCustomClazz(javaClass);
- if (clazz != null){
+ if (clazz != null) {
return clazz;
}
}
- if (!isSupportedClass(javaClass)){
+ if (!isSupportedClass(javaClass)) {
return null;
}
return createClazz(javaClass);
@@ -142,10 +144,10 @@
Class customClazzClass;
try {
- if (classLoader == null){
+ if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
- if (classLoader != null){
+ if (classLoader != null) {
customClazzClass = classLoader.loadClass(customClazzName);
}
else {
@@ -207,7 +209,8 @@
return getPrimitiveType(classLoader, arrayDepth, Byte.TYPE, 'B');
}
else if (name.equals("char")) {
- return getPrimitiveType(classLoader, arrayDepth, Character.TYPE, 'C');
+ return
+ getPrimitiveType(classLoader, arrayDepth, Character.TYPE, 'C');
}
else if (name.equals("short")) {
return getPrimitiveType(classLoader, arrayDepth, Short.TYPE, 'S');
@@ -279,7 +282,7 @@
* @see ClazzLoader#isMember(Object)
*/
public boolean isMember(Object instance) {
- if (instance == null){
+ if (instance == null) {
return false;
}
return isSupportedClass(instance.getClass());
1.4 +4 -4 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedGroupClazzLoader.java
Index: ReflectedGroupClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedGroupClazzLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedGroupClazzLoader.java 9 Jan 2003 03:23:59 -0000 1.3
+++ ReflectedGroupClazzLoader.java 20 Jan 2003 18:29:42 -0000 1.4
@@ -69,11 +69,11 @@
*/
public class ReflectedGroupClazzLoader extends GroupClazzLoader {
- public ReflectedGroupClazzLoader(ModelClazzLoader modelClazzLoader){
+ public ReflectedGroupClazzLoader(ModelClazzLoader modelClazzLoader) {
super(modelClazzLoader);
}
- public boolean canAddClazzLoader(ClazzLoader loader){
+ public boolean canAddClazzLoader(ClazzLoader loader) {
return loader instanceof ReflectedClazzLoader;
}
@@ -88,7 +88,7 @@
* @see org.apache.commons.clazz.ClazzLoader#getClazzName(java.lang.Object)
*/
public String getClazzName(Object instance) {
- if (instance == null){
+ if (instance == null) {
return null;
}
return instance.getClass().getName();
1.2 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedInstanceFactoryIntrospector.java
Index: ReflectedInstanceFactoryIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedInstanceFactoryIntrospector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedInstanceFactoryIntrospector.java 14 Dec 2002 02:38:41 -0000 1.1
+++ ReflectedInstanceFactoryIntrospector.java 20 Jan 2003 18:29:42 -0000 1.2
@@ -69,7 +69,7 @@
* Find constructors, methods and perhaps fields constituting factories.
* Create ClazzInstanceFactory objects and return them as a list.
*/
- public List introspectInstanceFactories(
+ List introspectInstanceFactories(
ReflectedClazz clazz,
Class javaClass);
}
1.2 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedOperationIntrospector.java
Index: ReflectedOperationIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedOperationIntrospector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedOperationIntrospector.java 14 Dec 2002 02:38:41 -0000 1.1
+++ ReflectedOperationIntrospector.java 20 Jan 2003 18:29:42 -0000 1.2
@@ -69,5 +69,5 @@
* Find methods (and perhaps fields) constituting operations. Create
* ClazzOperation objects and return them as a list.
*/
- public List introspectOperations(ReflectedClazz clazz, Class javaClass);
+ List introspectOperations(ReflectedClazz clazz, Class javaClass);
}
1.4 +5 -6 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedProperty.java
Index: ReflectedProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedProperty.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedProperty.java 14 Dec 2002 02:38:41 -0000 1.3
+++ ReflectedProperty.java 20 Jan 2003 18:29:42 -0000 1.4
@@ -56,16 +56,15 @@
import org.apache.commons.clazz.ClazzProperty;
/**
- * The same reflected property may have more than one name. For example, if we
+ * The same reflected property may have more than one name. For example, if we
* have two methods: <code>Map getAuthors()</code> and <code>String getAuthor
- * (String)</code>, they both map to the same property, which then has two names:
- * "author" and "authors".
+ * (String)</code>, they both map to the same property, which then has two
+ * names: "author" and "authors".
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public interface ReflectedProperty extends ClazzProperty
-{
+public interface ReflectedProperty extends ClazzProperty {
/**
* Alternative names for the property.
*/
1.4 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedPropertyIntrospector.java
Index: ReflectedPropertyIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/ReflectedPropertyIntrospector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedPropertyIntrospector.java 14 Dec 2002 02:38:41 -0000 1.3
+++ ReflectedPropertyIntrospector.java 20 Jan 2003 18:29:42 -0000 1.4
@@ -72,5 +72,5 @@
* return them as a list. The clazz may already
* have been populated with properties created by other methods.
*/
- public List introspectProperties(ReflectedClazz clazz, Class javaClass);
+ List introspectProperties(ReflectedClazz clazz, Class javaClass);
}
1.4 +24 -25 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/AccessorMethodParser.java
Index: AccessorMethodParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/AccessorMethodParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AccessorMethodParser.java 9 Jan 2003 03:23:59 -0000 1.3
+++ AccessorMethodParser.java 20 Jan 2003 18:29:43 -0000 1.4
@@ -83,7 +83,7 @@
* To check constraints on the return type of methods parsed
* by this parser, override and perform the check.
*
* @param javaClass The return type of the method (never null)
* @return boolean True if the return type passes the parser's constraints
*/
- protected boolean testReturnType(Class javaClass){
+ protected boolean testReturnType(Class javaClass) {
return true;
}
@@ -94,7 +94,7 @@
* @param javaClass The return type of the method (never null)
* @return boolean True if the return type passes the parser's constraints
*/
- protected boolean testParameterType(int index, Class parameterType){
+ protected boolean testParameterType(int index, Class parameterType) {
return true;
}
@@ -103,7 +103,7 @@
* override this method, check that it does and remove the
* suffix.
*/
- protected String testAndRemoveSuffix(String methodName){
+ protected String testAndRemoveSuffix(String methodName) {
return methodName;
}
@@ -111,7 +111,7 @@
* Returns true if the character can be the first character of a Capitalized
* property name.
*/
- protected boolean testFirstCharacterOfPropertyName(char ch){
+ protected boolean testFirstCharacterOfPropertyName(char ch) {
return Character.isUpperCase(ch);
}
@@ -119,7 +119,7 @@
* Extract the value type from the method. Depending on the type
* of method, it could be the return type or the type of a parameter.
*/
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return null;
}
@@ -128,7 +128,7 @@
* For example a mapped property "get" method might have
* a "key" parameter.
*/
- protected Class getParameterType(Method method){
+ protected Class getParameterType(Method method) {
return null;
}
@@ -136,31 +136,31 @@
* Parses the supplied method according to the parser's configuration.
* If the parse process fails, returns null.
*
* @param method
* @return AccessorMethodParseResults
*/
- public AccessorMethodParseResults parse(Method method){
+ public AccessorMethodParseResults parse(Method method) {
int modifiers = method.getModifiers();
// An accessor methods must be public and non-static
- if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)){
+ if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) {
return null;
}
Class returnType = method.getReturnType();
- if (returnType == null){
+ if (returnType == null) {
returnType = Void.TYPE;
}
- if (!testReturnType(returnType)){
+ if (!testReturnType(returnType)) {
return null;
}
int reqParamCount = requiredParameterCount();
- if (reqParamCount != -1){
+ if (reqParamCount != -1) {
Class paramTypes[] = method.getParameterTypes();
- if (paramTypes.length != reqParamCount){
+ if (paramTypes.length != reqParamCount) {
return null;
}
for (int i = 0; i < paramTypes.length; i++) {
- if (!testParameterType(i, paramTypes[i])){
+ if (!testParameterType(i, paramTypes[i])) {
return null;
}
}
@@ -187,29 +187,29 @@
* method name starts with the specified prefix followed
* by an optionally capitalized property name.
*
* @param methodName
* @return String
*/
- protected String getPropertyName(Method method){
+ protected String getPropertyName(Method method) {
String name = method.getName();
name = testAndRemoveSuffix(name);
- if (name == null){
+ if (name == null) {
return null;
}
String prefix = requiredPrefix();
- if (prefix == null){
+ if (prefix == null) {
return name;
}
int prefixLength = prefix.length();
- if (name.length() <= prefixLength){
+ if (name.length() <= prefixLength) {
return null;
}
- if (!name.startsWith(prefix)){
+ if (!name.startsWith(prefix)) {
return null;
}
- if (!testFirstCharacterOfPropertyName(name.charAt(prefixLength))){
+ if (!testFirstCharacterOfPropertyName(name.charAt(prefixLength))) {
return null;
}
@@ -224,18 +224,17 @@
* @param candidate
* @return String
*/
- protected String decapitalize(String string)
- {
+ protected String decapitalize(String string) {
char firstChar = string.charAt(0);
- if (!Character.isUpperCase(firstChar)){
+ if (!Character.isUpperCase(firstChar)) {
return string;
}
int len = string.length();
- if (len == 1){
+ if (len == 1) {
return String.valueOf(Character.toLowerCase(firstChar));
}
- else if (Character.isLowerCase(string.charAt(1))){
+ else if (Character.isLowerCase(string.charAt(1))) {
char buffer[] = new char[len];
buffer[0] = Character.toLowerCase(firstChar);
string.getChars(1, len, buffer, 1);
1.2 +6 -6 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedAccessorPairProperty.java
Index: ReflectedAccessorPairProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedAccessorPairProperty.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedAccessorPairProperty.java 14 Dec 2002 02:38:42 -0000 1.1
+++ ReflectedAccessorPairProperty.java 20 Jan 2003 18:29:43 -0000 1.2
@@ -113,7 +113,7 @@
* @see org.apache.commons.clazz.ClazzProperty#getClazz()
*/
public Clazz getClazz() {
- if (clazz == null){
+ if (clazz == null) {
clazz = getDeclaringClazz().
getClazzLoader().getClazzForName(type.getName());
}
@@ -194,7 +194,7 @@
* @see org.apache.commons.clazz.ClazzProperty#get(java.lang.Object)
*/
public Object get(Object instance) {
- if (readMethod == null){
+ if (readMethod == null) {
throw new ClazzAccessException(
"Cannot read property " + name + ": no read method");
}
@@ -212,10 +212,10 @@
}
/**
- * @see org.apache.commons.clazz.ClazzProperty#set(java.lang.Object, java.lang.Object)
+ * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object)
*/
public void set(Object instance, Object value) {
- if (writeMethod == null){
+ if (writeMethod == null) {
throw new ClazzAccessException(
"Cannot modify property " + name + ": no write method");
}
@@ -234,7 +234,7 @@
/**
- * Returns the valueClass.
+ * Returns the type.
* @return Class
*/
public Class getType() {
1.2 +7 -7 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedConstructorInstanceFactory.java
Index: ReflectedConstructorInstanceFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedConstructorInstanceFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedConstructorInstanceFactory.java 14 Dec 2002 02:38:42 -0000 1.1
+++ ReflectedConstructorInstanceFactory.java 20 Jan 2003 18:29:43 -0000 1.2
@@ -86,11 +86,11 @@
this.constructor = constructor;
}
- public Constructor getConstructor(){
+ public Constructor getConstructor() {
return constructor;
}
- public String getName(){
+ public String getName() {
return null;
}
@@ -109,15 +109,15 @@
* @see org.apache.commons.clazz.ClazzOperation#getParameterClazzes()
*/
public Clazz[] getParameterClazzes() {
- if (parameterClazzes == null){
+ if (parameterClazzes == null) {
Class paramClasses[] = constructor.getParameterTypes();
- if (paramClasses == null){
+ if (paramClasses == null) {
parameterClazzes = EMPTY_CLAZZ_ARRAY;
}
else {
parameterClazzes = new Clazz[paramClasses.length];
ClazzLoader loader = getDeclaringClazz().getClazzLoader();
- for (int i = 0; i < paramClasses.length; i++){
+ for (int i = 0; i < paramClasses.length; i++) {
String name = Clazz.getCanonicalClassName(paramClasses[i]);
parameterClazzes[i] = loader.getClazzForName(name);
}
@@ -137,7 +137,7 @@
}
}
- public String toString(){
+ public String toString() {
return getSignature();
}
}
1.3 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedConstructorInstanceFactoryIntrospector.java
Index: ReflectedConstructorInstanceFactoryIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedConstructorInstanceFactoryIntrospector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedConstructorInstanceFactoryIntrospector.java 9 Jan 2003 03:23:59 -0000 1.2
+++ ReflectedConstructorInstanceFactoryIntrospector.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -70,7 +70,7 @@
implements ReflectedInstanceFactoryIntrospector
{
/**
- * @see org.apache.commons.clazz.reflect.ReflectedInstanceFactoryIntrospector#introspectInstanceFactories(org.apache.commons.clazz.reflect.ReflectedClazz, java.lang.Class)
+ * @see ReflectedInstanceFactoryIntrospector#introspectInstanceFactories(ReflectedClazz, Class)
*/
public List introspectInstanceFactories(
ReflectedClazz clazz,
1.4 +118 -116 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedList.java
Index: ReflectedList.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedList.java 16 Dec 2002 23:17:41 -0000 1.3
+++ ReflectedList.java 20 Jan 2003 18:29:43 -0000 1.4
@@ -56,7 +56,11 @@
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
import org.apache.commons.clazz.ClazzAccessException;
@@ -81,34 +85,30 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class ReflectedList extends AbstractList
-{
+public class ReflectedList extends AbstractList {
/*
* We have a concurrent modification issue with ReflectedList. We have no
* way of knowing if somebody has modified the property value unless it was
* modified through this very ReflectedList. So, in some cases we will not
* get a ConcurrentModificationException when we are supposed to.
- */
-
+ */
+
private Object instance;
private ReflectedListProperty property;
-
+
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
+
/**
* Constructor for ReflectedList.
*/
- public ReflectedList(
- Object instance,
- ReflectedListProperty property)
- {
+ public ReflectedList(Object instance, ReflectedListProperty property) {
this.instance = instance;
this.property = property;
}
-
- public Object getPropertyValue(){
+
+ public Object getPropertyValue() {
Method readMethod = property.getReadMethod();
- if (readMethod == null){
+ if (readMethod == null) {
throw new ClazzAccessException(
"Cannot read property "
+ property.getName()
@@ -124,7 +124,7 @@
public void setPropertyValue(Object value) {
Method writeMethod = property.getWriteMethod();
- if (writeMethod == null){
+ if (writeMethod == null) {
throw new ClazzAccessException(
"Cannot set property: "
+ property.getName()
@@ -138,16 +138,16 @@
throw accessException("Cannot set property", writeMethod, ex);
}
}
-
+
/**
* @see java.util.Collection#size()
*/
public int size() {
Method sizeMethod = property.getSizeMethod();
- if (sizeMethod != null){
+ if (sizeMethod != null) {
try {
Object value = sizeMethod.invoke(instance, null);
- return ((Integer)value).intValue();
+ return ((Integer) value).intValue();
}
catch (Exception ex) {
throw accessException("Cannot get list size", sizeMethod, ex);
@@ -155,14 +155,14 @@
}
else {
Object list = getPropertyValue();
- if (list == null){
+ if (list == null) {
return 0;
}
-
- if (list instanceof List){
- return ((List)list).size();
+
+ if (list instanceof List) {
+ return ((List) list).size();
}
-
+
return Array.getLength(list);
}
}
@@ -172,7 +172,7 @@
*/
public Object get(int index) {
Method getMethod = property.getGetMethod();
- if (getMethod != null){
+ if (getMethod != null) {
Object value;
try {
value =
@@ -187,12 +187,12 @@
}
else {
Object list = getPropertyValue();
- if (list == null){
+ if (list == null) {
return null;
}
- if (list instanceof List){
- return ((List)list).get(index);
+ if (list instanceof List) {
+ return ((List) list).get(index);
}
return Array.get(list, index);
@@ -202,7 +202,7 @@
/**
* @see java.util.Collection#iterator()
*/
- public Iterator iterator(){
+ public Iterator iterator() {
return new QuickList().iterator();
}
@@ -226,12 +226,12 @@
public Object set(int index, Object element) {
modCount++;
Method setMethod = property.getSetMethod();
- if (setMethod != null){
+ if (setMethod != null) {
Object oldValue = null;
try {
oldValue = get(index);
}
- catch (Throwable t){
+ catch (Throwable t) {
// Ignore
}
try {
@@ -241,18 +241,20 @@
}
catch (Exception ex) {
throw accessException(
- "Cannot set property element", setMethod, ex);
+ "Cannot set property element",
+ setMethod,
+ ex);
}
return oldValue;
}
else {
Object list = getPropertyValue();
- if (list == null){
+ if (list == null) {
return null;
}
- if (list instanceof List){
- return ((List)list).set(index, element);
+ if (list instanceof List) {
+ return ((List) list).set(index, element);
}
Object oldValue = Array.get(list, index);
@@ -287,16 +289,16 @@
*/
public boolean add(Object element) {
modCount++;
- if (property.getAddMethod() != null){
+ if (property.getAddMethod() != null) {
Method addMethod = property.getAddMethod();
try {
- addMethod.invoke(
- instance,
- new Object[] { element });
+ addMethod.invoke(instance, new Object[] { element });
}
catch (Exception ex) {
throw accessException(
- "Cannot add value to property", addMethod, ex);
+ "Cannot add value to property",
+ addMethod,
+ ex);
}
}
else {
@@ -330,10 +332,10 @@
*/
public void add(int index, Object element) {
modCount++;
- if (property.getAddIndexedMethod() != null){
- if (index == -1){ // This would indicate that the call
- // is coming from add(element) and
- // the addMethod does not exist
+ if (property.getAddIndexedMethod() != null) {
+ if (index == -1) { // This would indicate that the call
+ // is coming from add(element) and
+ // the addMethod does not exist
index = size();
}
Method addIndexedMethod = property.getAddIndexedMethod();
@@ -344,19 +346,21 @@
}
catch (Exception ex) {
throw accessException(
- "Cannot add value to property", addIndexedMethod, ex);
+ "Cannot add value to property",
+ addIndexedMethod,
+ ex);
}
return;
}
-
- if (property.getAddMethod() != null && index == size()){ // This
- // guarantees that the call is not coming from add(element),
- // therefore we can call it without the fear of recursion
+
+ if (property.getAddMethod() != null && index == size()) { // This
+ // guarantees that the call is not coming from add(element),
+ // therefore we can call it without the fear of recursion
add(element);
}
- else if (property.getType().isArray()){
+ else if (property.getType().isArray()) {
addToArray(index, element);
- }
+ }
else {
addToList(index, element);
}
@@ -365,14 +369,14 @@
/**
* Inserts a new element into an array. Creates the array if necessary.
*/
- private void addToArray(int index, Object element){
+ private void addToArray(int index, Object element) {
Object newList;
Object list = getPropertyValue();
- if (list == null){
- if (index != 0 && index != -1){
+ if (list == null) {
+ if (index != 0 && index != -1) {
throw new ArrayIndexOutOfBoundsException(
"Size: 0; Index: " + index);
- }
+ }
Class contentType = property.getContentType();
newList = Array.newInstance(contentType, 1);
Array.set(newList, 0, element);
@@ -380,34 +384,33 @@
else {
Class contentType = property.getContentType();
int size = Array.getLength(list);
- if (index == -1){
+ if (index == -1) {
index = size;
}
- if (index < 0 || index > size){
+ if (index < 0 || index > size) {
throw new ArrayIndexOutOfBoundsException(
"Size: " + size + "; Index: " + index);
}
newList = Array.newInstance(contentType, size + 1);
System.arraycopy(list, 0, newList, 0, index);
Array.set(newList, index, element);
- System.arraycopy(
- list, index, newList, index + 1, size - index);
+ System.arraycopy(list, index, newList, index + 1, size - index);
}
setPropertyValue(newList);
}
-
+
/**
* Inserts a new element into an List. Creates the list if necessary.
*/
- private void addToList(int index, Object element){
+ private void addToList(int index, Object element) {
Object list = getPropertyValue();
- if (list == null){
- List newList;
+ if (list == null) {
+ List newList;
Class type = property.getType();
- if (!type.isInterface()){
+ if (!type.isInterface()) {
try {
- newList = (List)type.newInstance();
+ newList = (List) type.newInstance();
}
catch (Exception ex) {
throw new ClazzAccessException(
@@ -425,14 +428,14 @@
setPropertyValue(newList);
}
- else if (index == -1){
- ((List)list).add(element);
+ else if (index == -1) {
+ ((List) list).add(element);
}
else {
- ((List)list).add(index, element);
+ ((List) list).add(index, element);
}
}
-
+
/**
* Will perform the following steps:
* <ol>
@@ -450,18 +453,18 @@
*/
public boolean remove(Object element) {
modCount++;
- if (property.getRemoveMethod() != null){
+ if (property.getRemoveMethod() != null) {
Method removeMethod = property.getRemoveMethod();
try {
- removeMethod.invoke(
- instance,
- new Object[] { element });
+ removeMethod.invoke(instance, new Object[] { element });
}
catch (Exception ex) {
throw accessException(
- "Cannot remove value from property", removeMethod, ex);
+ "Cannot remove value from property",
+ removeMethod,
+ ex);
}
- return true; // @todo: we really don't know if it got removed
+ return true; // @todo: we really don't know if it got removed
}
else {
return super.remove(element);
@@ -494,17 +497,17 @@
*/
public Object remove(int index) {
modCount++;
-
- if (property.getRemoveIndexedMethod() != null){
+
+ if (property.getRemoveIndexedMethod() != null) {
Object value = null;
-
+
try {
value = get(index);
}
- catch (Throwable t){
+ catch (Throwable t) {
// Ignore
}
-
+
Method removeIndexedMethod = property.getRemoveIndexedMethod();
try {
removeIndexedMethod.invoke(
@@ -517,20 +520,20 @@
removeIndexedMethod,
ex);
}
-
+
return value;
}
-
+
Object list = getPropertyValue();
- if (list == null){
+ if (list == null) {
throw new ArrayIndexOutOfBoundsException(
"Size: 0; Index: " + index);
}
- else if (property.getType().isArray()){
+ else if (property.getType().isArray()) {
Object value;
Class contentType = property.getContentType();
int size = Array.getLength(list);
- if (index < 0 || index >= size){
+ if (index < 0 || index >= size) {
throw new ArrayIndexOutOfBoundsException(
"Size: " + size + "; Index: " + index);
}
@@ -538,25 +541,24 @@
Object newList = Array.newInstance(contentType, size - 1);
System.arraycopy(list, 0, newList, 0, index);
- System.arraycopy(
- list, index + 1, newList, index, size - index - 1);
+ System.arraycopy(list, index + 1, newList, index, size - index - 1);
setPropertyValue(newList);
return value;
}
else {
- return ((List)list).remove(index);
+ return ((List) list).remove(index);
}
}
private RuntimeException accessException(
String message,
Method method,
- Throwable ex)
+ Throwable ex)
{
if (ex instanceof InvocationTargetException) {
ex = ((InvocationTargetException) ex).getTargetException();
}
-
+
// Just re-throw all runtime exceptions - there is really no
// point in wrapping them
if (ex instanceof RuntimeException) {
@@ -565,7 +567,7 @@
if (ex instanceof Error) {
throw (Error) ex;
}
-
+
throw new ClazzAccessException(
message
+ ": "
@@ -574,8 +576,8 @@
+ method.getName(),
ex);
}
-
- private int getModCount(){
+
+ private int getModCount() {
return modCount;
}
@@ -596,30 +598,30 @@
private Object list;
private int size;
- public QuickList(){
+ public QuickList() {
update();
}
-
- public void refresh(){
+
+ public void refresh() {
// If QuickList is out of sync with the parent ReflectedList,
// update the cached list and size
- if (super.modCount != getModCount()){
+ if (super.modCount != getModCount()) {
update();
- }
+ }
}
-
- public void update(){
+
+ public void update() {
// Make sure modCount of QuickList is maintained in sync with
// that of the embracing List
super.modCount = getModCount();
-
- if (property.getReadMethod() != null){
+
+ if (property.getReadMethod() != null) {
list = getPropertyValue();
- if (list == null){
+ if (list == null) {
size = 0;
- }
- else if (list instanceof List){
- size = ((List)list).size();
+ }
+ else if (list instanceof List) {
+ size = ((List) list).size();
}
else {
size = Array.getLength(list);
@@ -630,12 +632,12 @@
size = ReflectedList.this.size();
}
}
-
- public int size(){
+
+ public int size() {
refresh();
return size;
}
-
+
public Object get(int index) {
refresh();
if (list != NOT_ACCESSIBLE) {
@@ -654,20 +656,20 @@
return ReflectedList.this.get(index);
}
}
-
- public Object set(int index, Object value){
+
+ public Object set(int index, Object value) {
return ReflectedList.this.set(index, value);
}
-
- public void add(int index, Object value){
+
+ public void add(int index, Object value) {
ReflectedList.this.add(index, value);
}
-
- public Object remove(int index){
+
+ public Object remove(int index) {
return ReflectedList.this.remove(index);
}
}
-
+
private static final Object NOT_ACCESSIBLE = new Object();
}
1.3 +14 -14 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedListProperty.java
Index: ReflectedListProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedListProperty.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedListProperty.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedListProperty.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -217,51 +217,51 @@
this.sizeMethod = sizeMethod;
}
- public String toString(){
+ public String toString() {
StringBuffer buffer = new StringBuffer("[ReflectedListProperty ");
- if (getType() != null){
+ if (getType() != null) {
buffer.append(getType().getName());
buffer.append(" ");
}
- if (getContentType() != null){
+ if (getContentType() != null) {
buffer.append("[content: ");
buffer.append(getContentType().getName());
buffer.append("] ");
}
buffer.append(getName());
- if (getReadMethod() != null){
+ if (getReadMethod() != null) {
buffer.append("\n [read method] ");
buffer.append(getReadMethod());
}
- if (getWriteMethod() != null){
+ if (getWriteMethod() != null) {
buffer.append("\n [write method] ");
buffer.append(getWriteMethod());
}
- if (getGetMethod() != null){
+ if (getGetMethod() != null) {
buffer.append("\n [get method] ");
buffer.append(getGetMethod());
}
- if (getSetMethod() != null){
+ if (getSetMethod() != null) {
buffer.append("\n [set method] ");
buffer.append(getSetMethod());
}
- if (getAddMethod() != null){
+ if (getAddMethod() != null) {
buffer.append("\n [add method] ");
buffer.append(getAddMethod());
}
- if (getAddIndexedMethod() != null){
+ if (getAddIndexedMethod() != null) {
buffer.append("\n [add(i) method] ");
buffer.append(getAddIndexedMethod());
}
- if (getRemoveMethod() != null){
+ if (getRemoveMethod() != null) {
buffer.append("\n [remove method] ");
buffer.append(getRemoveMethod());
}
- if (getRemoveIndexedMethod() != null){
+ if (getRemoveIndexedMethod() != null) {
buffer.append("\n [remove(i) method] ");
buffer.append(getRemoveIndexedMethod());
}
- if (getSizeMethod() != null){
+ if (getSizeMethod() != null) {
buffer.append("\n [size method] ");
buffer.append(getSizeMethod());
}
@@ -280,7 +280,7 @@
}
/**
- * @see org.apache.commons.clazz.ClazzProperty#set(java.lang.Object, java.lang.Object)
+ * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object)
*/
public void set(Object instance, Object value) {
super.set(instance, value);
1.4 +25 -25 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedListPropertyIntrospectorSupport.java
Index: ReflectedListPropertyIntrospectorSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedListPropertyIntrospectorSupport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedListPropertyIntrospectorSupport.java 9 Jan 2003 03:23:59 -0000 1.3
+++ ReflectedListPropertyIntrospectorSupport.java 20 Jan 2003 18:29:43 -0000 1.4
@@ -57,7 +57,7 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.clazz.reflect.*;
+import org.apache.commons.clazz.reflect.ReflectedClazz;
/**
* A ReflectedPropertyIntrospector that discovers list (aka indexed) properties.
@@ -80,19 +80,19 @@
protected static final AccessorMethodParser SET_METHOD_PARSER =
new SetAccessorMethodParser();
- protected AccessorMethodParser getReadAccessMethodParser(){
+ protected AccessorMethodParser getReadAccessMethodParser() {
return READ_METHOD_PARSER;
}
- protected AccessorMethodParser getWriteAccessMethodParser(){
+ protected AccessorMethodParser getWriteAccessMethodParser() {
return WRITE_METHOD_PARSER;
}
- protected AccessorMethodParser getGetAccessMethodParser(){
+ protected AccessorMethodParser getGetAccessMethodParser() {
return GET_METHOD_PARSER;
}
- protected AccessorMethodParser getSetAccessMethodParser(){
+ protected AccessorMethodParser getSetAccessMethodParser() {
return SET_METHOD_PARSER;
}
@@ -181,7 +181,7 @@
new ReflectedListProperty(clazz, parseResults.getPropertyName());
ReflectedListPropertyParseResults parseResultsList =
- (ReflectedListPropertyParseResults)parseResults;
+ (ReflectedListPropertyParseResults) parseResults;
property.setAliases(parseResultsList.getAliases());
property.setType(parseResultsList.getPropertyType());
@@ -211,16 +211,16 @@
* property as NotAProperty.
*/
public static class ReadAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return !returnType.equals(Void.TYPE);
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "get";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 0;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getReturnType();
}
}
@@ -238,16 +238,16 @@
* property as NotAProperty.
*/
public static class WriteAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return returnType.equals(Void.TYPE);
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "set";
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -262,19 +262,19 @@
* </ul>
*/
public static class GetAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return !returnType.equals(Void.TYPE);
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "get";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected boolean testParameterType(int index, Class parameterType){
+ protected boolean testParameterType(int index, Class parameterType) {
return parameterType.equals(Integer.TYPE);
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getReturnType();
}
}
@@ -289,19 +289,19 @@
* </ul>
*/
public static class SetAccessorMethodParser extends AccessorMethodParser {
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "set";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 2;
}
- protected boolean testParameterType(int index, Class parameterType){
- if (index == 0){
+ protected boolean testParameterType(int index, Class parameterType) {
+ if (index == 0) {
return parameterType.equals(Integer.TYPE);
}
return true;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[1];
}
}
1.3 +77 -77 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedListPropertyParseResults.java
Index: ReflectedListPropertyParseResults.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedListPropertyParseResults.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedListPropertyParseResults.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedListPropertyParseResults.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -88,7 +88,7 @@
super(clazz, propertyName);
}
- protected String getPropertyCategory(){
+ protected String getPropertyCategory() {
return "list";
}
@@ -96,23 +96,23 @@
* Returns <code>true</code> if the property is an array or
* implements java.util.List.
*/
- public boolean isList(){
- if (readMethodParseResults != null &&
- isList(readMethodParseResults.getType())){
+ public boolean isList() {
+ if (readMethodParseResults != null
+ && isList(readMethodParseResults.getType())) {
return true;
}
- if (writeMethodParseResults != null &&
- isList(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null
+ && isList(writeMethodParseResults.getType())) {
return true;
}
- return false;
+ return false;
}
/**
* Returns <code>true</code> if javaClass is an array or
* implements java.util.List.
*/
- protected boolean isList(Class javaClass){
+ protected boolean isList(Class javaClass) {
return javaClass != null
&& (List.class.isAssignableFrom(javaClass) || javaClass.isArray());
}
@@ -120,31 +120,31 @@
/**
* Returns the type of the list/array element, if known.
* Returns <code>null</code> otherwise.
*/
- public Class getContentType(){
- if (getMethodParseResults != null){
+ public Class getContentType() {
+ if (getMethodParseResults != null) {
return getMethodParseResults.getType();
}
- if (setMethodParseResults != null){
+ if (setMethodParseResults != null) {
return setMethodParseResults.getType();
}
- if (addMethodParseResults != null){
+ if (addMethodParseResults != null) {
return addMethodParseResults.getType();
}
- if (addIndexedMethodParseResults != null){
+ if (addIndexedMethodParseResults != null) {
return addIndexedMethodParseResults.getType();
}
- if (removeMethodParseResults != null){
+ if (removeMethodParseResults != null) {
return removeMethodParseResults.getType();
}
- if (readMethodParseResults != null){
+ if (readMethodParseResults != null) {
Class type = readMethodParseResults.getType();
- if (type.isArray()){
+ if (type.isArray()) {
return type.getComponentType();
}
}
- if (writeMethodParseResults != null){
+ if (writeMethodParseResults != null) {
Class type = writeMethodParseResults.getType();
- if (type.isArray()){
+ if (type.isArray()) {
return type.getComponentType();
}
}
@@ -161,7 +161,7 @@
}
public Method getGetMethod() {
- if (getMethodParseResults == null){
+ if (getMethodParseResults == null) {
return null;
}
return getMethodParseResults.getMethod();
@@ -177,7 +177,7 @@
}
public Method getSetMethod() {
- if (setMethodParseResults == null){
+ if (setMethodParseResults == null) {
return null;
}
return setMethodParseResults.getMethod();
@@ -193,7 +193,7 @@
}
public Method getAddMethod() {
- if (addMethodParseResults == null){
+ if (addMethodParseResults == null) {
return null;
}
return addMethodParseResults.getMethod();
@@ -209,7 +209,7 @@
}
public Method getAddIndexedMethod() {
- if (addIndexedMethodParseResults == null){
+ if (addIndexedMethodParseResults == null) {
return null;
}
return addIndexedMethodParseResults.getMethod();
@@ -225,7 +225,7 @@
}
public Method getRemoveMethod() {
- if (removeMethodParseResults == null){
+ if (removeMethodParseResults == null) {
return null;
}
return removeMethodParseResults.getMethod();
@@ -241,7 +241,7 @@
}
public Method getRemoveIndexedMethod() {
- if (removeIndexedMethodParseResults == null){
+ if (removeIndexedMethodParseResults == null) {
return null;
}
return removeIndexedMethodParseResults.getMethod();
@@ -258,7 +258,7 @@
}
public Method getSizeMethod() {
- if (sizeMethodParseResults == null){
+ if (sizeMethodParseResults == null) {
return null;
}
return sizeMethodParseResults.getMethod();
@@ -272,88 +272,88 @@
* Node that the property name is not copied from the
* <code>other</code> object.
*/
- public void merge(ReflectedListPropertyParseResults other){
+ public void merge(ReflectedListPropertyParseResults other) {
super.merge(other);
- if (other.readMethodParseResults != null){
+ if (other.readMethodParseResults != null) {
setReadMethodParseResults(other.readMethodParseResults);
}
- if (other.writeMethodParseResults != null){
+ if (other.writeMethodParseResults != null) {
setWriteMethodParseResults(other.writeMethodParseResults);
}
- if (other.getMethodParseResults != null){
+ if (other.getMethodParseResults != null) {
setGetMethodParseResults(other.getMethodParseResults);
}
- if (other.setMethodParseResults != null){
+ if (other.setMethodParseResults != null) {
setSetMethodParseResults(other.setMethodParseResults);
}
- if (other.addMethodParseResults != null){
+ if (other.addMethodParseResults != null) {
setAddMethodParseResults(other.addMethodParseResults);
}
- if (other.addIndexedMethodParseResults != null){
+ if (other.addIndexedMethodParseResults != null) {
setAddIndexedMethodParseResults(other.addIndexedMethodParseResults);
}
- if (other.removeMethodParseResults != null){
+ if (other.removeMethodParseResults != null) {
setRemoveMethodParseResults(other.removeMethodParseResults);
}
- if (other.sizeMethodParseResults != null){
+ if (other.sizeMethodParseResults != null) {
setSizeMethodParseResults(other.sizeMethodParseResults);
}
}
- protected void appendDescription(StringBuffer buffer){
+ protected void appendDescription(StringBuffer buffer) {
super.appendDescription(buffer);
Class contentType = getContentType();
- if (contentType != null){
+ if (contentType != null) {
buffer.append("\n [content type] ");
buffer.append(Clazz.getCanonicalClassName(contentType));
}
}
- protected void appendMethodDescriptions(StringBuffer buffer){
+ protected void appendMethodDescriptions(StringBuffer buffer) {
super.appendMethodDescriptions(buffer);
- if (getMethodParseResults != null){
+ if (getMethodParseResults != null) {
buffer.append("\n [get~(int)] ");
buffer.append(getMethodParseResults.getMethod());
}
- if (setMethodParseResults != null){
+ if (setMethodParseResults != null) {
buffer.append("\n [set~(int,v)] ");
buffer.append(setMethodParseResults.getMethod());
}
- if (addMethodParseResults != null){
+ if (addMethodParseResults != null) {
buffer.append("\n [add~(v)] ");
buffer.append(addMethodParseResults.getMethod());
}
- if (addIndexedMethodParseResults != null){
+ if (addIndexedMethodParseResults != null) {
buffer.append("\n [add~(int,v)] ");
buffer.append(addIndexedMethodParseResults.getMethod());
}
- if (removeMethodParseResults != null){
+ if (removeMethodParseResults != null) {
buffer.append("\n [remove~(v)] ");
buffer.append(removeMethodParseResults.getMethod());
}
- if (removeIndexedMethodParseResults != null){
+ if (removeIndexedMethodParseResults != null) {
buffer.append("\n [remove~(i)] ");
buffer.append(removeIndexedMethodParseResults.getMethod());
}
- if (sizeMethodParseResults != null){
+ if (sizeMethodParseResults != null) {
buffer.append("\n [get~Count()] ");
buffer.append(sizeMethodParseResults.getMethod());
}
}
- public boolean checkConsistency(){
- if (!super.checkConsistency()){
+ public boolean checkConsistency() {
+ if (!super.checkConsistency()) {
return false;
}
- if (readMethodParseResults == null && getMethodParseResults == null){
+ if (readMethodParseResults == null && getMethodParseResults == null) {
return false;
}
- if (readMethodParseResults != null){
+ if (readMethodParseResults != null) {
Class type = readMethodParseResults.getType();
- if (writeMethodParseResults != null){
- if (!type.equals(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null) {
+ if (!type.equals(writeMethodParseResults.getType())) {
return false;
}
}
@@ -361,12 +361,12 @@
Class contentType = null;
- if (getMethodParseResults != null){
+ if (getMethodParseResults != null) {
contentType = getMethodParseResults.getType();
}
- if (setMethodParseResults != null){
- if (contentType == null){
+ if (setMethodParseResults != null) {
+ if (contentType == null) {
contentType = setMethodParseResults.getType();
}
else {
@@ -376,8 +376,8 @@
}
}
- if (addMethodParseResults != null){
- if (contentType == null){
+ if (addMethodParseResults != null) {
+ if (contentType == null) {
contentType = addMethodParseResults.getType();
}
else {
@@ -387,21 +387,21 @@
}
}
- if (addIndexedMethodParseResults != null){
- if (contentType == null){
+ if (addIndexedMethodParseResults != null) {
+ if (contentType == null) {
contentType = addIndexedMethodParseResults.getType();
}
else {
if (!contentType.equals(
- addIndexedMethodParseResults.getType())){
+ addIndexedMethodParseResults.getType())) {
return false;
}
}
}
if (removeMethodParseResults != null) {
- if (contentType != null){
- if (!contentType.equals(removeMethodParseResults.getType())){
+ if (contentType != null) {
+ if (!contentType.equals(removeMethodParseResults.getType())) {
return false;
}
}
@@ -410,21 +410,21 @@
return true;
}
- protected boolean appendInconsistencyDescriptions(StringBuffer buffer){
- if (!super.appendInconsistencyDescriptions(buffer)){
+ protected boolean appendInconsistencyDescriptions(StringBuffer buffer) {
+ if (!super.appendInconsistencyDescriptions(buffer)) {
return false;
}
- if (readMethodParseResults == null && getMethodParseResults == null){
+ if (readMethodParseResults == null && getMethodParseResults == null) {
buffer.append(
"\n - Does not have either get() or get(int) method");
return true;
}
- if (readMethodParseResults != null){
+ if (readMethodParseResults != null) {
Class type = readMethodParseResults.getType();
- if (writeMethodParseResults != null){
- if (!type.equals(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null) {
+ if (!type.equals(writeMethodParseResults.getType())) {
buffer.append(
"\n - Get() and set(v) types do not match");
}
@@ -433,12 +433,12 @@
Class contentType = null;
- if (getMethodParseResults != null){
+ if (getMethodParseResults != null) {
contentType = getMethodParseResults.getType();
}
- if (setMethodParseResults != null){
- if (contentType == null){
+ if (setMethodParseResults != null) {
+ if (contentType == null) {
contentType = setMethodParseResults.getType();
}
else {
@@ -450,8 +450,8 @@
}
}
- if (addMethodParseResults != null){
- if (contentType == null){
+ if (addMethodParseResults != null) {
+ if (contentType == null) {
contentType = addMethodParseResults.getType();
}
else {
@@ -463,13 +463,13 @@
}
}
- if (addIndexedMethodParseResults != null){
- if (contentType == null){
+ if (addIndexedMethodParseResults != null) {
+ if (contentType == null) {
contentType = addIndexedMethodParseResults.getType();
}
else {
if (!contentType.equals(
- addIndexedMethodParseResults.getType())){
+ addIndexedMethodParseResults.getType())) {
buffer.append(
"\n - Content type mismatch between "
+ "get(int) and add(int,v)");
@@ -478,9 +478,9 @@
}
if (removeMethodParseResults != null) {
- if (contentType != null){
+ if (contentType != null) {
Class removeType = removeMethodParseResults.getType();
- if (removeType != null && !contentType.equals(removeType)){
+ if (removeType != null && !contentType.equals(removeType)) {
buffer.append(
"\n - Content type mismatch between "
+ "get(int) and remove(v)");
1.2 +11 -11 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedMethodFeatureSupport.java
Index: ReflectedMethodFeatureSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedMethodFeatureSupport.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedMethodFeatureSupport.java 14 Dec 2002 02:38:42 -0000 1.1
+++ ReflectedMethodFeatureSupport.java 20 Jan 2003 18:29:43 -0000 1.2
@@ -73,7 +73,7 @@
private String signature;
private static final Clazz[] EMPTY_CLAZZ_ARRAY = new Clazz[0];
private Clazz[] parameterClazzes;
- boolean returnClazzCached = false;
+ private boolean returnClazzCached = false;
private Clazz returnClazz;
/**
@@ -84,11 +84,11 @@
this.method = method;
}
- public Method getMethod(){
+ public Method getMethod() {
return method;
}
- public String getName(){
+ public String getName() {
return method.getName();
}
@@ -109,17 +109,17 @@
* @see org.apache.commons.clazz.ClazzOperation#getParameterClazzes()
*/
public Clazz[] getParameterClazzes() {
- if (parameterClazzes == null){
+ if (parameterClazzes == null) {
Class paramClasses[] = method.getParameterTypes();
- if (paramClasses == null){
+ if (paramClasses == null) {
parameterClazzes = EMPTY_CLAZZ_ARRAY;
}
else {
parameterClazzes = new Clazz[paramClasses.length];
ClazzLoader loader = getDeclaringClazz().getClazzLoader();
- for (int i = 0; i < paramClasses.length; i++){
+ for (int i = 0; i < paramClasses.length; i++) {
String name = Clazz.getCanonicalClassName(paramClasses[i]);
- parameterClazzes[i] = loader.getClazzForName(name);
+ parameterClazzes[i] = loader.getClazzForName(name);
}
}
}
@@ -130,10 +130,10 @@
* @see org.apache.commons.clazz.ClazzOperation#getReturnClazz()
*/
public Clazz getReturnClazz() {
- if (!returnClazzCached){
+ if (!returnClazzCached) {
returnClazzCached = true;
Class returnType = method.getReturnType();
- if (returnType == null || returnType.equals(Void.TYPE)){
+ if (returnType == null || returnType.equals(Void.TYPE)) {
returnClazz = null;
}
else {
@@ -144,7 +144,7 @@
return returnClazz;
}
- public String toString(){
+ public String toString() {
return getSignature();
}
}
1.3 +4 -3 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedMethodInstanceFactoryIntrospector.java
Index: ReflectedMethodInstanceFactoryIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedMethodInstanceFactoryIntrospector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedMethodInstanceFactoryIntrospector.java 9 Jan 2003 03:23:59 -0000 1.2
+++ ReflectedMethodInstanceFactoryIntrospector.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -67,10 +67,11 @@
* @version $Id$
*/
public class ReflectedMethodInstanceFactoryIntrospector
- implements ReflectedInstanceFactoryIntrospector {
+ implements ReflectedInstanceFactoryIntrospector
+{
/**
- * @see org.apache.commons.clazz.reflect.ReflectedInstanceFactoryIntrospector#introspectInstanceFactories(org.apache.commons.clazz.reflect.ReflectedClazz, java.lang.Class)
+ * @see ReflectedInstanceFactoryIntrospector#introspectInstanceFactories(ReflectedClazz, Class)
*/
public List introspectInstanceFactories(
ReflectedClazz clazz,
1.3 +3 -3 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedMethodOperationIntrospector.java
Index: ReflectedMethodOperationIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedMethodOperationIntrospector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedMethodOperationIntrospector.java 9 Jan 2003 03:23:59 -0000 1.2
+++ ReflectedMethodOperationIntrospector.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -77,9 +77,9 @@
{
ArrayList list = new ArrayList();
Method methods[] = javaClass.getDeclaredMethods();
- for (int i = 0; i < methods.length; i++){
+ for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
- if (Modifier.isPublic(method.getModifiers())){
+ if (Modifier.isPublic(method.getModifiers())) {
list.add(new ReflectedMethodOperation(clazz, method));
}
}
1.3 +37 -30 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedPropertyIntrospectorSupport.java
Index: ReflectedPropertyIntrospectorSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedPropertyIntrospectorSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedPropertyIntrospectorSupport.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedPropertyIntrospectorSupport.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -53,10 +53,16 @@
*/
package org.apache.commons.clazz.reflect.common;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.clazz.ClazzProperty;
-import org.apache.commons.clazz.reflect.*;
+import org.apache.commons.clazz.reflect.ReflectedClazz;
+import org.apache.commons.clazz.reflect.ReflectedPropertyIntrospector;
/**
*
@@ -68,38 +74,38 @@
{
/**
*/
- public List introspectProperties(ReflectedClazz clazz, Class javaClass) {
+ public List introspectProperties(ReflectedClazz clazz, Class javaClass) {
HashMap parseResultMap = new HashMap();
introspectProperties(clazz, javaClass, parseResultMap);
-
+
boolean loggingEnabled = clazz.isLoggingEnabled();
-
+
ArrayList list = new ArrayList();
Iterator iter = parseResultMap.values().iterator();
while (iter.hasNext()) {
- ReflectedPropertyParseResults parseResults =
- (ReflectedPropertyParseResults) iter.next();
- if (clazz.getProperty(parseResults.getPropertyName()) != null){
+ ReflectedPropertyParseResults parseResults =
+ (ReflectedPropertyParseResults) iter.next();
+ if (clazz.getProperty(parseResults.getPropertyName()) != null) {
continue;
}
-
+
boolean aliasExists = false;
String aliases[] = parseResults.getAliases();
- for (int i = 0; i < aliases.length; i++){
- if (clazz.getProperty(aliases[i]) != null){
+ for (int i = 0; i < aliases.length; i++) {
+ if (clazz.getProperty(aliases[i]) != null) {
aliasExists = true;
break;
}
}
- if (aliasExists){
+ if (aliasExists) {
continue;
}
boolean consistent = parseResults.checkConsistency();
- if (consistent){
+ if (consistent) {
list.add(createProperty(clazz, parseResults));
}
- if (loggingEnabled){
+ if (loggingEnabled) {
clazz.logPropertyParseResults(parseResults);
}
}
@@ -117,29 +123,29 @@
{
Class instanceClass = clazz.getInstanceClass();
List declaredPropertyList = null;
- if (instanceClass.getSuperclass() == null){
+ if (instanceClass.getSuperclass() == null) {
declaredPropertyList = clazz.getProperties();
}
else {
List superProperties = clazz.getSuperclazz().getProperties();
- if (superProperties.size() == 0){
+ if (superProperties.size() == 0) {
declaredPropertyList = clazz.getProperties();
}
else {
HashSet superNames = new HashSet();
- for (int i = 0; i < superProperties.size(); i++){
+ for (int i = 0; i < superProperties.size(); i++) {
ClazzProperty property =
- (ClazzProperty)superProperties.get(i);
+ (ClazzProperty) superProperties.get(i);
superNames.add(property.getName());
}
List properties = clazz.getProperties();
declaredPropertyList = new ArrayList();
- for (int i = 0; i < properties.size(); i++){
+ for (int i = 0; i < properties.size(); i++) {
ClazzProperty property =
(ClazzProperty) properties.get(i);
String name = property.getName();
- if (!superNames.contains(name)){
+ if (!superNames.contains(name)) {
declaredPropertyList.add(property);
}
}
@@ -163,22 +169,23 @@
* with the singular form and the remaining part of the plural form.
* Separately handles the "~y" - "~ies" substitution for English.
*/
- protected boolean isCorrectPluralForm(String singular, String plural){
- if (plural.startsWith(singular)){
+ protected boolean isCorrectPluralForm(String singular, String plural) {
+ if (plural.startsWith(singular)) {
return isCorrectPluralSuffix(
- singular,
- plural.substring(singular.length()));
+ singular,
+ plural.substring(singular.length()));
}
- else if (singular.endsWith("y") &&
- plural.endsWith("ies") &&
- plural.substring(0, plural.length() - 3).
- equals(singular.substring(singular.length() - 1))){
+ else if (
+ singular.endsWith("y")
+ && plural.endsWith("ies")
+ && plural.substring(0, plural.length() - 3).equals(
+ singular.substring(singular.length() - 1))) {
return true;
}
return false;
}
- protected boolean isCorrectPluralSuffix(String singular, String suffix){
+ protected boolean isCorrectPluralSuffix(String singular, String suffix) {
return suffix.equals("s");
}
}
1.3 +73 -73 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedPropertyParseResults.java
Index: ReflectedPropertyParseResults.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedPropertyParseResults.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedPropertyParseResults.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedPropertyParseResults.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -67,30 +67,29 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ReflectedPropertyParseResults implements Comparable
-{
+public abstract class ReflectedPropertyParseResults implements Comparable {
private ReflectedClazz clazz;
private String propertyName;
private List aliases;
-
+
protected AccessorMethodParseResults readMethodParseResults;
protected AccessorMethodParseResults writeMethodParseResults;
protected List extraneousAccessors;
-
+
private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
+
public ReflectedPropertyParseResults(
- ReflectedClazz clazz,
- String propertyName)
+ ReflectedClazz clazz,
+ String propertyName)
{
this.clazz = clazz;
this.propertyName = propertyName;
}
-
- public ReflectedClazz getClazz(){
+
+ public ReflectedClazz getClazz() {
return clazz;
}
-
+
/**
* Returns the propertyName.
* @return String
@@ -98,79 +97,79 @@
public String getPropertyName() {
return propertyName;
}
-
- public int compareTo(Object object){
+
+ public int compareTo(Object object) {
String n1 = getPropertyName();
String n2 = ((ReflectedPropertyParseResults) object).getPropertyName();
return n1.compareTo(n2);
}
-
- public String[] getAliases(){
- if (aliases == null){
+
+ public String[] getAliases() {
+ if (aliases == null) {
return EMPTY_STRING_ARRAY;
}
- return (String[])aliases.toArray(EMPTY_STRING_ARRAY);
+ return (String[]) aliases.toArray(EMPTY_STRING_ARRAY);
}
-
- public void addAlias(String alias){
- if (!alias.equals(propertyName)){
- if (aliases == null){
+
+ public void addAlias(String alias) {
+ if (!alias.equals(propertyName)) {
+ if (aliases == null) {
aliases = new ArrayList();
aliases.add(alias);
}
- else if (!aliases.contains(alias)){
+ else if (!aliases.contains(alias)) {
aliases.add(alias);
}
}
}
-
+
protected abstract String getPropertyCategory();
-
- public void merge(ReflectedPropertyParseResults other){
+
+ public void merge(ReflectedPropertyParseResults other) {
addAlias(other.getPropertyName());
String[] aliases = other.getAliases();
for (int i = 0; i < aliases.length; i++) {
addAlias(aliases[i]);
}
- }
-
- public Class getPropertyType(){
- if (readMethodParseResults != null){
+ }
+
+ public Class getPropertyType() {
+ if (readMethodParseResults != null) {
return readMethodParseResults.getType();
}
- if (writeMethodParseResults != null){
+ if (writeMethodParseResults != null) {
return writeMethodParseResults.getType();
}
return null;
}
-
+
public Method getReadMethod() {
- if (readMethodParseResults == null){
+ if (readMethodParseResults == null) {
return null;
}
return readMethodParseResults.getMethod();
}
-
+
public Method getWriteMethod() {
- if (writeMethodParseResults == null){
+ if (writeMethodParseResults == null) {
return null;
}
return writeMethodParseResults.getMethod();
}
-
+
/**
* Sets the readMethodParseResults.
* @param readMethodParseResults The readMethodParseResults to set
*/
public void setReadMethodParseResults(
- AccessorMethodParseResults readMethodParseResults)
+ AccessorMethodParseResults readMethodParseResults)
{
checkForExtraneousAccessor(
this.readMethodParseResults,
readMethodParseResults);
this.readMethodParseResults = readMethodParseResults;
}
-
+
/**
* Sets the writeMethodParseResults.
* @param writeMethodParseResults The writeMethodParseResults to set
@@ -183,39 +182,41 @@
writeMethodParseResults);
this.writeMethodParseResults = writeMethodParseResults;
}
-
+
/**
* Checks if there is an existing parse result recorded and if
- * so saves it into the extraneousAccessors for error reporting.
*/
+ * so saves it into the extraneousAccessors for error reporting.
+ */
protected void checkForExtraneousAccessor(
- AccessorMethodParseResults currentValue,
- AccessorMethodParseResults newValue)
+ AccessorMethodParseResults currentValue,
+ AccessorMethodParseResults newValue)
{
- if (currentValue != null && newValue != null &&
- currentValue != newValue){
- if (extraneousAccessors == null){
+ if (currentValue != null
+ && newValue != null
+ && currentValue != newValue) {
+ if (extraneousAccessors == null) {
extraneousAccessors = new ArrayList();
extraneousAccessors.add(currentValue);
}
}
}
-
- public boolean checkConsistency(){
- if (extraneousAccessors != null){
+
+ public boolean checkConsistency() {
+ if (extraneousAccessors != null) {
return false;
}
-
+
return true;
}
-
- public String toString(){
+
+ public String toString() {
boolean consistent = checkConsistency();
-
+
StringBuffer buffer = new StringBuffer();
buffer.append("[");
- if (consistent){
+ if (consistent) {
buffer.append(propertyName);
- if (!getPropertyCategory().equals("scalar")){
+ if (!getPropertyCategory().equals("scalar")) {
buffer.append(" (");
buffer.append(getPropertyCategory());
buffer.append(")");
@@ -223,18 +224,18 @@
}
else {
buffer.append("*");
- buffer.append(propertyName);
+ buffer.append(propertyName);
buffer.append(" - NOT a ");
- if (!getPropertyCategory().equals("scalar")){
+ if (!getPropertyCategory().equals("scalar")) {
buffer.append(getPropertyCategory());
}
buffer.append(" property");
appendInconsistencyDescriptions(buffer);
}
- if (aliases != null){
+ if (aliases != null) {
buffer.append("\n [aliases: ");
- for (int i = 0; i < aliases.size(); i++){
- if (i != 0){
+ for (int i = 0; i < aliases.size(); i++) {
+ if (i != 0) {
buffer.append(", ");
}
buffer.append(aliases.get(i));
@@ -248,37 +249,36 @@
buffer.append("\n]");
return buffer.toString();
}
-
- protected void appendDescription(StringBuffer buffer){
+
+ protected void appendDescription(StringBuffer buffer) {
Class type = getPropertyType();
- if (type != null){
+ if (type != null) {
buffer.append("\n [type] ");
buffer.append(Clazz.getCanonicalClassName(type));
}
}
-
- protected void appendMethodDescriptions(StringBuffer buffer){
- if (readMethodParseResults != null){
+
+ protected void appendMethodDescriptions(StringBuffer buffer) {
+ if (readMethodParseResults != null) {
buffer.append("\n [get~()] ");
buffer.append(readMethodParseResults.getMethod());
}
- if (writeMethodParseResults != null){
+ if (writeMethodParseResults != null) {
buffer.append("\n [set~(v)] ");
buffer.append(writeMethodParseResults.getMethod());
}
}
-
- protected boolean appendInconsistencyDescriptions(StringBuffer buffer){
- if (extraneousAccessors != null){
- buffer.append(
- "\n - Has extraneous accessors:");
+
+ protected boolean appendInconsistencyDescriptions(StringBuffer buffer) {
+ if (extraneousAccessors != null) {
+ buffer.append("\n - Has extraneous accessors:");
for (int i = 0; i < extraneousAccessors.size(); i++) {
AccessorMethodParseResults results =
- (AccessorMethodParseResults)extraneousAccessors.get(i);
+ (AccessorMethodParseResults) extraneousAccessors.get(i);
buffer.append("\n ");
buffer.append(results.getMethod());
}
- }
+ }
return true;
- }
+ }
}
1.3 +5 -5 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedScalarProperty.java
Index: ReflectedScalarProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedScalarProperty.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedScalarProperty.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedScalarProperty.java 20 Jan 2003 18:29:43 -0000 1.3
@@ -70,18 +70,18 @@
super(declaringClazz, name);
}
- public String toString(){
+ public String toString() {
StringBuffer buffer = new StringBuffer("[ReflectedScalarProperty ");
- if (getType() != null){
+ if (getType() != null) {
buffer.append(getType().getName());
buffer.append(" ");
}
buffer.append(getName());
- if (getReadMethod() != null){
+ if (getReadMethod() != null) {
buffer.append("\n [read method] ");
buffer.append(getReadMethod());
}
- if (getWriteMethod() != null){
+ if (getWriteMethod() != null) {
buffer.append("\n [write method] ");
buffer.append(getWriteMethod());
}
1.4 +29 -30 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedScalarPropertyIntrospector.java
Index: ReflectedScalarPropertyIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedScalarPropertyIntrospector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedScalarPropertyIntrospector.java 9 Jan 2003 03:23:59 -0000 1.3
+++ ReflectedScalarPropertyIntrospector.java 20 Jan 2003 18:29:43 -0000 1.4
@@ -67,10 +67,10 @@
public class ReflectedScalarPropertyIntrospector
extends ReflectedPropertyIntrospectorSupport
{
- protected static AccessorMethodParser READ_METHOD_PARSER =
+ protected static final AccessorMethodParser READ_METHOD_PARSER =
new JBReadAccessorMethodParser();
- protected static AccessorMethodParser WRITE_METHOD_PARSER =
+ protected static final AccessorMethodParser WRITE_METHOD_PARSER =
new WriteAccessorMethodParser();
public void introspectProperties(
@@ -81,14 +81,14 @@
Method methods[] = javaClass.getMethods();
ReflectedScalarPropertyParseResults parseResults;
AccessorMethodParseResults results;
- for (int i = 0; i < methods.length; i++){
+ for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
- if (method.getDeclaringClass().equals(Object.class)){
+ if (method.getDeclaringClass().equals(Object.class)) {
continue;
}
results = getReadAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -99,7 +99,7 @@
}
results = getWriteAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -114,11 +114,11 @@
/**
* Override to return an alternative parser for the read accessor method.
*/
- protected AccessorMethodParser getReadAccessorMethodParser(){
+ protected AccessorMethodParser getReadAccessorMethodParser() {
return READ_METHOD_PARSER;
}
- protected AccessorMethodParser getWriteAccessorMethodParser(){
+ protected AccessorMethodParser getWriteAccessorMethodParser() {
return WRITE_METHOD_PARSER;
}
@@ -165,18 +165,17 @@
* <li>No parameters</li>
* </ul>
*/
- public static class ReadAccessorMethodParser extends AccessorMethodParser
- {
- protected boolean testReturnType(Class returnType){
+ public static class ReadAccessorMethodParser extends AccessorMethodParser {
+ protected boolean testReturnType(Class returnType) {
return !returnType.equals(Void.TYPE);
- }
- protected int requiredParameterCount(){
+ }
+ protected int requiredParameterCount() {
return 0;
- }
- protected String requiredPrefix(){
+ }
+ protected String requiredPrefix() {
return "get";
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getReturnType();
}
}
@@ -193,29 +192,29 @@
public static class JBReadAccessorMethodParser
extends ReadAccessorMethodParser
{
- protected String getPropertyName(Method method){
+ protected String getPropertyName(Method method) {
String name = method.getName();
String propertyName = null;
- if (name.startsWith("get")){
- if (name.length() <= 3){
+ if (name.startsWith("get")) {
+ if (name.length() <= 3) {
return null;
}
- if (!testFirstCharacterOfPropertyName(name.charAt(3))){
+ if (!testFirstCharacterOfPropertyName(name.charAt(3))) {
return null;
}
propertyName = decapitalize(name.substring(3));
}
- else if (method.getReturnType().equals(Boolean.TYPE) &&
- name.startsWith("is")){
- if (name.length() <= 2){
+ else if (method.getReturnType().equals(Boolean.TYPE)
+ && name.startsWith("is")) {
+ if (name.length() <= 2) {
return null;
}
- if (!testFirstCharacterOfPropertyName(name.charAt(2))){
+ if (!testFirstCharacterOfPropertyName(name.charAt(2))) {
return null;
}
propertyName = decapitalize(name.substring(2));
}
- return propertyName;
+ return propertyName;
}
};
@@ -228,16 +227,16 @@
* </ul>
*/
public static class WriteAccessorMethodParser extends AccessorMethodParser {
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "set";
}
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return returnType.equals(Void.TYPE);
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[0];
}
}
1.2 +12 -12 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedScalarPropertyParseResults.java
Index: ReflectedScalarPropertyParseResults.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/common/ReflectedScalarPropertyParseResults.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedScalarPropertyParseResults.java 6 Dec 2002 01:12:49 -0000 1.1
+++ ReflectedScalarPropertyParseResults.java 20 Jan 2003 18:29:43 -0000 1.2
@@ -74,41 +74,41 @@
super(clazz, propertyName);
}
- protected String getPropertyCategory(){
+ protected String getPropertyCategory() {
return "scalar";
}
- public boolean checkConsistency(){
- if (!super.checkConsistency()){
+ public boolean checkConsistency() {
+ if (!super.checkConsistency()) {
return false;
}
- if (readMethodParseResults == null){
+ if (readMethodParseResults == null) {
return false;
}
Class type = readMethodParseResults.getType();
- if (writeMethodParseResults != null){
- if (!type.equals(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null) {
+ if (!type.equals(writeMethodParseResults.getType())) {
return false;
}
}
return true;
}
- protected boolean appendInconsistencyDescriptions(StringBuffer buffer){
- if (!super.appendInconsistencyDescriptions(buffer)){
+ protected boolean appendInconsistencyDescriptions(StringBuffer buffer) {
+ if (!super.appendInconsistencyDescriptions(buffer)) {
return false;
}
- if (readMethodParseResults == null){
+ if (readMethodParseResults == null) {
buffer.append("\n - Does not have a get() method");
return true;
}
Class type = readMethodParseResults.getType();
- if (writeMethodParseResults != null){
- if (!type.equals(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null) {
+ if (!type.equals(writeMethodParseResults.getType())) {
buffer.append("\n - Get() and set(v) types do not match");
}
}
1.4 +39 -39 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ExtendedReflectedListPropertyIntrospector.java
Index: ExtendedReflectedListPropertyIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ExtendedReflectedListPropertyIntrospector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ExtendedReflectedListPropertyIntrospector.java 9 Jan 2003 03:24:00 -0000 1.3
+++ ExtendedReflectedListPropertyIntrospector.java 20 Jan 2003 18:29:44 -0000 1.4
@@ -58,7 +58,7 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.clazz.reflect.*;
+import org.apache.commons.clazz.reflect.ReflectedClazz;
import org.apache.commons.clazz.reflect.common.*;
/**
@@ -103,7 +103,7 @@
// because the parser for the latter is generic enough
// to include the former
results = getSizeAccessorMethodParser().parse(method3);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -114,7 +114,7 @@
}
results = getReadAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -125,7 +125,7 @@
}
results = getWriteAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -136,7 +136,7 @@
}
results = getGetAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -147,7 +147,7 @@
}
results = getSetAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -158,7 +158,7 @@
}
results = getAddAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -169,7 +169,7 @@
}
results = getAddIndexedAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -180,7 +180,7 @@
}
results = getRemoveAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -191,7 +191,7 @@
}
results = getRemoveIndexedAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -207,7 +207,7 @@
Map.Entry entry = (Map.Entry) iter.next();
ReflectedListPropertyParseResults result =
(ReflectedListPropertyParseResults) entry.getValue();
- if (!result.isList()){
+ if (!result.isList()) {
iter.remove();
}
}
@@ -241,11 +241,11 @@
*
* @see ReflectedPropertyIntrospectorSupport#isCorrectPluralSuffix(String,String)
*/
- protected boolean isCorrectPluralSuffix(String singular, String suffix){
- return super.isCorrectPluralSuffix(singular, suffix) ||
- suffix.equals("List") ||
- suffix.equals("Array") ||
- suffix.equals("Vector");
+ protected boolean isCorrectPluralSuffix(String singular, String suffix) {
+ return super.isCorrectPluralSuffix(singular, suffix)
+ || suffix.equals("List")
+ || suffix.equals("Array")
+ || suffix.equals("Vector");
}
/**
@@ -258,13 +258,13 @@
* </ul>
*/
public static class AddAccessorMethodParser extends AccessorMethodParser {
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "add";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -278,22 +278,22 @@
* <li>Two parameters, first integer</li>
* </ul>
*/
- public static class AddIndexedAccessorMethodParser
+ public static class AddIndexedAccessorMethodParser
extends AccessorMethodParser
{
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "add";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 2;
}
- protected boolean testParameterType(int index, Class parameterType){
- if (index == 0){
+ protected boolean testParameterType(int index, Class parameterType) {
+ if (index == 0) {
return parameterType.equals(Integer.TYPE);
}
return true;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[1];
}
}
@@ -309,13 +309,13 @@
public static class RemoveIndexedAccessorMethodParser
extends AccessorMethodParser
{
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "remove";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected boolean testParameterType(int index, Class parameterType){
+ protected boolean testParameterType(int index, Class parameterType) {
return parameterType.equals(Integer.TYPE);
}
}
@@ -331,16 +331,16 @@
public static class RemoveAccessorMethodParser
extends AccessorMethodParser
{
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "remove";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected boolean testParameterType(int index, Class parameterType){
+ protected boolean testParameterType(int index, Class parameterType) {
return !parameterType.equals(Integer.TYPE);
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -355,20 +355,20 @@
* </ul>
*/
public static class SizeAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class javaClass){
+ protected boolean testReturnType(Class javaClass) {
return javaClass.equals(Integer.TYPE);
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "get";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 0;
}
- protected String testAndRemoveSuffix(String methodName){
- if (methodName.endsWith("Count")){
+ protected String testAndRemoveSuffix(String methodName) {
+ if (methodName.endsWith("Count")) {
return methodName.substring(0, methodName.length() - 5);
}
- if (methodName.endsWith("Size")){
+ if (methodName.endsWith("Size")) {
return methodName.substring(0, methodName.length() - 4);
}
return null;
1.3 +37 -29 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMap.java
Index: ReflectedMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMap.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedMap.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedMap.java 20 Jan 2003 18:29:44 -0000 1.3
@@ -56,7 +56,16 @@
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import org.apache.commons.clazz.ClazzAccessException;
@@ -80,8 +89,7 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class ReflectedMap extends AbstractMap
-{
+public class ReflectedMap extends AbstractMap {
private Object instance;
private ReflectedMappedProperty property;
private int modCount = 0;
@@ -97,16 +105,16 @@
this.property = property;
}
- public Map getPropertyValue(){
+ public Map getPropertyValue() {
Method readMethod = property.getReadMethod();
- if (readMethod == null){
+ if (readMethod == null) {
throw new ClazzAccessException(
"Cannot read property "
+ property.getName()
+ ": no read method");
}
try {
- return (Map)readMethod.invoke(instance, null);
+ return (Map) readMethod.invoke(instance, null);
}
catch (Exception ex) {
throw accessException("Cannot read property", readMethod, ex);
@@ -115,7 +123,7 @@
public void setPropertyValue(Map value) {
Method writeMethod = property.getWriteMethod();
- if (writeMethod == null){
+ if (writeMethod == null) {
throw new ClazzAccessException(
"Cannot set property: "
+ property.getName()
@@ -178,7 +186,7 @@
*/
public Object get(Object key) {
Method getMethod = property.getGetMethod();
- if (getMethod != null){
+ if (getMethod != null) {
Object value;
try {
value = getMethod.invoke(instance, new Object[]{key});
@@ -195,7 +203,7 @@
}
else {
Map map = getPropertyValue();
- if (map == null){
+ if (map == null) {
return null;
}
return map.get(key);
@@ -259,12 +267,12 @@
*/
public Object put(Object key, Object value) {
Method putMethod = property.getPutMethod();
- if (putMethod != null){
+ if (putMethod != null) {
Object oldValue = null;
try {
oldValue = get(key);
}
- catch (Throwable t){
+ catch (Throwable t) {
// Ignore
}
@@ -283,7 +291,7 @@
}
else {
Map map = getPropertyValue();
- if (map == null){
+ if (map == null) {
map = new HashMap();
setPropertyValue(map);
}
@@ -296,12 +304,12 @@
*/
public Object remove(Object key) {
Method removeMethod = property.getRemoveMethod();
- if (removeMethod != null){
+ if (removeMethod != null) {
Object oldValue = null;
try {
oldValue = get(key);
}
- catch (Throwable t){
+ catch (Throwable t) {
// Ignore
}
@@ -320,7 +328,7 @@
}
else {
Map map = getPropertyValue();
- if (map != null){
+ if (map != null) {
return map.remove(key);
}
return null;
@@ -367,20 +375,20 @@
private Set keySet;
private int size;
- public EntrySet(int type){
+ public EntrySet(int type) {
this.type = type;
update();
}
- public void refresh(){
+ public void refresh() {
// If EntrySet is out of sync with the
// parent ReflectedMap, update the cached key set and size
- if (modCount != ReflectedMap.this.modCount){
+ if (modCount != ReflectedMap.this.modCount) {
update();
}
}
- public void update(){
+ public void update() {
// Make sure modCount of EntrySet is maintained in sync with
// that of the embracing List
modCount = ReflectedMap.this.modCount;
@@ -389,17 +397,17 @@
size = keySet.size();
}
- public int size(){
+ public int size() {
refresh();
return size;
}
- public Iterator iterator(){
+ public Iterator iterator() {
refresh();
return new EntryIterator(keySet, type);
}
- public boolean remove(Object object){
+ public boolean remove(Object object) {
refresh();
Object key =
(type == KEYS ? object : ((Map.Entry) object).getKey());
@@ -408,10 +416,10 @@
try {
exists = keySet.contains(key);
}
- catch (Throwable t){
+ catch (Throwable t) {
// Ignore
}
- if (exists){
+ if (exists) {
ReflectedMap.this.remove(key);
}
return exists;
@@ -428,7 +436,7 @@
private Iterator keyIterator;
private Object lastReturned = UNINITIALIZED;
- public EntryIterator(Set keySet, int type){
+ public EntryIterator(Set keySet, int type) {
this.type = type;
this.keySet = keySet;
this.keyIterator = keySet.iterator();
@@ -446,7 +454,7 @@
*/
public Object next() {
lastReturned = keyIterator.next();
- if (type == KEYS){
+ if (type == KEYS) {
return lastReturned;
}
else {
@@ -458,7 +466,7 @@
* @see java.util.Iterator#remove()
*/
public void remove() {
- if (lastReturned == UNINITIALIZED){
+ if (lastReturned == UNINITIALIZED) {
throw new IllegalStateException();
}
ensureConcurrentChangeSafety();
@@ -549,7 +557,7 @@
* directly from the map value of the property.
*/
private static class ConcurrentChangeSafeSet extends HashSet {
- public ConcurrentChangeSafeSet(Collection collection){
+ public ConcurrentChangeSafeSet(Collection collection) {
super(collection);
}
}
1.3 +14 -14 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMappedProperty.java
Index: ReflectedMappedProperty.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMappedProperty.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedMappedProperty.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedMappedProperty.java 20 Jan 2003 18:29:44 -0000 1.3
@@ -186,44 +186,44 @@
this.keySetMethod = keySetMethod;
}
- public String toString(){
+ public String toString() {
StringBuffer buffer = new StringBuffer("[ReflectedMappedProperty ");
- if (getType() != null){
+ if (getType() != null) {
buffer.append(getType().getName());
buffer.append(" ");
}
- if (getKeyType() != null){
+ if (getKeyType() != null) {
buffer.append("[key: ");
buffer.append(getKeyType().getName());
buffer.append("] ");
}
- if (getContentType() != null){
+ if (getContentType() != null) {
buffer.append("[content: ");
buffer.append(getContentType().getName());
buffer.append("] ");
}
buffer.append(getName());
- if (getReadMethod() != null){
+ if (getReadMethod() != null) {
buffer.append("\n [read method] ");
buffer.append(getReadMethod());
}
- if (getWriteMethod() != null){
+ if (getWriteMethod() != null) {
buffer.append("\n [write method] ");
buffer.append(getWriteMethod());
}
- if (getGetMethod() != null){
+ if (getGetMethod() != null) {
buffer.append("\n [get method] ");
buffer.append(getGetMethod());
}
- if (getPutMethod() != null){
+ if (getPutMethod() != null) {
buffer.append("\n [put method] ");
buffer.append(getPutMethod());
}
- if (getRemoveMethod() != null){
+ if (getRemoveMethod() != null) {
buffer.append("\n [remove method] ");
buffer.append(getRemoveMethod());
}
- if (getKeySetMethod() != null){
+ if (getKeySetMethod() != null) {
buffer.append("\n [keySet method] ");
buffer.append(getKeySetMethod());
}
@@ -238,15 +238,15 @@
}
public Map getMap(Object instance) {
- if (getReadMethod() == null){
+ if (getReadMethod() == null) {
return null;
}
- return (Map)super.get(instance);
+ return (Map) super.get(instance);
}
/**
- * @see org.apache.commons.clazz.ClazzProperty#set(java.lang.Object, java.lang.Object)
+ * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object)
*/
public void set(Object instance, Object value) {
super.set(instance, value);
1.4 +58 -53 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMappedPropertyIntrospector.java
Index: ReflectedMappedPropertyIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMappedPropertyIntrospector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectedMappedPropertyIntrospector.java 9 Jan 2003 03:24:00 -0000 1.3
+++ ReflectedMappedPropertyIntrospector.java 20 Jan 2003 18:29:44 -0000 1.4
@@ -54,9 +54,12 @@
package org.apache.commons.clazz.reflect.extended;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
-import org.apache.commons.clazz.reflect.*;
+import org.apache.commons.clazz.reflect.ReflectedClazz;
import org.apache.commons.clazz.reflect.common.*;
/**
@@ -105,7 +108,7 @@
// because the parser for the latter is generic enough
// to include the former
results = getKeySetAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -116,7 +119,7 @@
}
results = getReadAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -127,7 +130,7 @@
}
results = getWriteAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -138,7 +141,7 @@
}
results = getGetAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -149,7 +152,7 @@
}
results = getPutAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -160,7 +163,7 @@
}
results = getRemoveAccessorMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -176,7 +179,7 @@
Map.Entry entry = (Map.Entry) iter.next();
ReflectedMappedPropertyParseResults result =
(ReflectedMappedPropertyParseResults) entry.getValue();
- if (!result.isMap()){
+ if (!result.isMap()) {
iter.remove();
}
}
@@ -184,27 +187,27 @@
mergeSingularMethods(parseResultMap, parseResultMapSingular);
}
- protected AccessorMethodParser getReadAccessorMethodParser(){
+ protected AccessorMethodParser getReadAccessorMethodParser() {
return READ_METHOD_PARSER;
}
- protected AccessorMethodParser getWriteAccessorMethodParser(){
+ protected AccessorMethodParser getWriteAccessorMethodParser() {
return WRITE_METHOD_PARSER;
}
- protected AccessorMethodParser getGetAccessorMethodParser(){
+ protected AccessorMethodParser getGetAccessorMethodParser() {
return GET_METHOD_PARSER;
}
- protected AccessorMethodParser getPutAccessorMethodParser(){
+ protected AccessorMethodParser getPutAccessorMethodParser() {
return PUT_METHOD_PARSER;
}
- protected AccessorMethodParser getRemoveAccessorMethodParser(){
+ protected AccessorMethodParser getRemoveAccessorMethodParser() {
return REMOVE_METHOD_PARSER;
}
- protected AccessorMethodParser getKeySetAccessorMethodParser(){
+ protected AccessorMethodParser getKeySetAccessorMethodParser() {
return KEY_SET_METHOD_PARSER;
}
@@ -265,9 +268,9 @@
*
* @see ReflectedPropertyIntrospectorSupport#isCorrectPluralSuffix(String,String)
*/
- protected boolean isCorrectPluralSuffix(String singular, String suffix){
- return super.isCorrectPluralSuffix(singular, suffix) ||
- suffix.equals("Map");
+ protected boolean isCorrectPluralSuffix(String singular, String suffix) {
+ return super.isCorrectPluralSuffix(singular, suffix)
+ || suffix.equals("Map");
}
@@ -302,7 +305,7 @@
new ReflectedMappedProperty(clazz, parseResults.getPropertyName());
ReflectedMappedPropertyParseResults parseResultsMapped =
- (ReflectedMappedPropertyParseResults)parseResults;
+ (ReflectedMappedPropertyParseResults) parseResults;
property.setAliases(parseResultsMapped.getAliases());
property.setType(parseResultsMapped.getPropertyType());
@@ -330,16 +333,16 @@
* property as NotAProperty.
*/
public static class ReadAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return !returnType.equals(Void.TYPE);
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "get";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 0;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getReturnType();
}
}
@@ -357,16 +360,16 @@
* property as NotAProperty.
*/
public static class WriteAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return returnType.equals(Void.TYPE);
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "set";
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -381,19 +384,19 @@
* </ul>
*/
public static class GetAccessorMethodParser extends AccessorMethodParser {
- protected boolean testReturnType(Class returnType){
+ protected boolean testReturnType(Class returnType) {
return !returnType.equals(Void.TYPE);
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "get";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getReturnType();
}
- protected Class getParameterType(Method method){
+ protected Class getParameterType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -408,16 +411,16 @@
* </ul>
*/
public static class PutAccessorMethodParser extends AccessorMethodParser {
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "set";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 2;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
return method.getParameterTypes()[1];
}
- protected Class getParameterType(Method method){
+ protected Class getParameterType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -430,21 +433,23 @@
* <li>One parameter</li>
* </ul>
*/
- public static class RemoveAccessorMethodParser extends AccessorMethodParser {
- protected String requiredPrefix(){
+ public static class RemoveAccessorMethodParser
+ extends AccessorMethodParser
+ {
+ protected String requiredPrefix() {
return "remove";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 1;
}
- protected Class getValueType(Method method){
+ protected Class getValueType(Method method) {
Class returnType = method.getReturnType();
- if (Void.TYPE.equals(returnType)){
+ if (Void.TYPE.equals(returnType)) {
return null;
}
return returnType;
}
- protected Class getParameterType(Method method){
+ protected Class getParameterType(Method method) {
return method.getParameterTypes()[0];
}
}
@@ -458,24 +463,24 @@
* <li>No parameters</li>
* </ul>
*/
- public static class KeySetAccessorMethodParser
- extends AccessorMethodParser
+ public static class KeySetAccessorMethodParser
+ extends AccessorMethodParser
{
- protected boolean testReturnType(Class javaClass){
- return javaClass.isArray() ||
- Collection.class.isAssignableFrom(javaClass);
+ protected boolean testReturnType(Class javaClass) {
+ return javaClass.isArray()
+ || Collection.class.isAssignableFrom(javaClass);
}
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "get";
}
- protected int requiredParameterCount(){
+ protected int requiredParameterCount() {
return 0;
}
- protected String testAndRemoveSuffix(String methodName){
- if (methodName.endsWith("Keys")){
+ protected String testAndRemoveSuffix(String methodName) {
+ if (methodName.endsWith("Keys")) {
return methodName.substring(0, methodName.length() - 4);
}
- if (methodName.endsWith("KeySet")){
+ if (methodName.endsWith("KeySet")) {
return methodName.substring(0, methodName.length() - 6);
}
return null;
1.3 +64 -64 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMappedPropertyParseResults.java
Index: ReflectedMappedPropertyParseResults.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/extended/ReflectedMappedPropertyParseResults.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedMappedPropertyParseResults.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedMappedPropertyParseResults.java 20 Jan 2003 18:29:44 -0000 1.3
@@ -85,7 +85,7 @@
super(clazz, propertyName);
}
- protected String getPropertyCategory(){
+ protected String getPropertyCategory() {
return "mapped";
}
@@ -93,43 +93,43 @@
* Returns <code>true</code> if the property is
* java.util.Map or implements java.util.Map.
*/
- protected boolean isMap(){
- if (readMethodParseResults != null &&
- isMap(readMethodParseResults.getType())){
+ protected boolean isMap() {
+ if (readMethodParseResults != null
+ && isMap(readMethodParseResults.getType())) {
return true;
}
- if (writeMethodParseResults != null &&
- isMap(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null
+ && isMap(writeMethodParseResults.getType())) {
return true;
}
- return false;
+ return false;
}
- private boolean isMap(Class javaClass){
+ private boolean isMap(Class javaClass) {
return javaClass != null && Map.class.isAssignableFrom(javaClass);
}
- public Class getKeyType(){
- if (getMethodParseResults != null){
+ public Class getKeyType() {
+ if (getMethodParseResults != null) {
return getMethodParseResults.getParameterType();
}
- if (putMethodParseResults != null){
+ if (putMethodParseResults != null) {
return putMethodParseResults.getParameterType();
}
- if (removeMethodParseResults != null){
+ if (removeMethodParseResults != null) {
return removeMethodParseResults.getParameterType();
}
return null;
}
- public Class getContentType(){
- if (getMethodParseResults != null){
+ public Class getContentType() {
+ if (getMethodParseResults != null) {
return getMethodParseResults.getType();
}
- if (putMethodParseResults != null){
+ if (putMethodParseResults != null) {
return putMethodParseResults.getType();
}
- if (removeMethodParseResults != null){
+ if (removeMethodParseResults != null) {
return removeMethodParseResults.getType();
}
return null;
@@ -146,7 +146,7 @@
}
public Method getGetMethod() {
- if (getMethodParseResults == null){
+ if (getMethodParseResults == null) {
return null;
}
return getMethodParseResults.getMethod();
@@ -163,7 +163,7 @@
}
public Method getPutMethod() {
- if (putMethodParseResults == null){
+ if (putMethodParseResults == null) {
return null;
}
return putMethodParseResults.getMethod();
@@ -179,7 +179,7 @@
}
public Method getRemoveMethod() {
- if (removeMethodParseResults == null){
+ if (removeMethodParseResults == null) {
return null;
}
return removeMethodParseResults.getMethod();
@@ -195,7 +195,7 @@
}
public Method getKeySetMethod() {
- if (keySetMethodParseResults == null){
+ if (keySetMethodParseResults == null) {
return null;
}
return keySetMethodParseResults.getMethod();
@@ -209,76 +209,76 @@
* Node that the property name is not copied from the
* <code>other</code> object.
*/
- public void merge(ReflectedMappedPropertyParseResults other){
+ public void merge(ReflectedMappedPropertyParseResults other) {
super.merge(other);
- if (other.readMethodParseResults != null){
+ if (other.readMethodParseResults != null) {
setReadMethodParseResults(other.readMethodParseResults);
}
- if (other.writeMethodParseResults != null){
+ if (other.writeMethodParseResults != null) {
setWriteMethodParseResults(other.writeMethodParseResults);
}
- if (other.getMethodParseResults != null){
+ if (other.getMethodParseResults != null) {
setGetMethodParseResults(other.getMethodParseResults);
}
- if (other.putMethodParseResults != null){
+ if (other.putMethodParseResults != null) {
setPutMethodParseResults(other.putMethodParseResults);
}
- if (other.removeMethodParseResults != null){
+ if (other.removeMethodParseResults != null) {
setRemoveMethodParseResults(other.removeMethodParseResults);
}
- if (other.keySetMethodParseResults != null){
+ if (other.keySetMethodParseResults != null) {
setKeySetMethodParseResults(other.keySetMethodParseResults);
}
}
- protected void appendDescription(StringBuffer buffer){
+ protected void appendDescription(StringBuffer buffer) {
super.appendDescription(buffer);
Class keyType = getKeyType();
- if (keyType != null){
+ if (keyType != null) {
buffer.append("\n [key type] ");
buffer.append(Clazz.getCanonicalClassName(keyType));
}
Class contentType = getContentType();
- if (contentType != null){
+ if (contentType != null) {
buffer.append("\n [content type] ");
buffer.append(Clazz.getCanonicalClassName(contentType));
}
}
- protected void appendMethodDescriptions(StringBuffer buffer){
+ protected void appendMethodDescriptions(StringBuffer buffer) {
super.appendMethodDescriptions(buffer);
- if (getMethodParseResults != null){
+ if (getMethodParseResults != null) {
buffer.append("\n [get~(key)] ");
buffer.append(getMethodParseResults.getMethod());
}
- if (putMethodParseResults != null){
+ if (putMethodParseResults != null) {
buffer.append("\n [set~(key,v)] ");
buffer.append(putMethodParseResults.getMethod());
}
- if (removeMethodParseResults != null){
+ if (removeMethodParseResults != null) {
buffer.append("\n [remove~(key)] ");
buffer.append(removeMethodParseResults.getMethod());
}
- if (keySetMethodParseResults != null){
+ if (keySetMethodParseResults != null) {
buffer.append("\n [get~KeySet()] ");
buffer.append(keySetMethodParseResults.getMethod());
}
}
- public boolean checkConsistency(){
- if (!super.checkConsistency()){
+ public boolean checkConsistency() {
+ if (!super.checkConsistency()) {
return false;
}
- if (readMethodParseResults == null && getMethodParseResults == null){
+ if (readMethodParseResults == null && getMethodParseResults == null) {
return false;
}
- if (readMethodParseResults != null){
+ if (readMethodParseResults != null) {
Class type = readMethodParseResults.getType();
- if (writeMethodParseResults != null){
- if (!type.equals(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null) {
+ if (!type.equals(writeMethodParseResults.getType())) {
return false;
}
}
@@ -287,27 +287,27 @@
Class keyType = null;
Class contentType = null;
- if (getMethodParseResults != null){
+ if (getMethodParseResults != null) {
keyType = getMethodParseResults.getParameterType();
contentType = getMethodParseResults.getType();
}
- if (putMethodParseResults != null){
- if (keyType == null){
+ if (putMethodParseResults != null) {
+ if (keyType == null) {
keyType = putMethodParseResults.getParameterType();
}
else {
- if (!keyType.equals(putMethodParseResults.getParameterType())){
+ if (!keyType.equals(putMethodParseResults.getParameterType())) {
return false;
}
}
- if (contentType == null){
+ if (contentType == null) {
contentType = putMethodParseResults.getType();
}
else {
if (!contentType.equals(
- putMethodParseResults.getType())){
+ putMethodParseResults.getType())) {
return false;
}
}
@@ -320,9 +320,9 @@
return false;
}
- if (contentType != null){
+ if (contentType != null) {
Class removeType = removeMethodParseResults.getType();
- if (removeType != null && !contentType.equals(removeType)){
+ if (removeType != null && !contentType.equals(removeType)) {
return false;
}
}
@@ -331,21 +331,21 @@
return true;
}
- protected boolean appendInconsistencyDescriptions(StringBuffer buffer){
- if (!super.appendInconsistencyDescriptions(buffer)){
+ protected boolean appendInconsistencyDescriptions(StringBuffer buffer) {
+ if (!super.appendInconsistencyDescriptions(buffer)) {
return false;
}
- if (readMethodParseResults == null && getMethodParseResults == null){
+ if (readMethodParseResults == null && getMethodParseResults == null) {
buffer.append(
"\n - Does not have either get() or get(key) method");
return true;
}
- if (readMethodParseResults != null){
+ if (readMethodParseResults != null) {
Class type = readMethodParseResults.getType();
- if (writeMethodParseResults != null){
- if (!type.equals(writeMethodParseResults.getType())){
+ if (writeMethodParseResults != null) {
+ if (!type.equals(writeMethodParseResults.getType())) {
buffer.append(
"\n - Get() and set(v) types do not match");
}
@@ -355,29 +355,29 @@
Class keyType = null;
Class contentType = null;
- if (getMethodParseResults != null){
+ if (getMethodParseResults != null) {
keyType = getMethodParseResults.getParameterType();
contentType = getMethodParseResults.getType();
}
- if (putMethodParseResults != null){
- if (keyType == null){
+ if (putMethodParseResults != null) {
+ if (keyType == null) {
keyType = putMethodParseResults.getParameterType();
}
else {
- if (!keyType.equals(putMethodParseResults.getParameterType())){
+ if (!keyType.equals(putMethodParseResults.getParameterType())) {
buffer.append(
"\n - Key type mismatch between "
+ "get(key) and set(key,v)");
}
}
- if (contentType == null){
+ if (contentType == null) {
contentType = putMethodParseResults.getType();
}
else {
if (!contentType.equals(
- putMethodParseResults.getType())){
+ putMethodParseResults.getType())) {
buffer.append(
"\n - Content type mismatch between "
+ "get(key) and set(key,v)");
@@ -394,9 +394,9 @@
+ "get(key) and remove(key)");
}
- if (contentType != null){
+ if (contentType != null) {
Class removeType = removeMethodParseResults.getType();
- if (removeType != null && !contentType.equals(removeType)){
+ if (removeType != null && !contentType.equals(removeType)) {
buffer.append(
"\n - Content type mismatch between "
+ "get(key) and set(key,v)");
1.4 +2 -3 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/standard/StandardReflectedClazzLoader.java
Index: StandardReflectedClazzLoader.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/standard/StandardReflectedClazzLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StandardReflectedClazzLoader.java 9 Jan 2003 03:24:00 -0000 1.3
+++ StandardReflectedClazzLoader.java 20 Jan 2003 18:29:44 -0000 1.4
@@ -63,8 +63,7 @@
* @author Dmitri Plotnikov
* @version $Revision$ $Date$
*/
-public class StandardReflectedClazzLoader extends ReflectedClazzLoader
-{
+public class StandardReflectedClazzLoader extends ReflectedClazzLoader {
/**
* Constructor for StandardReflectedClazzLoader.
* @param modelClazzLoader
1.3 +7 -7 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/standard/StandardReflectedListPropertyIntrospector.java
Index: StandardReflectedListPropertyIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/reflect/standard/StandardReflectedListPropertyIntrospector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StandardReflectedListPropertyIntrospector.java 9 Jan 2003 03:24:00 -0000 1.2
+++ StandardReflectedListPropertyIntrospector.java 20 Jan 2003 18:29:44 -0000 1.3
@@ -58,7 +58,7 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.clazz.reflect.*;
+import org.apache.commons.clazz.reflect.ReflectedClazz;
import org.apache.commons.clazz.reflect.common.*;
/**
@@ -83,7 +83,7 @@
Method method = methods[i];
results = getReadAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -94,7 +94,7 @@
}
results = getWriteAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -105,7 +105,7 @@
}
results = getGetAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -116,7 +116,7 @@
}
results = getSetAccessMethodParser().parse(method);
- if (results != null){
+ if (results != null) {
parseResults =
getParseResults(
clazz,
@@ -151,7 +151,7 @@
* With the standard JavaBean indexed properties the plural form is the same
* as the singular form.
*/
- protected boolean isCorrectPluralForm(String singular, String plural){
+ protected boolean isCorrectPluralForm(String singular, String plural) {
return singular.equals(plural);
}
}
1.5 +3 -3 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/bean/BeanClazzLoaderTest.java
Index: BeanClazzLoaderTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/bean/BeanClazzLoaderTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BeanClazzLoaderTest.java 9 Jan 2003 03:24:00 -0000 1.4
+++ BeanClazzLoaderTest.java 20 Jan 2003 18:29:44 -0000 1.5
@@ -78,11 +78,11 @@
junit.textui.TestRunner.run(BeanClazzLoaderTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
return new TestSuite(BeanClazzLoaderTest.class);
}
- private Clazz defineClazz(){
+ private Clazz defineClazz() {
BeanClazz clazz =
(BeanClazz) Clazz
.getDefaultClazzLoader(getClass().getClassLoader())
1.6 +65 -76 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/bean/BeanClazzTest.java
Index: BeanClazzTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/bean/BeanClazzTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BeanClazzTest.java 9 Jan 2003 03:24:00 -0000 1.5
+++ BeanClazzTest.java 20 Jan 2003 18:29:44 -0000 1.6
@@ -70,9 +70,8 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class BeanClazzTest extends ClazzTestSupport
-{
-
+public class BeanClazzTest extends ClazzTestSupport {
+
public static final String TEST_PACKAGE = "clazz.test";
public static final String TEST_SUPERCLAZZ_SHORT_NAME = "TestBase";
public static final String TEST_CLAZZ_SHORT_NAME = "Test";
@@ -83,7 +82,7 @@
private BeanClazz superClazz;
private BeanClazz clazz;
-
+
/**
* Constructor for BeanClazzTest.
* @param name
@@ -96,14 +95,14 @@
junit.textui.TestRunner.run(BeanClazzTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
TestSuite suite = new TestSuite("BeanClazz tests");
suite.addTestSuite(BeanClazzLoaderTest.class);
suite.addTestSuite(BeanClazzTest.class);
return suite;
}
- public void setUp(){
+ public void setUp() {
ClazzLoader loader =
Clazz.getDefaultClazzLoader(getClass().getClassLoader());
superClazz =
@@ -125,45 +124,45 @@
new BeanClazzProperty(clazz, "objectProperty"));
clazz.addDeclaredProperty(
new BeanClazzProperty(clazz, "integerProperty", "int"));
-
-
- clazz.addDeclaredOperation(
- new BeanClazzOperation(clazz, null, "twoPlusTwo", null){
- public Object invoke(Object instance, Object[] parameters){
- return new Integer(4);
- }
+
+ clazz
+ .addDeclaredOperation(new BeanClazzOperation(
+ clazz,
+ null,
+ "twoPlusTwo",
+ null) {
+ public Object invoke(Object instance, Object[] parameters) {
+ return new Integer(4);
}
- );
+ });
- clazz.addDeclaredOperation(
- new BeanClazzOperation(
- clazz,
- "java.lang.Integer",
- "computeAplusB",
- new String[] { "java.lang.Integer", "java.lang.Integer" }) {
- public Object invoke(Object instance, Object[] parameters) {
- Integer arg1 = (Integer)parameters[0];
- Integer arg2 = (Integer)parameters[1];
- return new Integer(arg1.intValue() + arg2.intValue());
- }
+ clazz
+ .addDeclaredOperation(new BeanClazzOperation(
+ clazz,
+ "java.lang.Integer",
+ "computeAplusB",
+ new String[] { "java.lang.Integer", "java.lang.Integer" }) {
+ public Object invoke(Object instance, Object[] parameters) {
+ Integer arg1 = (Integer) parameters[0];
+ Integer arg2 = (Integer) parameters[1];
+ return new Integer(arg1.intValue() + arg2.intValue());
}
- );
-
- clazz.addInstanceFactory(
- new BeanClazzInstanceFactory(
- clazz,
- null,
- new String[]{"java.lang.String"}){
- public Object newInstance(Object parameters[]){
- String value = (String)parameters[0];
- BasicBean bb = new BasicBean(clazz);
- bb.set("objectProperty", value);
- return bb;
- }
+ });
+
+ clazz
+ .addInstanceFactory(new BeanClazzInstanceFactory(
+ clazz,
+ null,
+ new String[] { "java.lang.String" }) {
+ public Object newInstance(Object parameters[]) {
+ String value = (String) parameters[0];
+ BasicBean bb = new BasicBean(clazz);
+ bb.set("objectProperty", value);
+ return bb;
}
- );
+ });
}
-
+
public void testGetName() {
assertEquals("Clazz name", TEST_CLAZZ_NAME, clazz.getName());
}
@@ -191,25 +190,22 @@
public void testGetDeclaredProperties() {
assertPropertyList(
"Get properties",
- new String[]{
- "integerProperty",
- "objectProperty",
- },
- clazz.getDeclaredProperties());
+ new String[] { "integerProperty", "objectProperty", },
+ clazz.getDeclaredProperties());
}
public void testGetProperties() {
assertPropertyList(
"Get properties",
- new String[]{
+ new String[] {
"baseProperty",
"integerProperty",
"objectProperty",
- },
+ },
clazz.getProperties());
}
- public void testGetProperty() {
+ public void testGetProperty() {
ClazzProperty property = clazz.getProperty("integerProperty");
assertNotNull(property);
assertEquals("Property name", "integerProperty", property.getName());
@@ -220,14 +216,13 @@
assertNotNull(property);
assertEquals("Property name", "baseProperty", property.getName());
}
-
+
public void testGetOperations() {
assertOperationList(
"Get operations",
- new String[]{
+ new String[] {
"twoPlusTwo()",
- "computeAplusB(java.lang.Integer,java.lang.Integer)"
- },
+ "computeAplusB(java.lang.Integer,java.lang.Integer)" },
clazz.getOperations());
}
@@ -244,7 +239,7 @@
Object object = clazz.newInstance();
op.invoke(object, null);
}
-
+
public void testInvokeOperationWithParameters() {
ClazzOperation op =
clazz.getOperation(
@@ -254,15 +249,11 @@
op.invoke(object, new Object[] { new Integer(3), new Integer(4)});
assertEquals("Result value", new Integer(7), result);
}
-
+
public void testGetInstanceFactories() {
assertInstanceFactoryList(
"Get instance factories",
- new String[]{
- "()",
- "(java.util.Map)",
- "(java.lang.String)"
- },
+ new String[] { "()", "(java.util.Map)", "(java.lang.String)" },
clazz.getInstanceFactories());
}
@@ -288,12 +279,12 @@
public void testNewInstanceObjectArray() {
Map initialValues = new HashMap();
initialValues.put("integerProperty", new Integer(3));
-
+
Object object =
clazz.newInstance(
"(java.util.Map)",
new Object[] { initialValues });
-
+
assertNotNull(object);
assertTrue("New instance type ", object instanceof BasicBean);
assertEquals(
@@ -307,9 +298,7 @@
*/
public void testNewInstanceWithCustomFactory() {
Object object =
- clazz.newInstance(
- "(java.lang.String)",
- new Object[] { "foo" });
+ clazz.newInstance("(java.lang.String)", new Object[] { "foo" });
assertNotNull(object);
assertTrue("New instance type ", object instanceof BasicBean);
@@ -334,36 +323,36 @@
public void testIsAssignableFrom() {
}
- public void testRevealOverloadedProperty(){
- ClazzProperty superFoo = new BeanClazzProperty(superClazz, "foo");
+ public void testRevealOverloadedProperty() {
+ ClazzProperty superFoo = new BeanClazzProperty(superClazz, "foo");
superClazz.addDeclaredProperty(superFoo);
-
+
assertTrue(
"Super foo exposed on subclazz",
clazz.getProperty("foo") == superFoo);
-
+
ClazzProperty subFoo = new BeanClazzProperty(clazz, "foo");
clazz.addDeclaredProperty(subFoo);
assertTrue(
"Super foo masked by subclazz foo",
clazz.getProperty("foo") == subFoo);
-
+
clazz.removeDeclaredProperty(subFoo);
-
+
assertTrue(
"Super foo revealed when subclazz foo removed",
- clazz.getProperty("foo") == superFoo);
+ clazz.getProperty("foo") == superFoo);
}
- public void testRevealOverloadedOperation(){
+ public void testRevealOverloadedOperation() {
ClazzOperation superFoo =
- new BeanClazzOperation(superClazz, null, "foo", null) {
+ new BeanClazzOperation(superClazz, null, "foo", null) {
public Object invoke(Object instance, Object[] parameters) {
return null;
}
};
-
+
superClazz.addDeclaredOperation(superFoo);
assertTrue(
@@ -371,7 +360,7 @@
clazz.getOperation("foo()") == superFoo);
ClazzOperation subFoo =
- new BeanClazzOperation(clazz, null, "foo", null) {
+ new BeanClazzOperation(clazz, null, "foo", null) {
public Object invoke(Object instance, Object[] parameters) {
return null;
}
1.4 +104 -104 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectableInstance.java
Index: ReflectableInstance.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectableInstance.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectableInstance.java 14 Dec 2002 02:38:43 -0000 1.3
+++ ReflectableInstance.java 20 Jan 2003 18:29:44 -0000 1.4
@@ -66,8 +66,7 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class ReflectableInstance extends ReflectedSuperclazzInstance
-{
+public class ReflectableInstance extends ReflectedSuperclazzInstance {
private ArrayList traceList = new ArrayList();
private int integerProperty;
private boolean booleanProperty;
@@ -76,48 +75,50 @@
private Map mappedBooleans;
private int[] intArray;
private List stringList = new ArrayList();
- private String notAProperty; // Get/set have different types
-
- public ReflectableInstance(){
+ private String notAProperty; // Get/set have different types
+
+ public ReflectableInstance() {
}
-
- public ReflectableInstance(int intInit){
+
+ public ReflectableInstance(int intInit) {
integerProperty = intInit;
}
-
- public List trace(){
+
+ public List trace() {
return traceList;
}
-
- public void resetTrace(){
+
+ public void resetTrace() {
traceList.clear();
}
-
- private void trace(String methodName){
+
+ private void trace(String methodName) {
traceList.add(methodName);
}
-
- public String getter(){
+
+ public String getter() {
return null;
}
-
- public String get2er(){
+
+ public String get2er() {
return null;
}
-
- public String get_er(){
+
+ public String get_er() {
return null;
}
-
+
/**
* Please note that the write method for this property
* is declared by the superclass.
- *
* @return String
*/
- public String getHalfProperty(){
+ *
+ * @return String
+ */
+ public String getHalfProperty() {
trace("getHalfProperty()");
return halfProperty;
}
-
+
/**
* Returns the integerProperty.
* @return int
@@ -157,119 +158,118 @@
/**
* MappedStrings property has the full set of accessors.
*/
- public Map getMappedStrings(){
+ public Map getMappedStrings() {
trace("getMappedStrings()");
return Collections.unmodifiableMap(mappedStrings);
}
-
- public void setMappedStrings(Map mappedStrings){
+
+ public void setMappedStrings(Map mappedStrings) {
trace("setMappedStrings(Map)");
this.mappedStrings = new HashMap(mappedStrings);
- }
-
- public void setMappedString(String key, String value){
+ }
+
+ public void setMappedString(String key, String value) {
trace("setMappedString(String,String)");
mappedStrings.put(key, value);
}
-
- public String getMappedString(String key){
+
+ public String getMappedString(String key) {
trace("getMappedString(String)");
- return (String)mappedStrings.get(key);
+ return (String) mappedStrings.get(key);
}
-
- public void removeMappedString(String key){
+
+ public void removeMappedString(String key) {
trace("removeMappedString(String)");
mappedStrings.remove(key);
}
-
- public Set getMappedStringKeys(){
+
+ public Set getMappedStringKeys() {
trace("getMappedStringKeys()");
return mappedStrings.keySet();
}
-
+
/*
- * The mappedInteger property does not have "normal" get/set methods.
*/
- public void setMappedInteger(Integer key, Integer value){
+ * The mappedInteger property does not have "normal" get/set methods.
+ */
+ public void setMappedInteger(Integer key, Integer value) {
trace("setMappedInteger(Integer,Integer)");
mappedIntegers.put(key, value);
}
-
- public Integer getMappedInteger(Integer key){
+
+ public Integer getMappedInteger(Integer key) {
trace("getMappedInteger(Integer)");
- return (Integer)mappedIntegers.get(key);
+ return (Integer) mappedIntegers.get(key);
}
-
- public void removeMappedInteger(Integer key){
+
+ public void removeMappedInteger(Integer key) {
trace("removeMappedInteger(Integer)");
mappedIntegers.remove(key);
}
-
- public Integer[] getMappedIntegerKeys(){
+
+ public Integer[] getMappedIntegerKeys() {
trace("getMappedIntegerKeys()");
- return (Integer[])mappedIntegers.keySet().toArray(new Integer[0]);
+ return (Integer[]) mappedIntegers.keySet().toArray(new Integer[0]);
}
-
/*
* The mappedBooleans property does not have
* parameterized get/set/remove methods.
- */
- public Map getMappedBooleans(){
+ */
+ public Map getMappedBooleans() {
trace("getMappedBooleans()");
return mappedBooleans;
}
-
- public void setMappedBooleans(Map mappedBooleans){
+
+ public void setMappedBooleans(Map mappedBooleans) {
trace("setMappedBooleans(Map)");
this.mappedBooleans = mappedBooleans;
- }
-
+ }
- public int[] getIntArray(){
+ public int[] getIntArray() {
trace("getIntArray()");
return intArray;
}
-
- public void setIntArray(int[] array){
+
+ public void setIntArray(int[] array) {
trace("setIntArray(int[])");
this.intArray = array;
}
-
- public String getString(int index){
+
+ public String getString(int index) {
trace("getString(int)");
- return (String)stringList.get(index);
+ return (String) stringList.get(index);
}
-
- public void setString(int index, String string){
+
+ public void setString(int index, String string) {
trace("setString(int,String)");
stringList.set(index, string);
}
-
- public void addString(int index, String string){
+
+ public void addString(int index, String string) {
trace("addString(int,String)");
stringList.add(index, string);
}
-
- public void addString(String string){
+
+ public void addString(String string) {
trace("addString()");
stringList.add(string);
}
-
- public void removeString(String string){
+
+ public void removeString(String string) {
trace("removeString(String)");
stringList.remove(string);
}
-
- public void removeString(int index){
+
+ public void removeString(int index) {
trace("removeString(int)");
stringList.remove(index);
}
- public int getStringCount(){
+ public int getStringCount() {
trace("getStringCount()");
return stringList.size();
}
-
+
/**
* Returns the notAProperty.
* @return String
@@ -298,49 +298,49 @@
}
/**
- * If there is not "get" method, there is no mapped property
*/
- public void setNotAMappedProperty(String key, String value){
+ * If there is not "get" method, there is no mapped property
+ */
+ public void setNotAMappedProperty(String key, String value) {
trace("setNotAMappedProperty(String,String)");
}
-
- public void doNothing(){
+
+ public void doNothing() {
}
- public String toUpperCase(String string){
+ public String toUpperCase(String string) {
return string.toUpperCase();
}
-
+
public void scalars(
- boolean a,
- byte b,
- char c,
- short d,
- int e,
- long f,
- float g,
- double h,
- Object i,
- String j)
+ boolean a,
+ byte b,
+ char c,
+ short d,
+ int e,
+ long f,
+ float g,
+ double h,
+ Object i,
+ String j)
{
}
-
+
public void arrays(
- boolean[] a,
- byte[] b,
- char[] c,
- short[] d,
- int[] e,
- long[] f,
- float[] g,
- double[] h,
- Object[] i,
- String[] j,
- boolean[][] k,
- String[][] l
- )
+ boolean[] a,
+ byte[] b,
+ char[] c,
+ short[] d,
+ int[] e,
+ long[] f,
+ float[] g,
+ double[] h,
+ Object[] i,
+ String[] j,
+ boolean[][] k,
+ String[][] l)
{
}
-
+
/**
* Factory method
*/
1.2 +7 -7 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedClazzTestCommon.java
Index: ReflectedClazzTestCommon.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedClazzTestCommon.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedClazzTestCommon.java 9 Jan 2003 03:24:00 -0000 1.1
+++ ReflectedClazzTestCommon.java 20 Jan 2003 18:29:44 -0000 1.2
@@ -80,9 +80,9 @@
/**
* Checks that get/set methods are recognized properly.
*/
- public void testRecognitionOfScalarPropertyMethods(){
+ public void testRecognitionOfScalarPropertyMethods() {
ReflectedScalarProperty property =
- (ReflectedScalarProperty)clazz.getProperty("integerProperty");
+ (ReflectedScalarProperty) clazz.getProperty("integerProperty");
assertMethodSignature("Read method",
"getIntegerProperty()",
@@ -96,9 +96,9 @@
/**
* Checks that the "is" method is recognized for a boolean property.
*/
- public void testRecognitionOfScalarBooleanPropertyMethods(){
+ public void testRecognitionOfScalarBooleanPropertyMethods() {
ReflectedScalarProperty property =
- (ReflectedScalarProperty)clazz.getProperty("booleanProperty");
+ (ReflectedScalarProperty) clazz.getProperty("booleanProperty");
assertMethodSignature("Read method",
"isBooleanProperty()",
@@ -313,7 +313,7 @@
public void testIsAssignableFrom() {
}
- public void testGetScalarPropertyValue(){
+ public void testGetScalarPropertyValue() {
ClazzProperty property =
(ClazzProperty) clazz.getProperty("integerProperty");
Object result = property.get(instance);
@@ -323,7 +323,7 @@
assertEquals(result, new Integer(0));
}
- public void testPutScalarPropertyValue(){
+ public void testPutScalarPropertyValue() {
ClazzProperty property =
(ClazzProperty) clazz.getProperty("integerProperty");
property.set(instance, new Integer(3));
1.7 +7 -9 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedClazzTestSupport.java
Index: ReflectedClazzTestSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedClazzTestSupport.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ReflectedClazzTestSupport.java 9 Jan 2003 03:24:00 -0000 1.6
+++ ReflectedClazzTestSupport.java 20 Jan 2003 18:29:44 -0000 1.7
@@ -68,11 +68,10 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ReflectedClazzTestSupport extends ClazzTestSupport
-{
+public abstract class ReflectedClazzTestSupport extends ClazzTestSupport {
protected ReflectableInstance instance;
protected Clazz clazz;
- private static boolean ENABLE_LOGGING = false;
+ private static final boolean ENABLE_LOGGING = false;
/**
* Constructor for ReflectedClazzTestSupport.
@@ -89,7 +88,7 @@
*
* @return ClazzLoader
*/
- protected ClazzLoader getClazzLoader(){
+ protected ClazzLoader getClazzLoader() {
return Clazz.getClazzLoader(getModelKey(), getClass().getClassLoader());
}
@@ -101,7 +100,7 @@
protected void setUp() throws Exception {
instance = new ReflectableInstance();
clazz = getClazzLoader().getClazz(instance);
- if (ENABLE_LOGGING){
+ if (ENABLE_LOGGING) {
getClazzLoader().enableLogging(clazz.getName());
}
}
@@ -118,7 +117,7 @@
buffer.append("(");
Class paramTypes[] = method.getParameterTypes();
for (int i = 0; i < paramTypes.length; i++) {
- if (i > 0){
+ if (i > 0) {
buffer.append(",");
}
buffer.append(paramTypes[i].getName());
@@ -127,8 +126,7 @@
assertEquals(text, signature, buffer.toString());
}
- protected void assertTraceEmpty(String text)
- {
+ protected void assertTraceEmpty(String text) {
assertEquals(
"Methods invoked for " + text,
Collections.EMPTY_LIST,
1.2 +3 -2 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedInstanceFactoryTestCommon.java
Index: ReflectedInstanceFactoryTestCommon.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedInstanceFactoryTestCommon.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedInstanceFactoryTestCommon.java 9 Jan 2003 03:24:00 -0000 1.1
+++ ReflectedInstanceFactoryTestCommon.java 20 Jan 2003 18:29:44 -0000 1.2
@@ -61,7 +61,8 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ReflectedInstanceFactoryTestCommon extends ReflectedClazzTestSupport
+public abstract class ReflectedInstanceFactoryTestCommon
+ extends ReflectedClazzTestSupport
{
protected ClazzInstanceFactory zeroParameterFactory;
protected ClazzInstanceFactory oneParameterFactory;
1.2 +63 -73 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedListPropertyTestCommon.java
Index: ReflectedListPropertyTestCommon.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedListPropertyTestCommon.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedListPropertyTestCommon.java 9 Jan 2003 03:24:00 -0000 1.1
+++ ReflectedListPropertyTestCommon.java 20 Jan 2003 18:29:44 -0000 1.2
@@ -65,12 +65,12 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ReflectedListPropertyTestCommon
- extends ReflectedClazzTestSupport
+public abstract class ReflectedListPropertyTestCommon
+ extends ReflectedClazzTestSupport
{
protected ReflectedListProperty intArrayProperty;
protected ReflectedListProperty stringProperty;
-
+
/**
* Constructor for ReflectedPropertyMapTest.
* @param name Is the test method name
@@ -81,40 +81,37 @@
public void setUp() throws Exception {
super.setUp();
- intArrayProperty =
- (ReflectedListProperty)clazz.getProperty("intArray");
- stringProperty =
- (ReflectedListProperty)clazz.getProperty("string");
+ intArrayProperty =
+ (ReflectedListProperty) clazz.getProperty("intArray");
+ stringProperty = (ReflectedListProperty) clazz.getProperty("string");
}
- public void testSizeWithArray(){
+ public void testSizeWithArray() {
populateIntArray();
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
int count = list.size();
- assertTrace(
- "getting size with count getter",
- "getIntArray()");
+ assertTrace("getting size with count getter", "getIntArray()");
assertEquals(3, count);
}
public void testSizeWithEmpty() {
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
int count = list.size();
-
+
assertTrace("getting size", "getIntArray()");
assertEquals(0, count);
}
public void testIsEmptyWithArray() {
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
boolean empty = list.isEmpty();
assertTrace("empty", "getIntArray()");
assertTrue(empty);
- populateIntArray();
-// list = (List)intArrayProperty.get(instance);
+ populateIntArray();
+ // list = (List)intArrayProperty.get(instance);
empty = list.isEmpty();
assertTrace("not empty", "getIntArray()");
assertTrue(!empty);
@@ -122,17 +119,17 @@
public void testContainsWithArraySuccess() {
populateIntArray();
-
- List list = (List)intArrayProperty.get(instance);
+
+ List list = (List) intArrayProperty.get(instance);
boolean contains = list.contains(new Integer(2));
assertTrace("contains", "getIntArray()");
assertTrue(contains);
}
-
+
public void testContainsWithArrayFailure() {
populateIntArray();
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
boolean contains = list.contains(new Integer(371));
assertTrace("does not contain", "getIntArray()");
assertTrue(!contains);
@@ -140,21 +137,21 @@
public void testIteratorWithArray() {
populateIntArray();
-
- List list = (List)intArrayProperty.get(instance);
+
+ List list = (List) intArrayProperty.get(instance);
Iterator it = list.iterator();
ArrayList result = new ArrayList();
- while (it.hasNext()){
+ while (it.hasNext()) {
result.add(it.next());
- }
-
+ }
+
assertTrace("iterator", "getIntArray()");
-
+
ArrayList expected = new ArrayList();
expected.add(new Integer(1));
expected.add(new Integer(2));
expected.add(new Integer(3));
-
+
assertEquals("iterator", expected, result);
}
@@ -174,7 +171,7 @@
* Test for boolean add(Object)
*/
public void testAddObjectWithArrayStartEmpty() {
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
list.add(new Integer(1));
assertTrace("add", "getIntArray()", "setIntArray(int[])");
@@ -182,8 +179,8 @@
ArrayList expected = new ArrayList();
expected.add(new Integer(1));
assertEquals("result of add via list", expected, list);
-
- int array[] = instance.getIntArray();
+
+ int array[] = instance.getIntArray();
assertEquals("result of add directly (length)", 1, array.length);
assertEquals("result of add directly (value)", 1, array[0]);
}
@@ -193,13 +190,13 @@
*/
public void testAddObjectWithArrayStartPopulated() {
populateIntArray();
-
- List list = (List)intArrayProperty.get(instance);
+
+ List list = (List) intArrayProperty.get(instance);
list.add(new Integer(4));
assertTrace("add", "getIntArray()", "setIntArray(int[])");
-// System.err.println("LIST: " + list);
+// System.err.println("LIST: " + list);
ArrayList expected = new ArrayList();
expected.add(new Integer(1));
expected.add(new Integer(2));
@@ -211,7 +208,7 @@
assertEquals("result of add directly (length)", 4, array.length);
assertEquals("result of add directly (value)", 4, array[3]);
}
-
+
/*
* Test for boolean add(Object)
*/
@@ -219,17 +216,17 @@
populateIntArray();
boolean ex = false;
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
Iterator it = list.iterator();
it.next();
list.add(new Integer(4));
try {
it.next();
}
- catch (ConcurrentModificationException e){
+ catch (ConcurrentModificationException e) {
ex = true;
}
-
+
assertTrue("concurrent mod exception", ex);
}
@@ -239,16 +236,13 @@
public void testRemoveObjectFromArray() {
populateIntArray();
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
list.remove(new Integer(2));
- assertTrace(
- "remove",
- new String[] {
- "getIntArray()", // For iteration
- "getIntArray()", // For removal
- "setIntArray(int[])" }); // New shorter array
-
+ assertTrace("remove", new String[] { "getIntArray()", // For iteration
+ "getIntArray()", // For removal
+ "setIntArray(int[])" }); // New shorter array
+
ArrayList expected = new ArrayList();
expected.add(new Integer(1));
expected.add(new Integer(3));
@@ -264,7 +258,7 @@
public void testRemoveWithIndexFromArray() {
populateIntArray();
- List list = (List)intArrayProperty.get(instance);
+ List list = (List) intArrayProperty.get(instance);
list.remove(1);
assertTrace("remove", "getIntArray()", "setIntArray(int[])");
@@ -277,7 +271,7 @@
int array[] = instance.getIntArray();
assertEquals("result of remove directly (length)", 2, array.length);
}
-
+
public void testContainsAll() {
}
@@ -304,52 +298,48 @@
public void testGetWithArray() {
populateIntArray();
-
- List list = (List)intArrayProperty.get(instance);
+
+ List list = (List) intArrayProperty.get(instance);
Object value = list.get(1);
-
- assertTrace(
- "getting value with direct getter",
- "getIntArray()");
+
+ assertTrace("getting value with direct getter", "getIntArray()");
assertEquals(new Integer(2), value);
}
public void testGetWithList() {
populateStringList();
-
- List list = (List)stringProperty.get(instance);
+
+ List list = (List) stringProperty.get(instance);
Object value = list.get(1);
-
+
assertTrace(
"getting value with parameterized getter",
"getString(int)");
-
+
assertEquals("bar", value);
}
public void testSetWithArray() {
populateIntArray();
-
- List list = (List)intArrayProperty.get(instance);
+
+ List list = (List) intArrayProperty.get(instance);
list.set(1, new Integer(7));
-
- assertTrace(
- "setting value with direct getter",
- "getIntArray()");
+
+ assertTrace("setting value with direct getter", "getIntArray()");
assertEquals(7, instance.getIntArray()[1]);
}
-
+
public void testSetWithList() {
populateStringList();
-
- List list = (List)stringProperty.get(instance);
+
+ List list = (List) stringProperty.get(instance);
list.set(1, "biz");
-
+
assertTrace(
"setting value with parameterized setter",
"getString(int)",
"setString(int,String)");
-
+
assertEquals("biz", instance.getString(1));
}
@@ -373,7 +363,7 @@
public void testSubList() {
}
-
+
/**
* We are supposed to get different results for standard and extended models
* when the corresponding property does not have a <code>get</code> method
@@ -381,7 +371,7 @@
* this as long as there is a <code>get<i>Foo</i>Count()</code> method.
*/
public abstract void testSizeWithList();
- public abstract void testIsEmptyWithList();
+ public abstract void testIsEmptyWithList();
public abstract void testContainsWithListSuccess();
public abstract void testContainsWithListFailure();
public abstract void testIteratorWithList();
@@ -390,7 +380,7 @@
public abstract void testAddIndexedWithList();
public void populateIntArray() {
- instance.setIntArray(new int[]{1, 2, 3});
+ instance.setIntArray(new int[] { 1, 2, 3 });
instance.resetTrace();
}
1.2 +11 -11 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedOperationCommon.java
Index: ReflectedOperationCommon.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedOperationCommon.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReflectedOperationCommon.java 9 Jan 2003 03:24:00 -0000 1.1
+++ ReflectedOperationCommon.java 20 Jan 2003 18:29:44 -0000 1.2
@@ -61,13 +61,14 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ReflectedOperationCommon extends ReflectedClazzTestSupport
+public abstract class ReflectedOperationCommon
+ extends ReflectedClazzTestSupport
{
protected ClazzOperation voidOperationWithoutParameters;
protected ClazzOperation stringOperationWithParameters;
protected ClazzOperation operationWithScalarParameters;
protected ClazzOperation operationWithArrayParameters;
-
+
/**
* Constructor for ReflectedOperationTest.
* @param name
@@ -75,21 +76,20 @@
public ReflectedOperationCommon(String name) {
super(name);
}
-
+
public void setUp() throws Exception {
super.setUp();
- voidOperationWithoutParameters =
- clazz.getOperation("doNothing()");
-
+ voidOperationWithoutParameters = clazz.getOperation("doNothing()");
+
stringOperationWithParameters =
clazz.getOperation("toUpperCase(java.lang.String)");
-
+
operationWithScalarParameters =
clazz.getOperation(
"scalars("
+ "boolean,byte,char,short,int,long,float,double,"
+ "java.lang.Object,java.lang.String)");
-
+
operationWithArrayParameters =
clazz.getOperation(
"arrays("
@@ -149,7 +149,7 @@
public void testGetReturnClazz() {
Clazz returnClazz = stringOperationWithParameters.getReturnClazz();
assertNotNull(returnClazz);
- assertEquals("Return clazz", "java.lang.String", returnClazz.getName());
+ assertEquals("Return clazz", "java.lang.String", returnClazz.getName());
}
public void testInvokeWithStringResult() {
@@ -169,7 +169,7 @@
null);
assertNull(result);
}
-
+
/*
* Test for String toString()
*/
1.3 +2 -2 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedSuperclazzInstance.java
Index: ReflectedSuperclazzInstance.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/ReflectedSuperclazzInstance.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedSuperclazzInstance.java 6 Dec 2002 01:12:50 -0000 1.2
+++ ReflectedSuperclazzInstance.java 20 Jan 2003 18:29:44 -0000 1.3
@@ -88,7 +88,7 @@
* by the subclass ReflectedInstance, therefore "halfProperty" will
* be a declared property of the subclass.
*/
- public void setHalfProperty(String halfProperty){
+ public void setHalfProperty(String halfProperty) {
this.halfProperty = halfProperty;
}
1.2 +3 -2 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean1ExtendedClazz.java
Index: CustomBean1ExtendedClazz.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean1ExtendedClazz.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomBean1ExtendedClazz.java 9 Jan 2003 03:24:00 -0000 1.1
+++ CustomBean1ExtendedClazz.java 20 Jan 2003 18:29:45 -0000 1.2
@@ -80,7 +80,8 @@
property.setWriteMethod(
javaClass.getMethod("storeData", new Class[]{String.class}));
}
- catch (NoSuchMethodException e){
+ catch (NoSuchMethodException e) {
+ // Won't happen
}
addProperty(property);
}
1.2 +5 -6 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean1ExtendedClazzTest.java
Index: CustomBean1ExtendedClazzTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean1ExtendedClazzTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomBean1ExtendedClazzTest.java 9 Jan 2003 03:24:00 -0000 1.1
+++ CustomBean1ExtendedClazzTest.java 20 Jan 2003 18:29:45 -0000 1.2
@@ -65,8 +65,7 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class CustomBean1ExtendedClazzTest extends ClazzTestSupport
-{
+public class CustomBean1ExtendedClazzTest extends ClazzTestSupport {
private Clazz clazz;
/**
@@ -77,7 +76,7 @@
super(name);
}
- public void setUp(){
+ public void setUp() {
// Step 1. Obtain a ClazzLoader for the custom clazz model.
ClazzLoader clazzLoader =
Clazz.getClazzLoader(
@@ -88,13 +87,13 @@
clazz = clazzLoader.getClazzForName(CustomBean1.class.getName());
}
- public void testCustomClazzRecognition(){
+ public void testCustomClazzRecognition() {
assertTrue(
"Custom Clazz recognized",
clazz instanceof CustomBean1ExtendedClazz);
}
- public void testPropertyRecognition(){
+ public void testPropertyRecognition() {
List properties = clazz.getProperties();
assertEquals("All properties found", 1, properties.size());
1.2 +3 -2 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomClazz.java
Index: CustomClazz.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomClazz.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomClazz.java 9 Jan 2003 03:24:00 -0000 1.1
+++ CustomClazz.java 20 Jan 2003 18:29:45 -0000 1.2
@@ -63,7 +63,8 @@
*/
public class CustomClazz extends ExtendedReflectedClazz {
- protected static final ReflectedPropertyIntrospector[] PROPERTY_INTROSPECTORS =
+ protected static final
+ ReflectedPropertyIntrospector[] PROPERTY_INTROSPECTORS =
new ReflectedPropertyIntrospector[] { new CustomPropertyIntrospector()};
public CustomClazz(ClazzLoader loader, Class instanceClass) {
1.2 +5 -6 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomClazzLoaderTest.java
Index: CustomClazzLoaderTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomClazzLoaderTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomClazzLoaderTest.java 9 Jan 2003 03:24:01 -0000 1.1
+++ CustomClazzLoaderTest.java 20 Jan 2003 18:29:45 -0000 1.2
@@ -66,8 +66,7 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class CustomClazzLoaderTest extends ClazzTestSupport
-{
+public class CustomClazzLoaderTest extends ClazzTestSupport {
private Clazz clazz;
static {
ClazzLoaderFactory factory =
@@ -83,7 +82,7 @@
super(name);
}
- public void setUp(){
+ public void setUp() {
// Step 1. Obtain a ClazzLoader for the custom clazz model.
ClazzLoader clazzLoader =
Clazz.getClazzLoader(
@@ -94,13 +93,13 @@
clazz = clazzLoader.getClazzForName(CustomBean2.class.getName());
}
- public void testCustomClazzRecognition(){
+ public void testCustomClazzRecognition() {
assertTrue(
"Custom Clazz Loader recognized",
clazz instanceof CustomClazz);
}
- public void testPropertyRecognition(){
+ public void testPropertyRecognition() {
List properties = clazz.getProperties();
assertEquals("Count properties found", 1, properties.size());
1.2 +6 -7 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomPropertyIntrospector.java
Index: CustomPropertyIntrospector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomPropertyIntrospector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomPropertyIntrospector.java 9 Jan 2003 03:24:01 -0000 1.1
+++ CustomPropertyIntrospector.java 20 Jan 2003 18:29:45 -0000 1.2
@@ -53,8 +53,7 @@
*/
package org.apache.commons.clazz.reflect.extended;
-import org.apache.commons.clazz.reflect.common.AccessorMethodParser;
-import org.apache.commons.clazz.reflect.common.ReflectedScalarPropertyIntrospector;
+import org.apache.commons.clazz.reflect.common.*;
/**
*
@@ -67,7 +66,7 @@
private static final AccessorMethodParser READ_METHOD_PARSER =
new ReadAccessorMethodParser()
{
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "produce";
}
};
@@ -75,16 +74,16 @@
private static final AccessorMethodParser WRITE_METHOD_PARSER =
new WriteAccessorMethodParser()
{
- protected String requiredPrefix(){
+ protected String requiredPrefix() {
return "consume";
}
};
- protected AccessorMethodParser getReadAccessorMethodParser(){
+ protected AccessorMethodParser getReadAccessorMethodParser() {
return READ_METHOD_PARSER;
}
- protected AccessorMethodParser getWriteAccessorMethodParser(){
+ protected AccessorMethodParser getWriteAccessorMethodParser() {
return WRITE_METHOD_PARSER;
}
}
1.6 +4 -3 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedClazzTest.java
Index: ExtendedReflectedClazzTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedClazzTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ExtendedReflectedClazzTest.java 9 Jan 2003 03:24:01 -0000 1.5
+++ ExtendedReflectedClazzTest.java 20 Jan 2003 18:29:45 -0000 1.6
@@ -78,7 +78,7 @@
junit.textui.TestRunner.run(ExtendedReflectedClazzTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
TestSuite suite = new TestSuite("ExtendedReflectedClazz tests");
suite.addTestSuite(ExtendedReflectedClazzTest.class);
suite.addTestSuite(ExtendedReflectedListPropertyTest.class);
@@ -87,10 +87,11 @@
suite.addTestSuite(ExtendedReflectedInstanceFactoryTest.class);
suite.addTestSuite(CustomBean1ExtendedClazzTest.class);
suite.addTestSuite(CustomClazzLoaderTest.class);
+ suite.addTestSuite(CustomBean3BeanInfoTest.class);
return suite;
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.EXTENDED_CLAZZ_MODEL;
}
1.5 +6 -4 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedInstanceFactoryTest.java
Index: ExtendedReflectedInstanceFactoryTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedInstanceFactoryTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExtendedReflectedInstanceFactoryTest.java 9 Jan 2003 03:24:01 -0000 1.4
+++ ExtendedReflectedInstanceFactoryTest.java 20 Jan 2003 18:29:45 -0000 1.5
@@ -61,7 +61,9 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class ExtendedReflectedInstanceFactoryTest extends ReflectedOperationCommon {
+public class ExtendedReflectedInstanceFactoryTest
+ extends ReflectedOperationCommon
+{
/**
* Constructor for ExtendedReflectedOperationTest.
@@ -71,8 +73,8 @@
super(name);
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.EXTENDED_CLAZZ_MODEL;
}
-
+
}
1.6 +65 -66 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedListPropertyTest.java
Index: ExtendedReflectedListPropertyTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedListPropertyTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ExtendedReflectedListPropertyTest.java 9 Jan 2003 03:24:01 -0000 1.5
+++ ExtendedReflectedListPropertyTest.java 20 Jan 2003 18:29:45 -0000 1.6
@@ -67,7 +67,8 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class ExtendedReflectedListPropertyTest extends ReflectedListPropertyTestCommon
+public class ExtendedReflectedListPropertyTest
+ extends ReflectedListPropertyTestCommon
{
/**
* Constructor for ReflectedPropertyMapTest.
@@ -81,80 +82,80 @@
junit.textui.TestRunner.run(ExtendedReflectedListPropertyTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
return new TestSuite(ExtendedReflectedListPropertyTest.class);
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.EXTENDED_CLAZZ_MODEL;
}
-
+
/**
* Checks the set of methods recognized for a List property that
* does not have regular get/set methods.
*/
- public void testRecognitionOfListPropertyWithoutReadWriteMethods(){
- assertNull("Read method",
- stringProperty.getReadMethod());
-
- assertNull("Write method",
- stringProperty.getWriteMethod());
+ public void testRecognitionOfListPropertyWithoutReadWriteMethods() {
+ assertNull("Read method", stringProperty.getReadMethod());
+
+ assertNull("Write method", stringProperty.getWriteMethod());
- assertMethodSignature("Get method",
+ assertMethodSignature(
+ "Get method",
"getString(int)",
stringProperty.getGetMethod());
- assertMethodSignature("Set method",
+ assertMethodSignature(
+ "Set method",
"setString(int,java.lang.String)",
stringProperty.getSetMethod());
-
- assertMethodSignature("Add method",
+
+ assertMethodSignature(
+ "Add method",
"addString(java.lang.String)",
stringProperty.getAddMethod());
-
- assertMethodSignature("Add(i) method",
+
+ assertMethodSignature(
+ "Add(i) method",
"addString(int,java.lang.String)",
stringProperty.getAddIndexedMethod());
-
- assertMethodSignature("Remove method",
+
+ assertMethodSignature(
+ "Remove method",
"removeString(java.lang.String)",
- stringProperty.getRemoveMethod());
+ stringProperty.getRemoveMethod());
- assertMethodSignature("Size method",
+ assertMethodSignature(
+ "Size method",
"getStringCount()",
- stringProperty.getSizeMethod());
+ stringProperty.getSizeMethod());
}
-
+
/**
* Checks the a property is recognized as List even if it
* does not have parameterized get/set/remove methods.
*/
- public void testRecognitionOfListPropertyWithoutGetSetAddRemoveMethods(){
- assertMethodSignature("Read method",
+ public void testRecognitionOfListPropertyWithoutGetSetAddRemoveMethods() {
+ assertMethodSignature(
+ "Read method",
"getIntArray()",
intArrayProperty.getReadMethod());
-
- assertMethodSignature("Write method",
+
+ assertMethodSignature(
+ "Write method",
"setIntArray([I)",
intArrayProperty.getWriteMethod());
- assertNull("Get method",
- intArrayProperty.getGetMethod());
+ assertNull("Get method", intArrayProperty.getGetMethod());
- assertNull("Set method",
- intArrayProperty.getSetMethod());
+ assertNull("Set method", intArrayProperty.getSetMethod());
- assertNull("Add method",
- intArrayProperty.getAddMethod());
+ assertNull("Add method", intArrayProperty.getAddMethod());
- assertNull("Add(i) method",
- intArrayProperty.getAddIndexedMethod());
+ assertNull("Add(i) method", intArrayProperty.getAddIndexedMethod());
- assertNull("Remove method",
- intArrayProperty.getRemoveMethod());
+ assertNull("Remove method", intArrayProperty.getRemoveMethod());
- assertNull("Size method",
- intArrayProperty.getSizeMethod());
+ assertNull("Size method", intArrayProperty.getSizeMethod());
}
/**
@@ -166,30 +167,28 @@
instance.addString("bar");
instance.addString("baz");
instance.resetTrace();
-
- List list = (List)stringProperty.get(instance);
+
+ List list = (List) stringProperty.get(instance);
int count = list.size();
-
- assertTrace(
- "getting size with count getter",
- "getStringCount()");
+
+ assertTrace("getting size with count getter", "getStringCount()");
assertEquals(3, count);
}
-
- public void testIsEmptyWithList(){
- List list = (List)stringProperty.get(instance);
+
+ public void testIsEmptyWithList() {
+ List list = (List) stringProperty.get(instance);
boolean empty = list.isEmpty();
assertTrace("empty", "getStringCount()");
assertTrue(empty);
populateStringList();
- list = (List)stringProperty.get(instance);
+ list = (List) stringProperty.get(instance);
empty = list.isEmpty();
assertTrace("not empty", "getStringCount()");
assertTrue(!empty);
}
-
+
public void testContainsWithListSuccess() {
populateStringList();
@@ -198,7 +197,7 @@
assertTrace("contains", "getStringCount()", "getString(int)");
assertTrue(contains);
}
-
+
public void testContainsWithListFailure() {
populateStringList();
@@ -213,24 +212,24 @@
"getString(int)" });
assertTrue(!contains);
}
-
+
public void testIteratorWithList() {
populateStringList();
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
Iterator it = list.iterator();
ArrayList result = new ArrayList();
- while (it.hasNext()){
+ while (it.hasNext()) {
result.add(it.next());
}
assertTrace(
"iterator",
- new String[] {
- "getStringCount()",
- "getString(int)",
- "getString(int)",
- "getString(int)"});
+ new String[] {
+ "getStringCount()",
+ "getString(int)",
+ "getString(int)",
+ "getString(int)" });
ArrayList expected = new ArrayList();
expected.add("foo");
@@ -238,13 +237,13 @@
expected.add("baz");
assertEquals("iterator", expected, result);
- }
-
+ }
+
/*
* Test for boolean add(Object)
*/
public void testAddObjectWithListStartEmpty() {
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
list.add("biz");
assertTrace("add", "addString()");
@@ -269,7 +268,7 @@
public void testAddObjectWithListStartPopulated() {
populateStringList();
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
list.add("biz");
assertTrace("add", "addString()");
@@ -290,14 +289,14 @@
"biz",
instance.getString(3));
}
-
+
/*
* Test for boolean add(Object)
*/
public void testAddIndexedWithList() {
populateStringList();
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
list.add(1, "biz");
assertTrace("add", "addString(int,String)");
@@ -346,7 +345,7 @@
public void testRemoveWithIndexFromList() {
populateStringList();
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
list.remove(1);
assertTrace("remove", "getString(int)", "removeString(int)");
1.5 +3 -3 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedOperationTest.java
Index: ExtendedReflectedOperationTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ExtendedReflectedOperationTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExtendedReflectedOperationTest.java 9 Jan 2003 03:24:01 -0000 1.4
+++ ExtendedReflectedOperationTest.java 20 Jan 2003 18:29:45 -0000 1.5
@@ -71,8 +71,8 @@
super(name);
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.EXTENDED_CLAZZ_MODEL;
}
-
+
}
1.6 +92 -100 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ReflectedMappedPropertyTest.java
Index: ReflectedMappedPropertyTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/ReflectedMappedPropertyTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ReflectedMappedPropertyTest.java 9 Jan 2003 03:24:01 -0000 1.5
+++ ReflectedMappedPropertyTest.java 20 Jan 2003 18:29:45 -0000 1.6
@@ -69,12 +69,11 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class ReflectedMappedPropertyTest extends ReflectedClazzTestSupport
-{
+public class ReflectedMappedPropertyTest extends ReflectedClazzTestSupport {
private ReflectedMappedProperty mappedStringsProperty;
private ReflectedMappedProperty mappedIntegerProperty;
private ReflectedMappedProperty mappedBooleansProperty;
-
+
/**
* Constructor for ReflectedPropertyMapTest.
* @param name Is the test method name
@@ -87,121 +86,125 @@
junit.textui.TestRunner.run(ReflectedMappedPropertyTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
return new TestSuite(ReflectedMappedPropertyTest.class);
}
-
+
public void setUp() throws Exception {
super.setUp();
- mappedStringsProperty =
- (ReflectedMappedProperty)clazz.getProperty("mappedStrings");
- mappedIntegerProperty =
- (ReflectedMappedProperty)clazz.getProperty("mappedInteger");
- mappedBooleansProperty =
- (ReflectedMappedProperty)clazz.getProperty("mappedBooleans");
+ mappedStringsProperty =
+ (ReflectedMappedProperty) clazz.getProperty("mappedStrings");
+ mappedIntegerProperty =
+ (ReflectedMappedProperty) clazz.getProperty("mappedInteger");
+ mappedBooleansProperty =
+ (ReflectedMappedProperty) clazz.getProperty("mappedBooleans");
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.EXTENDED_CLAZZ_MODEL;
}
-
/**
* Checks the full set of methods recognized for a mapped property.
*/
- public void testRecognitionOfMappedPropertyMethods(){
-
- assertMethodSignature("Read method",
+ public void testRecognitionOfMappedPropertyMethods() {
+
+ assertMethodSignature(
+ "Read method",
"getMappedStrings()",
mappedStringsProperty.getReadMethod());
-
- assertMethodSignature("Write method",
+
+ assertMethodSignature(
+ "Write method",
"setMappedStrings(java.util.Map)",
mappedStringsProperty.getWriteMethod());
- assertMethodSignature("Get method",
+ assertMethodSignature(
+ "Get method",
"getMappedString(java.lang.String)",
mappedStringsProperty.getGetMethod());
- assertMethodSignature("Put method",
+ assertMethodSignature(
+ "Put method",
"setMappedString(java.lang.String,java.lang.String)",
mappedStringsProperty.getPutMethod());
- assertMethodSignature("Remove method",
+ assertMethodSignature(
+ "Remove method",
"removeMappedString(java.lang.String)",
mappedStringsProperty.getRemoveMethod());
-
- assertMethodSignature("KeySet method",
+
+ assertMethodSignature(
+ "KeySet method",
"getMappedStringKeys()",
mappedStringsProperty.getKeySetMethod());
}
-
+
/**
* Checks the set of methods recognized for a mapped property that
* does not have regular get/set methods.
*/
- public void testRecognitionOfMappedPropertyWithoutReadWriteMethods(){
- assertNull("Read method",
- mappedIntegerProperty.getReadMethod());
-
- assertNull("Write method",
- mappedIntegerProperty.getWriteMethod());
+ public void testRecognitionOfMappedPropertyWithoutReadWriteMethods() {
+ assertNull("Read method", mappedIntegerProperty.getReadMethod());
- assertMethodSignature("Get method",
+ assertNull("Write method", mappedIntegerProperty.getWriteMethod());
+
+ assertMethodSignature(
+ "Get method",
"getMappedInteger(java.lang.Integer)",
mappedIntegerProperty.getGetMethod());
- assertMethodSignature("Put method",
+ assertMethodSignature(
+ "Put method",
"setMappedInteger(java.lang.Integer,java.lang.Integer)",
mappedIntegerProperty.getPutMethod());
- assertMethodSignature("Remove method",
+ assertMethodSignature(
+ "Remove method",
"removeMappedInteger(java.lang.Integer)",
mappedIntegerProperty.getRemoveMethod());
- assertMethodSignature("KeySet method",
+ assertMethodSignature(
+ "KeySet method",
"getMappedIntegerKeys()",
mappedIntegerProperty.getKeySetMethod());
}
-
+
/**
* Checks the a property is recognized as Mapped even if it
* does not have specific get/set/remove methods.
*/
- public void testRecognitionOfMappedPropertyWithoutGetPutRemoveMethods(){
- assertMethodSignature("Read method",
+ public void testRecognitionOfMappedPropertyWithoutGetPutRemoveMethods() {
+ assertMethodSignature(
+ "Read method",
"getMappedBooleans()",
mappedBooleansProperty.getReadMethod());
-
- assertMethodSignature("Write method",
+
+ assertMethodSignature(
+ "Write method",
"setMappedBooleans(java.util.Map)",
mappedBooleansProperty.getWriteMethod());
- assertNull("Get method",
- mappedBooleansProperty.getGetMethod());
+ assertNull("Get method", mappedBooleansProperty.getGetMethod());
- assertNull("Put method",
- mappedBooleansProperty.getPutMethod());
+ assertNull("Put method", mappedBooleansProperty.getPutMethod());
- assertNull("Remove method",
- mappedBooleansProperty.getRemoveMethod());
+ assertNull("Remove method", mappedBooleansProperty.getRemoveMethod());
- assertNull("KeySet method",
- mappedBooleansProperty.getKeySetMethod());
+ assertNull("KeySet method", mappedBooleansProperty.getKeySetMethod());
}
-
- public void testGetMappedPropertyValue(){
+
+ public void testGetMappedPropertyValue() {
Object result = mappedStringsProperty.get(instance);
- assertTraceEmpty(
- "getting mapped property value");
-
+ assertTraceEmpty("getting mapped property value");
+
assertTrue(result instanceof ReflectedMap);
}
-
+
public void testGetEmptyMap() {
Map map = (Map) mappedBooleansProperty.get(instance);
Object value = map.get("bar");
-
+
assertTrace("getting value from empty map", "getMappedBooleans()");
assertNull(value);
}
@@ -231,28 +234,28 @@
public void testPutWithSpecificAccessor() {
populateMappedStrings();
-
+
Map map = (Map) mappedStringsProperty.get(instance);
Object oldValue = map.put("foo", "baz");
assertTrace(
"setting value with specific setter",
"getMappedString(String)",
"setMappedString(String,String)");
- assertEquals("baz", instance.getMappedStrings().get("foo"));
- assertEquals("1", oldValue);
+ assertEquals("baz", instance.getMappedStrings().get("foo"));
+ assertEquals("1", oldValue);
}
public void testPutWithDirectAccessor() {
instance.setMappedBooleans(new HashMap());
instance.resetTrace();
-
+
Map map = (Map) mappedBooleansProperty.get(instance);
Object oldValue = map.put("foo", Boolean.TRUE);
assertTrace(
"setting value with principal setter",
"getMappedBooleans()");
- assertEquals(Boolean.TRUE, instance.getMappedBooleans().get("foo"));
- assertNull(oldValue);
+ assertEquals(Boolean.TRUE, instance.getMappedBooleans().get("foo"));
+ assertNull(oldValue);
}
public void testPutEmptyMap() {
@@ -262,40 +265,40 @@
"setting value with initially empty map",
"getMappedBooleans()",
"setMappedBooleans(Map)");
- assertEquals(Boolean.TRUE, instance.getMappedBooleans().get("foo"));
- assertNull(oldValue);
+ assertEquals(Boolean.TRUE, instance.getMappedBooleans().get("foo"));
+ assertNull(oldValue);
}
public void testKeySetWithSpecificAccessor() {
populateMappedStrings();
-
+
Map map = (Map) mappedStringsProperty.get(instance);
Set keySet = map.keySet();
assertTrace(
"getting key set with specific accessor",
"getMappedStringKeys()");
-
+
HashSet expected = new HashSet();
expected.add("foo");
expected.add("bar");
-
- assertEquals(expected, keySet);
+
+ assertEquals(expected, keySet);
}
public void testKeySetWithPrincipalAccessor() {
populateMappedBooleans();
-
+
Map map = (Map) mappedBooleansProperty.get(instance);
Set keySet = map.keySet();
assertTrace(
"getting key set with principal accessor",
"getMappedBooleans()");
-
+
HashSet expected = new HashSet();
expected.add("foo");
expected.add("bar");
-
- assertEquals(expected, keySet);
+
+ assertEquals(expected, keySet);
}
public void testEntrySetWithPrincipalAccessor() {
@@ -303,10 +306,8 @@
Map map = (Map) mappedBooleansProperty.get(instance);
Set entrySet = map.entrySet();
- assertTrace(
- "getting entry set",
- "getMappedBooleans()");
-
+ assertTrace("getting entry set", "getMappedBooleans()");
+
assertEquals("Regular entry set size", 2, entrySet.size());
}
@@ -315,9 +316,7 @@
Map map = (Map) mappedIntegerProperty.get(instance);
Set entrySet = map.entrySet();
- assertTrace(
- "getting entry set",
- "getMappedIntegerKeys()");
+ assertTrace("getting entry set", "getMappedIntegerKeys()");
assertEquals("Custom entry set size", 2, entrySet.size());
}
@@ -330,8 +329,8 @@
HashSet keys = new HashSet();
HashSet values = new HashSet();
Iterator it = entrySet.iterator();
- while (it.hasNext()){
- Map.Entry entry = (Map.Entry)it.next();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry) it.next();
keys.add(entry.getKey());
values.add(entry.getValue());
}
@@ -358,11 +357,11 @@
public void testRemoveWithEntryIterator() {
testRemoveWithIterator(false);
}
-
+
public void testRemoveWithKeyIterator() {
testRemoveWithIterator(true);
}
-
+
public void testRemoveWithIterator(boolean keys) {
populateMappedStrings();
@@ -370,11 +369,11 @@
Set set = keys ? map.keySet() : map.entrySet();
Iterator it = set.iterator();
- while (it.hasNext()){
+ while (it.hasNext()) {
it.next();
it.remove();
}
-
+
assertTrace(
"getting entry set",
new String[] {
@@ -394,11 +393,11 @@
Map map = (Map) mappedStringsProperty.get(instance);
Set set = map.keySet();
-
+
boolean eFoo = set.remove("foo");
boolean eBar = set.remove("bar");
boolean eBiz = set.remove("biz");
-
+
assertTrace(
"getting entry set",
new String[] {
@@ -406,7 +405,7 @@
"getMappedString(String)",
"removeMappedString(String)",
"getMappedString(String)",
- "removeMappedString(String)"});
+ "removeMappedString(String)" });
assertTrue("existed foo", eFoo);
assertTrue("existed bar", eBar);
@@ -438,7 +437,7 @@
"getMappedString(String)",
"removeMappedString(String)",
"getMappedString(String)",
- "removeMappedString(String)"});
+ "removeMappedString(String)" });
assertTrue(map.isEmpty());
}
@@ -455,13 +454,10 @@
populateMappedIntegers();
Map map = (Map) mappedIntegerProperty.get(instance);
int size = map.size();
-
- assertTrace(
- "getting size",
- new String[] {
- "getMappedIntegerKeys()"});
- assertEquals("size", 2, size);
+ assertTrace("getting size", new String[] { "getMappedIntegerKeys()" });
+
+ assertEquals("size", 2, size);
}
public void testSizeWithMap() {
@@ -469,10 +465,7 @@
Map map = (Map) mappedBooleansProperty.get(instance);
int size = map.size();
- assertTrace(
- "getting size",
- new String[] {
- "getMappedBooleans()"});
+ assertTrace("getting size", new String[] { "getMappedBooleans()" });
assertEquals("size", 2, size);
}
@@ -491,7 +484,6 @@
"getMappedString(String)",
"getMappedString(String)" });
-
Set expected = new HashSet();
expected.add("1");
expected.add("2");
@@ -505,7 +497,7 @@
instance.getMappedBooleans().put("bar", Boolean.FALSE);
instance.resetTrace();
}
-
+
private void populateMappedStrings() {
instance.setMappedString("foo", "1");
instance.setMappedString("bar", "2");
1.1 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean3.java
Index: CustomBean3.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz.reflect.extended;
/**
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: CustomBean3.java,v 1.1 2003/01/20 18:29:45 dmitri Exp $
*/
public class CustomBean3 {
private String data;
public String retrieveData() {
return data;
}
public void storeData(String data) {
this.data = data;
}
}
1.1 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean3BeanInfo.java
Index: CustomBean3BeanInfo.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz.reflect.extended;
import java.beans.IntrospectionException;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.lang.reflect.Method;
/**
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: CustomBean3BeanInfo.java,v 1.1 2003/01/20 18:29:45 dmitri Exp $
*/
public class CustomBean3BeanInfo extends SimpleBeanInfo {
/**
* @see BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
Method getter = null;
Method setter = null;
Class javaClass = CustomBean3.class;
try {
getter = javaClass.getMethod("retrieveData", null);
setter =
javaClass.getMethod("storeData", new Class[] { String.class });
}
catch (NoSuchMethodException e) {
// Won't happen
}
PropertyDescriptor property = null;
try {
property = new PropertyDescriptor("data", getter, setter);
}
catch (IntrospectionException e) {
// Won't happen
}
return new PropertyDescriptor[] { property };
}
/**
* @see BeanInfo#getMethodDescriptors()
*/
public MethodDescriptor[] getMethodDescriptors() {
return null;
}
}
1.1 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/extended/CustomBean3BeanInfoTest.java
Index: CustomBean3BeanInfoTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz.reflect.extended;
import java.util.List;
import org.apache.commons.clazz.Clazz;
import org.apache.commons.clazz.ClazzLoader;
import org.apache.commons.clazz.ClazzProperty;
import org.apache.commons.clazz.ClazzTestSupport;
/**
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: CustomBean3BeanInfoTest.java,v 1.1 2003/01/20 18:29:45 dmitri Exp $
*/
public class CustomBean3BeanInfoTest extends ClazzTestSupport {
private Clazz clazz;
public CustomBean3BeanInfoTest(String name) {
super(name);
}
public void setUp() {
// Step 1. Obtain a ClazzLoader for the custom clazz model.
ClazzLoader clazzLoader =
Clazz.getClazzLoader(
Clazz.EXTENDED_CLAZZ_MODEL,
getClass().getClassLoader());
// Step 2. Find the Clazz
clazz = clazzLoader.getClazzForName(CustomBean3.class.getName());
}
public void testCustomClazzRecognition() {
assertEquals(
"Custom Clazz recognized",
ExtendedReflectedClazz.class, clazz.getClass());
}
public void testPropertyRecognition() {
List properties = clazz.getProperties();
assertEquals("All properties found", 1, properties.size());
CustomBean3 bean = new CustomBean3();
ClazzProperty property = clazz.getProperty("data");
assertNotNull("Property found", property);
property.set(bean, "foo");
Object value = property.get(bean);
assertEquals("Property set/get", "foo", value);
}
}
1.6 +3 -3 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedClazzTest.java
Index: StandardReflectedClazzTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedClazzTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StandardReflectedClazzTest.java 9 Jan 2003 03:24:01 -0000 1.5
+++ StandardReflectedClazzTest.java 20 Jan 2003 18:29:45 -0000 1.6
@@ -78,7 +78,7 @@
junit.textui.TestRunner.run(StandardReflectedClazzTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
TestSuite suite = new TestSuite("StandardReflectedClazz tests");
suite.addTestSuite(StandardReflectedClazzTest.class);
suite.addTestSuite(StandardReflectedListPropertyTest.class);
@@ -87,7 +87,7 @@
return suite;
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.STANDARD_CLAZZ_MODEL;
}
1.5 +6 -4 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedInstanceFactoryTest.java
Index: StandardReflectedInstanceFactoryTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedInstanceFactoryTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StandardReflectedInstanceFactoryTest.java 9 Jan 2003 03:24:01 -0000 1.4
+++ StandardReflectedInstanceFactoryTest.java 20 Jan 2003 18:29:45 -0000 1.5
@@ -61,7 +61,9 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public class StandardReflectedInstanceFactoryTest extends ReflectedOperationCommon {
+public class StandardReflectedInstanceFactoryTest
+ extends ReflectedOperationCommon
+{
/**
* Constructor for StandardReflectedOperationTest.
@@ -71,8 +73,8 @@
super(name);
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.STANDARD_CLAZZ_MODEL;
}
-
+
}
1.6 +32 -32 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedListPropertyTest.java
Index: StandardReflectedListPropertyTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedListPropertyTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StandardReflectedListPropertyTest.java 9 Jan 2003 03:24:01 -0000 1.5
+++ StandardReflectedListPropertyTest.java 20 Jan 2003 18:29:45 -0000 1.6
@@ -80,11 +80,11 @@
junit.textui.TestRunner.run(StandardReflectedListPropertyTest.suite());
}
- public static TestSuite suite(){
+ public static TestSuite suite() {
return new TestSuite(StandardReflectedListPropertyTest.class);
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.STANDARD_CLAZZ_MODEL;
}
@@ -93,7 +93,7 @@
* Checks the set of methods recognized for a List property that
* does not have regular get/set methods.
*/
- public void testRecognitionOfListPropertyWithoutReadWriteMethods(){
+ public void testRecognitionOfListPropertyWithoutReadWriteMethods() {
assertNull("Read method",
stringProperty.getReadMethod());
@@ -125,7 +125,7 @@
* Checks the a property is recognized as List even if it
* does not have parameterized get/set/remove methods.
*/
- public void testRecognitionOfListPropertyWithoutGetSetAddRemoveMethods(){
+ public void testRecognitionOfListPropertyWithoutGetSetAddRemoveMethods() {
assertMethodSignature("Read method",
"getIntArray()",
intArrayProperty.getReadMethod());
@@ -158,94 +158,94 @@
instance.addString("bar");
instance.addString("baz");
instance.resetTrace();
-
- List list = (List)stringProperty.get(instance);
+
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.size();
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
}
-
- public void testIsEmptyWithList(){
- List list = (List)stringProperty.get(instance);
+
+ public void testIsEmptyWithList() {
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.isEmpty();
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
}
-
+
public void testContainsWithListSuccess() {
testContainsWithListFailure();
}
-
+
public void testContainsWithListFailure() {
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.contains("foo");
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
- }
-
- public void testIteratorWithList(){
- List list = (List)stringProperty.get(instance);
+ }
+
+ public void testIteratorWithList() {
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.iterator();
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
- }
-
+ }
+
public void testAddObjectWithListStartEmpty() {
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.add("biz");
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
}
-
+
public void testAddObjectWithListStartPopulated() {
populateStringList();
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.add("biz");
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
}
-
+
public void testAddIndexedWithList() {
populateStringList();
- List list = (List)stringProperty.get(instance);
+ List list = (List) stringProperty.get(instance);
boolean ex = false;
try {
list.add(1, "biz");
}
- catch (Throwable t){
+ catch (Throwable t) {
ex = true;
}
assertTrue("Exception because there is no read method ", ex);
}
-
+
}
1.5 +2 -2 jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedOperationTest.java
Index: StandardReflectedOperationTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/reflect/standard/StandardReflectedOperationTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StandardReflectedOperationTest.java 9 Jan 2003 03:24:01 -0000 1.4
+++ StandardReflectedOperationTest.java 20 Jan 2003 18:29:45 -0000 1.5
@@ -71,7 +71,7 @@
super(name);
}
- protected String getModelKey(){
+ protected String getModelKey() {
return Clazz.STANDARD_CLAZZ_MODEL;
}
1.2 +174 -7 jakarta-commons-sandbox/clazz/xdocs/overview.xml
Index: overview.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/xdocs/overview.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- overview.xml 9 Jan 2003 03:24:01 -0000 1.1
+++ overview.xml 20 Jan 2003 18:29:45 -0000 1.2
@@ -15,7 +15,6 @@
requirements, new de facto standards and a wider range of potential
applications.
</p>
-<!-- TBD: TOC
<ul>
<li><a href="#Requirements">Requirements</a>
<ul>
@@ -23,7 +22,7 @@
</li>
</ul>
</li>
-
+<!--
<li><a href="#Clazz Class">Clazz Class</a>
</li>
<li><a href="#Client Side of Clazz">Client Side of Clazz</a>
@@ -32,8 +31,8 @@
<li><a href="#Metadata Provider">Metadata Provider</a></li>
</ul>
</li>
- </ul>
-->
+ </ul>
</section>
@@ -230,7 +229,7 @@
<!--============================ + SOURCE + ============================-->
<source>
<b/>
-public class MyExample2 {
+public class MyExample3 {
// Create and register a ClazzLoaderFactory for a custom model
static {
@@ -297,17 +296,174 @@
<section name="Extended Property Types">
<p>
- TBD
+ Clazz introduces two new kinds of properties: List and Mapped. A List property
+ is similar to the JavaBeans indexed property, except that to access a List
+ property you can use <code>java.util.List</code> interface. Similarly,
+ a Mapped property is accessed via the <code>java.util.Map</code> interface.
</p>
<subsection name="List Property">
<p>
- TBD
+ The List property behaves differently in different models.
+ </p>
+ <p>
+ In the Standard model, Clazz recognizes methods like <code>getBook()</code>,
+ returning an array as well as indexed accessors: <code>getBook(int index)</code> and
+ <code>setBook(int index, value)</code>.
+ </p>
+ <p>
+ In the Extended model, the range of recognized accessors is much wider.
+
+ For a property called "book", Clazz will recognize and use the following accessors:
+ <ul>
+ <li>Whole collection read method as a method returning an array or a list
+ and named: <code>getBook()</code>,
+ <code>getBooks()</code>, <code>getBookList()</code>,
+ <code>getBookArray()</code> or <code>getBookVector()</code>.
+ </li>
+ <li>Whole collection set method as a method taking an array or a list as
+ its only argument and named: <code>setBook(array or list)</code>,
+ <code>setBooks(...)</code>, <code>setBookList(...)</code>,
+ <code>setBookArray(...)</code> or <code>setBookVector(...)</code>.
+ </li>
+ <li>Indexed get method: <code>getBook(int index)</code>
+ </li>
+ <li>Indexed set method: <code>setBook(int index, book)</code>
+ </li>
+ <li>Add method: <code>addBook(book)</code>
+ </li>
+ <li>Indexed add method: <code>addBook(int index, book)</code>
+ </li>
+ <li>Remove method: <code>removeBook(book)</code>
+ </li>
+ <li>Indexed remove method: <code>removeBook(int index)</code>
+ </li>
+ <li>Count method: <code>int getBookCount()</code> or <code>int getBookSize()</code>
+ etc.
+ </li>
+ </ul>
+ </p>
+ <p>
+ These accessors are not required. One get method, indexed or not is sufficient
+ for Clazz to recognize a List property.
</p>
+ <p>
+ When you acquire the value of this property using the Clazz API, you get an
+ object implementing the complete <code>java.util.List</code> interface.
+ The implementations of List methods invoke relevant accessor methods on the bean.
+ The implementation is smart enough to get by with whatever accessors are
+ available. However, complete lack of accessors will render the List inoperable.
+ For example, if the only accessors available are <code>getBook(int)</code>
+ and <code>setBook(int,book)</code>, you will be able to call <code>list.get(i)</code>
+ and <code>list.set(int,book)</code>, but you won't be able to iterate over the
+ list or add anything to it. In order enable those operations, you need either
+ <code>int getBookCount()</code> or <code>getBooks()</code>.
+ </p>
+ <p>
+ Whole collection accessors are used only in the absense of more specific accessors.
+ </p>
+ <p>
+ Example:
+ </p>
+<!--============================ + SOURCE + ============================-->
+<source>
+ <b/>
+public class Album {
+
+ String getTrackTitle(int trackNumber) {...}
+ int getTrackTitleCount() {...}
+}
+
+public class MyExample4 {
+
+ void listAllTracks(Album album){
+
+ // Step 1. Find the Extended Clazz
+ Clazz clazz = Clazz.getClazz(album, "Extended");
+
+ // Step 2. Acquire the property value
+ List trackTitles = (List)clazz.get("trackTitles");
+
+ // Step 3. Work with the property value
+ for (Iterator iter = trackTitles.iterator(); iter.hasNext();) {
+ String title = (String) iter.next();
+ System.out.println("Track: " + title);
+ }
+ }
+}
+
+</source>
+<!--============================ - SOURCE - ============================-->
</subsection>
<subsection name="Mapped Property">
<p>
- TBD
+ Mapped property is similar to List property, except values are identified by keys
+ rather than integer indexes.
+ </p>
+ <p>
+ In the Standard model Mapped properties are not supported.
+ </p>
+ <p>
+ In the Extended model, the following accesors are recognized.
+ <ul>
+ <li>Whole collection read method as a method returning a Map
+ and named: <code>getBook()</code>,
+ <code>getBooks()</code> or <code>getBookMap()</code>.
+ </li>
+ <li>Whole collection set method as a method taking a Map as
+ its only argument and named: <code>setBook(...)</code>,
+ <code>setBooks(...)</code> or <code>setBookMap(...)</code>.
+ </li>
+ <li>Keyed get method: <code>getBook(key)</code>
+ </li>
+ <li>Keyed set method: <code>setBook(key, book)</code>
+ </li>
+ <li>Remove method: <code>removeBook(key)</code>
+ </li>
+ <li>Key-set method: <code>getBookKeys()</code> or <code>getBookKeySet()</code>.
+ This method returns an array or Collection of keys.
+ </li>
+ </ul>
+ </p>
+ <p>
+ These accessors are not required. One get method, keyed or not is sufficient
+ for Clazz to recognize a Mapped property.
+ </p>
+ <p>
+ When you acquire the value of this property using the Clazz API, you get an
+ object implementing the complete <code>java.util.Map</code> interface.
+ The implementations of the Map methods invoke relevant accessor methods on the bean.
+ Whole collection accessors are used only in the absense of more specific accessors.
+ </p>
+ <p>
+ Example:
</p>
+<!--============================ + SOURCE + ============================-->
+<source>
+ <b/>
+public class Album {
+
+ String getComposer(String trackTitle) {...}
+
+}
+
+public class MyExample5 {
+
+ void listAllTracks(Album album){
+
+ // Step 1. Find the Extended Clazz
+ Clazz clazz = Clazz.getClazz(album, "Extended");
+
+ // Step 2. Acquire the property value
+ Map composerMap = (Map)clazz.get("composer");
+
+ // Step 3. Work with the property value
+ String composer = (String) composerMap.get("Love Me Two Times");
+ System.out.println("Composer: " + composer);
+ }
+}
+
+</source>
+<!--============================ - SOURCE - ============================-->
</subsection>
</section>
@@ -442,6 +598,17 @@
</source>
<!--============================ - SOURCE - ============================-->
+ </subsection>
+
+ <subsection name="Customizing a Clazz using BeanInfo">
+ <p>
+ If you have a custom implementation of BeanInfo for a custom bean,
+ that implementation will be used in the construction of the Clazz.
+ This method is not as flexible as the one described in the previous
+ section. However, you don't have to redo your customizations
+ if you already have a BeanInfo implementaion or if you
+ generate one automatically using XDoclet.
+ </p>
</subsection>
<subsection name="Customizing a Family of Reflected Clazzes">
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>