1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.strategy.impl.propertysuppression;
18
19 import org.apache.commons.betwixt.strategy.PropertySuppressionStrategy;
20
21 /***
22 * Suppresses properties based on the package of their type.
23 * Limited regex is supported. If the package name ends in <code>.*</code>
24 * them all child packages will be suppressed.
25 * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a> of the <a href='http://www.apache.org'>Apache Software Foundation</a>
26 * @since 0.8
27 */
28 public class PackageSuppressor extends PropertySuppressionStrategy {
29
30 /*** Package to be suppressed */
31 private final String suppressedPackage;
32 private final boolean exact;
33
34 /***
35 * Constructs a suppressor for packages.
36 * @param suppressedPackage package name (for exact match)
37 * or base package and <code>.*</code>to suppress children
38 */
39 public PackageSuppressor(String suppressedPackage) {
40 if (suppressedPackage.endsWith(".*")) {
41 exact = false;
42 suppressedPackage = suppressedPackage.substring(0, suppressedPackage.length()-2);
43 }
44 else
45 {
46 exact =true;
47 }
48 this.suppressedPackage = suppressedPackage;
49 }
50
51 public boolean suppressProperty(Class classContainingTheProperty, Class propertyType, String propertyName) {
52 boolean result = false;
53 if (propertyType != null) {
54 Package propertyTypePackage = propertyType.getPackage();
55 if (propertyTypePackage != null) {
56 String packageName = propertyTypePackage.getName();
57 if (exact) {
58 result = suppressedPackage.equals(packageName);
59 }
60 ng>else if (packageName != null)
61 {
62 result = packageName.startsWith(suppressedPackage);
63 }
64 }
65 }
66 return result;
67 }
68
69 public String toString() {
70 StringBuffer buffer = new StringBuffer("Suppressing package " );
71 buffer.append(suppressedPackage);
72 if (exact) {
73 buffer.append("(exact)");
74 }
75 return buffer.toString();
76 }
77 }