Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 2007 Esmertec AG.
      3  * Copyright (C) 2007 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mms.dom;
     19 
     20 import java.util.Vector;
     21 
     22 import org.w3c.dom.DOMException;
     23 import org.w3c.dom.NamedNodeMap;
     24 import org.w3c.dom.Node;
     25 
     26 public class NamedNodeMapImpl implements NamedNodeMap {
     27 
     28     private Vector<Node> mNodes = new Vector<Node>();
     29 
     30     public int getLength() {
     31         return mNodes.size();
     32     }
     33 
     34     public Node getNamedItem(String name) {
     35         Node node = null;
     36         for (int i = 0; i < mNodes.size(); i++) {
     37             if (name.equals(mNodes.elementAt(i).getNodeName())) {
     38                 node = mNodes.elementAt(i);
     39                 break;
     40             }
     41         }
     42         return node;
     43     }
     44 
     45     public Node getNamedItemNS(String namespaceURI, String localName) {
     46         // TODO Auto-generated method stub
     47         return null;
     48     }
     49 
     50     public Node item(int index) {
     51         if (index < mNodes.size()) {
     52             return mNodes.elementAt(index);
     53         }
     54         return null;
     55     }
     56 
     57     public Node removeNamedItem(String name) throws DOMException {
     58         Node node = getNamedItem(name);
     59         if (node == null) {
     60             throw new DOMException(DOMException.NOT_FOUND_ERR, "Not found");
     61         } else {
     62             mNodes.remove(node);
     63         }
     64         return node;
     65     }
     66 
     67     public Node removeNamedItemNS(String namespaceURI, String localName)
     68             throws DOMException {
     69         // TODO Auto-generated method stub
     70         return null;
     71     }
     72 
     73     public Node setNamedItem(Node arg) throws DOMException {
     74         Node existing = getNamedItem(arg.getNodeName());
     75         if (existing != null) {
     76             mNodes.remove(existing);
     77         }
     78         mNodes.add(arg);
     79         return existing;
     80     }
     81 
     82     public Node setNamedItemNS(Node arg) throws DOMException {
     83         // TODO Auto-generated method stub
     84         return null;
     85     }
     86 
     87 }
     88