KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > dtm > ref > DTMNodeProxy


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: DTMNodeProxy.java,v
18  */

19 package com.sun.org.apache.xml.internal.dtm.ref;
20
21 import com.sun.org.apache.xml.internal.dtm.DTM;
22 import com.sun.org.apache.xml.internal.dtm.DTMDOMException;
23
24 import org.w3c.dom.Attr JavaDoc;
25 import org.w3c.dom.CDATASection JavaDoc;
26 import org.w3c.dom.Comment JavaDoc;
27 import org.w3c.dom.DOMException JavaDoc;
28 import org.w3c.dom.DOMImplementation JavaDoc;
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.DocumentFragment JavaDoc;
31 import org.w3c.dom.DocumentType JavaDoc;
32 import org.w3c.dom.Element JavaDoc;
33 import org.w3c.dom.EntityReference JavaDoc;
34 import org.w3c.dom.NamedNodeMap JavaDoc;
35 import org.w3c.dom.Node JavaDoc;
36 import org.w3c.dom.NodeList JavaDoc;
37 import org.w3c.dom.ProcessingInstruction JavaDoc;
38 import org.w3c.dom.Text JavaDoc;
39
40 import org.w3c.dom.UserDataHandler JavaDoc;
41 import org.w3c.dom.DOMConfiguration JavaDoc;
42
43 import org.w3c.dom.TypeInfo JavaDoc;
44
45 /**
46  * <meta name="usage" content="internal"/>
47  * <code>DTMNodeProxy</code> presents a DOM Node API front-end to the DTM model.
48  * <p>
49  * It does _not_ attempt to address the "node identity" question; no effort
50  * is made to prevent the creation of multiple proxies referring to a single
51  * DTM node. Users can create a mechanism for managing this, or relinquish the
52  * use of "==" and use the .sameNodeAs() mechanism, which is under
53  * consideration for future versions of the DOM.
54  * <p>
55  * DTMNodeProxy may be subclassed further to present specific DOM node types.
56  *
57  * @see org.w3c.dom
58  */

59 public class DTMNodeProxy
60   implements Node JavaDoc, Document JavaDoc, Text JavaDoc, Element JavaDoc, Attr JavaDoc,
61                    ProcessingInstruction JavaDoc, Comment JavaDoc, DocumentFragment JavaDoc
62 {
63
64   /** The DTM for this node. */
65   public DTM dtm;
66
67   /** The DTM node handle. */
68   int node;
69         
70   /** The DOMImplementation object */
71   static final DOMImplementation JavaDoc implementation=new DTMNodeProxyImplementation();
72
73   /**
74    * Create a DTMNodeProxy Node representing a specific Node in a DTM
75    *
76    * @param dtm The DTM Reference, must be non-null.
77    * @param node The DTM node handle.
78    */

79   public DTMNodeProxy(DTM dtm, int node)
80   {
81     this.dtm = dtm;
82     this.node = node;
83   }
84
85   /**
86    * NON-DOM: Return the DTM model
87    *
88    * @return The DTM that this proxy is a representative for.
89    */

90   public final DTM getDTM()
91   {
92     return dtm;
93   }
94
95   /**
96    * NON-DOM: Return the DTM node number
97    *
98    * @return The DTM node handle.
99    */

100   public final int getDTMNodeNumber()
101   {
102     return node;
103   }
104
105   /**
106    * Test for equality based on node number.
107    *
108    * @param node A DTM node proxy reference.
109    *
110    * @return true if the given node has the same handle as this node.
111    */

112   public final boolean equals(Node JavaDoc node)
113   {
114
115     try
116     {
117       DTMNodeProxy dtmp = (DTMNodeProxy) node;
118
119       // return (dtmp.node == this.node);
120
// Patch attributed to Gary L Peskin <garyp@firstech.com>
121
return (dtmp.node == this.node) && (dtmp.dtm == this.dtm);
122     }
123     catch (ClassCastException JavaDoc cce)
124     {
125       return false;
126     }
127   }
128
129   /**
130    * Test for equality based on node number.
131    *
132    * @param node A DTM node proxy reference.
133    *
134    * @return true if the given node has the same handle as this node.
135    */

136   public final boolean equals(Object JavaDoc node)
137   {
138
139     try
140     {
141
142       // DTMNodeProxy dtmp = (DTMNodeProxy)node;
143
// return (dtmp.node == this.node);
144
// Patch attributed to Gary L Peskin <garyp@firstech.com>
145
return equals((Node JavaDoc) node);
146     }
147     catch (ClassCastException JavaDoc cce)
148     {
149       return false;
150     }
151   }
152
153   /**
154    * FUTURE DOM: Test node identity, in lieu of Node==Node
155    *
156    * @param other
157    *
158    * @return true if the given node has the same handle as this node.
159    */

160   public final boolean sameNodeAs(Node JavaDoc other)
161   {
162
163     if (!(other instanceof DTMNodeProxy))
164       return false;
165
166     DTMNodeProxy that = (DTMNodeProxy) other;
167
168     return this.dtm == that.dtm && this.node == that.node;
169   }
170
171   /**
172    *
173    * @return
174    * @see org.w3c.dom.Node
175    */

176   public final String JavaDoc getNodeName()
177   {
178     return dtm.getNodeName(node);
179   }
180
181   /**
182    * A PI's "target" states what processor channel the PI's data
183    * should be directed to. It is defined differently in HTML and XML.
184    * <p>
185    * In XML, a PI's "target" is the first (whitespace-delimited) token
186    * following the "<?" token that begins the PI.
187    * <p>
188    * In HTML, target is always null.
189    * <p>
190    * Note that getNodeName is aliased to getTarget.
191    *
192    * @return
193    */

194   public final String JavaDoc getTarget()
195   {
196     return dtm.getNodeName(node);
197   } // getTarget():String
198

199   /**
200    *
201    * @return
202    * @see org.w3c.dom.Node as of DOM Level 2
203    */

204   public final String JavaDoc getLocalName()
205   {
206     return dtm.getLocalName(node);
207   }
208
209   /**
210    * @return The prefix for this node.
211    * @see org.w3c.dom.Node as of DOM Level 2
212    */

213   public final String JavaDoc getPrefix()
214   {
215     return dtm.getPrefix(node);
216   }
217
218   /**
219    *
220    * @param prefix
221    *
222    * @throws DOMException
223    * @see org.w3c.dom.Node as of DOM Level 2 -- DTMNodeProxy is read-only
224    */

225   public final void setPrefix(String JavaDoc prefix) throws DOMException
226   {
227     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
228   }
229
230   /**
231    *
232    * @return
233    * @see org.w3c.dom.Node as of DOM Level 2
234    */

235   public final String JavaDoc getNamespaceURI()
236   {
237     return dtm.getNamespaceURI(node);
238   }
239
240   /** Ask whether we support a given DOM feature.
241    * In fact, we do not _fully_ support any DOM feature -- we're a
242    * read-only subset -- so arguably we should always return false.
243    * Or we could say that we support DOM Core Level 2 but all nodes
244    * are read-only. Unclear which answer is least misleading.
245    *
246    * NON-DOM method. This was present in early drafts of DOM Level 2,
247    * but was renamed isSupported. It's present here only because it's
248    * cheap, harmless, and might help some poor fool who is still trying
249    * to use an early Working Draft of the DOM.
250    *
251    * @param feature
252    * @param version
253    *
254    * @return false
255    */

256   public final boolean supports(String JavaDoc feature, String JavaDoc version)
257   {
258     return implementation.hasFeature(feature,version);
259     //throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
260
}
261
262   /** Ask whether we support a given DOM feature.
263    * In fact, we do not _fully_ support any DOM feature -- we're a
264    * read-only subset -- so arguably we should always return false.
265    *
266    * @param feature
267    * @param version
268    *
269    * @return false
270    * @see org.w3c.dom.Node as of DOM Level 2
271    */

272   public final boolean isSupported(String JavaDoc feature, String JavaDoc version)
273   {
274     return implementation.hasFeature(feature,version);
275     // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
276
}
277
278   /**
279    *
280    * @return
281    *
282    * @throws DOMException
283    * @see org.w3c.dom.Node
284    */

285   public final String JavaDoc getNodeValue() throws DOMException
286   {
287     return dtm.getNodeValue(node);
288   }
289   
290   /**
291    * @return The string value of the node
292    *
293    * @throws DOMException
294    */

295   public final String JavaDoc getStringValue() throws DOMException
296   {
297     return dtm.getStringValue(node).toString();
298   }
299
300   /**
301    *
302    * @param nodeValue
303    *
304    * @throws DOMException
305    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
306    */

307   public final void setNodeValue(String JavaDoc nodeValue) throws DOMException
308   {
309     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
310   }
311
312   /**
313    *
314    * @return
315    * @see org.w3c.dom.Node
316    */

317   public final short getNodeType()
318   {
319     return (short) dtm.getNodeType(node);
320   }
321
322   /**
323    *
324    * @return
325    * @see org.w3c.dom.Node
326    */

327   public final Node JavaDoc getParentNode()
328   {
329
330     if (getNodeType() == Node.ATTRIBUTE_NODE)
331       return null;
332
333     int newnode = dtm.getParent(node);
334
335     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
336   }
337
338   /**
339    *
340    * @return
341    * @see org.w3c.dom.Node
342    */

343   public final Node JavaDoc getOwnerNode()
344   {
345
346     int newnode = dtm.getParent(node);
347
348     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
349   }
350
351   /**
352    *
353    * @return
354    * @see org.w3c.dom.Node
355    */

356   public final NodeList JavaDoc getChildNodes()
357   {
358                 
359     // Annoyingly, AxisIterators do not currently implement DTMIterator, so
360
// we can't just wap DTMNodeList around an Axis.CHILD iterator.
361
// Instead, we've created a special-case operating mode for that object.
362
return new DTMChildIterNodeList(dtm,node);
363
364     // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
365
}
366
367   /**
368    *
369    * @return
370    * @see org.w3c.dom.Node
371    */

372   public final Node JavaDoc getFirstChild()
373   {
374
375     int newnode = dtm.getFirstChild(node);
376
377     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
378   }
379
380   /**
381    *
382    * @return
383    * @see org.w3c.dom.Node
384    */

385   public final Node JavaDoc getLastChild()
386   {
387
388     int newnode = dtm.getLastChild(node);
389
390     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
391   }
392
393   /**
394    *
395    * @return
396    * @see org.w3c.dom.Node
397    */

398   public final Node JavaDoc getPreviousSibling()
399   {
400
401     int newnode = dtm.getPreviousSibling(node);
402
403     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
404   }
405
406   /**
407    *
408    * @return
409    * @see org.w3c.dom.Node
410    */

411   public final Node JavaDoc getNextSibling()
412   {
413
414     // Attr's Next is defined at DTM level, but not at DOM level.
415
if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE)
416       return null;
417
418     int newnode = dtm.getNextSibling(node);
419
420     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
421   }
422
423   // DTMNamedNodeMap m_attrs;
424

