KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > 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 1.20 2004/02/16 23:06:11 minchau Exp $
18  */

19 package org.apache.xml.dtm.ref;
20
21 import org.apache.xml.dtm.DTM;
22 import org.apache.xml.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 /**
41  * <code>DTMNodeProxy</code> presents a DOM Node API front-end to the DTM model.
42  * <p>
43  * It does _not_ attempt to address the "node identity" question; no effort
44  * is made to prevent the creation of multiple proxies referring to a single
45  * DTM node. Users can create a mechanism for managing this, or relinquish the
46  * use of "==" and use the .sameNodeAs() mechanism, which is under
47  * consideration for future versions of the DOM.
48  * <p>
49  * DTMNodeProxy may be subclassed further to present specific DOM node types.
50  *
51  * @see org.w3c.dom
52  * @xsl.usage internal
53  */

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

74   public DTMNodeProxy(DTM dtm, int node)
75   {
76     this.dtm = dtm;
77     this.node = node;
78   }
79
80   /**
81    * NON-DOM: Return the DTM model
82    *
83    * @return The DTM that this proxy is a representative for.
84    */

85   public final DTM getDTM()
86   {
87     return dtm;
88   }
89
90   /**
91    * NON-DOM: Return the DTM node number
92    *
93    * @return The DTM node handle.
94    */

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

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

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

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

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

189   public final String JavaDoc getTarget()
190   {
191     return dtm.getNodeName(node);
192   } // getTarget():String
193

194   /**
195    *
196    *
197    * @see org.w3c.dom.Node as of DOM Level 2
198    */

199   public final String JavaDoc getLocalName()
200   {
201     return dtm.getLocalName(node);
202   }
203
204   /**
205    * @return The prefix for this node.
206    * @see org.w3c.dom.Node as of DOM Level 2
207    */

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

220   public final void setPrefix(String JavaDoc prefix) throws DOMException
221   {
222     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
223   }
224
225   /**
226    *
227    *
228    * @see org.w3c.dom.Node as of DOM Level 2
229    */

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

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

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

280   public final String JavaDoc getNodeValue() throws DOMException
281   {
282     return dtm.getNodeValue(node);
283   }
284   
285   /**
286    * @return The string value of the node
287    *
288    * @throws DOMException
289    */

290   public final String JavaDoc getStringValue() throws DOMException
291   {
292     return dtm.getStringValue(node).toString();
293   }
294
295   /**
296    *
297    * @param nodeValue
298    *
299    * @throws DOMException
300    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
301    */

302   public final void setNodeValue(String JavaDoc nodeValue) throws DOMException
303   {
304     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
305   }
306
307   /**
308    *
309    *
310    * @see org.w3c.dom.Node
311    */

312   public final short getNodeType()
313   {
314     return (short) dtm.getNodeType(node);
315   }
316
317   /**
318    *
319    *
320    * @see org.w3c.dom.Node
321    */

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

338   public final Node JavaDoc getOwnerNode()
339   {
340
341     int newnode = dtm.getParent(node);
342
343     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
344   }
345
346   /**
347    *
348    *
349    * @see org.w3c.dom.Node
350    */

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

367   public final Node JavaDoc getFirstChild()
368   {
369
370     int newnode = dtm.getFirstChild(node);
371
372     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
373   }
374
375   /**
376    *
377    *
378    * @see org.w3c.dom.Node
379    */

380   public final Node JavaDoc getLastChild()
381   {
382
383     int newnode = dtm.getLastChild(node);
384
385     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
386   }
387
388   /**
389    *
390    *
391    * @see org.w3c.dom.Node
392    */

393   public final Node JavaDoc getPreviousSibling()
394   {
395
396     int newnode = dtm.getPreviousSibling(node);
397
398     return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
399   }
400
401   /**
402    *
403    *
404    * @see org.w3c.dom.Node
405    */

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

420   /**
421    *
422    *
423    * @see org.w3c.dom.Node
424    */

425   public final NamedNodeMap JavaDoc getAttributes()
426   {
427
428     return new DTMNamedNodeMap(dtm, node);
429   }
430
431   /**
432    * Method hasAttribute
433    *
434    *
435    * @param name
436    *
437    *
438    */

439   public boolean hasAttribute(String JavaDoc name)
440   {
441     return DTM.NULL != dtm.getAttributeNode(node,null,name);
442   }
443
444   /**
445    * Method hasAttributeNS
446    *
447    *
448    * @param name
449    * @param x
450    *
451    *
452    */

