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 2002/12/17 00:17:42 UTC
cvs commit: jakarta-commons-sandbox/clazz/src/test/org/apache/commons/clazz/bean BeanClazzTest.java
dmitri 2002/12/16 15:17:42
Modified: clazz/src/java/org/apache/commons/clazz Clazz.java
ClazzFeature.java
clazz/src/java/org/apache/commons/clazz/common
ClazzFeatureSupport.java
clazz/src/java/org/apache/commons/clazz/reflect/common
ReflectedList.java
clazz/src/test/org/apache/commons/clazz/bean
BeanClazzTest.java
Added: clazz/src/java/org/apache/commons/clazz ClazzElement.java
clazz/src/java/org/apache/commons/clazz/bean
BeanClazzOperation.java
clazz/src/java/org/apache/commons/clazz/common
ClazzElementSupport.java
Removed: clazz/src/java/org/apache/commons/clazz/bean
BeanClazzOperaiton.java
Log:
Clean-up
Revision Changes Path
1.5 +11 -3 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Clazz.java 14 Dec 2002 02:38:41 -0000 1.4
+++ Clazz.java 16 Dec 2002 23:17:41 -0000 1.5
@@ -59,6 +59,7 @@
import org.apache.commons.clazz.bean.BeanClazzLoader;
import org.apache.commons.clazz.bean.BeanGroupClazzLoader;
import org.apache.commons.clazz.common.CachingGroupClazzLoader;
+import org.apache.commons.clazz.common.ClazzElementSupport;
import org.apache.commons.clazz.common.GroupClazzLoader;
import org.apache.commons.clazz.reflect.ReflectedGroupClazzLoader;
import org.apache.commons.clazz.reflect.extended.ExtendedReflectedClazzLoader;
@@ -70,7 +71,8 @@
* @author <a href="mailto:scolebourne@apache.org">Stephen Colebourne</a>
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class Clazz
+public abstract class Clazz extends ClazzElementSupport
+ implements ClazzElement
{
private ClazzLoader loader;
private String name;
@@ -82,19 +84,25 @@
public static final String STANDARD_CLAZZLOADER =
"org.apache.commons.clazz.StandardClazzLoader";
+ public static final String EXTENDED_CLAZZLOADER =
+ "org.apache.commons.clazz.ExtendedClazzLoader";
+
private static ClazzLoader defaultClazzLoader;
private static Map clazzLoaders = new HashMap();
static {
- setClazzLoader(DEFAULT_CLAZZLOADER, buildDefaultClazzLoader());
setClazzLoader(STANDARD_CLAZZLOADER, buildStandardClazzLoader());
+ ClazzLoader extended = buildExtendedClazzLoader();
+ setClazzLoader(EXTENDED_CLAZZLOADER, extended);
+
+ setClazzLoader(DEFAULT_CLAZZLOADER, extended);
}
/**
* Construct the default clazz loader, that is the one based on the extended
* notion of JavaBeans.
*/
- private static ClazzLoader buildDefaultClazzLoader(){
+ private static ClazzLoader buildExtendedClazzLoader(){
GroupClazzLoader loader = new CachingGroupClazzLoader(null);
// First build a general reflection-based ClazzLoader
1.3 +2 -2 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzFeature.java
Index: ClazzFeature.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzFeature.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ClazzFeature.java 6 Dec 2002 01:12:48 -0000 1.2
+++ ClazzFeature.java 16 Dec 2002 23:17:41 -0000 1.3
@@ -58,7 +58,7 @@
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public interface ClazzFeature {
+public interface ClazzFeature extends ClazzElement {
/**
*/
1.1 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/ClazzElement.java
Index: ClazzElement.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;
/**
* Attribute API.
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: ClazzElement.java,v 1.1 2002/12/16 23:17:41 dmitri Exp $
*/
public interface ClazzElement {
// @todo: attribute API goes here
Object getAttribute(String attribute);
}
1.1 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/bean/BeanClazzOperation.java
Index: BeanClazzOperation.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.bean;
import org.apache.commons.clazz.Clazz;
import org.apache.commons.clazz.ClazzLoader;
import org.apache.commons.clazz.ClazzOperation;
import org.apache.commons.clazz.common.ClazzFeatureSupport;
/**
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: BeanClazzOperation.java,v 1.1 2002/12/16 23:17:41 dmitri Exp $
*/
public abstract class BeanClazzOperation
extends ClazzFeatureSupport
implements ClazzOperation
{
private String returnClazzName;
private Clazz returnClazz;
private String name;
private final String[] EMPTY_STRING_ARRAY = new String[0];
private String[] parameterClazzNames;
private Clazz[] parameterClazzes;
private String signature;
/**
* Constructor for BeanClazzOperaiton.
*
* @param declaringClazz the Clazz this Operation belongs to
* @param returnClazzName the return type of the operation, pass
* <code>null</code> for <code>void</code>.
* @param name the name of the operation.
* @param parameterClazzNames types of operation parameters, pass
* <code>null</code> if the operation does not take any parameters.
*/
public BeanClazzOperation(
Clazz declaringClazz,
String returnClazzName,
String name,
String[] parameterClazzNames)
{
super(declaringClazz);
this.returnClazzName = returnClazzName;
this.name = name;
this.parameterClazzNames =
(parameterClazzNames != null
? parameterClazzNames
: EMPTY_STRING_ARRAY);
}
/**
* @see org.apache.commons.clazz.ClazzOperation#getSignature()
*/
public String getSignature() {
if (signature == null) {
signature = Clazz.constructSignature(name, getParameterClazzes());
}
return signature;
}
/**
* @see org.apache.commons.clazz.ClazzOperation#getName()
*/
public String getName() {
return name;
}
/**
* @see org.apache.commons.clazz.ClazzOperation#getParameterClazzes()
*/
public Clazz[] getParameterClazzes() {
if (parameterClazzes == null) {
parameterClazzes = new Clazz[parameterClazzNames.length];
ClazzLoader loader = getDeclaringClazz().getClazzLoader();
for (int i = 0; i < parameterClazzes.length; i++) {
parameterClazzes[i] =
loader.getClazzForName(parameterClazzNames[i]);
if (parameterClazzes[i] == null){
throw new BeanClazzConfigurationException(
"Invalid argument type: "
+ parameterClazzNames[i]
+ ". Clazz not found.");
}
}
}
return parameterClazzes;
}
/**
* @see org.apache.commons.clazz.ClazzOperation#getReturnClazz()
*/
public Clazz getReturnClazz() {
if (returnClazzName == null){
return null;
}
if (returnClazz == null) {
ClazzLoader loader = getDeclaringClazz().getClazzLoader();
returnClazz = loader.getClazzForName(returnClazzName);
}
return returnClazz;
}
/**
* @see org.apache.commons.clazz.ClazzOperation#invoke(java.lang.Object, java.lang.Object)
*/
public abstract Object invoke(Object target, Object[] parameters);
}
1.2 +5 -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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClazzFeatureSupport.java 6 Dec 2002 01:12:48 -0000 1.1
+++ ClazzFeatureSupport.java 16 Dec 2002 23:17:41 -0000 1.2
@@ -62,7 +62,10 @@
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id$
*/
-public abstract class ClazzFeatureSupport implements ClazzFeature {
+public abstract class ClazzFeatureSupport
+ extends ClazzElementSupport
+ implements ClazzFeature
+{
private Clazz declaringClazz;
1.1 jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/common/ClazzElementSupport.java
Index: ClazzElementSupport.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.common;
import org.apache.commons.clazz.ClazzElement;
/**
*
* @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
* @version $Id: ClazzElementSupport.java,v 1.1 2002/12/16 23:17:41 dmitri Exp $
*/
public abstract class ClazzElementSupport implements ClazzElement {
/**
* @see org.apache.commons.clazz.ClazzElement#getAttribute(java.lang.String)
*/
public Object getAttribute(String attribute) {
throw new UnsupportedOperationException(
"No such attribute: " + attribute);
}
}
1.3 +6 -2 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedList.java 14 Dec 2002 02:38:42 -0000 1.2
+++ ReflectedList.java 16 Dec 2002 23:17:41 -0000 1.3
@@ -574,6 +574,10 @@
+ method.getName(),
ex);
}
+
+ private int getModCount(){
+ return modCount;
+ }
/**
* QuickList is used exclusively as short-lived helper object for
@@ -599,7 +603,7 @@
public void refresh(){
// If QuickList is out of sync with the parent ReflectedList,
// update the cached list and size
- if (super.modCount != ReflectedList.this.modCount){
+ if (super.modCount != getModCount()){
update();
}
}
@@ -607,7 +611,7 @@
public void update(){
// Make sure modCount of QuickList is maintained in sync with
// that of the embracing List
- super.modCount = ReflectedList.this.modCount;
+ super.modCount = getModCount();
if (property.getReadMethod() != null){
list = getPropertyValue();
1.3 +58 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BeanClazzTest.java 14 Dec 2002 02:38:43 -0000 1.2
+++ BeanClazzTest.java 16 Dec 2002 23:17:41 -0000 1.3
@@ -107,6 +107,8 @@
(BeanClazz) Clazz.getDefaultClazzLoader().defineClazz(
TEST_SUPERCLAZZ_NAME,
BeanClazz.class, null);
+ superClazz.addDeclaredProperty(
+ new BeanClazzProperty(superClazz, "baseProperty"));
clazz =
(BeanClazz) Clazz.getDefaultClazzLoader().defineClazz(
@@ -114,8 +116,6 @@
BeanClazz.class, null);
clazz.setSuperclazz(superClazz);
- superClazz.addDeclaredProperty(
- new BeanClazzProperty(superClazz, "baseProperty"));
clazz.addDeclaredProperty(
new BeanClazzProperty(clazz, "objectProperty"));
clazz.addDeclaredProperty(
@@ -123,7 +123,7 @@
clazz.addDeclaredOperation(
- new BeanClazzOperaiton(clazz, null, "twoPlusTwo", null){
+ new BeanClazzOperation(clazz, null, "twoPlusTwo", null){
public Object invoke(Object instance, Object[] parameters){
return new Integer(4);
}
@@ -131,7 +131,7 @@
);
clazz.addDeclaredOperation(
- new BeanClazzOperaiton(
+ new BeanClazzOperation(
clazz,
"java.lang.Integer",
"computeAplusB",
@@ -329,4 +329,58 @@
public void testIsAssignableFrom() {
}
+ 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);
+ }
+
+ public void testRevealOverloadedOperation(){
+ ClazzOperation superFoo =
+ new BeanClazzOperation(superClazz, null, "foo", null) {
+ public Object invoke(Object instance, Object[] parameters) {
+ return null;
+ }
+ };
+
+ superClazz.addDeclaredOperation(superFoo);
+
+ assertTrue(
+ "Super foo exposed on subclazz",
+ clazz.getOperation("foo()") == superFoo);
+
+ ClazzOperation subFoo =
+ new BeanClazzOperation(clazz, null, "foo", null) {
+ public Object invoke(Object instance, Object[] parameters) {
+ return null;
+ }
+ };
+ clazz.addDeclaredOperation(subFoo);
+
+ assertTrue(
+ "Super foo masked by subclazz foo",
+ clazz.getOperation("foo()") == subFoo);
+
+ clazz.removeDeclaredOperation(subFoo);
+
+ assertTrue(
+ "Super foo revealed when subclazz foo removed",
+ clazz.getOperation("foo()") == superFoo);
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>