425   /**
426    *
427    * @return
428    * @see org.w3c.dom.Node
429    */

430   public final NamedNodeMap JavaDoc getAttributes()
431   {
432
433     return new DTMNamedNodeMap(dtm, node);
434   }
435
436   /**
437    * Method hasAttribute
438    *
439    *
440    * @param name
441    *
442    * (hasAttribute) @return
443    */

444   public boolean hasAttribute(String JavaDoc name)
445   {
446     return DTM.NULL != dtm.getAttributeNode(node,null,name);
447   }
448
449   /**
450    * Method hasAttributeNS
451    *
452    *
453    * @param name
454    * @param x
455    *
456    * (hasAttributeNS) @return
457    */

458   public boolean hasAttributeNS(String JavaDoc name, String JavaDoc x)
459   {
460     return DTM.NULL != dtm.getAttributeNode(node,x,name);
461   }
462
463   /**
464    *
465    * @return
466    * @see org.w3c.dom.Node
467    */

468   public final Document JavaDoc getOwnerDocument()
469   {
470     // Note that this uses the DOM-compatable version of the call
471
return (Document JavaDoc)(dtm.getNode(dtm.getOwnerDocument(node)));
472   }
473
474   /**
475    *
476    * @param newChild
477    * @param refChild
478    *
479    * @return
480    *
481    * @throws DOMException
482    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
483    */

484   public final Node JavaDoc insertBefore(Node JavaDoc newChild, Node JavaDoc refChild)
485     throws DOMException
486   {
487     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
488   }
489
490   /**
491    *
492    * @param newChild
493    * @param oldChild
494    *
495    * @return
496    *
497    * @throws DOMException
498    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
499    */

500   public final Node JavaDoc replaceChild(Node JavaDoc newChild, Node JavaDoc oldChild)
501     throws DOMException
502   {
503     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
504   }
505
506   /**
507    *
508    * @param oldChild
509    *
510    * @return
511    *
512    * @throws DOMException
513    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
514    */

515   public final Node JavaDoc removeChild(Node JavaDoc oldChild) throws DOMException
516   {
517     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
518   }
519
520   /**
521    *
522    * @param newChild
523    *
524    * @return
525    *
526    * @throws DOMException
527    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
528    */

529   public final Node JavaDoc appendChild(Node JavaDoc newChild) throws DOMException
530   {
531     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
532   }
533
534   /**
535    *
536    * @return
537    * @see org.w3c.dom.Node
538    */

539   public final boolean hasChildNodes()
540   {
541     return (DTM.NULL != dtm.getFirstChild(node));
542   }
543
544   /**
545    *
546    * @param deep
547    *
548    * @return
549    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
550    */

551   public final Node JavaDoc cloneNode(boolean deep)
552   {
553     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
554   }
555
556   /**
557    *
558    * @return
559    * @see org.w3c.dom.Document
560    */

561   public final DocumentType JavaDoc getDoctype()
562   {
563     return null;
564   }
565
566   /**
567    *
568    * @return
569    * @see org.w3c.dom.Document
570    */

571   public final DOMImplementation JavaDoc getImplementation()
572   {
573     return implementation;
574   }
575
576   /** This is a bit of a problem in DTM, since a DTM may be a Document
577    * Fragment and hence not have a clear-cut Document Element. We can
578    * make it work in the well-formed cases but would that be confusing for others?
579    *
580    * @return
581    * @see org.w3c.dom.Document
582    */

583   public final Element JavaDoc getDocumentElement()
584   {
585         int dochandle=dtm.getDocument();
586         int elementhandle=DTM.NULL;
587         for(int kidhandle=dtm.getFirstChild(dochandle);
588                 kidhandle!=DTM.NULL;
589                 kidhandle=dtm.getNextSibling(kidhandle))
590         {
591             switch(dtm.getNodeType(kidhandle))
592             {
593             case Node.ELEMENT_NODE:
594                 if(elementhandle!=DTM.NULL)
595                 {
596                     elementhandle=DTM.NULL; // More than one; ill-formed.
597
kidhandle=dtm.getLastChild(dochandle); // End loop
598
}
599                 else
600                     elementhandle=kidhandle;
601                 break;
602                 
603             // These are harmless; document is still wellformed
604
case Node.COMMENT_NODE:
605             case Node.PROCESSING_INSTRUCTION_NODE:
606             case Node.DOCUMENT_TYPE_NODE:
607                 break;
608                     
609             default:
610                 elementhandle=DTM.NULL; // ill-formed
611
kidhandle=dtm.getLastChild(dochandle); // End loop
612
break;
613             }
614         }
615         if(elementhandle==DTM.NULL)
616             throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
617         else
618             return (Element JavaDoc)(dtm.getNode(elementhandle));
619   }
620
621   /**
622    *
623    * @param tagName
624    *
625    * @return
626    *
627    * @throws DOMException
628    * @see org.w3c.dom.Document
629    */

