Clover coverage report - SOJO - 1.0.0
Coverage timestamp: Mo Mai 4 2009 16:26:33 CEST
file stats: LOC: 118   Methods: 14
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassPropertyFilter.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Copyright 2002-2005 the original author or authors.
 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.sojo.core.filter;
 17   
 18    import java.util.ArrayList;
 19    import java.util.List;
 20    import java.util.regex.Pattern;
 21   
 22    import net.sf.sojo.util.Util;
 23   
 24    /**
 25    * This class descripe, which properties are to ignore by convert class to a new representation.
 26    * The properties, which are added to this filter are transient by
 27    * call a serialize method by the <code>net.sf.sojo.interchange.Serializer</code>.
 28    *
 29    * <b>Hint:</b> a property is by a JavaBean the name of the getter/setter method. By a Map is the property equivalent with the key.
 30    *
 31    * @author linke
 32    *
 33    */
 34    public class ClassPropertyFilter {
 35   
 36   
 37    private Class filterClass = null;
 38    private List propertyList = new ArrayList();
 39    private boolean support4AddClassProperty = false;
 40   
 41  2 public ClassPropertyFilter() { }
 42   
 43  57 public ClassPropertyFilter(Class pvClass) {
 44  57 setFilterClass(pvClass);
 45    }
 46   
 47   
 48  13 public ClassPropertyFilter(Class pvClass, String pvProperties[]) {
 49  13 setFilterClass(pvClass);
 50  13 addProperties(pvProperties);
 51    }
 52   
 53   
 54  59 public Class getFilterClass() { return filterClass; }
 55  70 private void setFilterClass(Class pvClass) { this.filterClass = pvClass; }
 56   
 57  29 public void setSupport4AddClassProperty(boolean pvSupport4AddClassProperty) { support4AddClassProperty = pvSupport4AddClassProperty; }
 58  43 public boolean getSupport4AddClassProperty() { return support4AddClassProperty; }
 59   
 60   
 61  31 public ClassPropertyFilter addProperties(String pvProperties[]) {
 62  31 if (pvProperties != null) {
 63  29 for (int i = 0; i < pvProperties.length; i++) {
 64  44 addProperty(pvProperties[i]);
 65    }
 66    }
 67  31 return this;
 68    }
 69   
 70  200 public ClassPropertyFilter addProperty(String pvProperty) {
 71  200 if (Util.getKeyWordClass().equals(pvProperty) == false || getSupport4AddClassProperty()) {
 72  177 propertyList.add(pvProperty);
 73    }
 74  200 return this;
 75    }
 76   
 77  18 public ClassPropertyFilter removeProperty(String pvProperty) {
 78  18 for (int i=0; i<propertyList.size(); i++) {
 79  45 if (propertyList.get(i).equals(pvProperty)) {
 80  14 propertyList.remove(i);
 81    }
 82    }
 83  18 return this;
 84    }
 85   
 86  3 public ClassPropertyFilter removeProperties(String pvProperty[]) {
 87  3 if (pvProperty != null) {
 88  2 for (int i = 0; i < pvProperty.length; i++) {
 89  6 removeProperty(pvProperty[i]);
 90    }
 91    }
 92  3 return this;
 93    }
 94   
 95  261 public boolean isKnownProperty(String pvProperty) {
 96  261 for (int i=0; i<propertyList.size(); i++) {
 97  435 if (propertyList.get(i).equals(pvProperty)) {
 98  81 return true;
 99    }
 100    else {
 101  354 boolean b = Pattern.matches((String) propertyList.get(i), pvProperty);
 102  354 if (b == true) {
 103  1 return true;
 104    }
 105    }
 106    }
 107  179 return false;
 108    }
 109   
 110  17 public int getPropertySize() {
 111  17 return propertyList.size();
 112    }
 113   
 114  6 public String[] getAllProperties() {
 115  6 return (String[]) propertyList.toArray(new String [propertyList.size()]);
 116    }
 117   
 118    }