KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > bdi > PatternReferenceTypeSpec


1 /*
2  * @(#)PatternReferenceTypeSpec.java 1.10 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.bdi;
36
37 import com.sun.jdi.*;
38 import java.util.StringTokenizer JavaDoc;
39
40 class PatternReferenceTypeSpec implements ReferenceTypeSpec {
41     final boolean isWild;
42     final String JavaDoc classId;
43
44     PatternReferenceTypeSpec(String JavaDoc classId)
45 // throws ClassNotFoundException
46
{
47 // checkClassName(classId);
48
isWild = classId.startsWith("*.");
49         if (isWild) {
50             this.classId = classId.substring(1);
51         } else {
52             this.classId = classId;
53         }
54     }
55
56     /**
57      * Does the specified ReferenceType match this spec.
58      */

59     public boolean matches(ReferenceType refType) {
60         if (isWild) {
61             return refType.name().endsWith(classId);
62         } else {
63             return refType.name().equals(classId);
64         }
65     }
66
67     public int hashCode() {
68         return classId.hashCode();
69     }
70
71     public boolean equals(Object JavaDoc obj) {
72         if (obj instanceof PatternReferenceTypeSpec) {
73             PatternReferenceTypeSpec spec = (PatternReferenceTypeSpec)obj;
74
75             return classId.equals(spec.classId) && (isWild == spec.isWild);
76         } else {
77             return false;
78         }
79     }
80
81     private void checkClassName(String JavaDoc className) throws ClassNotFoundException JavaDoc {
82         // Do stricter checking of class name validity on deferred
83
// because if the name is invalid, it will
84
// never match a future loaded class, and we'll be silent
85
// about it.
86
StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(className, ".");
87         boolean first = true;
88         while (tokenizer.hasMoreTokens()) {
89             String JavaDoc token = tokenizer.nextToken();
90             // Each dot-separated piece must be a valid identifier
91
// and the first token can also be "*". (Note that
92
// numeric class ids are not permitted. They must
93
// match a loaded class.)
94
if (!Utils.isJavaIdentifier(token) && !(first && token.equals("*"))) {
95                 throw new ClassNotFoundException JavaDoc();
96             }
97             first = false;
98         }
99     }
100
101     public String JavaDoc toString() {
102         return isWild? "*" + classId : classId;
103     }
104 }
105
106
107
Popular Tags