630   public final Element JavaDoc createElement(String JavaDoc tagName) throws DOMException
631   {
632     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
633   }
634
635   /**
636    *
637    * @return
638    * @see org.w3c.dom.Document
639    */

640   public final DocumentFragment JavaDoc createDocumentFragment()
641   {
642     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
643   }
644
645   /**
646    *
647    * @param data
648    *
649    * @return
650    * @see org.w3c.dom.Document
651    */

652   public final Text JavaDoc createTextNode(String JavaDoc data)
653   {
654     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
655   }
656
657   /**
658    *
659    * @param data
660    *
661    * @return
662    * @see org.w3c.dom.Document
663    */

664   public final Comment JavaDoc createComment(String JavaDoc data)
665   {
666     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
667   }
668
669   /**
670    *
671    * @param data
672    *
673    * @return
674    *
675    * @throws DOMException
676    * @see org.w3c.dom.Document
677    */

678   public final CDATASection JavaDoc createCDATASection(String JavaDoc data)
679     throws DOMException
680   {
681     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
682   }
683
684   /**
685    *
686    * @param target
687    * @param data
688    *
689    * @return
690    *
691    * @throws DOMException
692    * @see org.w3c.dom.Document
693    */

694   public final ProcessingInstruction JavaDoc createProcessingInstruction(
695                                                                  String JavaDoc target, String JavaDoc data) throws DOMException
696   {
697     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
698   }
699
700   /**
701    *
702    * @param name
703    *
704    * @return
705    *
706    * @throws DOMException
707    * @see org.w3c.dom.Document
708    */

709   public final Attr JavaDoc createAttribute(String JavaDoc name) throws DOMException
710   {
711     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
712   }
713
714   /**
715    *
716    * @param name
717    *
718    * @return
719    *
720    * @throws DOMException
721    * @see org.w3c.dom.Document
722    */

723   public final EntityReference JavaDoc createEntityReference(String JavaDoc name)
724     throws DOMException
725   {
726     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
727   }
728
729   /**
730    *
731    * @param tagname
732    *
733    * @return
734    * @see org.w3c.dom.Document
735    */

736   public final NodeList JavaDoc getElementsByTagName(String JavaDoc tagname)
737   {
738     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
739   }
740
741   /**
742    *
743    * @param importedNode
744    * @param deep
745    *
746    * @return
747    *
748    * @throws DOMException
749    * @see org.w3c.dom.Document as of DOM Level 2 -- DTMNodeProxy is read-only
750    */

751   public final Node JavaDoc importNode(Node JavaDoc importedNode, boolean deep)
752     throws DOMException
753   {
754     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
755   }
756
757   /**
758    *
759    * @param namespaceURI
760    * @param qualifiedName
761    *
762    * @return
763    *
764    * @throws DOMException
765    * @see org.w3c.dom.Document as of DOM Level 2
766    */

767   public final Element JavaDoc createElementNS(
768                                        String JavaDoc namespaceURI, String JavaDoc qualifiedName) throws DOMException
769   {
770     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
771   }
772
773   /**
774    *
775    * @param namespaceURI
776    * @param qualifiedName
777    *
778    * @return
779    *
780    * @throws DOMException
781    * @see org.w3c.dom.Document as of DOM Level 2
782    */

783   public final Attr JavaDoc createAttributeNS(
784                                       String JavaDoc namespaceURI, String JavaDoc qualifiedName) throws DOMException
785   {
786     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
787   }
788
789   /**
790    *
791    * @param namespaceURI
792    * @param localName
793    *
794    * @return
795    * @see org.w3c.dom.Document as of DOM Level 2
796    */

797   public final NodeList JavaDoc getElementsByTagNameNS(String JavaDoc namespaceURI,
798                                                String JavaDoc localName)
799   {
800     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
801   }
802
803   /**
804    *
805    * @param elementId
806    *
807    * @return
808    * @see org.w3c.dom.Document as of DOM Level 2
809    */

810   public final Element JavaDoc getElementById(String JavaDoc elementId)
811   {
812     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
813   }
814
815   /**
816    *
817    * @param offset
818    *
819    * @return
820    *
821    * @throws DOMException
822    * @see org.w3c.dom.Text
823    */

824   public final Text JavaDoc splitText(int offset) throws DOMException
825   {
826     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
827   }
828
829   /**
830    *
831    * @return
832    *
833    * @throws DOMException
834    * @see org.w3c.dom.CharacterData
835    */

836   public final String JavaDoc getData() throws DOMException
837   {
838     return dtm.getNodeValue(node);
839   }
840
841   /**
842    *
843    * @param data
844    *
845    * @throws DOMException
846    * @see org.w3c.dom.CharacterData
847    */

848   public final void setData(String JavaDoc data) throws DOMException
849   {
850     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
851   }
852
853   /**
854    *
855    * @return
856    * @see org.w3c.dom.CharacterData
857    */

858   public final int getLength()
859   {
860     // %OPT% This should do something smarter?
861
return dtm.getNodeValue(node).length();
862   }
863
864   /**
865    *
866    * @param offset
867    * @param count
868    *
869    * @return
870    *
871    * @throws DOMException
872    * @see org.w3c.dom.CharacterData
873    */

874   public final String JavaDoc substringData(int offset, int count) throws DOMException
875   {
876     return getData().substring(offset,offset+count);
877   }
878
879   /**
880    *
881    * @param arg
882    *
883    * @throws DOMException
884    * @see org.w3c.dom.CharacterData
885    */

886   public final void appendData(String JavaDoc arg) throws DOMException
887   {
888     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
889   }
890
891   /**
892    *
893    * @param offset
894    * @param arg
895    *
896    * @throws DOMException
897    * @see org.w3c.dom.CharacterData
898    */

899   public final void insertData(int offset, String JavaDoc arg) throws DOMException
900   {
901     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
902   }
903
904   /**
905    *
906    * @param offset
907    * @param count
908    *
909    * @throws DOMException
910    * @see org.w3c.dom.CharacterData
911    */

912   public final void deleteData(int offset, int count) throws DOMException
913   {
914     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
915   }
916
917   /**
918    *
919    * @param offset
920    * @param count
921    * @param arg
922    *
923    * @throws DOMException
924    * @see org.w3c.dom.CharacterData
925    */

926   public final void replaceData(int offset, int count, String JavaDoc arg)
927     throws DOMException
928   {
929     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
930   }
931
932   /**
933    *
934    * @return
935    * @see org.w3c.dom.Element
936    */

937   public final String JavaDoc getTagName()
938   {
939     return dtm.getNodeName(node);
940   }
941
942   /**
943    *
944    * @param name
945    *
946    * @return
947    * @see org.w3c.dom.Element
948    */

949   public final String JavaDoc getAttribute(String JavaDoc name)
950   {
951
952     DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
953     Node JavaDoc node = map.getNamedItem(name);
954     return (null == node) ? null : node.getNodeValue();
955   }
956
957   /**
958    *
959    * @param name
960    * @param value
961    *
962    * @throws DOMException
963    * @see org.w3c.dom.Element
964    */

965   public final void setAttribute(String JavaDoc name, String JavaDoc value)
966     throws DOMException
967   {
968     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
969   }
970
971   /**
972    *
973    * @param name
974    *
975    * @throws DOMException
976    * @see org.w3c.dom.Element
977    */

