Source Code Cross Referenced for XMLObjectImpl.java in  » Scripting » rhino » org » mozilla » javascript » xml » impl » xmlbeans » 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 » rhino » org.mozilla.javascript.xml.impl.xmlbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002:         *
003:         * ***** BEGIN LICENSE BLOCK *****
004:         * Version: MPL 1.1/GPL 2.0
005:         *
006:         * The contents of this file are subject to the Mozilla Public License Version
007:         * 1.1 (the "License"); you may not use this file except in compliance with
008:         * the License. You may obtain a copy of the License at
009:         * http://www.mozilla.org/MPL/
010:         *
011:         * Software distributed under the License is distributed on an "AS IS" basis,
012:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013:         * for the specific language governing rights and limitations under the
014:         * License.
015:         *
016:         * The Original Code is Rhino code, released
017:         * May 6, 1999.
018:         *
019:         * The Initial Developer of the Original Code is
020:         * Netscape Communications Corporation.
021:         * Portions created by the Initial Developer are Copyright (C) 1997-2000
022:         * the Initial Developer. All Rights Reserved.
023:         *
024:         * Contributor(s):
025:         *   Igor Bukanov
026:         *   Ethan Hugg
027:         *   Terry Lucas
028:         *   Milen Nankov
029:         *
030:         * Alternatively, the contents of this file may be used under the terms of
031:         * the GNU General Public License Version 2 or later (the "GPL"), in which
032:         * case the provisions of the GPL are applicable instead of those above. If
033:         * you wish to allow use of your version of this file only under the terms of
034:         * the GPL and not to allow others to use your version of this file under the
035:         * MPL, indicate your decision by deleting the provisions above and replacing
036:         * them with the notice and other provisions required by the GPL. If you do
037:         * not delete the provisions above, a recipient may use your version of this
038:         * file under either the MPL or the GPL.
039:         *
040:         * ***** END LICENSE BLOCK ***** */
041:
042:        package org.mozilla.javascript.xml.impl.xmlbeans;
043:
044:        import org.mozilla.javascript.*;
045:        import org.mozilla.javascript.xml.*;
046:
047:        /**
048:         *  This abstract class describes what all XML objects (XML, XMLList) should have in common.
049:         *
050:         * @see XML
051:         */
052:        abstract class XMLObjectImpl extends XMLObject {
053:            private static final Object XMLOBJECT_TAG = new Object();
054:
055:            protected final XMLLibImpl lib;
056:            protected boolean prototypeFlag;
057:
058:            protected XMLObjectImpl(XMLLibImpl lib, XMLObject prototype) {
059:                super (lib.globalScope(), prototype);
060:                this .lib = lib;
061:            }
062:
063:            /**
064:             * ecmaHas(cx, id) calls this after resolving when id to XMLName
065:             * and checking it is not Uint32 index.
066:             */
067:            abstract boolean hasXMLProperty(XMLName name);
068:
069:            /**
070:             * ecmaGet(cx, id) calls this after resolving when id to XMLName
071:             * and checking it is not Uint32 index.
072:             */
073:            abstract Object getXMLProperty(XMLName name);
074:
075:            /**
076:             * ecmaPut(cx, id, value) calls this after resolving when id to XMLName
077:             * and checking it is not Uint32 index.
078:             */
079:            abstract void putXMLProperty(XMLName name, Object value);
080:
081:            /**
082:             * ecmaDelete(cx, id) calls this after resolving when id to XMLName
083:             * and checking it is not Uint32 index.
084:             */
085:            abstract void deleteXMLProperty(XMLName name);
086:
087:            /**
088:             * Test XML equality with target the target.
089:             */
090:            abstract boolean equivalentXml(Object target);
091:
092:            // Methods from section 12.4.4 in the spec
093:            abstract XML addNamespace(Namespace ns);
094:
095:            abstract XML appendChild(Object xml);
096:
097:            abstract XMLList attribute(XMLName xmlName);
098:
099:            abstract XMLList attributes();
100:
101:            abstract XMLList child(long index);
102:
103:            abstract XMLList child(XMLName xmlName);
104:
105:            abstract int childIndex();
106:
107:            abstract XMLList children();
108:
109:            abstract XMLList comments();
110:
111:            abstract boolean contains(Object xml);
112:
113:            abstract Object copy();
114:
115:            abstract XMLList descendants(XMLName xmlName);
116:
117:            abstract Object[] inScopeNamespaces();
118:
119:            abstract XML insertChildAfter(Object child, Object xml);
120:
121:            abstract XML insertChildBefore(Object child, Object xml);
122:
123:            abstract boolean hasOwnProperty(XMLName xmlName);
124:
125:            abstract boolean hasComplexContent();
126:
127:            abstract boolean hasSimpleContent();
128:
129:            abstract int length();
130:
131:            abstract String localName();
132:
133:            abstract QName name();
134:
135:            abstract Object namespace(String prefix);
136:
137:            abstract Object[] namespaceDeclarations();
138:
139:            abstract Object nodeKind();
140:
141:            abstract void normalize();
142:
143:            abstract Object parent();
144:
145:            abstract XML prependChild(Object xml);
146:
147:            abstract Object processingInstructions(XMLName xmlName);
148:
149:            abstract boolean propertyIsEnumerable(Object member);
150:
151:            abstract XML removeNamespace(Namespace ns);
152:
153:            abstract XML replace(long index, Object xml);
154:
155:            abstract XML replace(XMLName name, Object xml);
156:
157:            abstract XML setChildren(Object xml);
158:
159:            abstract void setLocalName(String name);
160:
161:            abstract void setName(QName xmlName);
162:
163:            abstract void setNamespace(Namespace ns);
164:
165:            abstract XMLList text();
166:
167:            public abstract String toString();
168:
169:            abstract String toSource(int indent);
170:
171:            abstract String toXMLString(int indent);
172:
173:            abstract Object valueOf();
174:
175:            /**
176:             * Extension to access native implementation from scripts
177:             */
178:            abstract org.apache.xmlbeans.XmlObject getXmlObject();
179:
180:            protected abstract Object jsConstructor(Context cx,
181:                    boolean inNewExpr, Object[] args);
182:
183:            final Object getMethod(String id) {
184:                return super .get(id, this );
185:            }
186:
187:            //
188:            //
189:            // Methods overriding ScriptableObject
190:            //
191:            //
192:
193:            public final Object getDefaultValue(Class hint) {
194:                return toString();
195:            }
196:
197:            public void delete(String name) {
198:                throw new IllegalArgumentException("String: [" + name + "]");
199:            }
200:
201:            /**
202:             * XMLObject always compare with any value and equivalentValues
203:             * never returns {@link Scriptable#NOT_FOUND} for them but rather
204:             * calls equivalentXml(value) and wrap the result as Boolean.
205:             */
206:            protected final Object equivalentValues(Object value) {
207:                boolean result = equivalentXml(value);
208:                return result ? Boolean.TRUE : Boolean.FALSE;
209:            }
210:
211:            //
212:            //
213:            // Methods overriding XMLObject
214:            //
215:            //
216:
217:            public final XMLLib lib() {
218:                return lib;
219:            }
220:
221:            /**
222:             * Implementation of ECMAScript [[Has]]
223:             */
224:            public final boolean ecmaHas(Context cx, Object id) {
225:                if (cx == null)
226:                    cx = Context.getCurrentContext();
227:                XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
228:                if (xmlName == null) {
229:                    long index = ScriptRuntime.lastUint32Result(cx);
230:                    // XXX Fix this cast
231:                    return has((int) index, this );
232:                }
233:                return hasXMLProperty(xmlName);
234:            }
235:
236:            /**
237:             * Implementation of ECMAScript [[Get]]
238:             */
239:            public final Object ecmaGet(Context cx, Object id) {
240:                if (cx == null)
241:                    cx = Context.getCurrentContext();
242:                XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
243:                if (xmlName == null) {
244:                    long index = ScriptRuntime.lastUint32Result(cx);
245:                    // XXX Fix this cast
246:                    Object result = get((int) index, this );
247:                    if (result == Scriptable.NOT_FOUND) {
248:                        result = Undefined.instance;
249:                    }
250:                    return result;
251:                }
252:                return getXMLProperty(xmlName);
253:            }
254:
255:            /**
256:             * Implementation of ECMAScript [[Put]]
257:             */
258:            public final void ecmaPut(Context cx, Object id, Object value) {
259:                if (cx == null)
260:                    cx = Context.getCurrentContext();
261:                XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
262:                if (xmlName == null) {
263:                    long index = ScriptRuntime.lastUint32Result(cx);
264:                    // XXX Fix this cast
265:                    put((int) index, this , value);
266:                    return;
267:                }
268:                putXMLProperty(xmlName, value);
269:            }
270:
271:            /**
272:             * Implementation of ECMAScript [[Delete]].
273:             */
274:            public final boolean ecmaDelete(Context cx, Object id) {
275:                if (cx == null)
276:                    cx = Context.getCurrentContext();
277:                XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
278:                if (xmlName == null) {
279:                    long index = ScriptRuntime.lastUint32Result(cx);
280:                    // XXX Fix this
281:                    delete((int) index);
282:                    return true;
283:                }
284:                deleteXMLProperty(xmlName);
285:                return true;
286:            }
287:
288:            public Ref memberRef(Context cx, Object elem, int memberTypeFlags) {
289:                XMLName xmlName;
290:                if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {
291:                    xmlName = lib.toAttributeName(cx, elem);
292:                } else {
293:                    if ((memberTypeFlags & Node.DESCENDANTS_FLAG) == 0) {
294:                        // Code generation would use ecma(Get|Has|Delete|Set) for
295:                        // normal name idenrifiers so one ATTRIBUTE_FLAG
296:                        // or DESCENDANTS_FLAG has to be set
297:                        throw Kit.codeBug();
298:                    }
299:                    xmlName = lib.toXMLName(cx, elem);
300:                }
301:                if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) {
302:                    xmlName.setIsDescendants();
303:                }
304:                xmlName.initXMLObject(this );
305:                return xmlName;
306:            }
307:
308:            /**
309:             * Generic reference to implement x::ns, x.@ns::y, x..@ns::y etc.
310:             */
311:            public Ref memberRef(Context cx, Object namespace, Object elem,
312:                    int memberTypeFlags) {
313:                XMLName xmlName = lib.toQualifiedName(cx, namespace, elem);
314:                if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {
315:                    if (!xmlName.isAttributeName()) {
316:                        xmlName.setAttributeName();
317:                    }
318:                }
319:                if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) {
320:                    xmlName.setIsDescendants();
321:                }
322:                xmlName.initXMLObject(this );
323:                return xmlName;
324:            }
325:
326:            public NativeWith enterWith(Scriptable scope) {
327:                return new XMLWithScope(lib, scope, this );
328:            }
329:
330:            public NativeWith enterDotQuery(Scriptable scope) {
331:                XMLWithScope xws = new XMLWithScope(lib, scope, this );
332:                xws.initAsDotQuery();
333:                return xws;
334:            }
335:
336:            public final Object addValues(Context cx, boolean this IsLeft,
337:                    Object value) {
338:                if (value instanceof  XMLObject) {
339:                    XMLObject v1, v2;
340:                    if (this IsLeft) {
341:                        v1 = this ;
342:                        v2 = (XMLObject) value;
343:                    } else {
344:                        v1 = (XMLObject) value;
345:                        v2 = this ;
346:                    }
347:                    return lib.addXMLObjects(cx, v1, v2);
348:                }
349:                if (value == Undefined.instance) {
350:                    // both "xml + undefined" and "undefined + xml" gives String(xml)
351:                    return ScriptRuntime.toString(this );
352:                }
353:
354:                return super .addValues(cx, this IsLeft, value);
355:            }
356:
357:            //
358:            //
359:            // IdScriptableObject machinery
360:            //
361:            //
362:
363:            final void exportAsJSClass(boolean sealed) {
364:                prototypeFlag = true;
365:                exportAsJSClass(MAX_PROTOTYPE_ID, lib.globalScope(), sealed);
366:            }
367:
368:            // #string_id_map#
369:            private final static int Id_constructor = 1,
370:
371:            Id_addNamespace = 2, Id_appendChild = 3, Id_attribute = 4,
372:                    Id_attributes = 5, Id_child = 6, Id_childIndex = 7,
373:                    Id_children = 8, Id_comments = 9, Id_contains = 10,
374:                    Id_copy = 11, Id_descendants = 12,
375:                    Id_inScopeNamespaces = 13, Id_insertChildAfter = 14,
376:                    Id_insertChildBefore = 15, Id_hasOwnProperty = 16,
377:                    Id_hasComplexContent = 17, Id_hasSimpleContent = 18,
378:                    Id_length = 19, Id_localName = 20, Id_name = 21,
379:                    Id_namespace = 22, Id_namespaceDeclarations = 23,
380:                    Id_nodeKind = 24, Id_normalize = 25, Id_parent = 26,
381:                    Id_prependChild = 27, Id_processingInstructions = 28,
382:                    Id_propertyIsEnumerable = 29, Id_removeNamespace = 30,
383:                    Id_replace = 31, Id_setChildren = 32, Id_setLocalName = 33,
384:                    Id_setName = 34, Id_setNamespace = 35, Id_text = 36,
385:                    Id_toString = 37, Id_toSource = 38, Id_toXMLString = 39,
386:                    Id_valueOf = 40,
387:
388:                    Id_getXmlObject = 41,
389:
390:                    MAX_PROTOTYPE_ID = 41;
391:
392:            protected int findPrototypeId(String s) {
393:                int id;
394:                // #generated# Last update: 2004-11-10 15:38:11 CET
395:                L0: {
396:                    id = 0;
397:                    String X = null;
398:                    int c;
399:                    L: switch (s.length()) {
400:                    case 4:
401:                        c = s.charAt(0);
402:                        if (c == 'c') {
403:                            X = "copy";
404:                            id = Id_copy;
405:                        } else if (c == 'n') {
406:                            X = "name";
407:                            id = Id_name;
408:                        } else if (c == 't') {
409:                            X = "text";
410:                            id = Id_text;
411:                        }
412:                        break L;
413:                    case 5:
414:                        X = "child";
415:                        id = Id_child;
416:                        break L;
417:                    case 6:
418:                        c = s.charAt(0);
419:                        if (c == 'l') {
420:                            X = "length";
421:                            id = Id_length;
422:                        } else if (c == 'p') {
423:                            X = "parent";
424:                            id = Id_parent;
425:                        }
426:                        break L;
427:                    case 7:
428:                        c = s.charAt(0);
429:                        if (c == 'r') {
430:                            X = "replace";
431:                            id = Id_replace;
432:                        } else if (c == 's') {
433:                            X = "setName";
434:                            id = Id_setName;
435:                        } else if (c == 'v') {
436:                            X = "valueOf";
437:                            id = Id_valueOf;
438:                        }
439:                        break L;
440:                    case 8:
441:                        switch (s.charAt(4)) {
442:                        case 'K':
443:                            X = "nodeKind";
444:                            id = Id_nodeKind;
445:                            break L;
446:                        case 'a':
447:                            X = "contains";
448:                            id = Id_contains;
449:                            break L;
450:                        case 'd':
451:                            X = "children";
452:                            id = Id_children;
453:                            break L;
454:                        case 'e':
455:                            X = "comments";
456:                            id = Id_comments;
457:                            break L;
458:                        case 'r':
459:                            X = "toString";
460:                            id = Id_toString;
461:                            break L;
462:                        case 'u':
463:                            X = "toSource";
464:                            id = Id_toSource;
465:                            break L;
466:                        }
467:                        break L;
468:                    case 9:
469:                        switch (s.charAt(2)) {
470:                        case 'c':
471:                            X = "localName";
472:                            id = Id_localName;
473:                            break L;
474:                        case 'm':
475:                            X = "namespace";
476:                            id = Id_namespace;
477:                            break L;
478:                        case 'r':
479:                            X = "normalize";
480:                            id = Id_normalize;
481:                            break L;
482:                        case 't':
483:                            X = "attribute";
484:                            id = Id_attribute;
485:                            break L;
486:                        }
487:                        break L;
488:                    case 10:
489:                        c = s.charAt(0);
490:                        if (c == 'a') {
491:                            X = "attributes";
492:                            id = Id_attributes;
493:                        } else if (c == 'c') {
494:                            X = "childIndex";
495:                            id = Id_childIndex;
496:                        }
497:                        break L;
498:                    case 11:
499:                        switch (s.charAt(0)) {
500:                        case 'a':
501:                            X = "appendChild";
502:                            id = Id_appendChild;
503:                            break L;
504:                        case 'c':
505:                            X = "constructor";
506:                            id = Id_constructor;
507:                            break L;
508:                        case 'd':
509:                            X = "descendants";
510:                            id = Id_descendants;
511:                            break L;
512:                        case 's':
513:                            X = "setChildren";
514:                            id = Id_setChildren;
515:                            break L;
516:                        case 't':
517:                            X = "toXMLString";
518:                            id = Id_toXMLString;
519:                            break L;
520:                        }
521:                        break L;
522:                    case 12:
523:                        switch (s.charAt(0)) {
524:                        case 'a':
525:                            X = "addNamespace";
526:                            id = Id_addNamespace;
527:                            break L;
528:                        case 'g':
529:                            X = "getXmlObject";
530:                            id = Id_getXmlObject;
531:                            break L;
532:                        case 'p':
533:                            X = "prependChild";
534:                            id = Id_prependChild;
535:                            break L;
536:                        case 's':
537:                            c = s.charAt(3);
538:                            if (c == 'L') {
539:                                X = "setLocalName";
540:                                id = Id_setLocalName;
541:                            } else if (c == 'N') {
542:                                X = "setNamespace";
543:                                id = Id_setNamespace;
544:                            }
545:                            break L;
546:                        }
547:                        break L;
548:                    case 14:
549:                        X = "hasOwnProperty";
550:                        id = Id_hasOwnProperty;
551:                        break L;
552:                    case 15:
553:                        X = "removeNamespace";
554:                        id = Id_removeNamespace;
555:                        break L;
556:                    case 16:
557:                        c = s.charAt(0);
558:                        if (c == 'h') {
559:                            X = "hasSimpleContent";
560:                            id = Id_hasSimpleContent;
561:                        } else if (c == 'i') {
562:                            X = "insertChildAfter";
563:                            id = Id_insertChildAfter;
564:                        }
565:                        break L;
566:                    case 17:
567:                        c = s.charAt(3);
568:                        if (c == 'C') {
569:                            X = "hasComplexContent";
570:                            id = Id_hasComplexContent;
571:                        } else if (c == 'c') {
572:                            X = "inScopeNamespaces";
573:                            id = Id_inScopeNamespaces;
574:                        } else if (c == 'e') {
575:                            X = "insertChildBefore";
576:                            id = Id_insertChildBefore;
577:                        }
578:                        break L;
579:                    case 20:
580:                        X = "propertyIsEnumerable";
581:                        id = Id_propertyIsEnumerable;
582:                        break L;
583:                    case 21:
584:                        X = "namespaceDeclarations";
585:                        id = Id_namespaceDeclarations;
586:                        break L;
587:                    case 22:
588:                        X = "processingInstructions";
589:                        id = Id_processingInstructions;
590:                        break L;
591:                    }
592:                    if (X != null && X != s && !X.equals(s))
593:                        id = 0;
594:                }
595:                // #/generated#
596:                return id;
597:            }
598:
599:            // #/string_id_map#
600:
601:            protected void initPrototypeId(int id) {
602:                String s;
603:                int arity;
604:                switch (id) {
605:                case Id_constructor: {
606:                    IdFunctionObject ctor;
607:                    if (this  instanceof  XML) {
608:                        ctor = new XMLCtor((XML) this , XMLOBJECT_TAG, id, 1);
609:                    } else {
610:                        ctor = new IdFunctionObject(this , XMLOBJECT_TAG, id, 1);
611:                    }
612:                    initPrototypeConstructor(ctor);
613:                    return;
614:                }
615:
616:                case Id_addNamespace:
617:                    arity = 1;
618:                    s = "addNamespace";
619:                    break;
620:                case Id_appendChild:
621:                    arity = 1;
622:                    s = "appendChild";
623:                    break;
624:                case Id_attribute:
625:                    arity = 1;
626:                    s = "attribute";
627:                    break;
628:                case Id_attributes:
629:                    arity = 0;
630:                    s = "attributes";
631:                    break;
632:                case Id_child:
633:                    arity = 1;
634:                    s = "child";
635:                    break;
636:                case Id_childIndex:
637:                    arity = 0;
638:                    s = "childIndex";
639:                    break;
640:                case Id_children:
641:                    arity = 0;
642:                    s = "children";
643:                    break;
644:                case Id_comments:
645:                    arity = 0;
646:                    s = "comments";
647:                    break;
648:                case Id_contains:
649:                    arity = 1;
650:                    s = "contains";
651:                    break;
652:                case Id_copy:
653:                    arity = 0;
654:                    s = "copy";
655:                    break;
656:                case Id_descendants:
657:                    arity = 1;
658:                    s = "descendants";
659:                    break;
660:                case Id_hasComplexContent:
661:                    arity = 0;
662:                    s = "hasComplexContent";
663:                    break;
664:                case Id_hasOwnProperty:
665:                    arity = 1;
666:                    s = "hasOwnProperty";
667:                    break;
668:                case Id_hasSimpleContent:
669:                    arity = 0;
670:                    s = "hasSimpleContent";
671:                    break;
672:                case Id_inScopeNamespaces:
673:                    arity = 0;
674:                    s = "inScopeNamespaces";
675:                    break;
676:                case Id_insertChildAfter:
677:                    arity = 2;
678:                    s = "insertChildAfter";
679:                    break;
680:                case Id_insertChildBefore:
681:                    arity = 2;
682:                    s = "insertChildBefore";
683:                    break;
684:                case Id_length:
685:                    arity = 0;
686:                    s = "length";
687:                    break;
688:                case Id_localName:
689:                    arity = 0;
690:                    s = "localName";
691:                    break;
692:                case Id_name:
693:                    arity = 0;
694:                    s = "name";
695:                    break;
696:                case Id_namespace:
697:                    arity = 1;
698:                    s = "namespace";
699:                    break;
700:                case Id_namespaceDeclarations:
701:                    arity = 0;
702:                    s = "namespaceDeclarations";
703:                    break;
704:                case Id_nodeKind:
705:                    arity = 0;
706:                    s = "nodeKind";
707:                    break;
708:                case Id_normalize:
709:                    arity = 0;
710:                    s = "normalize";
711:                    break;
712:                case Id_parent:
713:                    arity = 0;
714:                    s = "parent";
715:                    break;
716:                case Id_prependChild:
717:                    arity = 1;
718:                    s = "prependChild";
719:                    break;
720:                case Id_processingInstructions:
721:                    arity = 1;
722:                    s = "processingInstructions";
723:                    break;
724:                case Id_propertyIsEnumerable:
725:                    arity = 1;
726:                    s = "propertyIsEnumerable";
727:                    break;
728:                case Id_removeNamespace:
729:                    arity = 1;
730:                    s = "removeNamespace";
731:                    break;
732:                case Id_replace:
733:                    arity = 2;
734:                    s = "replace";
735:                    break;
736:                case Id_setChildren:
737:                    arity = 1;
738:                    s = "setChildren";
739:                    break;
740:                case Id_setLocalName:
741:                    arity = 1;
742:                    s = "setLocalName";
743:                    break;
744:                case Id_setName:
745:                    arity = 1;
746:                    s = "setName";
747:                    break;
748:                case Id_setNamespace:
749:                    arity = 1;
750:                    s = "setNamespace";
751:                    break;
752:                case Id_text:
753:                    arity = 0;
754:                    s = "text";
755:                    break;
756:                case Id_toString:
757:                    arity = 0;
758:                    s = "toString";
759:                    break;
760:                case Id_toSource:
761:                    arity = 1;
762:                    s = "toSource";
763:                    break;
764:                case Id_toXMLString:
765:                    arity = 1;
766:                    s = "toXMLString";
767:                    break;
768:                case Id_valueOf:
769:                    arity = 0;
770:                    s = "valueOf";
771:                    break;
772:
773:                case Id_getXmlObject:
774:                    arity = 0;
775:                    s = "getXmlObject";
776:                    break;
777:                default:
778:                    throw new IllegalArgumentException(String.valueOf(id));
779:                }
780:                initPrototypeMethod(XMLOBJECT_TAG, id, s, arity);
781:            }
782:
783:            /**
784:             *
785:             * @param f
786:             * @param cx
787:             * @param scope
788:             * @param thisObj
789:             * @param args
790:             * @return
791:             */
792:            public Object execIdCall(IdFunctionObject f, Context cx,
793:                    Scriptable scope, Scriptable this Obj, Object[] args) {
794:                if (!f.hasTag(XMLOBJECT_TAG)) {
795:                    return super .execIdCall(f, cx, scope, this Obj, args);
796:                }
797:                int id = f.methodId();
798:                if (id == Id_constructor) {
799:                    return jsConstructor(cx, this Obj == null, args);
800:                }
801:
802:                // All (XML|XMLList).prototype methods require thisObj to be XML
803:                if (!(this Obj instanceof  XMLObjectImpl))
804:                    throw incompatibleCallError(f);
805:                XMLObjectImpl realThis = (XMLObjectImpl) this Obj;
806:
807:                switch (id) {
808:                case Id_addNamespace: {
809:                    Namespace ns = lib.castToNamespace(cx, arg(args, 0));
810:                    return realThis.addNamespace(ns);
811:                }
812:                case Id_appendChild:
813:                    return realThis.appendChild(arg(args, 0));
814:                case Id_attribute: {
815:                    XMLName xmlName = lib.toAttributeName(cx, arg(args, 0));
816:                    return realThis.attribute(xmlName);
817:                }
818:                case Id_attributes:
819:                    return realThis.attributes();
820:                case Id_child: {
821:                    XMLName xmlName = lib.toXMLNameOrIndex(cx, arg(args, 0));
822:                    if (xmlName == null) {
823:                        long index = ScriptRuntime.lastUint32Result(cx);
824:                        return realThis.child(index);
825:                    } else {
826:                        return realThis.child(xmlName);
827:                    }
828:                }
829:                case Id_childIndex:
830:                    return ScriptRuntime.wrapInt(realThis.childIndex());
831:                case Id_children:
832:                    return realThis.children();
833:                case Id_comments:
834:                    return realThis.comments();
835:                case Id_contains:
836:                    return ScriptRuntime.wrapBoolean(realThis.contains(arg(
837:                            args, 0)));
838:                case Id_copy:
839:                    return realThis.copy();
840:                case Id_descendants: {
841:                    XMLName xmlName = (args.length == 0) ? XMLName.formStar()
842:                            : lib.toXMLName(cx, args[0]);
843:                    return realThis.descendants(xmlName);
844:                }
845:                case Id_inScopeNamespaces: {
846:                    Object[] array = realThis.inScopeNamespaces();
847:                    return cx.newArray(scope, array);
848:                }
849:                case Id_insertChildAfter:
850:                    return realThis
851:                            .insertChildAfter(arg(args, 0), arg(args, 1));
852:                case Id_insertChildBefore:
853:                    return realThis.insertChildBefore(arg(args, 0),
854:                            arg(args, 1));
855:                case Id_hasOwnProperty: {
856:                    XMLName xmlName = lib.toXMLName(cx, arg(args, 0));
857:                    return ScriptRuntime.wrapBoolean(realThis
858:                            .hasOwnProperty(xmlName));
859:                }
860:                case Id_hasComplexContent:
861:                    return ScriptRuntime.wrapBoolean(realThis
862:                            .hasComplexContent());
863:                case Id_hasSimpleContent:
864:                    return ScriptRuntime.wrapBoolean(realThis
865:                            .hasSimpleContent());
866:                case Id_length:
867:                    return ScriptRuntime.wrapInt(realThis.length());
868:                case Id_localName:
869:                    return realThis.localName();
870:                case Id_name:
871:                    return realThis.name();
872:                case Id_namespace: {
873:                    String prefix = (args.length > 0) ? ScriptRuntime
874:                            .toString(args[0]) : null;
875:                    return realThis.namespace(prefix);
876:                }
877:                case Id_namespaceDeclarations: {
878:                    Object[] array = realThis.namespaceDeclarations();
879:                    return cx.newArray(scope, array);
880:                }
881:                case Id_nodeKind:
882:                    return realThis.nodeKind();
883:                case Id_normalize:
884:                    realThis.normalize();
885:                    return Undefined.instance;
886:                case Id_parent:
887:                    return realThis.parent();
888:                case Id_prependChild:
889:                    return realThis.prependChild(arg(args, 0));
890:                case Id_processingInstructions: {
891:                    XMLName xmlName = (args.length > 0) ? lib.toXMLName(cx,
892:                            args[0]) : XMLName.formStar();
893:                    return realThis.processingInstructions(xmlName);
894:                }
895:                case Id_propertyIsEnumerable: {
896:                    return ScriptRuntime.wrapBoolean(realThis
897:                            .propertyIsEnumerable(arg(args, 0)));
898:                }
899:                case Id_removeNamespace: {
900:                    Namespace ns = lib.castToNamespace(cx, arg(args, 0));
901:                    return realThis.removeNamespace(ns);
902:                }
903:                case Id_replace: {
904:                    XMLName xmlName = lib.toXMLNameOrIndex(cx, arg(args, 0));
905:                    Object arg1 = arg(args, 1);
906:                    if (xmlName == null) {
907:                        long index = ScriptRuntime.lastUint32Result(cx);
908:                        return realThis.replace(index, arg1);
909:                    } else {
910:                        return realThis.replace(xmlName, arg1);
911:                    }
912:                }
913:                case Id_setChildren:
914:                    return realThis.setChildren(arg(args, 0));
915:                case Id_setLocalName: {
916:                    String localName;
917:                    Object arg = arg(args, 0);
918:                    if (arg instanceof  QName) {
919:                        localName = ((QName) arg).localName();
920:                    } else {
921:                        localName = ScriptRuntime.toString(arg);
922:                    }
923:                    realThis.setLocalName(localName);
924:                    return Undefined.instance;
925:                }
926:                case Id_setName: {
927:                    Object arg = (args.length != 0) ? args[0]
928:                            : Undefined.instance;
929:                    QName qname;
930:                    if (arg instanceof  QName) {
931:                        qname = (QName) arg;
932:                        if (qname.uri() == null) {
933:                            qname = lib.constructQNameFromString(cx, qname
934:                                    .localName());
935:                        } else {
936:                            // E4X 13.4.4.35 requires to always construct QName
937:                            qname = lib.constructQName(cx, qname);
938:                        }
939:                    } else {
940:                        qname = lib.constructQName(cx, arg);
941:                    }
942:                    realThis.setName(qname);
943:                    return Undefined.instance;
944:                }
945:                case Id_setNamespace: {
946:                    Namespace ns = lib.castToNamespace(cx, arg(args, 0));
947:                    realThis.setNamespace(ns);
948:                    return Undefined.instance;
949:                }
950:                case Id_text:
951:                    return realThis.text();
952:                case Id_toString:
953:                    return realThis.toString();
954:                case Id_toSource: {
955:                    int indent = ScriptRuntime.toInt32(args, 0);
956:                    return realThis.toSource(indent);
957:                }
958:                case Id_toXMLString: {
959:                    int indent = ScriptRuntime.toInt32(args, 0);
960:                    return realThis.toXMLString(indent);
961:                }
962:                case Id_valueOf:
963:                    return realThis.valueOf();
964:
965:                case Id_getXmlObject: {
966:                    org.apache.xmlbeans.XmlObject xmlObject = realThis
967:                            .getXmlObject();
968:                    return Context.javaToJS(xmlObject, scope);
969:                }
970:                }
971:                throw new IllegalArgumentException(String.valueOf(id));
972:            }
973:
974:            private static Object arg(Object[] args, int i) {
975:                return (i < args.length) ? args[i] : Undefined.instance;
976:            }
977:
978:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.