Source Code Cross Referenced for SimpleKey.java in  » IDE-Netbeans » performance » org » netbeans » actions » simple » 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 » IDE Netbeans » performance » org.netbeans.actions.simple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SimpleKey.java
003:         *
004:         * Created on January 31, 2004, 6:28 PM
005:         */
006:
007:        package org.netbeans.actions.simple;
008:
009:        import java.lang.reflect.Method;
010:        import java.util.Map;
011:        import org.xml.sax.SAXException;
012:
013:        /**
014:         *
015:         * @author  Tim Boudreau
016:         */
017:        public class SimpleKey {
018:            private String value;
019:            private String method;
020:            private String clazz;
021:            private boolean mustContain;
022:            private String mustMatch;
023:
024:            /** Creates a new instance of SimpleKey */
025:            public SimpleKey(String value, String method, String clazz,
026:                    boolean mustContain, String mustMatch) throws SAXException {
027:                this .value = value;
028:                this .method = method;
029:                this .clazz = clazz;
030:                this .mustContain = mustContain;
031:                this .mustMatch = mustMatch;
032:                if ((clazz == null) != (method == null)) {
033:                    throw new SAXException(
034:                            "Key must define both a class and a "
035:                                    + "method to call on it if it defines one.  Class: "
036:                                    + clazz + " method " + method + " name "
037:                                    + value);
038:                }
039:                if (clazz != null && mustMatch != null) {
040:                    throw new SAXException(
041:                            "A key may define a method to call, or a value to match from the map, not both. Key:"
042:                                    + value);
043:                }
044:                System.err.println("SimpleKey: " + value + " mustContain "
045:                        + mustContain + " mustMatch " + mustMatch + " class "
046:                        + clazz + " method " + method);
047:            }
048:
049:            public boolean mustTest() {
050:                return clazz != null || mustMatch != null;
051:            }
052:
053:            public boolean isSimpleTest() {
054:                return clazz == null;
055:            }
056:
057:            public Object getValue() {
058:                return value;
059:            }
060:
061:            public boolean isMustContain() {
062:                return mustContain;
063:            }
064:
065:            public boolean test(Map m) {
066:                //        System.err.println("TEST CONSTRAINT " + value);
067:                String s = (String) m.get(value);
068:                boolean result = s != null;
069:                if (!mustContain) {
070:                    result = !result;
071:                } else if (result) {
072:                    if (mustMatch != null) {
073:                        //                System.err.println("TESTING " + value + " MUSTMATCH " + mustMatch + " value is " + s);
074:                        result = s.equals(mustMatch);
075:                    }
076:                }
077:                //        System.err.println("   SimpleKey test " + value + " result=" + result);
078:                if (result && clazz != null) {
079:                    result = invokeMethod(m, method, clazz);
080:                    //            System.err.println("   Invoked method - result " + result);
081:                }
082:                return result;
083:            }
084:
085:            public String toString() {
086:                return value;
087:            }
088:
089:            /** Asymmetric impl of equals & hashcode, but works for a quick demo */
090:            public boolean equals(Object o) {
091:                if (o instanceof  SimpleKey) {
092:                    SimpleKey oth = (SimpleKey) o;
093:                    return oth.method == method && oth.clazz == clazz
094:                            && oth.mustContain == mustContain
095:                            && oth.mustMatch == mustMatch && oth.value == value;
096:                } else if (o instanceof  String) {
097:                    return ((String) o).equals(value);
098:                } else {
099:                    return false;
100:                }
101:            }
102:
103:            public int hashCode() {
104:                return value.hashCode();
105:            }
106:
107:            private boolean invokeMethod(Map m, String method, String clazz) {
108:                if (theClass == null) {
109:                    try {
110:                        theClass = Class.forName(clazz);
111:                    } catch (Exception e) {
112:                        e.printStackTrace();
113:                        return false;
114:                    }
115:                }
116:                Object o = m.get(value);
117:                if (o == null) {
118:                    return false;
119:                }
120:                if (theMethod == null) {
121:                    try {
122:                        theMethod = theClass.getDeclaredMethod(method, null);
123:                    } catch (Exception e) {
124:                        e.printStackTrace();
125:                        return false;
126:                    }
127:
128:                    if (theMethod.getReturnType() != Boolean.class
129:                            && theMethod.getReturnType() != Boolean.TYPE) {
130:                        throw new IllegalArgumentException("Method " + method
131:                                + " on " + clazz
132:                                + " must return boolean or Boolean and "
133:                                + "take no arguments"); //NOI18N
134:                    }
135:                }
136:                Boolean result = Boolean.FALSE;
137:                try {
138:                    result = (Boolean) theMethod.invoke(o, null);
139:                } catch (Exception e) {
140:                    e.printStackTrace();
141:                }
142:                return result.booleanValue();
143:            }
144:
145:            private Class theClass = null;
146:            private Method theMethod = null;
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.