978   public final void removeAttribute(String JavaDoc name) throws DOMException
979   {
980     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
981   }
982
983   /**
984    *
985    * @param name
986    *
987    * @return
988    * @see org.w3c.dom.Element
989    */

990   public final Attr JavaDoc getAttributeNode(String JavaDoc name)
991   {
992
993     DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
994     return (Attr JavaDoc)map.getNamedItem(name);
995   }
996
997   /**
998    *
999    * @param newAttr
1000   *
1001   * @return
1002   *
1003   * @throws DOMException
1004   * @see org.w3c.dom.Element
1005   */

1006  public final Attr JavaDoc setAttributeNode(Attr JavaDoc newAttr) throws DOMException
1007  {
1008    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1009  }
1010
1011  /**
1012   *
1013   * @param oldAttr
1014   *
1015   * @return
1016   *
1017   * @throws DOMException
1018   * @see org.w3c.dom.Element
1019   */

1020  public final Attr JavaDoc removeAttributeNode(Attr JavaDoc oldAttr) throws DOMException
1021  {
1022    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1023  }
1024
1025  /**
1026   * Introduced in DOM Level 2.
1027   *
1028   * @return
1029   */

1030  public boolean hasAttributes()
1031  {
1032    return DTM.NULL != dtm.getFirstAttribute(node);
1033  }
1034
1035  /** @see org.w3c.dom.Element */
1036  public final void normalize()
1037  {
1038    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1039  }
1040
1041  /**
1042   *
1043   * @param namespaceURI
1044   * @param localName
1045   *
1046   * @return
1047   * @see org.w3c.dom.Element
1048   */

1049  public final String JavaDoc getAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName)
1050  {
1051    DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
1052    Node JavaDoc node = map.getNamedItemNS(namespaceURI,localName);
1053    return (null == node) ? null : node.getNodeValue();
1054  }
1055
1056  /**
1057   *
1058   * @param namespaceURI
1059   * @param qualifiedName
1060   * @param value
1061   *
1062   * @throws DOMException
1063   * @see org.w3c.dom.Element
1064   */

1065  public final void setAttributeNS(
1066                                   String JavaDoc namespaceURI, String JavaDoc qualifiedName, String JavaDoc value)
1067    throws DOMException
1068  {
1069    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1070  }
1071
1072  /**
1073   *
1074   * @param namespaceURI
1075   * @param localName
1076   *
1077   * @throws DOMException
1078   * @see org.w3c.dom.Element
1079   */

1080  public final void removeAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName)
1081    throws DOMException
1082  {
1083    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1084  }
1085
1086  /**
1087   *
1088   * @param namespaceURI
1089   * @param localName
1090   *
1091   * @return
1092   * @see org.w3c.dom.Element
1093   */

1094  public final Attr JavaDoc getAttributeNodeNS(String JavaDoc namespaceURI, String JavaDoc localName)
1095  {
1096    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1097  }
1098
1099  /**
1100   *
1101   * @param newAttr
1102   *
1103   * @return
1104   *
1105   * @throws DOMException
1106   * @see org.w3c.dom.Element
1107   */

1108  public final Attr JavaDoc setAttributeNodeNS(Attr JavaDoc newAttr) throws DOMException
1109  {
1110    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1111  }
1112
1113  /**
1114   *
1115   * @return
1116   * @see org.w3c.dom.Attr
1117   */

1118  public final String JavaDoc getName()
1119  {
1120    return dtm.getNodeName(node);
1121  }
1122
1123  /**
1124   *
1125   * @return
1126   * @see org.w3c.dom.Attr
1127   */

1128  public final boolean getSpecified()
1129  {
1130    // We really don't know which attributes might have come from the
1131
// source document versus from the DTD. Treat them all as having
1132
// been provided by the user.
1133
// %REVIEW% if/when we become aware of DTDs/schemae.
1134
return true;
1135  }
1136
1137  /**
1138   *
1139   * @return
1140   * @see org.w3c.dom.Attr
1141   */

1142  public final String JavaDoc getValue()
1143  {
1144    return dtm.getNodeValue(node);
1145  }
1146
1147  /**
1148   *
1149   * @param value
1150   * @see org.w3c.dom.Attr
1151   */

1152  public final void setValue(String JavaDoc value)
1153  {
1154    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1155  }
1156
1157  /**
1158   * Get the owner element of an attribute.
1159   *
1160   * @return
1161   * @see org.w3c.dom.Attr as of DOM Level 2
1162   */

1163  public final Element JavaDoc getOwnerElement()
1164  {
1165    if (getNodeType() != Node.ATTRIBUTE_NODE)
1166      return null;
1167    // In XPath and DTM data models, unlike DOM, an Attr's parent is its
1168
// owner element.
1169
int newnode = dtm.getParent(node);
1170    return (newnode == DTM.NULL) ? null : (Element JavaDoc)(dtm.getNode(newnode));
1171  }
1172
1173  /**
1174   * NEEDSDOC Method adoptNode
1175   *
1176   *
1177   * NEEDSDOC @param source
1178   *
1179   * NEEDSDOC (adoptNode) @return
1180   *
1181   * @throws DOMException
1182   */

1183  public Node JavaDoc adoptNode(Node JavaDoc source) throws DOMException
1184  {
1185
1186    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1187  }
1188
1189  /**
1190   * <p>EXPERIMENTAL! Based on the <a
1191   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1192   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1193   * <p>
1194   * An attribute specifying, as part of the XML declaration, the encoding
1195   * of this document. This is <code>null</code> when unspecified.
1196   * @since DOM Level 3
1197   *
1198   * NEEDSDOC ($objectName$) @return
1199   */

1200  public String JavaDoc getInputEncoding()
1201  {
1202
1203    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1204  }
1205
1206  /**
1207   * <p>EXPERIMENTAL! Based on the <a
1208   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1209   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1210   * <p>
1211   * An attribute specifying, as part of the XML declaration, the encoding
1212   * of this document. This is <code>null</code> when unspecified.
1213   * @since DOM Level 3
1214   *
1215   * NEEDSDOC @param encoding
1216   */

1217  public void setEncoding(String JavaDoc encoding)
1218  {
1219    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1220  }
1221
1222  /**
1223   * <p>EXPERIMENTAL! Based on the <a
1224   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1225   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1226   * <p>
1227   * An attribute specifying, as part of the XML declaration, whether this
1228   * document is standalone.
1229   * @since DOM Level 3
1230   *
1231   * NEEDSDOC ($objectName$) @return
1232   */

1233  public boolean getStandalone()
1234  {
1235
1236    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1237  }
1238
1239  /**
1240   * <p>EXPERIMENTAL! Based on the <a
1241   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1242   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1243   * <p>
1244   * An attribute specifying, as part of the XML declaration, whether this
1245   * document is standalone.
1246   * @since DOM Level 3
1247   *
1248   * NEEDSDOC @param standalone
1249   */

1250  public void setStandalone(boolean standalone)
1251  {
1252    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1253  }
1254
1255  /**
1256   * <p>EXPERIMENTAL! Based on the <a
1257   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1258   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1259   * <p>
1260   * An attribute specifying whether errors checking is enforced or not.
1261   * When set to <code>false</code>, the implementation is free to not
1262   * test every possible error case normally defined on DOM operations,
1263   * and not raise any <code>DOMException</code>. In case of error, the
1264   * behavior is undefined. This attribute is <code>true</code> by
1265   * defaults.
1266   * @since DOM Level 3
1267   *
1268   * NEEDSDOC ($objectName$) @return
1269   */

