Package org.mozilla.javascript

Examples of org.mozilla.javascript.Wrapper


     *  interface, the getPrototype method will be used to retrieve the name of the prototype
     * to use. Otherwise, a Java-Class-to-Script-Prototype mapping is consulted.
     */
    public Scriptable getElementWrapper(Object e) {
        WeakReference ref = (WeakReference) wrappercache.get(e);
        Wrapper wrapper = ref == null ? null : (Wrapper) ref.get();

        if (wrapper == null || wrapper.unwrap() != e) {
            // Gotta find out the prototype name to use for this object...
            String prototypeName = app.getPrototypeName(e);
            Scriptable op = getPrototype(prototypeName);

            if (op == null) {
View Full Code Here


                // if wrong type
                Scriptable s = (Scriptable)jsResp;
                Object out = ScriptableObject.callMethod(s,
                                                         "getXmlObject",
                                                         Context.emptyArgs);
                Wrapper wrapped = (Wrapper)out;
                XmlObject xml = (XmlObject)wrapped.unwrap();
                node = xml.getDomNode();
                response.setNode(node.getOwnerDocument());
            } else {
                if (jsResp instanceof Wrapper) {
                    jsResp = ((Wrapper)jsResp).unwrap();
View Full Code Here

            return super.fromScript(o);
        }

        // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost???
        Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
        Wrapper wrapper = (Wrapper) ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
        XmlObject xmlObject = (XmlObject)wrapper.unwrap();
        try {

            StAXOMBuilder builder = new StAXOMBuilder(xmlObject.newInputStream());
            OMElement omElement = builder.getDocumentElement();
View Full Code Here

        }

        // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost???
        Scriptable jsXML =
            (Scriptable) ScriptableObject.callMethod((Scriptable) scriptXML, "copy", new Object[0]);
        Wrapper wrapper =
            (Wrapper) ScriptableObject.callMethod(jsXML, "getXmlObject", new Object[0]);

        XmlObject xmlObject = (XmlObject) wrapper.unwrap();

        try {
            StAXOMBuilder builder = new StAXOMBuilder(xmlObject.newInputStream());
            return builder.getDocumentElement();
View Full Code Here

    * But, at the same time, we need to make few special cases
    * and hence the following function is used.
    */
    private Object jsToJava(Object jsObj) {
        if (jsObj instanceof Wrapper) {
            Wrapper njb = (Wrapper) jsObj;
            /* importClass feature of ImporterTopLevel puts
             * NativeJavaClass in global scope. If we unwrap
             * it, importClass won't work.
             */
            if (njb instanceof NativeJavaClass) {
                return njb;
            }

            /* script may use Java primitive wrapper type objects
             * (such as java.lang.Integer, java.lang.Boolean etc)
             * explicitly. If we unwrap, then these script objects
             * will become script primitive types. For example,
             *
             *    var x = new java.lang.Double(3.0); print(typeof x);
             *
             * will print 'number'. We don't want that to happen.
             */
            Object obj = njb.unwrap();
            if (obj instanceof Number || obj instanceof String ||
                obj instanceof Boolean || obj instanceof Character) {
                // special type wrapped -- we just leave it as is.
                return njb;
            } else {
View Full Code Here

     * @throws SAXException
     */
    private void xmlObjectToSax
        (SAXEventBufferImpl seb, XMLObject xmlObj, boolean fragment)
        throws SAXException {
        Wrapper wrap = (Wrapper) ScriptableObject.callMethod
            ((XMLObject)xmlObj, "getXmlObject", new Object[0]);
        XmlObject result = (XmlObject) wrap.unwrap();
        XmlCursor cursor = result.newCursor();
        result = cursor.getObject();
        ContentHandler ch = new NamespaceAttributesFilter(seb);
        if (fragment) {
            ch = new BodyFilter (ch);
View Full Code Here

     * @throws SAXException
     */
    private void xmlObjectToSax
        (SAXEventBufferImpl seb, XMLObject xmlObj, boolean fragment)
        throws SAXException {
        Wrapper wrap = (Wrapper) ScriptableObject.callMethod
            ((XMLObject)xmlObj, "getXmlObject", new Object[0]);
        XmlObject result = (XmlObject) wrap.unwrap();
        XmlCursor cursor = result.newCursor();
        result = cursor.getObject();
        ContentHandler ch = seb;
        if (fragment) {
            ch = new BodyFilter (ch);
View Full Code Here

            return super.fromScript(o);
        }

        // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost. See Mozilla bugzilla 361722
        Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
        Wrapper wrapper = (Wrapper) ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
        XmlObject xmlObject = (XmlObject)wrapper.unwrap();
        try {

            StAXOMBuilder builder = new StAXOMBuilder(xmlObject.newInputStream());
            OMElement omElement = builder.getDocumentElement();
View Full Code Here

        if (Context.getUndefinedValue().equals(o)) {
            response = null;
        } else if (o instanceof XMLObject) {
            // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost???
            Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
            Wrapper wrapper = (Wrapper) ScriptableObject.callMethod(jsXML, "getXmlObject", new Object[0]);
            response = wrapper.unwrap();
           
            XMLStreamReader xmlReader =
                StAXUtils.createXMLStreamReader(new ByteArrayInputStream(response.toString().getBytes()));
            StAXOMBuilder staxOMBuilder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), xmlReader);
            response = staxOMBuilder.getDocumentElement();
View Full Code Here

        if (Context.getUndefinedValue().equals(jsArg)) {
            javaArg = null;
        } else if (jsArg instanceof XMLObject) {
            // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost???
            Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) jsArg, "copy", new Object[0]);
            Wrapper wrapper = (Wrapper) ScriptableObject.callMethod(jsXML, "getXmlObject", new Object[0]);
            javaArg = wrapper.unwrap();

            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(javaArg.toString().getBytes()));
            StAXOMBuilder staxOMBuilder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), xmlReader);
            javaArg = staxOMBuilder.getDocumentElement();
        } else if (jsArg instanceof Wrapper) {
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Wrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.