Source Code Cross Referenced for Operator.java in  » EJB-Server-JBoss-4.2.1 » messaging » org » jboss » mq » selectors » 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 » EJB Server JBoss 4.2.1 » messaging » org.jboss.mq.selectors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * JBoss, Home of Professional Open Source.
0003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004:         * as indicated by the @author tags. See the copyright.txt file in the
0005:         * distribution for a full listing of individual contributors.
0006:         *
0007:         * This is free software; you can redistribute it and/or modify it
0008:         * under the terms of the GNU Lesser General Public License as
0009:         * published by the Free Software Foundation; either version 2.1 of
0010:         * the License, or (at your option) any later version.
0011:         *
0012:         * This software is distributed in the hope that it will be useful,
0013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015:         * Lesser General Public License for more details.
0016:         *
0017:         * You should have received a copy of the GNU Lesser General Public
0018:         * License along with this software; if not, write to the Free
0019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021:         */
0022:        package org.jboss.mq.selectors;
0023:
0024:        import java.util.HashSet;
0025:
0026:        import org.jboss.util.Primitives;
0027:
0028:        /**
0029:         * An operator for the selector system.
0030:         *
0031:         * @author     Norbert Lataille (Norbert.Lataille@m4x.org)
0032:         * @author     droy@boostmyscore.com
0033:         * @author     Scott.Stark@jboss.org
0034:         * @author     adrian@jboss.com
0035:         * @created    August 16, 2001
0036:         * @version    $Revision: 57198 $
0037:         */
0038:        public class Operator {
0039:            int operation;
0040:            Object oper1;
0041:            Object oper2;
0042:            Object oper3;
0043:
0044:            Object arg1;
0045:            Object arg2;
0046:            Object arg3;
0047:
0048:            int class1;
0049:            int class2;
0050:            int class3;
0051:
0052:            // info about the regular expression
0053:            // if this is a LIKE operator
0054:            // (perhaps this should be a subclass)
0055:            RegExp re = null;
0056:
0057:            public final static int EQUAL = 0;
0058:            public final static int NOT = 1;
0059:            public final static int AND = 2;
0060:            public final static int OR = 3;
0061:            public final static int GT = 4;
0062:            public final static int GE = 5;
0063:            public final static int LT = 6;
0064:            public final static int LE = 7;
0065:            public final static int DIFFERENT = 8;
0066:            public final static int ADD = 9;
0067:            public final static int SUB = 10;
0068:            public final static int NEG = 11;
0069:            public final static int MUL = 12;
0070:            public final static int DIV = 13;
0071:            public final static int BETWEEN = 14;
0072:            public final static int NOT_BETWEEN = 15;
0073:            public final static int LIKE = 16;
0074:            public final static int NOT_LIKE = 17;
0075:            public final static int LIKE_ESCAPE = 18;
0076:            public final static int NOT_LIKE_ESCAPE = 19;
0077:            public final static int IS_NULL = 20;
0078:            public final static int IS_NOT_NULL = 21;
0079:            public final static int IN = 22;
0080:            public final static int NOT_IN = 23;
0081:
0082:            public final static int STRING = 0;
0083:            public final static int DOUBLE = 1;
0084:            //DOUBLE FLOAT
0085:            public final static int LONG = 2;
0086:            //LONG BYTE SHORT INTEGER
0087:            public final static int BOOLEAN = 3;
0088:
0089:            public Operator(int operation, Object oper1, Object oper2,
0090:                    Object oper3) {
0091:                this .operation = operation;
0092:                this .oper1 = oper1;
0093:                this .oper2 = oper2;
0094:                this .oper3 = oper3;
0095:            }
0096:
0097:            public Operator(int operation, Object oper1, Object oper2) {
0098:                this .operation = operation;
0099:                this .oper1 = oper1;
0100:                this .oper2 = oper2;
0101:                this .oper3 = null;
0102:            }
0103:
0104:            public Operator(int operation, Object oper1) {
0105:                this .operation = operation;
0106:                this .oper1 = oper1;
0107:                this .oper2 = null;
0108:                this .oper3 = null;
0109:            }
0110:
0111:            //--- Print functions ---
0112:
0113:            public String toString() {
0114:                return print("");
0115:            }
0116:
0117:            public String print(String level) {
0118:                String st = level + operation + ":"
0119:                        + operationString(operation) + "(\n";
0120:
0121:                String nextLevel = level + "  ";
0122:
0123:                if (oper1 == null)
0124:                    st += nextLevel + "null\n";
0125:                else if (oper1 instanceof  Operator)
0126:                    st += ((Operator) oper1).print(nextLevel);
0127:                else
0128:                    st += nextLevel + oper1.toString() + "\n";
0129:
0130:                if (oper2 != null) {
0131:                    if (oper2 instanceof  Operator)
0132:                        st += ((Operator) oper2).print(nextLevel);
0133:                    else
0134:                        st += nextLevel + oper2.toString() + "\n";
0135:                }
0136:
0137:                if (oper3 != null) {
0138:                    if (oper3 instanceof  Operator)
0139:                        st += ((Operator) oper3).print(nextLevel);
0140:                    else
0141:                        st += nextLevel + oper3.toString() + "\n";
0142:                }
0143:
0144:                st += level + ")\n";
0145:
0146:                return st;
0147:            }
0148:
0149:            //Operator 20
0150:            Object is_null() throws Exception {
0151:                computeArgument1();
0152:                if (arg1 == null)
0153:                    return Boolean.TRUE;
0154:                else
0155:                    return Boolean.FALSE;
0156:            }
0157:
0158:            //Operator 21
0159:            Object is_not_null() throws Exception {
0160:                computeArgument1();
0161:                if (arg1 != null)
0162:                    return Boolean.TRUE;
0163:                else
0164:                    return Boolean.FALSE;
0165:            }
0166:
0167:            //Operation 0
0168:            Object equal() throws Exception {
0169:                computeArgument1();
0170:                if (arg1 == null)
0171:                    return Boolean.FALSE;
0172:
0173:                switch (class1) {
0174:                case LONG:
0175:                    computeArgument1();
0176:                    if (arg1 == null)
0177:                        return null;
0178:                    computeArgument2();
0179:                    if (arg2 == null)
0180:                        return null;
0181:                    if (class2 == LONG)
0182:                        return Primitives
0183:                                .valueOf(((Number) arg1).longValue() == ((Number) arg2)
0184:                                        .longValue());
0185:                    if (class2 == DOUBLE)
0186:                        return Primitives
0187:                                .valueOf(((Number) arg1).longValue() == ((Number) arg2)
0188:                                        .doubleValue());
0189:                    return Boolean.FALSE;
0190:                case DOUBLE:
0191:                    computeArgument1();
0192:                    if (arg1 == null)
0193:                        return null;
0194:                    computeArgument2();
0195:                    if (arg2 == null)
0196:                        return null;
0197:                    if (class2 == LONG)
0198:                        return Primitives
0199:                                .valueOf(((Number) arg1).doubleValue() == ((Number) arg2)
0200:                                        .longValue());
0201:                    if (class2 == DOUBLE)
0202:                        return Primitives
0203:                                .valueOf(((Number) arg1).doubleValue() == ((Number) arg2)
0204:                                        .doubleValue());
0205:                    return Boolean.FALSE;
0206:                case STRING:
0207:                case BOOLEAN:
0208:                    computeArgument2();
0209:                    if (arg2 == null)
0210:                        return Boolean.FALSE;
0211:                    if (class2 != class1)
0212:                        throwBadObjectException(class1, class2);
0213:                    return Primitives.valueOf(arg1.equals(arg2));
0214:                default:
0215:                    throwBadObjectException(class1);
0216:                    return null;
0217:                }
0218:
0219:            }
0220:
0221:            //Operation 1
0222:            Object not() throws Exception {
0223:                computeArgument1();
0224:                if (arg1 == null)
0225:                    return null;
0226:                if (class1 != BOOLEAN)
0227:                    throwBadObjectException(class1);
0228:                if (((Boolean) arg1).booleanValue())
0229:                    return Boolean.FALSE;
0230:                else
0231:                    return Boolean.TRUE;
0232:            }
0233:
0234:            //Operation 2
0235:            Object and() throws Exception {
0236:                computeArgument1();
0237:                if (arg1 == null) {
0238:                    computeArgument2();
0239:                    if (arg2 == null)
0240:                        return null;
0241:                    if (class2 != BOOLEAN)
0242:                        throwBadObjectException(class2);
0243:                    if (((Boolean) arg2).booleanValue() == false)
0244:                        return Boolean.FALSE;
0245:                    return null;
0246:                }
0247:
0248:                if (class1 == BOOLEAN) {
0249:                    if (((Boolean) arg1).booleanValue() == false)
0250:                        return Boolean.FALSE;
0251:                    computeArgument2();
0252:                    if (arg2 == null)
0253:                        return null;
0254:                    if (class2 != BOOLEAN)
0255:                        throwBadObjectException(class2);
0256:                    return arg2;
0257:                }
0258:
0259:                throwBadObjectException(class1);
0260:                return null;
0261:            }
0262:
0263:            /**
0264:             * Operation 3
0265:             * 
0266:             * | OR   |   T   |   F   |   U
0267:             * +------+-------+-------+--------
0268:             * |  T   |   T   |   T   |   T
0269:             * |  F   |   T   |   F   |   U
0270:             * |  U   |   T   |   U   |   U
0271:             * +------+-------+-------+------- 
0272:             */
0273:            Object or() throws Exception {
0274:                short falseCounter = 0;
0275:
0276:                computeArgument1();
0277:                if (arg1 != null) {
0278:                    if (class1 != BOOLEAN)
0279:                        throwBadObjectException(class1);
0280:                    if (((Boolean) arg1).booleanValue())
0281:                        return Boolean.TRUE;
0282:                    else
0283:                        falseCounter++;
0284:                }
0285:
0286:                computeArgument2();
0287:                if (arg2 != null) {
0288:                    if (class2 != BOOLEAN)
0289:                        throwBadObjectException(class2);
0290:                    if (((Boolean) arg2).booleanValue())
0291:                        return Boolean.TRUE;
0292:                    else
0293:                        falseCounter++;
0294:                }
0295:
0296:                if (falseCounter == 2)
0297:                    return Boolean.FALSE;
0298:
0299:                return null;
0300:            }
0301:
0302:            //Operation 4
0303:            Object gt() throws Exception {
0304:                computeArgument1();
0305:                if (arg1 == null)
0306:                    return null;
0307:
0308:                if (class1 == LONG) {
0309:                    computeArgument2();
0310:                    if (arg2 == null)
0311:                        return null;
0312:                    if (class2 == LONG)
0313:                        return Primitives
0314:                                .valueOf(((Number) arg1).longValue() > ((Number) arg2)
0315:                                        .longValue());
0316:                    if (class2 == DOUBLE)
0317:                        return Primitives
0318:                                .valueOf(((Number) arg1).longValue() > ((Number) arg2)
0319:                                        .doubleValue());
0320:                } else if (class1 == DOUBLE) {
0321:                    computeArgument2();
0322:                    if (arg2 == null)
0323:                        return null;
0324:                    if (class2 == LONG)
0325:                        return Primitives
0326:                                .valueOf(((Number) arg1).doubleValue() > ((Number) arg2)
0327:                                        .longValue());
0328:                    if (class2 == DOUBLE)
0329:                        return Primitives
0330:                                .valueOf(((Number) arg1).doubleValue() > ((Number) arg2)
0331:                                        .doubleValue());
0332:                    return Boolean.FALSE;
0333:                }
0334:                return Boolean.FALSE;
0335:            }
0336:
0337:            //Operation 5
0338:            Object ge() throws Exception {
0339:                computeArgument1();
0340:                if (arg1 == null)
0341:                    return null;
0342:
0343:                if (class1 == LONG) {
0344:                    computeArgument2();
0345:                    if (arg2 == null)
0346:                        return null;
0347:                    if (class2 == LONG)
0348:                        return Primitives
0349:                                .valueOf(((Number) arg1).longValue() >= ((Number) arg2)
0350:                                        .longValue());
0351:                    if (class2 == DOUBLE)
0352:                        return Primitives
0353:                                .valueOf(((Number) arg1).longValue() >= ((Number) arg2)
0354:                                        .doubleValue());
0355:                } else if (class1 == DOUBLE) {
0356:                    computeArgument2();
0357:                    if (arg2 == null)
0358:                        return null;
0359:                    if (class2 == LONG)
0360:                        return Primitives
0361:                                .valueOf(((Number) arg1).longValue() >= ((Number) arg2)
0362:                                        .longValue());
0363:                    if (class2 == DOUBLE)
0364:                        return Primitives
0365:                                .valueOf(((Number) arg1).doubleValue() >= ((Number) arg2)
0366:                                        .doubleValue());
0367:                    return Boolean.FALSE;
0368:                }
0369:                return Boolean.FALSE;
0370:            }
0371:
0372:            //Operation 6
0373:            Object lt() throws Exception {
0374:                computeArgument1();
0375:                if (arg1 == null)
0376:                    return null;
0377:
0378:                if (class1 == LONG) {
0379:                    computeArgument2();
0380:                    if (arg2 == null)
0381:                        return null;
0382:                    if (class2 == LONG)
0383:                        return Primitives
0384:                                .valueOf(((Number) arg1).longValue() < ((Number) arg2)
0385:                                        .longValue());
0386:                    if (class2 == DOUBLE)
0387:                        return Primitives
0388:                                .valueOf(((Number) arg1).longValue() < ((Number) arg2)
0389:                                        .doubleValue());
0390:                } else if (class1 == DOUBLE) {
0391:                    computeArgument2();
0392:                    if (arg2 == null)
0393:                        return null;
0394:                    if (class2 == LONG)
0395:                        return Primitives
0396:                                .valueOf(((Number) arg1).doubleValue() < ((Number) arg2)
0397:                                        .longValue());
0398:                    if (class2 == DOUBLE)
0399:                        return Primitives
0400:                                .valueOf(((Number) arg1).doubleValue() < ((Number) arg2)
0401:                                        .doubleValue());
0402:                }
0403:
0404:                return Boolean.FALSE;
0405:            }
0406:
0407:            //Operation 7
0408:            Object le() throws Exception {
0409:                computeArgument1();
0410:                if (arg1 == null)
0411:                    return null;
0412:
0413:                if (class1 == LONG) {
0414:                    computeArgument2();
0415:                    if (arg2 == null)
0416:                        return null;
0417:                    if (class2 == LONG)
0418:                        return Primitives
0419:                                .valueOf(((Number) arg1).longValue() <= ((Number) arg2)
0420:                                        .longValue());
0421:                    if (class2 == DOUBLE)
0422:                        return Primitives
0423:                                .valueOf(((Number) arg1).longValue() <= ((Number) arg2)
0424:                                        .doubleValue());
0425:                } else if (class1 == DOUBLE) {
0426:                    computeArgument2();
0427:                    if (arg2 == null)
0428:                        return null;
0429:                    if (class2 == LONG)
0430:                        return Primitives
0431:                                .valueOf(((Number) arg1).doubleValue() <= ((Number) arg2)
0432:                                        .longValue());
0433:                    if (class2 == DOUBLE)
0434:                        return Primitives
0435:                                .valueOf(((Number) arg1).doubleValue() <= ((Number) arg2)
0436:                                        .doubleValue());
0437:                }
0438:                return Boolean.FALSE;
0439:            }
0440:
0441:            //Operation 8
0442:            Object different() throws Exception {
0443:                computeArgument1();
0444:                if (arg1 == null)
0445:                    return Boolean.FALSE;
0446:
0447:                switch (class1) {
0448:                case LONG:
0449:                    computeArgument1();
0450:                    if (arg1 == null)
0451:                        return null;
0452:                    computeArgument2();
0453:                    if (arg2 == null)
0454:                        return null;
0455:                    if (class2 == LONG)
0456:                        return Primitives
0457:                                .valueOf(((Number) arg1).longValue() != ((Number) arg2)
0458:                                        .longValue());
0459:                    if (class2 == DOUBLE)
0460:                        return Primitives
0461:                                .valueOf(((Number) arg1).longValue() != ((Number) arg2)
0462:                                        .doubleValue());
0463:                    return Boolean.FALSE;
0464:                case DOUBLE:
0465:                    computeArgument1();
0466:                    if (arg1 == null)
0467:                        return null;
0468:                    computeArgument2();
0469:                    if (arg2 == null)
0470:                        return null;
0471:                    if (class2 == LONG)
0472:                        return Primitives
0473:                                .valueOf(((Number) arg1).doubleValue() != ((Number) arg2)
0474:                                        .longValue());
0475:                    if (class2 == DOUBLE)
0476:                        return Primitives
0477:                                .valueOf(((Number) arg1).doubleValue() != ((Number) arg2)
0478:                                        .doubleValue());
0479:                    return Boolean.FALSE;
0480:                case STRING:
0481:                case BOOLEAN:
0482:                    computeArgument2();
0483:                    if (arg2 == null)
0484:                        return Boolean.FALSE;
0485:                    if (class2 != class1)
0486:                        throwBadObjectException(class1, class2);
0487:                    return Primitives.valueOf(arg1.equals(arg2) == false);
0488:                default:
0489:                    throwBadObjectException(class1);
0490:                }
0491:                return null;
0492:            }
0493:
0494:            //Operator 9
0495:            Object add() throws Exception {
0496:                computeArgument1();
0497:                computeArgument2();
0498:
0499:                if (arg1 == null || arg2 == null)
0500:                    return null;
0501:                switch (class1) {
0502:                case DOUBLE:
0503:                    switch (class2) {
0504:                    case DOUBLE:
0505:                        return new Double(((Number) arg1).doubleValue()
0506:                                + ((Number) arg2).doubleValue());
0507:                    case LONG:
0508:                        return new Double(((Number) arg1).doubleValue()
0509:                                + ((Number) arg2).doubleValue());
0510:                    default:
0511:                        throwBadObjectException(class2);
0512:                    }
0513:                case LONG:
0514:                    switch (class2) {
0515:                    case DOUBLE:
0516:                        return new Double(((Number) arg1).doubleValue()
0517:                                + ((Number) arg2).doubleValue());
0518:                    case LONG:
0519:                        return new Long(((Number) arg1).longValue()
0520:                                + ((Number) arg2).longValue());
0521:                    default:
0522:                        throwBadObjectException(class2);
0523:                    }
0524:                default:
0525:                    throwBadObjectException(class1);
0526:                }
0527:                return null;
0528:            }
0529:
0530:            //Operator 10
0531:            Object sub() throws Exception {
0532:                computeArgument1();
0533:                computeArgument2();
0534:
0535:                if (arg1 == null || arg2 == null)
0536:                    return null;
0537:                switch (class1) {
0538:                case DOUBLE:
0539:                    switch (class2) {
0540:                    case DOUBLE:
0541:                        return new Double(((Number) arg1).doubleValue()
0542:                                - ((Number) arg2).doubleValue());
0543:                    case LONG:
0544:                        return new Double(((Number) arg1).doubleValue()
0545:                                - ((Number) arg2).doubleValue());
0546:                    default:
0547:                        throwBadObjectException(class2);
0548:                    }
0549:                case LONG:
0550:                    switch (class2) {
0551:                    case DOUBLE:
0552:                        return new Double(((Number) arg1).doubleValue()
0553:                                - ((Number) arg2).doubleValue());
0554:                    case LONG:
0555:                        return new Long(((Number) arg1).longValue()
0556:                                - ((Number) arg2).longValue());
0557:                    default:
0558:                        throwBadObjectException(class2);
0559:                    }
0560:                default:
0561:                    throwBadObjectException(class1);
0562:                }
0563:                return null;
0564:            }
0565:
0566:            //Operator 11
0567:            Object neg() throws Exception {
0568:                computeArgument1();
0569:                if (arg1 == null)
0570:                    return null;
0571:                switch (class1) {
0572:                case DOUBLE:
0573:                    return new Double(-((Number) arg1).doubleValue());
0574:                case LONG:
0575:                    return new Long(-((Number) arg1).longValue());
0576:                default:
0577:                    throwBadObjectException(class1);
0578:                }
0579:                return null;
0580:            }
0581:
0582:            //Operator 12
0583:            Object mul() throws Exception {
0584:                computeArgument1();
0585:                computeArgument2();
0586:                if (arg1 == null || arg2 == null)
0587:                    return null;
0588:                switch (class1) {
0589:                case DOUBLE:
0590:                    switch (class2) {
0591:                    case DOUBLE:
0592:                        return new Double(((Number) arg1).doubleValue()
0593:                                * ((Number) arg2).doubleValue());
0594:                    case LONG:
0595:                        return new Double(((Number) arg1).doubleValue()
0596:                                * ((Number) arg2).doubleValue());
0597:                    default:
0598:                        throwBadObjectException(class2);
0599:                    }
0600:                case LONG:
0601:                    switch (class2) {
0602:                    case DOUBLE:
0603:                        return new Double(((Number) arg1).doubleValue()
0604:                                * ((Number) arg2).doubleValue());
0605:                    case LONG:
0606:                        return new Long(((Number) arg1).longValue()
0607:                                * ((Number) arg2).longValue());
0608:                    default:
0609:                        throwBadObjectException(class2);
0610:                    }
0611:                default:
0612:                    throwBadObjectException(class1);
0613:                }
0614:                return null;
0615:            }
0616:
0617:            //Operator 13
0618:            Object div() throws Exception {
0619:                //Can throw Divide by zero exception...
0620:                computeArgument1();
0621:                computeArgument2();
0622:                if (arg1 == null || arg2 == null)
0623:                    return null;
0624:                switch (class1) {
0625:                case DOUBLE:
0626:                    switch (class2) {
0627:                    case DOUBLE:
0628:                        return new Double(((Number) arg1).doubleValue()
0629:                                / ((Number) arg2).doubleValue());
0630:                    case LONG:
0631:                        return new Double(((Number) arg1).doubleValue()
0632:                                / ((Number) arg2).doubleValue());
0633:                    default:
0634:                        throwBadObjectException(class2);
0635:                    }
0636:                case LONG:
0637:                    switch (class2) {
0638:                    case DOUBLE:
0639:                        return new Double(((Number) arg1).doubleValue()
0640:                                / ((Number) arg2).doubleValue());
0641:                    case LONG:
0642:                        return new Long(((Number) arg1).longValue()
0643:                                / ((Number) arg2).longValue());
0644:                    default:
0645:                        throwBadObjectException(class2);
0646:                    }
0647:                default:
0648:                    throwBadObjectException(class1);
0649:                }
0650:                return null;
0651:            }
0652:
0653:            //Operator 14
0654:            Object between() throws Exception {
0655:                Object res = ge();
0656:                if (res == null)
0657:                    return null;
0658:                if (((Boolean) res).booleanValue() == false)
0659:                    return res;
0660:
0661:                Object oper4 = oper2;
0662:                oper2 = oper3;
0663:                res = le();
0664:                oper2 = oper4;
0665:                return res;
0666:            }
0667:
0668:            //Operator 15
0669:            Object not_between() throws Exception {
0670:                Object res = lt();
0671:                if (res == null)
0672:                    return null;
0673:                if (((Boolean) res).booleanValue())
0674:                    return res;
0675:
0676:                Object oper4 = oper2;
0677:                oper2 = oper3;
0678:                res = gt();
0679:                oper2 = oper4;
0680:                return res;
0681:            }
0682:
0683:            //Operation 16,17,18,19
0684:            /**
0685:             *  Handle LIKE, NOT LIKE, LIKE ESCAPE, and NOT LIKE ESCAPE operators.
0686:             *
0687:             * @param  not            true if this is a NOT LIKE construct, false if this
0688:             *      is a LIKE construct.
0689:             * @param  use_escape     true if this is a LIKE ESCAPE construct, false if
0690:             *      there is no ESCAPE clause
0691:             * @return                Description of the Returned Value
0692:             * @exception  Exception  Description of Exception
0693:             */
0694:            Object like(boolean not, boolean use_escape) throws Exception {
0695:                Character escapeChar = null;
0696:
0697:                computeArgument1();
0698:                if (arg1 == null)
0699:                    return null;
0700:                if (class1 != STRING)
0701:                    throwBadObjectException(class1);
0702:
0703:                computeArgument2();
0704:                if (arg2 == null)
0705:                    return null;
0706:                if (class2 != STRING)
0707:                    throwBadObjectException(class2);
0708:
0709:                if (use_escape) {
0710:                    computeArgument3();
0711:                    if (arg3 == null)
0712:                        return null;
0713:
0714:                    if (class3 != STRING)
0715:                        throwBadObjectException(class3);
0716:
0717:                    StringBuffer escapeBuf = new StringBuffer((String) arg3);
0718:                    if (escapeBuf.length() != 1)
0719:                        throw new Exception(
0720:                                "LIKE ESCAPE: Bad escape character "
0721:                                        + escapeBuf.toString());
0722:
0723:                    escapeChar = new Character(escapeBuf.charAt(0));
0724:                }
0725:
0726:                if (re == null)
0727:                    // the first time through we prepare the regular expression
0728:                    re = new RegExp((String) arg2, escapeChar);
0729:
0730:                boolean result = re.isMatch(arg1);
0731:                if (not)
0732:                    result = !result;
0733:
0734:                if (result == true)
0735:                    return Boolean.TRUE;
0736:                else
0737:                    return Boolean.FALSE;
0738:            }
0739:
0740:            //Operator 22
0741:            Object in() throws Exception {
0742:                computeArgument1();
0743:                if (arg1 == null)
0744:                    return null;
0745:                if (((HashSet) oper2).contains(arg1))
0746:                    return Boolean.TRUE;
0747:                else
0748:                    return Boolean.FALSE;
0749:            }
0750:
0751:            //Operator 23
0752:            Object not_in() throws Exception {
0753:                computeArgument1();
0754:                if (arg1 == null)
0755:                    return null;
0756:                if (class1 != STRING)
0757:                    throwBadObjectException(class1);
0758:                if (((HashSet) oper2).contains(arg1))
0759:                    return Boolean.FALSE;
0760:                else
0761:                    return Boolean.TRUE;
0762:            }
0763:
0764:            void computeArgument1() throws Exception {
0765:                Class className = oper1.getClass();
0766:
0767:                if (className == Identifier.class)
0768:                    arg1 = ((Identifier) oper1).value;
0769:                else if (className == Operator.class)
0770:                    arg1 = ((Operator) oper1).apply();
0771:                else
0772:                    arg1 = oper1;
0773:
0774:                if (arg1 == null) {
0775:                    class1 = 0;
0776:                    return;
0777:                }
0778:
0779:                className = arg1.getClass();
0780:
0781:                if (className == String.class)
0782:                    class1 = STRING;
0783:                else if (className == Double.class)
0784:                    class1 = DOUBLE;
0785:                else if (className == Long.class)
0786:                    class1 = LONG;
0787:                else if (className == Integer.class) {
0788:                    class1 = LONG;
0789:                    arg1 = new Long(((Integer) arg1).longValue());
0790:                } else if (className == Short.class) {
0791:                    class1 = LONG;
0792:                    arg1 = new Long(((Short) arg1).longValue());
0793:                } else if (className == Byte.class) {
0794:                    class1 = LONG;
0795:                    arg1 = new Long(((Byte) arg1).longValue());
0796:                } else if (className == Float.class) {
0797:                    class1 = DOUBLE;
0798:                    arg1 = new Double(((Float) arg1).doubleValue());
0799:                } else if (className == Boolean.class)
0800:                    class1 = BOOLEAN;
0801:                else
0802:                    throwBadObjectException(className);
0803:            }
0804:
0805:            void computeArgument2() throws Exception {
0806:                Class className = oper2.getClass();
0807:
0808:                if (className == Identifier.class)
0809:                    arg2 = ((Identifier) oper2).value;
0810:                else if (className == Operator.class)
0811:                    arg2 = ((Operator) oper2).apply();
0812:                else
0813:                    arg2 = oper2;
0814:
0815:                if (arg2 == null) {
0816:                    class2 = 0;
0817:                    return;
0818:                }
0819:
0820:                className = arg2.getClass();
0821:
0822:                if (className == String.class)
0823:                    class2 = STRING;
0824:                else if (className == Double.class)
0825:                    class2 = DOUBLE;
0826:                else if (className == Long.class)
0827:                    class2 = LONG;
0828:                else if (className == Integer.class) {
0829:                    class2 = LONG;
0830:                    arg2 = new Long(((Integer) arg2).longValue());
0831:                } else if (className == Short.class) {
0832:                    class2 = LONG;
0833:                    arg2 = new Long(((Short) arg2).longValue());
0834:                } else if (className == Byte.class) {
0835:                    class2 = LONG;
0836:                    arg2 = new Long(((Byte) arg2).longValue());
0837:                } else if (className == Float.class) {
0838:                    class2 = DOUBLE;
0839:                    arg2 = new Double(((Float) arg2).doubleValue());
0840:                } else if (className == Boolean.class)
0841:                    class2 = BOOLEAN;
0842:                else
0843:                    throwBadObjectException(className);
0844:            }
0845:
0846:            void computeArgument3() throws Exception {
0847:                Class className = oper3.getClass();
0848:
0849:                if (className == Identifier.class)
0850:                    arg3 = ((Identifier) oper3).value;
0851:                else if (className == Operator.class)
0852:                    arg3 = ((Operator) oper3).apply();
0853:                else
0854:                    arg3 = oper3;
0855:
0856:                if (arg3 == null) {
0857:                    class3 = 0;
0858:                    return;
0859:                }
0860:
0861:                className = arg3.getClass();
0862:
0863:                if (className == String.class)
0864:                    class3 = STRING;
0865:                else if (className == Double.class)
0866:                    class3 = DOUBLE;
0867:                else if (className == Long.class)
0868:                    class3 = LONG;
0869:                else if (className == Integer.class) {
0870:                    class3 = LONG;
0871:                    arg3 = new Long(((Integer) arg3).longValue());
0872:                } else if (className == Short.class) {
0873:                    class3 = LONG;
0874:                    arg3 = new Long(((Short) arg3).longValue());
0875:                } else if (className == Byte.class) {
0876:                    class3 = LONG;
0877:                    arg3 = new Long(((Byte) arg3).longValue());
0878:                } else if (className == Float.class) {
0879:                    class3 = DOUBLE;
0880:                    arg3 = new Double(((Float) arg3).doubleValue());
0881:                } else if (className == Boolean.class)
0882:                    class3 = BOOLEAN;
0883:                else
0884:                    throwBadObjectException(className);
0885:            }
0886:
0887:            public Object apply() throws Exception {
0888:                switch (operation) {
0889:                case EQUAL:
0890:                    return equal();
0891:                case NOT:
0892:                    return not();
0893:                case AND:
0894:                    return and();
0895:                case OR:
0896:                    return or();
0897:                case GT:
0898:                    return gt();
0899:                case GE:
0900:                    return ge();
0901:                case LT:
0902:                    return lt();
0903:                case LE:
0904:                    return le();
0905:                case DIFFERENT:
0906:                    return different();
0907:                case ADD:
0908:                    return add();
0909:                case SUB:
0910:                    return sub();
0911:                case NEG:
0912:                    return neg();
0913:                case MUL:
0914:                    return mul();
0915:                case DIV:
0916:                    return div();
0917:                case BETWEEN:
0918:                    return between();
0919:                case NOT_BETWEEN:
0920:                    return not_between();
0921:                case LIKE:
0922:                    return like(false, false);
0923:                case NOT_LIKE:
0924:                    return like(true, false);
0925:                case LIKE_ESCAPE:
0926:                    return like(false, true);
0927:                case NOT_LIKE_ESCAPE:
0928:                    return like(true, true);
0929:                case IS_NULL:
0930:                    return is_null();
0931:                case IS_NOT_NULL:
0932:                    return is_not_null();
0933:                case IN:
0934:                    return in();
0935:                case NOT_IN:
0936:                    return not_in();
0937:                }
0938:
0939:                throw new Exception("Unknown operation: " + toString());
0940:            }
0941:
0942:            public void throwBadObjectException(Class class1) throws Exception {
0943:                throw new Exception("Bad Object: '" + class1.getName()
0944:                        + "' for operation: " + toString());
0945:            }
0946:
0947:            public void throwBadObjectException(int class1) throws Exception {
0948:                throw new Exception("Bad Object: '" + getClassName(class1)
0949:                        + "' for operation: " + toString());
0950:            }
0951:
0952:            public void throwBadObjectException(int class1, int class2)
0953:                    throws Exception {
0954:                throw new Exception("Bad Object: expected '"
0955:                        + getClassName(class1) + "' got '"
0956:                        + getClassName(class2) + "' for operation: "
0957:                        + toString());
0958:            }
0959:
0960:            static String getClassName(int class1) {
0961:                String str = "Unknown";
0962:                switch (class1) {
0963:                case STRING:
0964:                    str = "String";
0965:                    break;
0966:                case LONG:
0967:                    str = "Long";
0968:                    break;
0969:                case DOUBLE:
0970:                    str = "Double";
0971:                    break;
0972:                case BOOLEAN:
0973:                    str = "Boolean";
0974:                    break;
0975:                }
0976:                return str;
0977:            }
0978:
0979:            static String operationString(int operation) {
0980:                String str = "Unknown";
0981:                switch (operation) {
0982:                case EQUAL:
0983:                    str = "EQUAL";
0984:                    break;
0985:                case NOT:
0986:                    str = "NOT";
0987:                    break;
0988:                case AND:
0989:                    str = "AND";
0990:                    break;
0991:                case OR:
0992:                    str = "OR";
0993:                    break;
0994:                case GT:
0995:                    str = "GT";
0996:                    break;
0997:                case GE:
0998:                    str = "GE";
0999:                    break;
1000:                case LT:
1001:                    str = "LT";
1002:                    break;
1003:                case LE:
1004:                    str = "LE";
1005:                    break;
1006:                case DIFFERENT:
1007:                    str = "DIFFERENT";
1008:                    break;
1009:                case ADD:
1010:                    str = "ADD";
1011:                    break;
1012:                case SUB:
1013:                    str = "SUB";
1014:                    break;
1015:                case NEG:
1016:                    str = "NEG";
1017:                    break;
1018:                case MUL:
1019:                    str = "MUL";
1020:                    break;
1021:                case DIV:
1022:                    str = "DIV";
1023:                    break;
1024:                case BETWEEN:
1025:                    str = "BETWEEN";
1026:                    break;
1027:                case NOT_BETWEEN:
1028:                    str = "NOT_BETWEEN";
1029:                    break;
1030:                case LIKE:
1031:                    str = "LIKE";
1032:                    break;
1033:                case NOT_LIKE:
1034:                    str = "NOT_LIKE";
1035:                    break;
1036:                case LIKE_ESCAPE:
1037:                    str = "LIKE_ESCAPE";
1038:                    break;
1039:                case NOT_LIKE_ESCAPE:
1040:                    str = "NOT_LIKE_ESCAPE";
1041:                    break;
1042:                case IS_NULL:
1043:                    str = "IS_NULL";
1044:                    break;
1045:                case IS_NOT_NULL:
1046:                    str = "IS_NOT_NULL";
1047:                    break;
1048:                case IN:
1049:                    str = "IN";
1050:                    break;
1051:                case NOT_IN:
1052:                    str = "NOT_IN";
1053:                    break;
1054:                }
1055:                return str;
1056:            }
1057:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.