1270  public boolean getStrictErrorChecking()
1271  {
1272
1273    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1274  }
1275
1276  /**
1277   * <p>EXPERIMENTAL! Based on the <a
1278   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1279   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1280   * <p>
1281   * An attribute specifying whether errors checking is enforced or not.
1282   * When set to <code>false</code>, the implementation is free to not
1283   * test every possible error case normally defined on DOM operations,
1284   * and not raise any <code>DOMException</code>. In case of error, the
1285   * behavior is undefined. This attribute is <code>true</code> by
1286   * defaults.
1287   * @since DOM Level 3
1288   *
1289   * NEEDSDOC @param strictErrorChecking
1290   */

1291  public void setStrictErrorChecking(boolean strictErrorChecking)
1292  {
1293    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1294  }
1295
1296  /**
1297   * <p>EXPERIMENTAL! Based on the <a
1298   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1299   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1300   * <p>
1301   * An attribute specifying, as part of the XML declaration, the version
1302   * number of this document. This is <code>null</code> when unspecified.
1303   * @since DOM Level 3
1304   *
1305   * NEEDSDOC ($objectName$) @return
1306   */

1307  public String JavaDoc getVersion()
1308  {
1309
1310    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1311  }
1312
1313  /**
1314   * <p>EXPERIMENTAL! Based on the <a
1315   * HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
1316   * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
1317   * <p>
1318   * An attribute specifying, as part of the XML declaration, the version
1319   * number of this document. This is <code>null</code> when unspecified.
1320   * @since DOM Level 3
1321   *
1322   * NEEDSDOC @param version
1323   */

1324  public void setVersion(String JavaDoc version)
1325  {
1326    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1327  }
1328        
1329        
1330  /** Inner class to support getDOMImplementation.
1331   */

1332  static class DTMNodeProxyImplementation implements DOMImplementation JavaDoc
1333  {
1334    public DocumentType JavaDoc createDocumentType(String JavaDoc qualifiedName,String JavaDoc publicId, String JavaDoc systemId)
1335    {
1336      throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1337    }
1338    public Document JavaDoc createDocument(String JavaDoc namespaceURI,String JavaDoc qualfiedName,DocumentType JavaDoc doctype)
1339    {
1340      // Could create a DTM... but why, when it'd have to be permanantly empty?
1341
throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1342    }
1343    /** Ask whether we support a given DOM feature.
1344     *
1345     * In fact, we do not _fully_ support any DOM feature -- we're a
1346     * read-only subset -- so arguably we should always return false.
1347     * On the other hand, it may be more practically useful to return
1348     * true and simply treat the whole DOM as read-only, failing on the
1349     * methods we can't support. I'm not sure which would be more useful
1350     * to the caller.
1351     */

1352    public boolean hasFeature(String JavaDoc feature,String JavaDoc version)
1353    {
1354      if( ("CORE".equals(feature.toUpperCase()) || "XML".equals(feature.toUpperCase()))
1355                    &&
1356          ("1.0".equals(version) || "2.0".equals(version)))
1357        return true;
1358      return false;
1359    }
1360
1361    /**
1362     * This method returns a specialized object which implements the
1363     * specialized APIs of the specified feature and version. The
1364     * specialized object may also be obtained by using binding-specific
1365     * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations
1366.
1367     * @param feature The name of the feature requested (case-insensitive).
1368     * @param version This is the version number of the feature to test. If
1369     * the version is <code>null</code> or the empty string, supporting
1370     * any version of the feature will cause the method to return an
1371     * object that supports at least one version of the feature.
1372     * @return Returns an object which implements the specialized APIs of
1373     * the specified feature and version, if any, or <code>null</code> if
1374     * there is no object which implements interfaces associated with that
1375     * feature. If the <code>DOMObject</code> returned by this method
1376     * implements the <code>Node</code> interface, it must delegate to the
1377     * primary core <code>Node</code> and not return results inconsistent
1378     * with the primary core <code>Node</code> such as attributes,
1379     * childNodes, etc.
1380     * @since DOM Level 3
1381     */

1382    public Object JavaDoc getFeature(String JavaDoc feature, String JavaDoc version) {
1383        // we don't have any alternate node, either this node does the job
1384
// or we don't have anything that does
1385
//return hasFeature(feature, version) ? this : null;
1386
return null; //PENDING
1387
}
1388
1389  }
1390
1391
1392//RAMESH : Pending proper implementation of DOM Level 3
1393

1394    public Object JavaDoc setUserData(String JavaDoc key,
1395                              Object JavaDoc data,
1396                              UserDataHandler JavaDoc handler) {
1397        return getOwnerDocument().setUserData( key, data, handler);
1398    }
1399
1400    /**
1401     * Retrieves the object associated to a key on a this node. The object
1402     * must first have been set to this node by calling
1403     * <code>setUserData</code> with the same key.
1404     * @param key The key the object is associated to.
1405     * @return Returns the <code>DOMObject</code> associated to the given key
1406     * on this node, or <code>null</code> if there was none.
1407     * @since DOM Level 3
1408     */

1409    public Object JavaDoc getUserData(String JavaDoc key) {
1410        return getOwnerDocument().getUserData( key);
1411    }
1412
1413      /**
1414     * This method returns a specialized object which implements the
1415     * specialized APIs of the specified feature and version. The
1416     * specialized object may also be obtained by using binding-specific
1417     * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations.
1418     * @param feature The name of the feature requested (case-insensitive).
1419     * @param version This is the version number of the feature to test. If
1420     * the version is <code>null</code> or the empty string, supporting
1421     * any version of the feature will cause the method to return an
1422     * object that supports at least one version of the feature.
1423     * @return Returns an object which implements the specialized APIs of
1424     * the specified feature and version, if any, or <code>null</code> if
1425     * there is no object which implements interfaces associated with that
1426     * feature. If the <code>DOMObject</code> returned by this method
1427     * implements the <code>Node</code> interface, it must delegate to the
1428     * primary core <code>Node</code> and not return results inconsistent
1429     * with the primary core <code>Node</code> such as attributes,
1430     * childNodes, etc.
1431     * @since DOM Level 3
1432     */

1433    public Object JavaDoc getFeature(String JavaDoc feature, String JavaDoc version) {
1434        // we don't have any alternate node, either this node does the job
1435
// or we don't have anything that does
1436
return isSupported(feature, version) ? this : null;
1437    }
1438
1439    /**
1440     * Tests whether two nodes are equal.
1441     * <br>This method tests for equality of nodes, not sameness (i.e.,
1442     * whether the two nodes are references to the same object) which can be
1443     * tested with <code>Node.isSameNode</code>. All nodes that are the same
1444     * will also be equal, though the reverse may not be true.
1445     * <br>Two nodes are equal if and only if the following conditions are
1446     * satisfied: The two nodes are of the same type.The following string
1447     * attributes are equal: <code>nodeName</code>, <code>localName</code>,
1448     * <code>namespaceURI</code>, <code>prefix</code>, <code>nodeValue</code>
1449     * , <code>baseURI</code>. This is: they are both <code>null</code>, or
1450     * they have the same length and are character for character identical.
1451     * The <code>attributes</code> <code>NamedNodeMaps</code> are equal.
1452     * This is: they are both <code>null</code>, or they have the same
1453     * length and for each node that exists in one map there is a node that
1454     * exists in the other map and is equal, although not necessarily at the
1455     * same index.The <code>childNodes</code> <code>NodeLists</code> are
1456     * equal. This is: they are both <code>null</code>, or they have the
1457     * same length and contain equal nodes at the same index. This is true
1458     * for <code>Attr</code> nodes as for any other type of node. Note that
1459     * normalization can affect equality; to avoid this, nodes should be
1460     * normalized before being compared.
1461     * <br>For two <code>DocumentType</code> nodes to be equal, the following
1462     * conditions must also be satisfied: The following string attributes
1463     * are equal: <code>publicId</code>, <code>systemId</code>,
1464     * <code>internalSubset</code>.The <code>entities</code>
1465     * <code>NamedNodeMaps</code> are equal.The <code>notations</code>
1466     * <code>NamedNodeMaps</code> are equal.
1467     * <br>On the other hand, the following do not affect equality: the
1468     * <code>ownerDocument</code> attribute, the <code>specified</code>
1469     * attribute for <code>Attr</code> nodes, the
1470     * <code>isWhitespaceInElementContent</code> attribute for
1471     * <code>Text</code> nodes, as well as any user data or event listeners
1472     * registered on the nodes.
1473     * @param arg The node to compare equality with.
1474     * @param deep If <code>true</code>, recursively compare the subtrees; if
1475     * <code>false</code>, compare only the nodes themselves (and its
1476     * attributes, if it is an <code>Element</code>).
1477     * @return If the nodes, and possibly subtrees are equal,
1478     * <code>true</code> otherwise <code>false</code>.
1479     * @since DOM Level 3
1480     */

