Source Code Cross Referenced for Operation.java in  » Portal » Open-Portal » com » sun » portal » rproxy » configservlet » server » 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 » Portal » Open Portal » com.sun.portal.rproxy.configservlet.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Operation.java
003:         *
004:         * Created on May 27, 2003, 4:27 PM
005:         */
006:
007:        package com.sun.portal.rproxy.configservlet.server;
008:
009:        import java.util.HashMap;
010:        import java.util.Iterator;
011:        import java.util.LinkedList;
012:        import java.util.StringTokenizer;
013:
014:        /**
015:         * 
016:         * @author mm132998
017:         * @version
018:         */
019:        class Operation {
020:            /*
021:             * Operations supported are of following form : " < value" , "> value" ,
022:             * "value1 , value2" , value , "*"
023:             */
024:            public static final int INVALID = -1;
025:
026:            public static final int LESS_THAN = 1;
027:
028:            public static final int GREATER_THAN = 2;
029:
030:            public static final int RANGE = 3;
031:
032:            public static final int EXACT_VALUE = 4;
033:
034:            public static final int MATCH_ALL = 5;
035:
036:            public static final String LESS_THAN_STR = "<";
037:
038:            public static final String GREATER_THAN_STR = ">";
039:
040:            public static final String RANGE_STR = ",";
041:
042:            public static final String MATCH_ALL_STR = "*";
043:
044:            private static final LinkedList operators = new LinkedList();
045:
046:            private static final HashMap operatorsMap = new HashMap();
047:
048:            private static final HashMap unaryMap = new HashMap();
049:
050:            private int operator = INVALID;
051:
052:            private int leftOperand = -1;
053:
054:            private int rightOperand = -1;
055:
056:            private boolean unary = false;
057:
058:            private int unaryOperand = -1;
059:
060:            private String expr = "";
061:
062:            static {
063:                operators.add(LESS_THAN_STR);
064:                operators.add(GREATER_THAN_STR);
065:                operators.add(RANGE_STR);
066:
067:                operatorsMap.put(LESS_THAN_STR, new Integer(LESS_THAN));
068:                operatorsMap.put(GREATER_THAN_STR, new Integer(GREATER_THAN));
069:                operatorsMap.put(RANGE_STR, new Integer(RANGE));
070:
071:                unaryMap.put(LESS_THAN_STR, new Boolean(true));
072:                unaryMap.put(GREATER_THAN_STR, new Boolean(true));
073:                unaryMap.put(RANGE_STR, new Boolean(false));
074:            }
075:
076:            public Operation(String str) {
077:
078:                if (str != null) {
079:                    str = str.trim();
080:                    expr = str;
081:                    Iterator iter = operators.iterator();
082:                    int operation = INVALID;
083:                    String stringOperation = null;
084:                    int index = -1;
085:
086:                    while (iter.hasNext()) {
087:                        stringOperation = iter.next().toString();
088:                        index = str.indexOf(stringOperation);
089:                        if (index != -1) {
090:                            operation = ((Integer) operatorsMap
091:                                    .get(stringOperation)).intValue();
092:                            break;
093:                        }
094:                    }
095:
096:                    operator = operation;
097:
098:                    if (operation != INVALID) {
099:                        // Ok parse out whether this is a
100:                        // unary operation , and get its operands.
101:                        unary = ((Boolean) unaryMap.get(stringOperation))
102:                                .booleanValue();
103:
104:                        if (unary) {
105:                            str = str.substring(index + 1).trim();
106:                            try {
107:                                unaryOperand = Integer.parseInt(str);
108:                            } catch (NumberFormatException nfEx) {
109:                                if (UserProfileCache.doDebug) {
110:                                    UserProfileCache
111:                                            .writeLog("Unable to parse operation : "
112:                                                    + expr);
113:                                    UserProfileCache.writeLog(nfEx);
114:                                }
115:                            }
116:                        } else {
117:                            StringTokenizer stk = new StringTokenizer(str,
118:                                    stringOperation);
119:
120:                            if (stk.countTokens() == 2) {
121:                                // Ok get the operands.
122:                                try {
123:                                    leftOperand = Integer.parseInt(stk
124:                                            .nextToken().trim());
125:                                    rightOperand = Integer.parseInt(stk
126:                                            .nextToken().trim());
127:                                } catch (NumberFormatException nfEx) {
128:                                    if (UserProfileCache.doDebug) {
129:                                        UserProfileCache
130:                                                .writeLog("Unable to parse operation : "
131:                                                        + expr);
132:                                        UserProfileCache.writeLog(nfEx);
133:                                    }
134:                                }
135:                            } else {
136:                                if (UserProfileCache.doDebug) {
137:                                    UserProfileCache
138:                                            .writeLog("Unable to parse operation : "
139:                                                    + expr);
140:                                    UserProfileCache
141:                                            .writeLog("binary Operation expects two operands !\n");
142:                                }
143:                                operator = INVALID;
144:                            }
145:                        }
146:                    } else {
147:                        // Check whether this is Star operation.
148:                        if (expr.equals(MATCH_ALL_STR)) {
149:                            operator = MATCH_ALL;
150:                        } else {
151:                            // Can be an exact match.
152:                            try {
153:                                unaryOperand = Integer.parseInt(str);
154:                                operator = EXACT_VALUE;
155:                            } catch (NumberFormatException nfEx) {
156:                                if (UserProfileCache.doDebug) {
157:                                    UserProfileCache
158:                                            .writeLog("Unable to parse operation : "
159:                                                    + expr);
160:                                    UserProfileCache.writeLog(nfEx);
161:                                }
162:                            }
163:                        }
164:                    }
165:                }
166:            }
167:
168:            public boolean isValid() {
169:                return INVALID != getOperator();
170:            }
171:
172:            public int getOperator() {
173:                return operator;
174:            }
175:
176:            public int getLeftOperand() {
177:                return leftOperand;
178:            }
179:
180:            public int getRightOperand() {
181:                return rightOperand;
182:            }
183:
184:            public boolean isUnary() {
185:                return unary;
186:            }
187:
188:            public int getUnaryOperand() {
189:                return unaryOperand;
190:            }
191:
192:            public boolean evaluate(int value) {
193:                if (isValid()) {
194:                    switch (getOperator()) {
195:
196:                    case LESS_THAN:
197:                        if (value < unaryOperand) {
198:                            return true;
199:                        }
200:                        break;
201:
202:                    case GREATER_THAN:
203:                        if (value > unaryOperand) {
204:                            return true;
205:                        }
206:                        break;
207:
208:                    case EXACT_VALUE:
209:                        if (value == unaryOperand) {
210:                            return true;
211:                        }
212:                        break;
213:
214:                    case MATCH_ALL:
215:                        return true;
216:
217:                    case RANGE:
218:                        if (value >= leftOperand && value <= rightOperand) {
219:                            return true;
220:                        }
221:                        break;
222:                    default:
223:                        break;
224:                    }
225:                }
226:                return false;
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.