diff --git a/domain/src/main/java/org/acegisecurity/domain/impl/BusinessObject.java b/domain/src/main/java/org/acegisecurity/domain/impl/BusinessObject.java index f4219206b2..64d7272700 100644 --- a/domain/src/main/java/org/acegisecurity/domain/impl/BusinessObject.java +++ b/domain/src/main/java/org/acegisecurity/domain/impl/BusinessObject.java @@ -15,7 +15,7 @@ package net.sf.acegisecurity.domain.impl; -import net.sf.acegisecurity.domain.util.CollectionIgnoringReflectionToStringBuilder; +import net.sf.acegisecurity.domain.util.ReflectionToStringBuilder; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; @@ -77,6 +77,6 @@ public abstract class BusinessObject implements Serializable, Cloneable { * @see java.lang.Object#toString() */ public String toString() { - return new CollectionIgnoringReflectionToStringBuilder(this).toString(); + return new ReflectionToStringBuilder(this).toString(); } } diff --git a/domain/src/main/java/org/acegisecurity/domain/util/CollectionIgnoringReflectionToStringBuilder.java b/domain/src/main/java/org/acegisecurity/domain/util/CollectionIgnoringReflectionToStringBuilder.java deleted file mode 100644 index 12d77fe3f7..0000000000 --- a/domain/src/main/java/org/acegisecurity/domain/util/CollectionIgnoringReflectionToStringBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright 2004, 2005 Acegi Technology Pty Limited - * - * 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 net.sf.acegisecurity.domain.util; - -import java.lang.reflect.Field; - - -/** - * A toString() builder that ignores collections. - * - * @author Carlos Sanchez - * @version $Id$ - * - * @see org.apache.commons.lang.builder.ReflectionToStringBuilder - */ -public class CollectionIgnoringReflectionToStringBuilder - extends ReflectionToStringBuilder { - //~ Constructors =========================================================== - - public CollectionIgnoringReflectionToStringBuilder(Object object) { - super(object); - } - - //~ Methods ================================================================ - - /** - * Check if the field is a collection and return false in that case. - * - * @see org.apache.commons.lang.builder.ReflectionToStringBuilder#accept(java.lang.reflect.Field) - */ - protected boolean accept(Field field) { - if (CollectionUtils.isCollection(field.getType())) { - return false; - } - - return super.accept(field); - } -} diff --git a/domain/src/main/java/org/acegisecurity/domain/util/ReflectionToStringBuilder.java b/domain/src/main/java/org/acegisecurity/domain/util/ReflectionToStringBuilder.java index e6a8434335..5e2c0996df 100644 --- a/domain/src/main/java/org/acegisecurity/domain/util/ReflectionToStringBuilder.java +++ b/domain/src/main/java/org/acegisecurity/domain/util/ReflectionToStringBuilder.java @@ -15,28 +15,34 @@ package net.sf.acegisecurity.domain.util; -import org.apache.commons.lang.builder.ToStringStyle; - +import java.io.Serializable; import java.lang.reflect.Field; - import java.text.DateFormat; - import java.util.Calendar; +import java.util.Collection; + +import net.sf.acegisecurity.domain.PersistableEntity; + +import org.apache.commons.lang.builder.ToStringStyle; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** - * Customized Commons Lang ReflectionToStringBuilder. + * Customized Commons Lang ReflectionToStringBuilder + * that ignores collections and inaccessible (ie lazy-loaded) fields. * * @author Carlos Sanchez - * @version $Revision$ - * - * @see org.apache.commons.lang.builder.ReflectionToStringBuilder + * @author Ben Alex + * @version $Id$ */ public class ReflectionToStringBuilder extends org.apache.commons.lang.builder.ReflectionToStringBuilder { //~ Static fields/initializers ============================================= - private static DateFormat formatter = DateFormat.getDateTimeInstance(); + protected final transient Log logger = LogFactory.getLog(getClass()); + + private static DateFormat formatter = DateFormat.getDateTimeInstance(); //~ Constructors =========================================================== @@ -64,4 +70,38 @@ public class ReflectionToStringBuilder return value; } } + + protected boolean accept(Field field) { + // Ignore if field inaccessible or collection + try { + Object o = getValue(field); + if (o != null) { + if (o instanceof PersistableEntity) { + Serializable id = ((PersistableEntity)o).getInternalId(); + if (logger.isDebugEnabled()) { + logger.debug(field + " id: " + id); + } + } + if (o instanceof Collection) { + int size = ((Collection)o).size(); + this.append(field.getName(), ""); + if (logger.isDebugEnabled()) { + logger.debug(field + " size: " + size); + } + } + } + } catch (Exception fieldInaccessible) { + this.append(field.getName(), ""); + if (logger.isDebugEnabled()) { + logger.debug("Inaccessible: " + field); + } + return false; + } + + if (logger.isDebugEnabled()) { + logger.debug("Accessible: " + field); + } + + return true; + } }