1481    public boolean isEqualNode(Node JavaDoc arg) {
1482        if (arg == this) {
1483            return true;
1484        }
1485        if (arg.getNodeType() != getNodeType()) {
1486            return false;
1487        }
1488        // in theory nodeName can't be null but better be careful
1489
// who knows what other implementations may be doing?...
1490
if (getNodeName() == null) {
1491            if (arg.getNodeName() != null) {
1492                return false;
1493            }
1494        }
1495        else if (!getNodeName().equals(arg.getNodeName())) {
1496            return false;
1497        }
1498
1499        if (getLocalName() == null) {
1500            if (arg.getLocalName() != null) {
1501                return false;
1502            }
1503        }
1504        else if (!getLocalName().equals(arg.getLocalName())) {
1505            return false;
1506        }
1507
1508        if (getNamespaceURI() == null) {
1509            if (arg.getNamespaceURI() != null) {
1510                return false;
1511            }
1512        }
1513        else if (!getNamespaceURI().equals(arg.getNamespaceURI())) {
1514            return false;
1515        }
1516
1517        if (getPrefix() == null) {
1518            if (arg.getPrefix() != null) {
1519                return false;
1520            }
1521        }
1522        else if (!getPrefix().equals(arg.getPrefix())) {
1523            return false;
1524        }
1525
1526        if (getNodeValue() == null) {
1527            if (arg.getNodeValue() != null) {
1528                return false;
1529            }
1530        }
1531        else if (!getNodeValue().equals(arg.getNodeValue())) {
1532            return false;
1533        }
1534    /*
1535        if (getBaseURI() == null) {
1536            if (((NodeImpl) arg).getBaseURI() != null) {
1537                return false;
1538            }
1539        }
1540        else if (!getBaseURI().equals(((NodeImpl) arg).getBaseURI())) {
1541            return false;
1542        }
1543*/

1544
1545             return true;
1546    }
1547
1548      /**
1549     * DOM Level 3 - Experimental:
1550     * Look up the namespace URI associated to the given prefix, starting from this node.
1551     * Use lookupNamespaceURI(null) to lookup the default namespace
1552     *
1553     * @param namespaceURI
1554     * @return th URI for the namespace
1555     * @since DOM Level 3
1556     */

1557    public String JavaDoc lookupNamespaceURI(String JavaDoc specifiedPrefix) {
1558        short type = this.getNodeType();
1559        switch (type) {
1560        case Node.ELEMENT_NODE : {
1561
1562                String JavaDoc namespace = this.getNamespaceURI();
1563                String JavaDoc prefix = this.getPrefix();
1564                if (namespace !=null) {
1565                    // REVISIT: is it possible that prefix is empty string?
1566
if (specifiedPrefix== null && prefix==specifiedPrefix) {
1567                        // looking for default namespace
1568
return namespace;
1569                    } else if (prefix != null && prefix.equals(specifiedPrefix)) {
1570                        // non default namespace
1571
return namespace;
1572                    }
1573                }
1574                if (this.hasAttributes()) {
1575                    NamedNodeMap JavaDoc map = this.getAttributes();
1576                    int length = map.getLength();
1577                    for (int i=0;i<length;i++) {
1578                        Node JavaDoc attr = map.item(i);
1579                        String JavaDoc attrPrefix = attr.getPrefix();
1580                        String JavaDoc value = attr.getNodeValue();
1581                        namespace = attr.getNamespaceURI();
1582                        if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) {
1583                            // at this point we are dealing with DOM Level 2 nodes only
1584
if (specifiedPrefix == null &&
1585                                attr.getNodeName().equals("xmlns")) {
1586                                // default namespace
1587
return value;
1588                            } else if (attrPrefix !=null &&
1589                                       attrPrefix.equals("xmlns") &&
1590                                       attr.getLocalName().equals(specifiedPrefix)) {
1591                 // non default namespace
1592
return value;
1593                            }
1594                        }
1595                    }
1596                }
1597        /*
1598                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
1599                if (ancestor != null) {
1600                    return ancestor.lookupNamespaceURI(specifiedPrefix);
1601                }
1602        */

1603
1604                return null;
1605
1606
1607            }
1608/*
1609        case Node.DOCUMENT_NODE : {
1610                return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ;
1611            }
1612*/

1613        case Node.ENTITY_NODE :
1614        case Node.NOTATION_NODE:
1615        case Node.DOCUMENT_FRAGMENT_NODE:
1616        case Node.DOCUMENT_TYPE_NODE:
1617            // type is unknown
1618
return null;
1619        case Node.ATTRIBUTE_NODE:{
1620                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
1621                    return getOwnerElement().lookupNamespaceURI(specifiedPrefix);
1622
1623                }
1624                return null;
1625            }
1626        default:{
1627       /*
1628                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
1629                if (ancestor != null) {
1630                    return ancestor.lookupNamespaceURI(specifiedPrefix);
1631                }
1632             */

1633                return null;
1634            }
1635
1636        }
1637    }
1638
1639    
1640    /**
1641     * DOM Level 3: Experimental
1642     * This method checks if the specified <code>namespaceURI</code> is the
1643     * default namespace or not.
1644     * @param namespaceURI The namespace URI to look for.
1645     * @return <code>true</code> if the specified <code>namespaceURI</code>
1646     * is the default namespace, <code>false</code> otherwise.
1647     * @since DOM Level 3
1648     */

1649    public boolean isDefaultNamespace(String JavaDoc namespaceURI){
1650       /*
1651        // REVISIT: remove casts when DOM L3 becomes REC.
1652        short type = this.getNodeType();
1653        switch (type) {
1654        case Node.ELEMENT_NODE: {
1655            String namespace = this.getNamespaceURI();
1656            String prefix = this.getPrefix();
1657
1658            // REVISIT: is it possible that prefix is empty string?
1659            if (prefix == null || prefix.length() == 0) {
1660                if (namespaceURI == null) {
1661                    return (namespace == namespaceURI);
1662                }
1663                return namespaceURI.equals(namespace);
1664            }
1665            if (this.hasAttributes()) {
1666                ElementImpl elem = (ElementImpl)this;
1667                NodeImpl attr = (NodeImpl)elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns");
1668                if (attr != null) {
1669                    String value = attr.getNodeValue();
1670                    if (namespaceURI == null) {
1671                        return (namespace == value);
1672                    }
1673                    return namespaceURI.equals(value);
1674                }
1675            }
1676
1677            NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
1678            if (ancestor != null) {
1679                return ancestor.isDefaultNamespace(namespaceURI);
1680            }
1681            return false;
1682        }
1683        case Node.DOCUMENT_NODE:{
1684                return((NodeImpl)((Document)this).getDocumentElement()).isDefaultNamespace(namespaceURI);
1685            }
1686
1687        case Node.ENTITY_NODE :
1688          case Node.NOTATION_NODE:
1689        case Node.DOCUMENT_FRAGMENT_NODE:
1690        case Node.DOCUMENT_TYPE_NODE:
1691            // type is unknown
1692            return false;
1693        case Node.ATTRIBUTE_NODE:{
1694                if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) {
1695                    return ownerNode.isDefaultNamespace(namespaceURI);
1696
1697                }
1698                return false;
1699            }
1700        default:{
1701                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
1702                if (ancestor != null) {
1703                    return ancestor.isDefaultNamespace(namespaceURI);
1704                }
1705                return false;
1706            }
1707
1708        }
1709*/

1710        return false;
1711
1712
1713    }
1714
1715      /**
1716     *
1717     * DOM Level 3 - Experimental:
1718     * Look up the prefix associated to the given namespace URI, starting from this node.
1719     *
1720     * @param namespaceURI
1721     * @return the prefix for the namespace
1722     */

