alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Apache CXF example source code file (JsNamedNodeMap.java)

This example Apache CXF source code file (JsNamedNodeMap.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Apache CXF tags/keywords

context, dom, illegalaccessexception, instantiationexception, jsnamednodemap, jsnamednodemap, namednodemap, namednodemap, object, object, override, reflection, runtimeexception, runtimeexception, scriptableobject, string

The Apache CXF JsNamedNodeMap.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cxf.javascript;

import java.lang.reflect.InvocationTargetException;

import org.w3c.dom.NamedNodeMap;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

/**
 * 
 */
public class JsNamedNodeMap extends ScriptableObject {
    
    private NamedNodeMap wrappedMap;
    
    public JsNamedNodeMap() {
        // just to make Rhino happy.
    }
    
    @Override
    public String getClassName() {
        return "NamedNodeMap";
    }
    
    public static void register(ScriptableObject scope) {
        try {
            ScriptableObject.defineClass(scope, JsNamedNodeMap.class);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

    /** * @return Returns the wrappedMap.
     */
    public NamedNodeMap getWrappedMap() {
        return wrappedMap;
    }

    /**
     * @param wrappedMap The wrappedMap to set.
     */
    public void setWrappedMap(NamedNodeMap wrappedMap) {
        this.wrappedMap = wrappedMap;
    }
    
    // Rhino won't let us use a constructor.
    void initialize(NamedNodeMap map) {
        wrappedMap = map;
    }
    
    public static JsNamedNodeMap wrapMap(Scriptable scope, NamedNodeMap map) {
        Context cx = ContextFactory.getGlobal().enterContext();
        JsNamedNodeMap newObject = (JsNamedNodeMap)cx.newObject(scope, "NamedNodeMap");
        newObject.initialize(map);
        return newObject;
    }

    // CHECKSTYLE:OFF
    
    public int jsGet_length() {
        return wrappedMap.getLength();
    }
    
    public Object jsFunction_getNamedItem(String name) {
        return JsSimpleDomNode.wrapNode(getParentScope(), wrappedMap.getNamedItem(name));
    }
    
    public Object jsFunction_getNamedItemNS(String uri, String local) {
        return JsSimpleDomNode.wrapNode(getParentScope(), wrappedMap.getNamedItemNS(uri, local));
    }

    public Object jsFunction_item(int index) {
        return JsSimpleDomNode.wrapNode(getParentScope(), wrappedMap.item(index));
    }
    
    // don't implement the 'modify' APIs.
}

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF JsNamedNodeMap.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.