Source Code Cross Referenced for JmxUtilities.java in  » JMX » XMOJO » com » adventnet » jmx » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » XMOJO » com.adventnet.jmx.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * The XMOJO Project 5
003:         * Copyright © 2003 XMOJO.org. All rights reserved.
004:
005:         * NO WARRANTY
006:
007:         * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
008:         * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
009:         * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
010:         * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
011:         * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
012:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
013:         * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
014:         * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
015:         * REPAIR OR CORRECTION.
016:
017:         * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
018:         * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
019:         * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
020:         * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
021:         * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
022:         * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
023:         * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
024:         * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
025:         * SUCH DAMAGES.
026:         **/package com.adventnet.jmx.utils;
027:
028:        import java.util.Enumeration;
029:        import java.util.Hashtable;
030:
031:        import javax.management.ObjectName;
032:
033:        /**
034:         * The internal utility class used by the jmx extension package classes.
035:         * This contains the pattern matching static methods useful for ObjectName
036:         * pattern matching.
037:         */
038:        public class JmxUtilities {
039:            public JmxUtilities() {
040:            }
041:
042:            public static boolean followsObjectNamePattern(String string,
043:                    String pattern) throws Exception {
044:                ObjectName patON = new ObjectName("tempDomain:" + pattern);
045:                if (patON.isPropertyPattern())
046:                    return true;
047:
048:                return false;
049:            }
050:
051:            public static boolean objectNameSpecificChecks(String string,
052:                    String pattern) throws Exception {
053:                ObjectName stringON = new ObjectName("tempDomain:" + string);
054:                ObjectName patON = new ObjectName("tempDomain:" + pattern);
055:
056:                Hashtable patProps = patON.getKeyPropertyList();
057:                Hashtable stringProps = stringON.getKeyPropertyList();
058:
059:                for (Enumeration e = patProps.keys(); e.hasMoreElements();) {
060:                    String key = (String) e.nextElement();
061:                    String value = (String) patProps.get(key);
062:
063:                    if (stringProps.get(key) != null
064:                            && stringProps.get(key).equals(value))
065:                        ;
066:                    else
067:                        return false;
068:
069:                }
070:                return true;
071:
072:            }
073:
074:            public static boolean checkPattern(String info, String pat,
075:                    boolean wc) {
076:                boolean returnFlag;
077:
078:                if (!wc) {
079:                    return info.equals(pat);
080:                }
081:
082:                try {
083:                    if (followsObjectNamePattern(info, pat))
084:                        return objectNameSpecificChecks(info, pat);
085:                } catch (Exception e) {
086:                }
087:
088:                returnFlag = wildcardMatch(pat, info);
089:
090:                return returnFlag;
091:            }
092:
093:            public static boolean wildCPattern(String p_string, String p_pattern) {
094:                char c;
095:                char p;
096:                boolean retval;
097:
098:                for (;;) {
099:                    if (p_pattern.length() == 0) /* End of pattern. If end of string return true */
100:                    {
101:                        if (p_string.length() == 0) {
102:                            return true;
103:                        } else {
104:                            return false;
105:                        }
106:                    }
107:
108:                    if (p_string.length() == 0) {
109:                        /*  Critical  condition */
110:                        return false;
111:                    }
112:
113:                    p = p_pattern.charAt(0);
114:                    p_pattern = p_pattern.substring(1);
115:
116:                    if (p == '$') {
117:                        if (p_pattern.length() == 0) {
118:                            /* Critical condition */
119:                            return false;
120:                        }
121:
122:                        p = p_pattern.charAt(0);
123:                        p_pattern = p_pattern.substring(1);
124:                        //System.out.println("P before switch is " + p);
125:
126:                        switch (p) {
127:                        case '*':
128:                            while (p_string.length() != 0) {
129:                                p_string = p_string.substring(1);
130:                                //System.out.println("PString is " + p_string);
131:
132:                                /* Match zero or more char */
133:                                retval = wildCPattern(p_string, p_pattern);
134:
135:                                if (retval == true) {
136:                                    //System.out.println("Returning as retVal true\n");
137:                                    return true;
138:                                }
139:                            }
140:
141:                            retval = wildCPattern(p_string, p_pattern);
142:
143:                            return retval;
144:
145:                        case '?':
146:                            /* match any one char */
147:                            if (p_string.length() == 0) {
148:                                /* not end of string */
149:                                //System.out.println("Returning as CRITICAL condition III\n");
150:                                return false;
151:                            }
152:                            p_string = p_string.substring(1);
153:
154:                            break;
155:                        case '$': /* check for $ character */
156:                            p_string = p_string.substring(1);
157:                            c = p_string.charAt(0);
158:                            //System.out.println("C is " + c);
159:                            if (c != '$') {
160:                                return false;
161:                            }
162:                            break;
163:                        default: /* Wild Character Not Found */
164:                            //System.out.println("Returning as NO_WILD CARD character found\n");
165:                            return false;
166:                        } /* End of switch */
167:                    } else {
168:                        c = p_string.charAt(0);
169:                        p_string = p_string.substring(1);
170:                        if (c != p) /* check for exact char */
171:                        {
172:                            //System.out.println("Returning as not match condition %c "+c + "\n");
173:                            return false; /* not a match */
174:                        }
175:                    }
176:
177:                } /* End of For */
178:
179:            }
180:
181:            public static boolean wildcardMatch(String pattern, String string) {
182:                int stringLength = string.length();
183:                int stringIndex = 0;
184:                for (int patternIndex = 0; patternIndex < pattern.length(); ++patternIndex) {
185:                    char c = pattern.charAt(patternIndex);
186:                    if (c == '*') {
187:                        // Recurse with the pattern without this '*' and the actual string, until
188:                        // match is found or we inspected the whole string
189:                        while (stringIndex < stringLength) {
190:                            if (wildcardMatch(pattern
191:                                    .substring(patternIndex + 1), string
192:                                    .substring(stringIndex))) {
193:                                return true;
194:                            }
195:                            // No match found, try a shorter string, since we are matching '*'
196:                            ++stringIndex;
197:                        }
198:                    } else if (c == '?') {
199:                        // Increment the string index, since '?' match a single char in the string
200:                        ++stringIndex;
201:                        if (stringIndex > stringLength) {
202:                            return false;
203:                        }
204:                    } else {
205:                        // A normal character in the pattern, must match the one in the string
206:                        if (stringIndex >= stringLength
207:                                || c != string.charAt(stringIndex)) {
208:                            return false;
209:                        }
210:                        ++stringIndex;
211:                    }
212:                }
213:
214:                // I've inspected the whole pattern, but not the whole string
215:                return stringIndex == stringLength;
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.