1723    public String JavaDoc lookupPrefix(String JavaDoc namespaceURI){
1724
1725        // REVISIT: When Namespaces 1.1 comes out this may not be true
1726
// Prefix can't be bound to null namespace
1727
if (namespaceURI == null) {
1728            return null;
1729        }
1730
1731        short type = this.getNodeType();
1732
1733        switch (type) {
1734/*
1735        case Node.ELEMENT_NODE: {
1736
1737                String namespace = this.getNamespaceURI(); // to flip out children
1738                return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
1739            }
1740
1741        case Node.DOCUMENT_NODE:{
1742                return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
1743            }
1744*/

1745        case Node.ENTITY_NODE :
1746        case Node.NOTATION_NODE:
1747        case Node.DOCUMENT_FRAGMENT_NODE:
1748        case Node.DOCUMENT_TYPE_NODE:
1749            // type is unknown
1750
return null;
1751        case Node.ATTRIBUTE_NODE:{
1752                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
1753                    return getOwnerElement().lookupPrefix(namespaceURI);
1754
1755                }
1756                return null;
1757            }
1758        default:{
1759/*
1760                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
1761                if (ancestor != null) {
1762                    return ancestor.lookupPrefix(namespaceURI);
1763                }
1764*/

1765                return null;
1766            }
1767         }
1768    }
1769
1770     /**
1771     * Returns whether this node is the same node as the given one.
1772     * <br>This method provides a way to determine whether two
1773     * <code>Node</code> references returned by the implementation reference
1774     * the same object. When two <code>Node</code> references are references
1775     * to the same object, even if through a proxy, the references may be
1776     * used completely interchangably, such that all attributes have the
1777     * same values and calling the same DOM method on either reference
1778     * always has exactly the same effect.
1779     * @param other The node to test against.
1780     * @return Returns <code>true</code> if the nodes are the same,
1781     * <code>false</code> otherwise.
1782     * @since DOM Level 3
1783     */

1784    public boolean isSameNode(Node JavaDoc other) {
1785        // we do not use any wrapper so the answer is obvious
1786
return this == other;
1787    }
1788
1789      /**
1790     * This attribute returns the text content of this node and its
1791     * descendants. When it is defined to be null, setting it has no effect.
1792     * When set, any possible children this node may have are removed and
1793     * replaced by a single <code>Text</code> node containing the string
1794     * this attribute is set to. On getting, no serialization is performed,
1795     * the returned string does not contain any markup. No whitespace
1796     * normalization is performed, the returned string does not contain the
1797     * element content whitespaces . Similarly, on setting, no parsing is
1798     * performed either, the input string is taken as pure textual content.
1799     * <br>The string returned is made of the text content of this node
1800     * depending on its type, as defined below:
1801     * <table border='1'>
1802     * <tr>
1803     * <th>Node type</th>
1804     * <th>Content</th>
1805     * </tr>
1806     * <tr>
1807     * <td valign='top' rowspan='1' colspan='1'>
1808     * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE,
1809     * DOCUMENT_FRAGMENT_NODE</td>
1810     * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code>
1811     * attribute value of every child node, excluding COMMENT_NODE and
1812     * PROCESSING_INSTRUCTION_NODE nodes</td>
1813     * </tr>
1814     * <tr>
1815     * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE,
1816     * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td>
1817     * <td valign='top' rowspan='1' colspan='1'>
1818     * <code>nodeValue</code></td>
1819     * </tr>
1820     * <tr>
1821     * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td>
1822     * <td valign='top' rowspan='1' colspan='1'>
1823     * null</td>
1824     * </tr>
1825     * </table>
1826     * @exception DOMException
1827     * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
1828     * @exception DOMException
1829     * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
1830     * fit in a <code>DOMString</code> variable on the implementation
1831     * platform.
1832       * @since DOM Level 3
1833     */

1834    public void setTextContent(String JavaDoc textContent)
1835        throws DOMException {
1836        setNodeValue(textContent);
1837    }
1838    /**
1839     * This attribute returns the text content of this node and its
1840     * descendants. When it is defined to be null, setting it has no effect.
1841     * When set, any possible children this node may have are removed and
1842     * replaced by a single <code>Text</code> node containing the string
1843     * this attribute is set to. On getting, no serialization is performed,
1844     * the returned string does not contain any markup. No whitespace
1845     * normalization is performed, the returned string does not contain the
1846     * element content whitespaces . Similarly, on setting, no parsing is
1847     * performed either, the input string is taken as pure textual content.
1848     * <br>The string returned is made of the text content of this node
1849     * depending on its type, as defined below:
1850     * <table border='1'>
1851     * <tr>
1852     * <th>Node type</th>
1853     * <th>Content</th>
1854     * </tr>
1855     * <tr>
1856     * <td valign='top' rowspan='1' colspan='1'>
1857     * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE,
1858     * DOCUMENT_FRAGMENT_NODE</td>
1859     * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code>
1860     * attribute value of every child node, excluding COMMENT_NODE and
1861     * PROCESSING_INSTRUCTION_NODE nodes</td>
1862     * </tr>
1863     * <tr>
1864     * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE,
1865     * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td>
1866     * <td valign='top' rowspan='1' colspan='1'>
1867     * <code>nodeValue</code></td>
1868     * </tr>
1869     * <tr>
1870     * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td>
1871     * <td valign='top' rowspan='1' colspan='1'>
1872     * null</td>
1873     * </tr>
1874     * </table>
1875     * @exception DOMException
1876     * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
1877     * @exception DOMException
1878     * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
1879     * fit in a <code>DOMString</code> variable on the implementation
1880     * platform.
1881     * @since DOM Level 3
1882     */

1883    public String JavaDoc getTextContent() throws DOMException {
1884        return getNodeValue(); // overriden in some subclasses
1885
}
1886
1887     /**
1888     * Compares a node with this node with regard to their position in the
1889     * document.
1890     * @param other The node to compare against this node.
1891     * @return Returns how the given node is positioned relatively to this
1892     * node.
1893     * @since DOM Level 3
1894     */

1895    public short compareDocumentPosition(Node JavaDoc other) throws DOMException {
1896        return 0;
1897    }
1898
1899     /**
1900     * The absolute base URI of this node or <code>null</code> if undefined.
1901     * This value is computed according to . However, when the
1902     * <code>Document</code> supports the feature "HTML" , the base URI is
1903     * computed using first the value of the href attribute of the HTML BASE
1904     * element if any, and the value of the <code>documentURI</code>
1905     * attribute from the <code>Document</code> interface otherwise.
1906     * <br> When the node is an <code>Element</code>, a <code>Document</code>
1907     * or a a <code>ProcessingInstruction</code>, this attribute represents
1908     * the properties [base URI] defined in . When the node is a
1909     * <code>Notation</code>, an <code>Entity</code>, or an
1910     * <code>EntityReference</code>, this attribute represents the
1911     * properties [declaration base URI] in the . How will this be affected
1912     * by resolution of relative namespace URIs issue?It's not.Should this
1913     * only be on Document, Element, ProcessingInstruction, Entity, and
1914     * Notation nodes, according to the infoset? If not, what is it equal to
1915     * on other nodes? Null? An empty string? I think it should be the
1916     * parent's.No.Should this be read-only and computed or and actual
1917     * read-write attribute?Read-only and computed (F2F 19 Jun 2000 and
1918     * teleconference 30 May 2001).If the base HTML element is not yet
1919     * attached to a document, does the insert change the Document.baseURI?
1920     * Yes. (F2F 26 Sep 2001)
1921     * @since DOM Level 3
1922     */

