You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2005/08/25 21:12:55 UTC
svn commit: r240121 - in /jakarta/commons/proper/betwixt/trunk:
src/java/org/apache/commons/betwixt/strategy/
src/java/org/apache/commons/betwixt/strategy/impl/
src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/
src/test/org/apache/...
Author: rdonkin
Date: Thu Aug 25 12:12:44 2005
New Revision: 240121
URL: http://svn.apache.org/viewcvs?rev=240121&view=rev
Log:
More property suppression.
Added:
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/PackageSuppressor.java
jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/
jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/propertysuppression/
jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/propertysuppression/TestPackageSuppressor.java
Modified:
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java
jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java?rev=240121&r1=240120&r2=240121&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java (original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java Thu Aug 25 12:12:44 2005
@@ -15,10 +15,13 @@
*/
package org.apache.commons.betwixt.strategy;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
import java.util.Collection;
/**
- * Pluggable strategy specifying whether property's should be surpressed.
+ * Pluggable strategy specifying whether property's should be suppressed.
* Implementations can be used to give rules about which properties
* should be ignored by Betwixt when introspecting.
* @since 0.7
@@ -27,11 +30,10 @@
public abstract class PropertySuppressionStrategy {
/**
- * Default implementation supresses the class property
- * found on every object. Also, the <code>isEmpty</code>
- * property is supressed for implementations of <code>Collection</code>.
+ * Default implementation.
+ * @see #DEFAULT
*/
- public static final PropertySuppressionStrategy DEFAULT = new PropertySuppressionStrategy() {
+ public static class Default extends PropertySuppressionStrategy {
public boolean suppressProperty(Class clazz, Class propertyType, String propertyName) {
boolean result = false;
// ignore class properties
@@ -45,7 +47,50 @@
return result;
}
- };
+
+ public String toString() {
+ return "Default Properties Suppressed";
+ }
+ }
+
+ /**
+ * Implementation delegates to a list of strategies
+ */
+ public static class Chain extends PropertySuppressionStrategy {
+
+ private final List strategies = new ArrayList();
+
+ /**
+ * @see #suppressProperty(Class, Class, String)
+ */
+ public boolean suppressProperty(Class classContainingTheProperty, Class propertyType, String propertyName) {
+ boolean result = false;
+ for (Iterator it=strategies.iterator(); it.hasNext();) {
+ PropertySuppressionStrategy strategy = (PropertySuppressionStrategy) it.next();
+ if (strategy.suppressProperty(classContainingTheProperty, propertyType, propertyName)) {
+ result = true;
+ break;
+ }
+
+ }
+ return result;
+ }
+
+ /**
+ * Adds a strategy to the list
+ * @param strategy <code>PropertySuppressionStrategy</code>, not null
+ */
+ public void addStrategy(PropertySuppressionStrategy strategy) {
+ strategies.add(strategy);
+ }
+ }
+
+ /**
+ * Default implementation suppresses the class property
+ * found on every object. Also, the <code>isEmpty</code>
+ * property is supressed for implementations of <code>Collection</code>.
+ */
+ public static final PropertySuppressionStrategy DEFAULT = new Default();
/**
* Should the given property be suppressed?
Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/PackageSuppressor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/PackageSuppressor.java?rev=240121&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/PackageSuppressor.java (added)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/propertysuppression/PackageSuppressor.java Thu Aug 25 12:12:44 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.betwixt.strategy.impl.propertysuppression;
+
+import org.apache.commons.betwixt.strategy.PropertySuppressionStrategy;
+
+/**
+ * Suppresses properties based on the package of their type.
+ * Limited regex is supported. If the package name ends in <code>.*</code>
+ * them all child packages will be suppressed.
+ * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a> of the <a href='http://www.apache.org'>Apache Software Foundation</a>
+ */
+public class PackageSuppressor extends PropertySuppressionStrategy {
+
+ /** Package to be suppressed */
+ private final String suppressedPackage;
+ private final boolean exact;
+
+ /**
+ * Constructs a suppressor for packages.
+ * @param suppressedPackage package name (for exact match)
+ * or base package and <code>.*</code>to suppress children
+ */
+ public PackageSuppressor(String suppressedPackage) {
+ if (suppressedPackage.endsWith(".*")) {
+ exact = false;
+ suppressedPackage = suppressedPackage.substring(0, suppressedPackage.length()-2);
+ }
+ else
+ {
+ exact =true;
+ }
+ this.suppressedPackage = suppressedPackage;
+ }
+
+ public boolean suppressProperty(Class classContainingTheProperty, Class propertyType, String propertyName) {
+ boolean result = false;
+ if (propertyType != null) {
+ Package propertyTypePackage = propertyType.getPackage();
+ if (propertyTypePackage != null) {
+ String packageName = propertyTypePackage.getName();
+ if (exact) {
+ result = suppressedPackage.equals(packageName);
+ }
+ else if (packageName != null)
+ {
+ result = packageName.startsWith(suppressedPackage);
+ }
+ }
+ }
+ return result;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer("Suppressing package " );
+ buffer.append(suppressedPackage);
+ if (exact) {
+ buffer.append("(exact)");
+ }
+ return buffer.toString();
+ }
+}
Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/propertysuppression/TestPackageSuppressor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/propertysuppression/TestPackageSuppressor.java?rev=240121&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/propertysuppression/TestPackageSuppressor.java (added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/strategy/impl/propertysuppression/TestPackageSuppressor.java Thu Aug 25 12:12:44 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.betwixt.strategy.impl.propertysuppression;
+
+import org.apache.commons.betwixt.XMLIntrospector;
+import org.apache.commons.betwixt.io.BeanWriter;
+
+import junit.framework.TestCase;
+
+public class TestPackageSuppressor extends TestCase {
+
+ public void testExact() throws Exception {
+ PackageSuppressor suppressor = new PackageSuppressor("org.apache.commons.betwixt");
+ assertFalse("Unrelated class", suppressor.suppressProperty(String.class, String.class,"bogus"));
+ assertFalse("Unrelated type", suppressor.suppressProperty(XMLIntrospector.class, String.class,"bogus"));
+ assertTrue("Type in package", suppressor.suppressProperty( String.class, XMLIntrospector.class,"bogus"));
+ assertFalse("Type in child package", suppressor.suppressProperty( String.class, BeanWriter.class,"bogus"));
+ }
+
+ public void testWild() throws Exception {
+ PackageSuppressor suppressor = new PackageSuppressor("org.apache.commons.betwixt.*");
+ assertFalse("Unrelated class", suppressor.suppressProperty(String.class, String.class,"bogus"));
+ assertFalse("Unrelated type", suppressor.suppressProperty(XMLIntrospector.class, String.class,"bogus"));
+ assertTrue("Type in package", suppressor.suppressProperty( String.class, XMLIntrospector.class,"bogus"));
+ assertTrue("Type in child package", suppressor.suppressProperty( String.class, BeanWriter.class,"bogus"));
+ }
+}
Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?rev=240121&r1=240120&r2=240121&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Thu Aug 25 12:12:44 2005
@@ -200,6 +200,10 @@
<subsection name='Since 0.7'>
<ul>
<li>
+Added package name property suppression strategy and make default property suppression strategy public
+nest so that it can be subclassed.
+ </li>
+ <li>
Fixed bug when introspecting in secure environments.
</li>
<li>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org