Source Code Cross Referenced for Value.java in  » Scripting » oscript-2.10.4 » oscript » data » 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 » Scripting » oscript 2.10.4 » oscript.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*=============================================================================
0002:         *     Copyright Texas Instruments 2000-2005.  All Rights Reserved.
0003:         *   
0004:         * This program is free software; you can redistribute it and/or
0005:         * modify it under the terms of the GNU Lesser General Public
0006:         * License as published by the Free Software Foundation; either
0007:         * version 2 of the License, or (at your option) any later version.
0008:         * 
0009:         * This program is distributed in the hope that it will be useful,
0010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012:         * Lesser General Public License for more details.
0013:         * 
0014:         * You should have received a copy of the GNU Lesser General Public
0015:         * License along with this library; if not, write to the Free Software
0016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0017:         */
0018:
0019:        package oscript.data;
0020:
0021:        import oscript.exceptions.*;
0022:        import oscript.util.StackFrame;
0023:        import oscript.util.MemberTable;
0024:        import oscript.classwrap.ClassWrapGen;
0025:
0026:        /**
0027:         * The base class of all values in the interpreter.  This class provides
0028:         * methods (which throw script-exceptions if not overloaded), so that the
0029:         * interpreter has a handy way of calling the methods needed to evaluate
0030:         * a program.  This methods can be overloaded by built-in (ie native java)
0031:         * methods for the built-in types, or via <code>ScriptObject</code> for
0032:         * script types.
0033:         * 
0034:         * @author Rob Clark (rob@ti.com)
0035:         */
0036:        public abstract class Value implements  java.io.Serializable {
0037:            /**
0038:             * Various and asundry special values.  UNDEFINED is different from
0039:             * NULL in that it is used for un-initialized variables or array
0040:             * entries.  A variable or array entry cannot be given the value
0041:             * UNDEFINED, but can be assigned the value NULL.
0042:             */
0043:            public static final Value UNDEFINED = OSpecial
0044:                    .makeSpecial("(undefined)");
0045:            public static final Value NULL = OSpecial.makeSpecial("(null)");
0046:
0047:            /**
0048:             * The type object for an instance of Value... value can't really be
0049:             * instantiated, but this is needed internally.
0050:             */
0051:            public final static BuiltinType TYPE = BuiltinType
0052:                    .makeBuiltinType("oscript.data.Value");
0053:            public final static String PARENT_TYPE_NAME = null;
0054:            public final static String TYPE_NAME = "Value";
0055:            public final static String[] MEMBER_NAMES = new String[] {
0056:            //                        "unhand",
0057:            //                        "getType",
0058:            //                        "castToJavaObject",
0059:            //                        "castToString",
0060:            //                        "bopInstanceOf",
0061:            //                        "bopInstanceOfR",
0062:            //                        "bopEquals",
0063:            //                        "bopNotEquals",
0064:            };
0065:
0066:            public final static boolean DEBUG = false;
0067:
0068:            /*=======================================================================*/
0069:            /**
0070:             * Class Constructor.
0071:             * 
0072:             * @param type         the type of this object
0073:             */
0074:            public Value() {
0075:            }
0076:
0077:            /*=======================================================================*/
0078:            /**
0079:             * For references to an object (ie variables), this returns the actual
0080:             * value this is a reference to, otherwise this return <code>this</code>.
0081:             * 
0082:             * @return the actual object
0083:             */
0084:            public Value unhand() {
0085:                return this ;
0086:            }
0087:
0088:            /*=======================================================================*/
0089:            /**
0090:             * Return the object used for implementing <i>synchronized</i>.  For a
0091:             * normal script object, the object is it's own monitor.  For a java
0092:             * object, it is the java object rather than the {@link JavaObjectWrapper}.
0093:             * 
0094:             * @return the object to synchronize on
0095:             */
0096:            public Object getMonitor() {
0097:                return this ;
0098:            }
0099:
0100:            /*=======================================================================*/
0101:            /**
0102:             * If this object is a type, determine if an instance of this type is
0103:             * an instance of the specified type, ie. if this is <code>type</code>,
0104:             * or a subclass.
0105:             * 
0106:             * @param type         the type to compare this type to
0107:             * @return <code>true</code> or <code>false</code>
0108:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0109:             */
0110:            public boolean isA(Value type) {
0111:                throw noSuchMember("isA");
0112:            }
0113:
0114:            /*=======================================================================*/
0115:            /**
0116:             * Get the type of this object.
0117:             * 
0118:             * @return the object's type
0119:             */
0120:            public Value getType() {
0121:                Value type = getTypeImpl();
0122:                Value scriptObject = ClassWrapGen.getScriptObject(this );
0123:
0124:                if (scriptObject != null)
0125:                    return scriptObject.getType();
0126:                else if (type == null)
0127:                    return UNDEFINED;
0128:                else
0129:                    return type;
0130:            }
0131:
0132:            /*=======================================================================*/
0133:            /**
0134:             * Get the type of this object.  The returned type doesn't have to take
0135:             * into account the possibility of a script type extending a built-in
0136:             * type, since that is handled by {@link #getType}.
0137:             * 
0138:             * @return the object's type
0139:             */
0140:            protected abstract Value getTypeImpl();
0141:
0142:            /*=======================================================================*/
0143:            /* The following methods are used to convert script objects to java
0144:             * objects.  Since everything is a method call, script objects can 
0145:             * implement these methods if they support a particular conversion.
0146:             * (The script object method actually returns a script object, whose
0147:             * corresponding method is called to convert to a java type... so
0148:             * the script object only converts to a built-in type.  The names of
0149:             * the methods for the script types are the same.)
0150:             */
0151:
0152:            /*=======================================================================*/
0153:            /**
0154:             * Convert this object to a native java <code>boolean</code> value.
0155:             * 
0156:             * @return a boolean value
0157:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0158:             */
0159:            public boolean castToBoolean() throws PackagedScriptObjectException {
0160:                throw noSuchMember("castToBoolean");
0161:            }
0162:
0163:            /*=======================================================================*/
0164:            /**
0165:             * Convert this object to a native java <code>String</code> value.
0166:             * 
0167:             * @return a String value
0168:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0169:             */
0170:            public String castToString() throws PackagedScriptObjectException {
0171:                // XXX this is sorta hacky... for the benefit of java objects, we want
0172:                // to defer to toString(), but the toString() method in this class 
0173:                // calls this method!  perhaps the best answer is to drop the "cast"
0174:                // part of the castToXXX() methods so the names match java...
0175:                if (this  != castToJavaObject())
0176:                    return castToJavaObject().toString();
0177:                else
0178:                    return "[object]";
0179:            }
0180:
0181:            /*=======================================================================*/
0182:            /**
0183:             * Convert this object to a native java <code>long</code> value.
0184:             * 
0185:             * @return a long value
0186:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0187:             */
0188:            public long castToExactNumber()
0189:                    throws PackagedScriptObjectException {
0190:                throw noSuchMember("castToExactNumber");
0191:            }
0192:
0193:            /*=======================================================================*/
0194:            /**
0195:             * Convert this object to a native java <code>double</code> value.
0196:             * 
0197:             * @return a double value
0198:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0199:             */
0200:            public double castToInexactNumber()
0201:                    throws PackagedScriptObjectException {
0202:                throw noSuchMember("castToInexactNumber");
0203:            }
0204:
0205:            /*=======================================================================*/
0206:            /**
0207:             * Convert this object to a native java <code>Object</code> value.
0208:             * 
0209:             * @return a java object
0210:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0211:             */
0212:            public Object castToJavaObject()
0213:                    throws PackagedScriptObjectException {
0214:                return this ;
0215:            }
0216:
0217:            /*=======================================================================*/
0218:            /* The binary operators:
0219:             */
0220:
0221:            /* 
0222:             * Description of binary operator negotiation protocol:
0223:             * 
0224:             *   Ok, so you have some code of the form "a <BOP> b", what do you do in
0225:             *   the case that b cannot be cast to a type that a can deal with?  Ie,
0226:             *   "a.<BOP_METHOD_NAME>(b)" won't work, so you flip the args, and call
0227:             *   the "reversed" method "b.<BOP_METHOD_NAME>R( a, e )".  Note that the
0228:             *   exception thrown while trying to evaluate "a.<BOP_METHOD_NAME>(b)" is
0229:             *   passed in to the R method, so it can be re-thrown if the R method
0230:             *   fails as well.  Note that the "R" method is called by the normal
0231:             *   method, and the "R" methods are technically not part of the public
0232:             *   interface... they are only public for the benefit of script-objects
0233:             *   that subclass a native type.
0234:             */
0235:
0236:            /*=======================================================================*/
0237:            /**
0238:             * Perform the cast operation, <code>(a)b</code> is equivalent to <code>a.bopCast(b)</code>
0239:             * 
0240:             * @param val          the other value
0241:             * @return the result
0242:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0243:             */
0244:            public Value bopCast(Value val)
0245:                    throws PackagedScriptObjectException {
0246:                if (val.bopInstanceOf(this ).castToBoolean())
0247:                    return val;
0248:                return bopCastR(val, noSuchMember("bopCast"));
0249:            }
0250:
0251:            public Value bopCastR(Value val, PackagedScriptObjectException e)
0252:                    throws PackagedScriptObjectException {
0253:                throw e;
0254:            }
0255:
0256:            /*=======================================================================*/
0257:            /**
0258:             * Perform the instanceof operation.
0259:             * 
0260:             * @param val          the other value
0261:             * @return the result
0262:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0263:             */
0264:            public Value bopInstanceOf(Value val)
0265:                    throws PackagedScriptObjectException {
0266:                try {
0267:                    if (this .getType().isA(val))
0268:                        return OBoolean.TRUE;
0269:                    else
0270:                        return OBoolean.FALSE;
0271:                } catch (PackagedScriptObjectException e) {
0272:                    return val.bopInstanceOfR(this , e);
0273:                }
0274:            }
0275:
0276:            public Value bopInstanceOfR(Value val,
0277:                    PackagedScriptObjectException e)
0278:                    throws PackagedScriptObjectException {
0279:                if (val.getType().isA(this ))
0280:                    return OBoolean.TRUE;
0281:                else
0282:                    return OBoolean.FALSE;
0283:            }
0284:
0285:            /*=======================================================================*/
0286:            /**
0287:             * Perform the logical OR operation.
0288:             * 
0289:             * @param val          the other value
0290:             * @return the result
0291:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0292:             */
0293:            public Value bopLogicalOr(Value val)
0294:                    throws PackagedScriptObjectException {
0295:                return val.bopLogicalOrR(this , noSuchMember("||"));
0296:            }
0297:
0298:            public Value bopLogicalOrR(Value val,
0299:                    PackagedScriptObjectException e)
0300:                    throws PackagedScriptObjectException {
0301:                throw e;
0302:            }
0303:
0304:            /*=======================================================================*/
0305:            /**
0306:             * Perform the logical AND operation.
0307:             * 
0308:             * @param val          the other value
0309:             * @return the result
0310:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0311:             */
0312:            public Value bopLogicalAnd(Value val)
0313:                    throws PackagedScriptObjectException {
0314:                return val.bopLogicalAndR(this , noSuchMember("&&"));
0315:            }
0316:
0317:            public Value bopLogicalAndR(Value val,
0318:                    PackagedScriptObjectException e)
0319:                    throws PackagedScriptObjectException {
0320:                throw e;
0321:            }
0322:
0323:            /*=======================================================================*/
0324:            /**
0325:             * Perform the bitwise OR operation.
0326:             * 
0327:             * @param val          the other value
0328:             * @return the result
0329:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0330:             */
0331:            public Value bopBitwiseOr(Value val)
0332:                    throws PackagedScriptObjectException {
0333:                return val.bopBitwiseOrR(this , noSuchMember("|"));
0334:            }
0335:
0336:            public Value bopBitwiseOrR(Value val,
0337:                    PackagedScriptObjectException e)
0338:                    throws PackagedScriptObjectException {
0339:                throw e;
0340:            }
0341:
0342:            /*=======================================================================*/
0343:            /**
0344:             * Perform the bitwise XOR operation.
0345:             * 
0346:             * @param val          the other value
0347:             * @return the result
0348:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0349:             */
0350:            public Value bopBitwiseXor(Value val)
0351:                    throws PackagedScriptObjectException {
0352:                return val.bopBitwiseXorR(this , noSuchMember("^"));
0353:            }
0354:
0355:            public Value bopBitwiseXorR(Value val,
0356:                    PackagedScriptObjectException e)
0357:                    throws PackagedScriptObjectException {
0358:                throw e;
0359:            }
0360:
0361:            /*=======================================================================*/
0362:            /**
0363:             * Perform the bitwise AND operation.
0364:             * 
0365:             * @param val          the other value
0366:             * @return the result
0367:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0368:             */
0369:            public Value bopBitwiseAnd(Value val)
0370:                    throws PackagedScriptObjectException {
0371:                return val.bopBitwiseAndR(this , noSuchMember("&"));
0372:            }
0373:
0374:            public Value bopBitwiseAndR(Value val,
0375:                    PackagedScriptObjectException e)
0376:                    throws PackagedScriptObjectException {
0377:                throw e;
0378:            }
0379:
0380:            /*=======================================================================*/
0381:            /**
0382:             * Perform the "==" operation.
0383:             * 
0384:             * @param val          the other value
0385:             * @return the result
0386:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0387:             */
0388:            public Value bopEquals(Value val)
0389:                    throws PackagedScriptObjectException {
0390:                return OBoolean.makeBoolean(unhand() == val.unhand());
0391:            }
0392:
0393:            public Value bopEqualsR(Value val, PackagedScriptObjectException e)
0394:                    throws PackagedScriptObjectException {
0395:                return OBoolean.makeBoolean(val.unhand() == unhand());
0396:            }
0397:
0398:            /*=======================================================================*/
0399:            /**
0400:             * Perform the "!=" operation.
0401:             * 
0402:             * @param val          the other value
0403:             * @return the result
0404:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0405:             */
0406:            public Value bopNotEquals(Value val)
0407:                    throws PackagedScriptObjectException {
0408:                return bopEquals(val).uopLogicalNot();
0409:            }
0410:
0411:            public Value bopNotEqualsR(Value val,
0412:                    PackagedScriptObjectException e)
0413:                    throws PackagedScriptObjectException {
0414:                return bopEqualsR(val, e).uopLogicalNot();
0415:            }
0416:
0417:            /*=======================================================================*/
0418:            /**
0419:             * Perform the "<" operation.
0420:             * 
0421:             * @param val          the other value
0422:             * @return the result
0423:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0424:             */
0425:            public Value bopLessThan(Value val)
0426:                    throws PackagedScriptObjectException {
0427:                return val.bopLessThanR(this , noSuchMember("<"));
0428:            }
0429:
0430:            public Value bopLessThanR(Value val, PackagedScriptObjectException e)
0431:                    throws PackagedScriptObjectException {
0432:                throw e;
0433:            }
0434:
0435:            /*=======================================================================*/
0436:            /**
0437:             * Perform the ">" operation.
0438:             * 
0439:             * @param val          the other value
0440:             * @return the result
0441:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0442:             */
0443:            public Value bopGreaterThan(Value val)
0444:                    throws PackagedScriptObjectException {
0445:                return val.bopGreaterThanR(this , noSuchMember(">"));
0446:            }
0447:
0448:            public Value bopGreaterThanR(Value val,
0449:                    PackagedScriptObjectException e)
0450:                    throws PackagedScriptObjectException {
0451:                throw e;
0452:            }
0453:
0454:            /*=======================================================================*/
0455:            /**
0456:             * Perform the "<=" operation.
0457:             * 
0458:             * @param val          the other value
0459:             * @return the result
0460:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0461:             */
0462:            public Value bopLessThanOrEquals(Value val)
0463:                    throws PackagedScriptObjectException {
0464:                return val.bopLessThanOrEqualsR(this , noSuchMember("<="));
0465:            }
0466:
0467:            public Value bopLessThanOrEqualsR(Value val,
0468:                    PackagedScriptObjectException e)
0469:                    throws PackagedScriptObjectException {
0470:                throw e;
0471:            }
0472:
0473:            /*=======================================================================*/
0474:            /**
0475:             * Perform the ">=" operation.
0476:             * 
0477:             * @param val          the other value
0478:             * @return the result
0479:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0480:             */
0481:            public Value bopGreaterThanOrEquals(Value val)
0482:                    throws PackagedScriptObjectException {
0483:                return val.bopGreaterThanOrEqualsR(this , noSuchMember(">="));
0484:            }
0485:
0486:            public Value bopGreaterThanOrEqualsR(Value val,
0487:                    PackagedScriptObjectException e)
0488:                    throws PackagedScriptObjectException {
0489:                throw e;
0490:            }
0491:
0492:            /*=======================================================================*/
0493:            /**
0494:             * Perform the "<<" operation.
0495:             * 
0496:             * @param val          the other value
0497:             * @return the result
0498:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0499:             */
0500:            public Value bopLeftShift(Value val)
0501:                    throws PackagedScriptObjectException {
0502:                return val.bopLeftShiftR(this , noSuchMember("<<"));
0503:            }
0504:
0505:            public Value bopLeftShiftR(Value val,
0506:                    PackagedScriptObjectException e)
0507:                    throws PackagedScriptObjectException {
0508:                throw e;
0509:            }
0510:
0511:            /*=======================================================================*/
0512:            /**
0513:             * Perform the ">>" operation.
0514:             * 
0515:             * @param val          the other value
0516:             * @return the result
0517:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0518:             */
0519:            public Value bopSignedRightShift(Value val)
0520:                    throws PackagedScriptObjectException {
0521:                return val.bopSignedRightShiftR(this , noSuchMember(">>"));
0522:            }
0523:
0524:            public Value bopSignedRightShiftR(Value val,
0525:                    PackagedScriptObjectException e)
0526:                    throws PackagedScriptObjectException {
0527:                throw e;
0528:            }
0529:
0530:            /*=======================================================================*/
0531:            /**
0532:             * Perform the ">>>" operation.
0533:             * 
0534:             * @param val          the other value
0535:             * @return the result
0536:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0537:             */
0538:            public Value bopUnsignedRightShift(Value val)
0539:                    throws PackagedScriptObjectException {
0540:                return val.bopUnsignedRightShiftR(this , noSuchMember(">>>"));
0541:            }
0542:
0543:            public Value bopUnsignedRightShiftR(Value val,
0544:                    PackagedScriptObjectException e)
0545:                    throws PackagedScriptObjectException {
0546:                throw e;
0547:            }
0548:
0549:            /*=======================================================================*/
0550:            /**
0551:             * Perform the "+" operation.
0552:             * 
0553:             * @param val          the other value
0554:             * @return the result
0555:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0556:             */
0557:            public Value bopPlus(Value val)
0558:                    throws PackagedScriptObjectException {
0559:                return val.bopPlusR(this , noSuchMember("+"));
0560:            }
0561:
0562:            public Value bopPlusR(Value val, PackagedScriptObjectException e)
0563:                    throws PackagedScriptObjectException {
0564:                throw e;
0565:            }
0566:
0567:            /*=======================================================================*/
0568:            /**
0569:             * Perform the "-" operation.
0570:             * 
0571:             * @param val          the other value
0572:             * @return the result
0573:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0574:             */
0575:            public Value bopMinus(Value val)
0576:                    throws PackagedScriptObjectException {
0577:                return val.bopMinusR(this , noSuchMember("-"));
0578:            }
0579:
0580:            public Value bopMinusR(Value val, PackagedScriptObjectException e)
0581:                    throws PackagedScriptObjectException {
0582:                throw e;
0583:            }
0584:
0585:            /*=======================================================================*/
0586:            /**
0587:             * Perform the "*" operation.
0588:             * 
0589:             * @param val          the other value
0590:             * @return the result
0591:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0592:             */
0593:            public Value bopMultiply(Value val)
0594:                    throws PackagedScriptObjectException {
0595:                return val.bopMultiplyR(this , noSuchMember("*"));
0596:            }
0597:
0598:            public Value bopMultiplyR(Value val, PackagedScriptObjectException e)
0599:                    throws PackagedScriptObjectException {
0600:                throw e;
0601:            }
0602:
0603:            /*=======================================================================*/
0604:            /**
0605:             * Perform the "/" operation.
0606:             * 
0607:             * @param val          the other value
0608:             * @return the result
0609:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0610:             */
0611:            public Value bopDivide(Value val)
0612:                    throws PackagedScriptObjectException {
0613:                return val.bopDivideR(this , noSuchMember("/"));
0614:            }
0615:
0616:            public Value bopDivideR(Value val, PackagedScriptObjectException e)
0617:                    throws PackagedScriptObjectException {
0618:                throw e;
0619:            }
0620:
0621:            /*=======================================================================*/
0622:            /**
0623:             * Perform the "%" operation.
0624:             * 
0625:             * @param val          the other value
0626:             * @return the result
0627:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0628:             */
0629:            public Value bopRemainder(Value val)
0630:                    throws PackagedScriptObjectException {
0631:                return val.bopRemainderR(this , noSuchMember("%"));
0632:            }
0633:
0634:            public Value bopRemainderR(Value val,
0635:                    PackagedScriptObjectException e)
0636:                    throws PackagedScriptObjectException {
0637:                throw e;
0638:            }
0639:
0640:            /*=======================================================================*/
0641:            /* The unary operators:
0642:             */
0643:
0644:            /*=======================================================================*/
0645:            /**
0646:             * Perform the "++" operation.
0647:             * 
0648:             * @return the result
0649:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0650:             */
0651:            public Value uopIncrement() throws PackagedScriptObjectException {
0652:                throw noSuchMember("++");
0653:            }
0654:
0655:            /*=======================================================================*/
0656:            /**
0657:             * Perform the "--" operation.
0658:             * 
0659:             * @return the result
0660:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0661:             */
0662:            public Value uopDecrement() throws PackagedScriptObjectException {
0663:                throw noSuchMember("--");
0664:            }
0665:
0666:            /*=======================================================================*/
0667:            /**
0668:             * Perform the "+" operation.
0669:             * 
0670:             * @return the result
0671:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0672:             */
0673:            public Value uopPlus() throws PackagedScriptObjectException {
0674:                throw noSuchMember("+");
0675:            }
0676:
0677:            /*=======================================================================*/
0678:            /**
0679:             * Perform the "-" operation.
0680:             * 
0681:             * @return the result
0682:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0683:             */
0684:            public Value uopMinus() throws PackagedScriptObjectException {
0685:                throw noSuchMember("-");
0686:            }
0687:
0688:            /*=======================================================================*/
0689:            /**
0690:             * Perform the "~" operation.
0691:             * 
0692:             * @return the result
0693:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0694:             */
0695:            public Value uopBitwiseNot() throws PackagedScriptObjectException {
0696:                throw noSuchMember("~");
0697:            }
0698:
0699:            /*=======================================================================*/
0700:            /**
0701:             * Perform the "!" operation.
0702:             * 
0703:             * @return the result
0704:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0705:             */
0706:            public Value uopLogicalNot() throws PackagedScriptObjectException {
0707:                throw noSuchMember("!");
0708:            }
0709:
0710:            /*=======================================================================*/
0711:            /* The misc operators:
0712:             */
0713:
0714:            /*=======================================================================*/
0715:            /**
0716:             * Perform assignment.  Set the value of this reference to the specified
0717:             * value.
0718:             * 
0719:             * @param val          the value to set this reference to
0720:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0721:             */
0722:            public void opAssign(Value val)
0723:                    throws PackagedScriptObjectException {
0724:                throw noSuchMember("=");
0725:            }
0726:
0727:            /* 
0728:             * Note that there are two variants on the callAsXXX() methods... the 
0729:             * first is the "simple" version, taking an array of parameters, and
0730:             * the second is the "optimized" version (which is used by the compiled
0731:             * code), which passes in the current stack-frame and passes the args
0732:             * as a MemberTable object
0733:             */
0734:
0735:            /*=======================================================================*/
0736:            /**
0737:             * Call this object as a function.
0738:             * 
0739:             * @param sf           the current stack frame
0740:             * @param args         the arguments to the function, or <code>null</code> if none
0741:             * @return the value returned by the function
0742:             * @throws PackagedScriptObjectException
0743:             * @see Function
0744:             */
0745:            public Value callAsFunction(StackFrame sf, MemberTable args)
0746:                    throws PackagedScriptObjectException {
0747:                throw PackagedScriptObjectException
0748:                        .makeExceptionWrapper(new OUnsupportedOperationException(
0749:                                "can't call as function"));
0750:            }
0751:
0752:            public final Value callAsFunction(Value[] args)
0753:                    throws PackagedScriptObjectException {
0754:                return callAsFunction(StackFrame.currentStackFrame(),
0755:                        new OArray(args));
0756:            }
0757:
0758:            /** @deprecated */
0759:            public final Value callAsFunction(StackFrame sf, Value[] args) {
0760:                throw new ProgrammingErrorException("shouldn't get here!!");
0761:            }
0762:
0763:            /*=======================================================================*/
0764:            /**
0765:             * Call this object as a constructor.
0766:             * 
0767:             * @param sf           the current stack frame
0768:             * @param args         the arguments to the function, or <code>null</code> if none
0769:             * @return the newly constructed object
0770:             * @throws PackagedScriptObjectException
0771:             * @see Function
0772:             */
0773:            public Value callAsConstructor(StackFrame sf, MemberTable args)
0774:                    throws PackagedScriptObjectException {
0775:                throw PackagedScriptObjectException
0776:                        .makeExceptionWrapper(new OUnsupportedOperationException(
0777:                                "can't call as constructor"));
0778:            }
0779:
0780:            public final Value callAsConstructor(Value[] args)
0781:                    throws PackagedScriptObjectException {
0782:                return callAsConstructor(StackFrame.currentStackFrame(),
0783:                        new OArray(args));
0784:            }
0785:
0786:            /** @deprecated */
0787:            public final Value callAsConstructor(StackFrame sf, Value[] args) {
0788:                throw new ProgrammingErrorException("shouldn't get here!!");
0789:            }
0790:
0791:            /*=======================================================================*/
0792:            /**
0793:             * Call this object as a parent class constructor.
0794:             * 
0795:             * @param sf           the current stack frame
0796:             * @param scope        the object
0797:             * @param args         the arguments to the function, or <code>null</code> if none
0798:             * @return the value returned by the function
0799:             * @throws PackagedScriptObjectException
0800:             * @see Function
0801:             */
0802:            public Value callAsExtends(StackFrame sf, Scope scope,
0803:                    MemberTable args) throws PackagedScriptObjectException {
0804:                throw PackagedScriptObjectException
0805:                        .makeExceptionWrapper(new OUnsupportedOperationException(
0806:                                "can't call as constructor"));
0807:            }
0808:
0809:            public final Value callAsExtends(Scope scope, MemberTable args)
0810:                    throws PackagedScriptObjectException {
0811:                return callAsExtends(StackFrame.currentStackFrame(), scope,
0812:                        args);
0813:            }
0814:
0815:            /** @deprecated */
0816:            public final Value callAsExtends(StackFrame sf, Scope scope,
0817:                    Value[] args) {
0818:                throw new ProgrammingErrorException("shouldn't get here!!");
0819:            }
0820:
0821:            /*=======================================================================*/
0822:            /**
0823:             * Get a member of this object.  This method is provided for convenience.
0824:             * 
0825:             * @param name         the name of the member
0826:             * @return a reference to the member
0827:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0828:             * @see #populateMemberSet
0829:             */
0830:            public final Value getMember(String name)
0831:                    throws PackagedScriptObjectException {
0832:                return getMember(Symbol.getSymbol(name).getId());
0833:            }
0834:
0835:            /*=======================================================================*/
0836:            /**
0837:             * Get a member of this object.
0838:             * 
0839:             * @param name         the name of the member
0840:             * @return a reference to the member
0841:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0842:             * @see #populateMemberSet
0843:             */
0844:            // NOTE: not final to fix OBJS56
0845:            public/*final*/Value getMember(Value name)
0846:                    throws PackagedScriptObjectException {
0847:                return getMember(Symbol.getSymbol(name).getId());
0848:            }
0849:
0850:            /*=======================================================================*/
0851:            /**
0852:             * Get a member of this object.
0853:             * 
0854:             * @param id           the id of the symbol that maps to the member
0855:             * @return a reference to the member
0856:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0857:             * @see #populateMemberSet
0858:             */
0859:            public final Value getMember(int id)
0860:                    throws PackagedScriptObjectException {
0861:                return getMember(id, true);
0862:            }
0863:
0864:            /**
0865:             * This isn't really part of the public interface, but is provided for
0866:             * the generated wrapper classes.
0867:             */
0868:            public final Value getMember(String name, boolean exception)
0869:                    throws PackagedScriptObjectException {
0870:                return getMember(Symbol.getSymbol(name).getId(), exception);
0871:            }
0872:
0873:            public final Value getMember(Value name, boolean exception)
0874:                    throws PackagedScriptObjectException {
0875:                return getMember(Symbol.getSymbol(name).getId(), exception);
0876:            }
0877:
0878:            public Value getMember(int id, boolean exception)
0879:                    throws PackagedScriptObjectException {
0880:                Value member = getType().getTypeMember(this , id);
0881:
0882:                if ((member == null) && exception)
0883:                    throw noSuchMember(Symbol.getSymbol(id).castToString());
0884:                else
0885:                    return member;
0886:            }
0887:
0888:            /*=======================================================================*/
0889:            /**
0890:             * Get a member of this type.  This is used to interface to the java
0891:             * method of having members be attributes of a type.  Regular object-
0892:             * script object's members are attributes of the object, but in the
0893:             * case of java types (including built-in types), the members are
0894:             * attributes of the type.
0895:             * 
0896:             * @param obj          an object of this type
0897:             * @param id           the id of the symbol that maps to the member
0898:             * @return a reference to the member, or null
0899:             * @see #populateTypeMemberSet
0900:             */
0901:            protected Value getTypeMember(Value obj, int id) {
0902:                return null;
0903:            }
0904:
0905:            // XXX hack to ensure classes that extend Value to access these protected methods
0906:            public static Value _getTypeMember(Value type, Value obj, int id) {
0907:                return type.getTypeMember(obj, id);
0908:            }
0909:
0910:            public static void _populateTypeMemberSet(Value type,
0911:                    java.util.Set s, boolean d) {
0912:                type.populateTypeMemberSet(s, d);
0913:            }
0914:
0915:            /**
0916:             * @deprecated use other getTypeMember
0917:             */
0918:            protected final Value getTypeMember(Value obj, Value name) {
0919:                return getTypeMember(obj, Symbol.getSymbol(name).getId());
0920:            }
0921:
0922:            /*=======================================================================*/
0923:            /**
0924:             * For types that implement <code>elementAt</code>, this returns the
0925:             * number of elements.
0926:             * 
0927:             * @return an integer length
0928:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0929:             * @see #elementAt
0930:             * @see #elementsAt
0931:             */
0932:            public int length() throws PackagedScriptObjectException {
0933:                throw noSuchMember("length");
0934:            }
0935:
0936:            /*=======================================================================*/
0937:            /**
0938:             * Get the specified index of this object, if this object is an array.  If
0939:             * needed, the array is grown to the appropriate size.
0940:             * 
0941:             * @param idx          the index to get
0942:             * @return a reference to the member
0943:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0944:             * @see #length
0945:             * @see #elementsAt
0946:             */
0947:            public Value elementAt(Value idx)
0948:                    throws PackagedScriptObjectException {
0949:                throw noSuchMember("elementAt");
0950:            }
0951:
0952:            /*=======================================================================*/
0953:            /**
0954:             * Get the specified range of this object, if this object is an array.  
0955:             * This returns a copy of a range of the array.
0956:             * 
0957:             * @param idx1         the index index of the beginning of the range, inclusive
0958:             * @param idx2         the index of the end of the range, inclusive
0959:             * @return a copy of the specified range of this array
0960:             * @throws PackagedScriptObjectException(NoSuchMemberException)
0961:             * @see #length
0962:             * @see #elementAt
0963:             */
0964:            public Value elementsAt(Value idx1, Value idx2)
0965:                    throws PackagedScriptObjectException {
0966:                throw noSuchMember("elementsAt");
0967:            }
0968:
0969:            /*=======================================================================*/
0970:            /**
0971:             * Returns the names of the members of this object.
0972:             * 
0973:             * @return a collection view of the names of the members of this object
0974:             */
0975:            public java.util.Set memberSet() {
0976:                java.util.Set s = new java.util.HashSet();
0977:                populateMemberSet(s, false);
0978:                getType().populateTypeMemberSet(s, false);
0979:                return s;
0980:            }
0981:
0982:            /*=======================================================================*/
0983:            /**
0984:             * Derived classes that implement {@link #getMember} should also
0985:             * implement this.
0986:             * 
0987:             * @param s   the set to populate
0988:             * @param debugger  <code>true</code> if being used by debugger, in
0989:             *   which case both public and private/protected field names should 
0990:             *   be returned
0991:             * @see #getMember
0992:             */
0993:            protected void populateMemberSet(java.util.Set s, boolean debugger) {
0994:            }
0995:
0996:            /*=======================================================================*/
0997:            /**
0998:             * Derived classes that implement {@link #getTypeMember} should also
0999:             * implement this.
1000:             * 
1001:             * @param s   the set to populate
1002:             * @param debugger  <code>true</code> if being used by debugger, in
1003:             *   which case both public and private/protected field names should 
1004:             *   be returned
1005:             * @see #getTypeMember
1006:             */
1007:            protected void populateTypeMemberSet(java.util.Set s,
1008:                    boolean debugger) {
1009:            }
1010:
1011:            /*=======================================================================*/
1012:            /**
1013:             * Convert this value to a string, for the benefit of java code.
1014:             * 
1015:             * @return a string
1016:             */
1017:            public String toString() {
1018:                return castToString();
1019:            }
1020:
1021:            protected PackagedScriptObjectException noSuchMember(String member) {
1022:                return PackagedScriptObjectException
1023:                        .makeExceptionWrapper(new ONoSuchMemberException(
1024:                                getType(), member));
1025:            }
1026:
1027:            /**
1028:             * Derived class that implements {@link java.io.Externalizable} must
1029:             * call this if it overrides it, or call {@link #_externalInit} from the
1030:             * {@link #readExternal} method.  This class doesn't (yet!) implement
1031:             * <code>Externalizable</code> because that would force all subclasses
1032:             * to implement it too (ie. override this methods).
1033:             */
1034:            public void readExternal(java.io.ObjectInput in)
1035:                    throws ClassNotFoundException, java.io.IOException {
1036:            }
1037:
1038:            /**
1039:             * Derived class that implements {@link java.io.Externalizable} must
1040:             * call this if it overrides it, or call {@link #setType} from the
1041:             * {@link #readExternal} method.  This class doesn't (yet!) implement
1042:             * <code>Externalizable</code> because that would force all subclasses
1043:             * to implement it too (ie. override this methods).
1044:             */
1045:            public void writeExternal(java.io.ObjectOutput out)
1046:                    throws java.io.IOException {
1047:            }
1048:        }
1049:
1050:        /*
1051:         *   Local Variables:
1052:         *   tab-width: 2
1053:         *   indent-tabs-mode: nil
1054:         *   mode: java
1055:         *   c-indentation-style: java
1056:         *   c-basic-offset: 2
1057:         *   eval: (c-set-offset 'substatement-open '0)
1058:         *   eval: (c-set-offset 'case-label '+)
1059:         *   eval: (c-set-offset 'inclass '+)
1060:         *   eval: (c-set-offset 'inline-open '0)
1061:         *   End:
1062:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.