1923    public String JavaDoc getBaseURI() {
1924        return null;
1925    }
1926
1927        /**
1928     * DOM Level 3 WD - Experimental.
1929     * Renaming node
1930     */

1931    public Node JavaDoc renameNode(Node JavaDoc n,
1932                           String JavaDoc namespaceURI,
1933                           String JavaDoc name)
1934                           throws DOMException{
1935        return n;
1936    }
1937
1938    
1939    /**
1940     * DOM Level 3 WD - Experimental
1941     * Normalize document.
1942     */

1943    public void normalizeDocument(){
1944
1945    }
1946    /**
1947     * The configuration used when <code>Document.normalizeDocument</code> is
1948     * invoked.
1949     * @since DOM Level 3
1950     */

1951    public DOMConfiguration JavaDoc getDomConfig(){
1952       return null;
1953    }
1954
1955    
1956    /**Experimental DOM Level 3 feature: documentURI */
1957    protected String JavaDoc fDocumentURI;
1958
1959    /**
1960     * DOM Level 3 WD - Experimental.
1961     */

1962    public void setDocumentURI(String JavaDoc documentURI){
1963        
1964        fDocumentURI= documentURI;
1965    }
1966
1967        /**
1968     * DOM Level 3 WD - Experimental.
1969     * The location of the document or <code>null</code> if undefined.
1970     * <br>Beware that when the <code>Document</code> supports the feature
1971     * "HTML" , the href attribute of the HTML BASE element takes precedence
1972     * over this attribute.
1973     * @since DOM Level 3
1974     */

1975    public String JavaDoc getDocumentURI(){
1976        return fDocumentURI;
1977    }
1978
1979        /**Experimental DOM Level 3 feature: Document actualEncoding */
1980    protected String JavaDoc actualEncoding;
1981
1982     /**
1983     * DOM Level 3 WD - Experimental.
1984     * An attribute specifying the actual encoding of this document. This is
1985     * <code>null</code> otherwise.
1986     * <br> This attribute represents the property [character encoding scheme]
1987     * defined in .
1988     * @since DOM Level 3
1989     */

1990    public String JavaDoc getActualEncoding() {
1991        return actualEncoding;
1992    }
1993
1994    /**
1995     * DOM Level 3 WD - Experimental.
1996     * An attribute specifying the actual encoding of this document. This is
1997     * <code>null</code> otherwise.
1998     * <br> This attribute represents the property [character encoding scheme]
1999     * defined in .
2000     * @since DOM Level 3
2001     */

2002    public void setActualEncoding(String JavaDoc value) {
2003        actualEncoding = value;
2004    }
2005
2006     /**
2007    * DOM Level 3 WD - Experimental.
2008    */

2009    public Text JavaDoc replaceWholeText(String JavaDoc content)
2010                                 throws DOMException{
2011/*
2012
2013        if (needsSyncData()) {
2014            synchronizeData();
2015        }
2016
2017        // make sure we can make the replacement
2018        if (!canModify(nextSibling)) {
2019            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
2020                DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
2021        }
2022
2023        Node parent = this.getParentNode();
2024        if (content == null || content.length() == 0) {
2025            // remove current node
2026            if (parent !=null) { // check if node in the tree
2027                parent.removeChild(this);
2028                return null;
2029            }
2030        }
2031        Text currentNode = null;
2032        if (isReadOnly()){
2033            Text newNode = this.ownerDocument().createTextNode(content);
2034            if (parent !=null) { // check if node in the tree
2035                parent.insertBefore(newNode, this);
2036                parent.removeChild(this);
2037                currentNode = newNode;
2038            } else {
2039                return newNode;
2040            }
2041        } else {
2042            this.setData(content);
2043            currentNode = this;
2044        }
2045        Node sibling = currentNode.getNextSibling();
2046        while ( sibling !=null) {
2047            parent.removeChild(sibling);
2048            sibling = currentNode.getNextSibling();
2049        }
2050
2051        return currentNode;
2052*/

2053        return null; //Pending
2054
}
2055
2056     /**
2057     * DOM Level 3 WD - Experimental.
2058     * Returns all text of <code>Text</code> nodes logically-adjacent text
2059     * nodes to this node, concatenated in document order.
2060     * @since DOM Level 3
2061     */

2062    public String JavaDoc getWholeText(){
2063
2064/*
2065        if (needsSyncData()) {
2066            synchronizeData();
2067        }
2068        if (nextSibling == null) {
2069            return data;
2070        }
2071        StringBuffer buffer = new StringBuffer();
2072        if (data != null && data.length() != 0) {
2073            buffer.append(data);
2074        }
2075        getWholeText(nextSibling, buffer);
2076        return buffer.toString();
2077*/

2078        return null; // PENDING
2079

2080    }
2081
2082      /**
2083    * DOM Level 3 WD - Experimental.
2084     * Returns whether this text node contains whitespace in element content,
2085     * often abusively called "ignorable whitespace".
2086     */

2087    public boolean isElementContentWhitespace(){
2088        return false;
2089    }
2090
2091
2092
2093
2094     /**
2095     * NON-DOM: set the type of this attribute to be ID type.
2096     *
2097     * @param id
2098     */

2099    public void setIdAttribute(boolean id){
2100        //PENDING
2101
}
2102
2103     /**
2104     * DOM Level 3: register the given attribute node as an ID attribute
2105     */

2106    public void setIdAttribute(String JavaDoc name, boolean makeId) {
2107        //PENDING
2108
}
2109
2110       
2111    /**
2112     * DOM Level 3: register the given attribute node as an ID attribute
2113     */

2114    public void setIdAttributeNode(Attr JavaDoc at, boolean makeId) {
2115        //PENDING
2116
}
2117
2118    /**
2119     * DOM Level 3: register the given attribute node as an ID attribute
2120     */

2121    public void setIdAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName,
2122                                    boolean makeId) {
2123        //PENDING
2124
}
2125         /**
2126         * Method getSchemaTypeInfo.
2127         * @return TypeInfo
2128         */

2129    public TypeInfo JavaDoc getSchemaTypeInfo(){
2130      return null; //PENDING
2131
}
2132
2133    public boolean isId() {
2134        return false; //PENDING
2135
}
2136
2137
2138    private String JavaDoc xmlEncoding;
2139    public String JavaDoc getXmlEncoding( ) {
2140        return xmlEncoding;
2141    }
2142    public void setXmlEncoding( String JavaDoc xmlEncoding ) {
2143        this.xmlEncoding = xmlEncoding;
2144    }
2145
2146    private boolean xmlStandalone;
2147    public boolean getXmlStandalone() {
2148        return xmlStandalone;
2149    }
2150
2151    public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
2152        this.xmlStandalone = xmlStandalone;
2153    }
2154
2155    private String JavaDoc xmlVersion;
2156    public String JavaDoc getXmlVersion() {
2157        return xmlVersion;
2158    }
2159
2160    public void setXmlVersion(String JavaDoc xmlVersion) throws DOMException {
2161        this.xmlVersion = xmlVersion;
2162    }
2163
2164
2165
2166}
2167
Popular Tags