453   public boolean hasAttributeNS(String JavaDoc name, String JavaDoc x)
454   {
455     return DTM.NULL != dtm.getAttributeNode(node,x,name);
456   }
457
458   /**
459    *
460    *
461    * @see org.w3c.dom.Node
462    */

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

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

495   public final Node JavaDoc replaceChild(Node JavaDoc newChild, Node JavaDoc oldChild)
496     throws DOMException
497   {
498     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
499   }
500
501   /**
502    *
503    * @param oldChild
504    *
505    *
506    *
507    * @throws DOMException
508    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
509    */

510   public final Node JavaDoc removeChild(Node JavaDoc oldChild) throws DOMException
511   {
512     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
513   }
514
515   /**
516    *
517    * @param newChild
518    *
519    *
520    *
521    * @throws DOMException
522    * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
523    */

524   public final Node JavaDoc appendChild(Node JavaDoc newChild) throws DOMException
525   {
526     throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
527   }
528
529   /**
530    *
531    *
532    * @see org.w3c.dom.Node
533    */

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

546   public final Node JavaDoc cloneNode(boolean deep)
547   {
548     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
549   }
550
551   /**
552    *
553    *
554    * @see org.w3c.dom.Document
555    */

556   public final DocumentType JavaDoc getDoctype()
557   {
558     return null;
559   }
560
561   /**
562    *
563    *
564    * @see org.w3c.dom.Document
565    */

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

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

625   public final Element JavaDoc createElement(String JavaDoc tagName) throws DOMException
626   {
627     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
628   }
629
630   /**
631    *
632    *
633    * @see org.w3c.dom.Document
634    */

635   public final DocumentFragment JavaDoc createDocumentFragment()
636   {
637     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
638   }
639
640   /**
641    *
642    * @param data
643    *
644    *
645    * @see org.w3c.dom.Document
646    */

647   public final Text JavaDoc createTextNode(String JavaDoc data)
648   {
649     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
650   }
651
652   /**
653    *
654    * @param data
655    *
656    *
657    * @see org.w3c.dom.Document
658    */

659   public final Comment JavaDoc createComment(String JavaDoc data)
660   {
661     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
662   }
663
664   /**
665    *
666    * @param data
667    *
668    *
669    *
670    * @throws DOMException
671    * @see org.w3c.dom.Document
672    */

673   public final CDATASection JavaDoc createCDATASection(String JavaDoc data)
674     throws DOMException
675   {
676     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
677   }
678
679   /**
680    *
681    * @param target
682    * @param data
683    *
684    *
685    *
686    * @throws DOMException
687    * @see org.w3c.dom.Document
688    */

689   public final ProcessingInstruction JavaDoc createProcessingInstruction(
690                                                                  String JavaDoc target, String JavaDoc data) throws DOMException
691   {
692     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
693   }
694
695   /**
696    *
697    * @param name
698    *
699    *
700    *
701    * @throws DOMException
702    * @see org.w3c.dom.Document
703    */

704   public final Attr JavaDoc createAttribute(String JavaDoc name) throws DOMException
705   {
706     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
707   }
708
709   /**
710    *
711    * @param name
712    *
713    *
714    *
715    * @throws DOMException
716    * @see org.w3c.dom.Document
717    */

718   public final EntityReference JavaDoc createEntityReference(String JavaDoc name)
719     throws DOMException
720   {
721     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
722   }
723
724   /**
725    *
726    * @param tagname
727    *
728    *
729    * @see org.w3c.dom.Document
730    */

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

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

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

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

792   public final NodeList JavaDoc getElementsByTagNameNS(String JavaDoc namespaceURI,
793                                                String JavaDoc localName)
794   {
795     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
796   }
797
798   /**
799    *
800    * @param elementId
801    *
802    *
803    * @see org.w3c.dom.Document as of DOM Level 2
804    */

805   public final Element JavaDoc getElementById(String JavaDoc elementId)
806   {
807     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
808   }
809
810   /**
811    *
812    * @param offset
813    *
814    *
815    *
816    * @throws DOMException
817    * @see org.w3c.dom.Text
818    */

819   public final Text JavaDoc splitText(int offset) throws DOMException
820   {
821     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
822   }
823
824   /**
825    *
826    *
827    *
828    * @throws DOMException
829    * @see org.w3c.dom.CharacterData
830    */

831   public final String JavaDoc getData() throws DOMException
832   {
833     return dtm.getNodeValue(node);
834   }
835
836   /**
837    *
838    * @param data
839    *
840    * @throws DOMException
841    * @see org.w3c.dom.CharacterData
842    */

843   public final void setData(String JavaDoc data) throws DOMException
844   {
845     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
846   }
847
848   /**
849    *
850    *
851    * @see org.w3c.dom.CharacterData
852    */

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

