View Javadoc

1   /*
2    * Copyright 2004 Carlos Sanchez.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.oness.common.model.bo;
17  
18  import java.lang.reflect.Field;
19  
20  import net.sf.oness.common.all.ReflectionToStringBuilder;
21  import net.sf.oness.common.model.util.CollectionUtils;
22  
23  /***
24   * Customized ReflectionToStringBuilder ignoring Collection fields.
25   * 
26   * @see org.apache.commons.lang.builder.ReflectionToStringBuilder
27   * 
28   * @author Carlos Sanchez
29   * @version $Revision: 1.2 $
30   */
31  public class CollectionIgnoringReflectionToStringBuilder extends
32          ReflectionToStringBuilder {
33  
34      public CollectionIgnoringReflectionToStringBuilder(Object object) {
35          super(object);
36      }
37  
38      /***
39       * Check if the field is a collection and return false in that case.
40       * 
41       * @see org.apache.commons.lang.builder.ReflectionToStringBuilder#accept(java.lang.reflect.Field)
42       */
43      protected boolean accept(Field field) {
44          if (CollectionUtils.isCollection(field.getType()))
45              return false;
46          return super.accept(field);
47      }
48  }