~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/bytecode/util/BasicClassFilter.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hibernate.bytecode.util;
 
2
 
 
3
import java.util.Set;
 
4
import java.util.HashSet;
 
5
 
 
6
/**
 
7
 * BasicClassFilter provides class filtering based on a series of packages to
 
8
 * be included and/or a series of explicit class names to be included.  If
 
9
 * neither is specified, then no restrictions are applied.
 
10
 *
 
11
 * @author Steve Ebersole
 
12
 */
 
13
public class BasicClassFilter implements ClassFilter {
 
14
        private final String[] includedPackages;
 
15
        private final Set includedClassNames = new HashSet();
 
16
        private final boolean isAllEmpty;
 
17
 
 
18
        public BasicClassFilter() {
 
19
                this( null, null );
 
20
        }
 
21
 
 
22
        public BasicClassFilter(String[] includedPackages, String[] includedClassNames) {
 
23
                this.includedPackages = includedPackages;
 
24
                if ( includedClassNames != null ) {
 
25
                        for ( int i = 0; i < includedClassNames.length; i++ ) {
 
26
                                this.includedClassNames.add( includedClassNames[i] );
 
27
                        }
 
28
                }
 
29
 
 
30
                isAllEmpty = ( this.includedPackages == null || this.includedPackages.length == 0 )
 
31
                             && ( this.includedClassNames.isEmpty() );
 
32
        }
 
33
 
 
34
        public boolean shouldInstrumentClass(String className) {
 
35
                if ( isAllEmpty ) {
 
36
                        return true;
 
37
                }
 
38
                else if ( includedClassNames.contains( className ) ) {
 
39
                        return true;
 
40
                }
 
41
                else if ( isInIncludedPackage( className ) ) {
 
42
                        return true;
 
43
                }
 
44
                else {
 
45
                        return false;
 
46
                }
 
47
        }
 
48
 
 
49
        private boolean isInIncludedPackage(String className) {
 
50
                if ( includedPackages != null ) {
 
51
                        for ( int i = 0; i < includedPackages.length; i++ ) {
 
52
                                if ( className.startsWith( includedPackages[i] ) ) {
 
53
                                        return true;
 
54
                                }
 
55
                        }
 
56
                }
 
57
                return false;
 
58
        }
 
59
}