869   public final String JavaDoc substringData(int offset, int count) throws DOMException
870   {
871     return getData().substring(offset,offset+count);
872   }
873
874   /**
875    *
876    * @param arg
877    *
878    * @throws DOMException
879    * @see org.w3c.dom.CharacterData
880    */

881   public final void appendData(String JavaDoc arg) throws DOMException
882   {
883     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
884   }
885
886   /**
887    *
888    * @param offset
889    * @param arg
890    *
891    * @throws DOMException
892    * @see org.w3c.dom.CharacterData
893    */

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

907   public final void deleteData(int offset, int count) throws DOMException
908   {
909     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
910   }
911
912   /**
913    *
914    * @param offset
915    * @param count
916    * @param arg
917    *
918    * @throws DOMException
919    * @see org.w3c.dom.CharacterData
920    */

921   public final void replaceData(int offset, int count, String JavaDoc arg)
922     throws DOMException
923   {
924     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
925   }
926
927   /**
928    *
929    *
930    * @see org.w3c.dom.Element
931    */

932   public final String JavaDoc getTagName()
933   {
934     return dtm.getNodeName(node);
935   }
936
937   /**
938    *
939    * @param name
940    *
941    *
942    * @see org.w3c.dom.Element
943    */

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

960   public final void setAttribute(String JavaDoc name, String JavaDoc value)
961     throws DOMException
962   {
963     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
964   }
965
966   /**
967    *
968    * @param name
969    *
970    * @throws DOMException
971    * @see org.w3c.dom.Element
972    */

973   public final void removeAttribute(String JavaDoc name) throws DOMException
974   {
975     throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
976   }
977
978   /**
979    *
980    * @param name
981    *
982    *
983    * @see org.w3c.dom.Element
984    */

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

1001  public final Attr JavaDoc setAttributeNode(Attr JavaDoc newAttr) throws DOMException
1002  {
1003    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1004  }
1005
1006  /**
1007   *
1008   * @param oldAttr
1009   *
1010   *
1011   *
1012   * @throws DOMException
1013   * @see org.w3c.dom.Element
1014   */

1015  public final Attr JavaDoc removeAttributeNode(Attr JavaDoc oldAttr) throws DOMException
1016  {
1017    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1018  }
1019
1020  /**
1021   * Introduced in DOM Level 2.
1022   *
1023   *
1024   */

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

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

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

1075  public final void removeAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName)
1076    throws DOMException
1077  {
1078    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1079  }
1080
1081  /**
1082   *
1083   * @param namespaceURI
1084   * @param localName
1085   *
1086   *
1087   * @see org.w3c.dom.Element
1088   */

1089  public final Attr JavaDoc getAttributeNodeNS(String JavaDoc namespaceURI, String JavaDoc localName)
1090  {
1091    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1092  }
1093
1094  /**
1095   *
1096   * @param newAttr
1097   *
1098   *
1099   *
1100   * @throws DOMException
1101   * @see org.w3c.dom.Element
1102   */

1103  public final Attr JavaDoc setAttributeNodeNS(Attr JavaDoc newAttr) throws DOMException
1104  {
1105    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1106  }
1107
1108  /**
1109   *
1110   *
1111   * @see org.w3c.dom.Attr
1112   */

1113  public final String JavaDoc getName()
1114  {
1115    return dtm.getNodeName(node);
1116  }
1117
1118  /**
1119   *
1120   *
1121   * @see org.w3c.dom.Attr
1122   */

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

1137  public final String JavaDoc getValue()
1138  {
1139    return dtm.getNodeValue(node);
1140  }
1141
1142  /**
1143   *
1144   * @param value
1145   * @see org.w3c.dom.Attr
1146   */

1147  public final void setValue(String JavaDoc value)
1148  {
1149    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1150  }
1151
1152  /**
1153   * Get the owner element of an attribute.
1154   *
1155   *
1156   * @see org.w3c.dom.Attr as of DOM Level 2
1157   */

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

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

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

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

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

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

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

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

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

1319  public void setVersion(String JavaDoc version)
1320  {
1321    throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
1322  }
1323        
1324        
1325  /** Inner class to support getDOMImplementation.
1326   */

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

1347    public boolean hasFeature(String JavaDoc feature,String JavaDoc version)
1348    {
1349      if( ("CORE".equals(feature.toUpperCase()) || "XML".equals(feature.toUpperCase()))
1350                    &&
1351          ("1.0".equals(version) || "2.0".equals(version))
1352          )
1353        return true;
1354      return false;
1355    }
1356  }
1357}
1358
Popular Tags