KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > dottedname > DottedNameWildcardMatcherImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin/mbeans/src/java/com/sun/enterprise/admin/dottedname/DottedNameWildcardMatcherImpl.java,v 1.3 2005/12/25 03:42:05 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:42:05 $
28  */

29
30
31 package com.sun.enterprise.admin.dottedname;
32
33 import java.util.HashSet JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.regex.Pattern JavaDoc;
39
40 import javax.management.ObjectName JavaDoc;
41
42
43 /*
44     Resolve a wildcarded dotted name.
45  */

46  
47 public class DottedNameWildcardMatcherImpl implements DottedNameWildcardMatcher
48 {
49     final Set JavaDoc mSearchSet;
50     
51         public
52     DottedNameWildcardMatcherImpl( final Set JavaDoc searchSet )
53     {
54         mSearchSet = searchSet;
55     }
56     
57     
58     /*
59         Return the set of all dotted names that match the specified wildcarded dotted name
60      */

61         Set JavaDoc
62     resolveAll( final String JavaDoc wildcardedName, final Iterator JavaDoc iter )
63     {
64         final HashSet JavaDoc resolvedSet = new HashSet JavaDoc();
65         
66         final Pattern JavaDoc pattern = Pattern.compile( wildcardedName );
67         
68         while ( iter.hasNext() )
69         {
70             final String JavaDoc candidate = (String JavaDoc)iter.next();
71             
72             if ( pattern.matcher( candidate ).matches() )
73             {
74                 resolvedSet.add( candidate );
75             }
76         }
77         
78         return( resolvedSet );
79     }
80
81     /*
82         IMPORTANT: the wildcard format must be that of java.util.regex
83         
84         @param dottedNameString a string using java.util.regex format
85      */

86         public Set JavaDoc
87     matchDottedNames( String JavaDoc dottedNameString )
88     {
89         Set JavaDoc resolvedSet = null;
90         
91         if ( dottedNameString.equals( ".*" ) )
92         {
93             // optimization; match all
94
resolvedSet = new HashSet JavaDoc();
95             resolvedSet.addAll( mSearchSet );
96         }
97         else
98         {
99             resolvedSet = resolveAll( dottedNameString, mSearchSet.iterator() );
100         }
101         
102         return( resolvedSet );
103     }
104 }
105
106
107
108
109
Popular Tags