View Javadoc
1   package org.opentrafficsim.editor;
2   
3   import org.w3c.dom.DOMException;
4   import org.w3c.dom.Document;
5   import org.w3c.dom.NamedNodeMap;
6   import org.w3c.dom.Node;
7   import org.w3c.dom.NodeList;
8   import org.w3c.dom.UserDataHandler;
9   
10  /**
11   * Singleton at {@code XiIncludeNode.XI_INCLUDE} to use for xi:include nodes in an {@code XsdTreeNode}. Most methods return
12   * {@code null} or do nothing. The attributes contain one attribute named 'File' and one named 'Fallback'. 
13   * <p>
14   * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  public final class XiIncludeNode implements Node
20  {
21  
22      /** Singleton instance for xi:include nodes. */
23      public static final Node XI_INCLUDE = new XiIncludeNode();
24  
25      /** Child node that represents the 'File' attribute. */
26      private static final Node FILE_CHILD = new FileNode(new Attributes("File"));
27      
28      /** Child node that represents the 'Fallback' attribute. */
29      private static final Node FALLBACK_CHILD = new FileNode(new Attributes("Fallback"));
30      
31      /**
32       * Private constructor.
33       */
34      private XiIncludeNode()
35      {
36  
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      public String getNodeName()
42      {
43          return "xi:include";
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public String getNodeValue() throws DOMException
49      {
50          return null;
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public void setNodeValue(final String nodeValue) throws DOMException
56      {
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public short getNodeType()
62      {
63          return Node.TEXT_NODE;
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public Node getParentNode()
69      {
70          return null;
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public NodeList getChildNodes()
76      {
77          return new NodeList()
78          {
79              /** {@inheritDoc} */
80              @Override
81              public Node item(final int index)
82              {
83                  if (index == 0)
84                  {
85                      return FILE_CHILD;
86                  }
87                  if (index == 1)
88                  {
89                      return FALLBACK_CHILD;
90                  }
91                  return null;
92              }
93  
94              /** {@inheritDoc} */
95              @Override
96              public int getLength()
97              {
98                  return 2;
99              }
100         };
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public Node getFirstChild()
106     {
107         return FILE_CHILD;
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public Node getLastChild()
113     {
114         return FALLBACK_CHILD;
115     }
116 
117     /** {@inheritDoc} */
118     @Override
119     public Node getPreviousSibling()
120     {
121         return null;
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     public Node getNextSibling()
127     {
128         return null;
129     }
130 
131     /** {@inheritDoc} */
132     @Override
133     public NamedNodeMap getAttributes()
134     {
135         return null;
136     }
137 
138     /** {@inheritDoc} */
139     @Override
140     public Document getOwnerDocument()
141     {
142         return null;
143     }
144 
145     /** {@inheritDoc} */
146     @Override
147     public Node insertBefore(final Node newChild, final Node refChild) throws DOMException
148     {
149         return null;
150     }
151 
152     /** {@inheritDoc} */
153     @Override
154     public Node replaceChild(final Node newChild, final Node oldChild) throws DOMException
155     {
156         return null;
157     }
158 
159     /** {@inheritDoc} */
160     @Override
161     public Node removeChild(final Node oldChild) throws DOMException
162     {
163         return null;
164     }
165 
166     /** {@inheritDoc} */
167     @Override
168     public Node appendChild(final Node newChild) throws DOMException
169     {
170         return null;
171     }
172 
173     /** {@inheritDoc} */
174     @Override
175     public boolean hasChildNodes()
176     {
177         return true;
178     }
179 
180     /** {@inheritDoc} */
181     @Override
182     public Node cloneNode(final boolean deep)
183     {
184         return null;
185     }
186 
187     /** {@inheritDoc} */
188     @Override
189     public void normalize()
190     {
191     }
192 
193     /** {@inheritDoc} */
194     @Override
195     public boolean isSupported(final String feature, final String version)
196     {
197         return false;
198     }
199 
200     /** {@inheritDoc} */
201     @Override
202     public String getNamespaceURI()
203     {
204         return null;
205     }
206 
207     /** {@inheritDoc} */
208     @Override
209     public String getPrefix()
210     {
211         return null;
212     }
213 
214     /** {@inheritDoc} */
215     @Override
216     public void setPrefix(final String prefix) throws DOMException
217     {
218     }
219 
220     /** {@inheritDoc} */
221     @Override
222     public String getLocalName()
223     {
224         return null;
225     }
226 
227     /** {@inheritDoc} */
228     @Override
229     public boolean hasAttributes()
230     {
231         return false;
232     }
233 
234     /** {@inheritDoc} */
235     @Override
236     public String getBaseURI()
237     {
238         return null;
239     }
240 
241     /** {@inheritDoc} */
242     @Override
243     public short compareDocumentPosition(final Node other) throws DOMException
244     {
245         return 0;
246     }
247 
248     /** {@inheritDoc} */
249     @Override
250     public String getTextContent() throws DOMException
251     {
252         return null;
253     }
254 
255     /** {@inheritDoc} */
256     @Override
257     public void setTextContent(final String textContent) throws DOMException
258     {
259     }
260 
261     /** {@inheritDoc} */
262     @Override
263     public boolean isSameNode(final Node other)
264     {
265         return false;
266     }
267 
268     /** {@inheritDoc} */
269     @Override
270     public String lookupPrefix(final String namespaceURI)
271     {
272         return null;
273     }
274 
275     /** {@inheritDoc} */
276     @Override
277     public boolean isDefaultNamespace(final String namespaceURI)
278     {
279         return false;
280     }
281 
282     /** {@inheritDoc} */
283     @Override
284     public String lookupNamespaceURI(final String prefix)
285     {
286         return null;
287     }
288 
289     /** {@inheritDoc} */
290     @Override
291     public boolean isEqualNode(final Node arg)
292     {
293         return false;
294     }
295 
296     /** {@inheritDoc} */
297     @Override
298     public Object getFeature(final String feature, final String version)
299     {
300         return null;
301     }
302 
303     /** {@inheritDoc} */
304     @Override
305     public Object setUserData(final String key, final Object data, final UserDataHandler handler)
306     {
307         return null;
308     }
309 
310     /** {@inheritDoc} */
311     @Override
312     public Object getUserData(final String key)
313     {
314         return null;
315     }
316 
317     /**
318      * Implementation of {@code Node} to provide the 'File' attribute child node.
319      * <p>
320  * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
321  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
322  * </p>
323  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
324      */
325     private static class FileNode implements Node
326     {
327 
328         /** Attributes. */
329         private final Attributes attributes;
330         
331         /**
332          * Constructor.
333          * @param attributes Attributes; attributes.
334          */
335         public FileNode(final Attributes attributes)
336         {
337             this.attributes = attributes;
338         }
339         
340         /** {@inheritDoc} */
341         @Override
342         public String getNodeName()
343         {
344             return "xsd:attribute";
345         }
346 
347         /** {@inheritDoc} */
348         @Override
349         public String getNodeValue() throws DOMException
350         {
351             return null;
352         }
353 
354         /** {@inheritDoc} */
355         @Override
356         public void setNodeValue(final String nodeValue) throws DOMException
357         {
358         }
359 
360         /** {@inheritDoc} */
361         @Override
362         public short getNodeType()
363         {
364             return Node.ATTRIBUTE_NODE;
365         }
366 
367         /** {@inheritDoc} */
368         @Override
369         public Node getParentNode()
370         {
371             return null;
372         }
373 
374         /** {@inheritDoc} */
375         @Override
376         public NodeList getChildNodes()
377         {
378             return null;
379         }
380 
381         /** {@inheritDoc} */
382         @Override
383         public Node getFirstChild()
384         {
385             return null;
386         }
387         
388         /** {@inheritDoc} */
389         @Override
390         public Node getLastChild()
391         {
392             return null;
393         }
394 
395         /** {@inheritDoc} */
396         @Override
397         public Node getPreviousSibling()
398         {
399             return null;
400         }
401 
402         /** {@inheritDoc} */
403         @Override
404         public Node getNextSibling()
405         {
406             return null;
407         }
408 
409         /** {@inheritDoc} */
410         @Override
411         public NamedNodeMap getAttributes()
412         {
413             return this.attributes;
414         }
415 
416         /** {@inheritDoc} */
417         @Override
418         public Document getOwnerDocument()
419         {
420             return null;
421         }
422 
423         /** {@inheritDoc} */
424         @Override
425         public Node insertBefore(final Node newChild, final Node refChild) throws DOMException
426         {
427             return null;
428         }
429 
430         /** {@inheritDoc} */
431         @Override
432         public Node replaceChild(final Node newChild, final Node oldChild) throws DOMException
433         {
434             return null;
435         }
436 
437         /** {@inheritDoc} */
438         @Override
439         public Node removeChild(final Node oldChild) throws DOMException
440         {
441             return null;
442         }
443 
444         /** {@inheritDoc} */
445         @Override
446         public Node appendChild(final Node newChild) throws DOMException
447         {
448             return null;
449         }
450 
451         /** {@inheritDoc} */
452         @Override
453         public boolean hasChildNodes()
454         {
455             return false;
456         }
457 
458         /** {@inheritDoc} */
459         @Override
460         public Node cloneNode(final boolean deep)
461         {
462             return null;
463         }
464 
465         /** {@inheritDoc} */
466         @Override
467         public void normalize()
468         {
469         }
470 
471         /** {@inheritDoc} */
472         @Override
473         public boolean isSupported(final String feature, final String version)
474         {
475             return false;
476         }
477 
478         /** {@inheritDoc} */
479         @Override
480         public String getNamespaceURI()
481         {
482             return null;
483         }
484 
485         /** {@inheritDoc} */
486         @Override
487         public String getPrefix()
488         {
489             return null;
490         }
491 
492         /** {@inheritDoc} */
493         @Override
494         public void setPrefix(final String prefix) throws DOMException
495         {
496         }
497 
498         /** {@inheritDoc} */
499         @Override
500         public String getLocalName()
501         {
502             return null;
503         }
504 
505         /** {@inheritDoc} */
506         @Override
507         public boolean hasAttributes()
508         {
509             return true;
510         }
511 
512         /** {@inheritDoc} */
513         @Override
514         public String getBaseURI()
515         {
516             return null;
517         }
518 
519         /** {@inheritDoc} */
520         @Override
521         public short compareDocumentPosition(final Node other) throws DOMException
522         {
523             return 0;
524         }
525 
526         /** {@inheritDoc} */
527         @Override
528         public String getTextContent() throws DOMException
529         {
530             return null;
531         }
532 
533         /** {@inheritDoc} */
534         @Override
535         public void setTextContent(final String textContent) throws DOMException
536         {
537         }
538 
539         /** {@inheritDoc} */
540         @Override
541         public boolean isSameNode(final Node other)
542         {
543             return false;
544         }
545 
546         /** {@inheritDoc} */
547         @Override
548         public String lookupPrefix(final String namespaceURI)
549         {
550             return null;
551         }
552 
553         /** {@inheritDoc} */
554         @Override
555         public boolean isDefaultNamespace(final String namespaceURI)
556         {
557             return false;
558         }
559 
560         /** {@inheritDoc} */
561         @Override
562         public String lookupNamespaceURI(final String prefix)
563         {
564             return null;
565         }
566 
567         /** {@inheritDoc} */
568         @Override
569         public boolean isEqualNode(final Node arg)
570         {
571             return false;
572         }
573 
574         /** {@inheritDoc} */
575         @Override
576         public Object getFeature(final String feature, final String version)
577         {
578             return null;
579         }
580 
581         /** {@inheritDoc} */
582         @Override
583         public Object setUserData(final String key, final Object data, final UserDataHandler handler)
584         {
585             return null;
586         }
587 
588         /** {@inheritDoc} */
589         @Override
590         public Object getUserData(final String key)
591         {
592             return null;
593         }
594         
595     }
596     
597     /**
598      * Implementation of {@code NamedNodeMap} to provide the 'File' attribute.
599      * <p>
600  * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
601  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
602  * </p>
603  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
604      */
605     private static class Attributes implements NamedNodeMap
606     {
607 
608         /** Attribute name in GUI. */
609         private final String name;
610         
611         /**
612          * Constructor.
613          * @param name String; attribute name in GUI.
614          */
615         public Attributes(final String name)
616         {
617             this.name = name;
618         }
619         
620         /** File node. */
621         private Node file = new Node()
622         {
623 
624             /** {@inheritDoc} */
625             @Override
626             public String getNodeName()
627             {
628                 return null;
629             }
630 
631             /** {@inheritDoc} */
632             @Override
633             public String getNodeValue() throws DOMException
634             {
635                 return Attributes.this.name;
636             }
637 
638             /** {@inheritDoc} */
639             @Override
640             public void setNodeValue(final String nodeValue) throws DOMException
641             {
642             }
643 
644             /** {@inheritDoc} */
645             @Override
646             public short getNodeType()
647             {
648                 return 0;
649             }
650 
651             /** {@inheritDoc} */
652             @Override
653             public Node getParentNode()
654             {
655                 return null;
656             }
657 
658             /** {@inheritDoc} */
659             @Override
660             public NodeList getChildNodes()
661             {
662                 return null;
663             }
664 
665             /** {@inheritDoc} */
666             @Override
667             public Node getFirstChild()
668             {
669                 return null;
670             }
671 
672             /** {@inheritDoc} */
673             @Override
674             public Node getLastChild()
675             {
676                 return null;
677             }
678 
679             /** {@inheritDoc} */
680             @Override
681             public Node getPreviousSibling()
682             {
683                 return null;
684             }
685 
686             /** {@inheritDoc} */
687             @Override
688             public Node getNextSibling()
689             {
690                 return null;
691             }
692 
693             /** {@inheritDoc} */
694             @Override
695             public NamedNodeMap getAttributes()
696             {
697                 return null;
698             }
699 
700             /** {@inheritDoc} */
701             @Override
702             public Document getOwnerDocument()
703             {
704                 return null;
705             }
706 
707             /** {@inheritDoc} */
708             @Override
709             public Node insertBefore(final Node newChild, final Node refChild) throws DOMException
710             {
711                 return null;
712             }
713 
714             /** {@inheritDoc} */
715             @Override
716             public Node replaceChild(final Node newChild, final Node oldChild) throws DOMException
717             {
718                 return null;
719             }
720 
721             /** {@inheritDoc} */
722             @Override
723             public Node removeChild(final Node oldChild) throws DOMException
724             {
725                 return null;
726             }
727 
728             /** {@inheritDoc} */
729             @Override
730             public Node appendChild(final Node newChild) throws DOMException
731             {
732                 return null;
733             }
734 
735             /** {@inheritDoc} */
736             @Override
737             public boolean hasChildNodes()
738             {
739                 return false;
740             }
741 
742             /** {@inheritDoc} */
743             @Override
744             public Node cloneNode(final boolean deep)
745             {
746                 return null;
747             }
748 
749             /** {@inheritDoc} */
750             @Override
751             public void normalize()
752             {
753             }
754 
755             /** {@inheritDoc} */
756             @Override
757             public boolean isSupported(final String feature, final String version)
758             {
759                 return false;
760             }
761 
762             /** {@inheritDoc} */
763             @Override
764             public String getNamespaceURI()
765             {
766                 return null;
767             }
768 
769             /** {@inheritDoc} */
770             @Override
771             public String getPrefix()
772             {
773                 return null;
774             }
775 
776             /** {@inheritDoc} */
777             @Override
778             public void setPrefix(final String prefix) throws DOMException
779             {
780             }
781 
782             /** {@inheritDoc} */
783             @Override
784             public String getLocalName()
785             {
786                 return null;
787             }
788 
789             /** {@inheritDoc} */
790             @Override
791             public boolean hasAttributes()
792             {
793                 return false;
794             }
795 
796             /** {@inheritDoc} */
797             @Override
798             public String getBaseURI()
799             {
800                 return null;
801             }
802 
803             /** {@inheritDoc} */
804             @Override
805             public short compareDocumentPosition(final Node other) throws DOMException
806             {
807                 return 0;
808             }
809 
810             /** {@inheritDoc} */
811             @Override
812             public String getTextContent() throws DOMException
813             {
814                 return null;
815             }
816 
817             /** {@inheritDoc} */
818             @Override
819             public void setTextContent(final String textContent) throws DOMException
820             {
821             }
822 
823             /** {@inheritDoc} */
824             @Override
825             public boolean isSameNode(final Node other)
826             {
827                 return false;
828             }
829 
830             /** {@inheritDoc} */
831             @Override
832             public String lookupPrefix(final String namespaceURI)
833             {
834                 return null;
835             }
836 
837             /** {@inheritDoc} */
838             @Override
839             public boolean isDefaultNamespace(final String namespaceURI)
840             {
841                 return false;
842             }
843 
844             /** {@inheritDoc} */
845             @Override
846             public String lookupNamespaceURI(final String prefix)
847             {
848                 return null;
849             }
850 
851             /** {@inheritDoc} */
852             @Override
853             public boolean isEqualNode(final Node arg)
854             {
855                 return false;
856             }
857 
858             /** {@inheritDoc} */
859             @Override
860             public Object getFeature(final String feature, final String version)
861             {
862                 return null;
863             }
864 
865             /** {@inheritDoc} */
866             @Override
867             public Object setUserData(final String key, final Object data, final UserDataHandler handler)
868             {
869                 return null;
870             }
871 
872             /** {@inheritDoc} */
873             @Override
874             public Object getUserData(final String key)
875             {
876                 return null;
877             }
878 
879         };
880 
881         /** {@inheritDoc} */
882         @Override
883         public Node getNamedItem(final String name)
884         {
885             if (name.equals("name"))
886             {
887                 return this.file;
888             }
889             return null;
890         }
891 
892         /** {@inheritDoc} */
893         @Override
894         public Node setNamedItem(final Node arg) throws DOMException
895         {
896             return null;
897         }
898 
899         /** {@inheritDoc} */
900         @Override
901         public Node removeNamedItem(final String name) throws DOMException
902         {
903             return null;
904         }
905 
906         /** {@inheritDoc} */
907         @Override
908         public Node item(final int index)
909         {
910             if (index == 0)
911             {
912                 return this.file;
913             }
914             return null;
915         }
916 
917         /** {@inheritDoc} */
918         @Override
919         public int getLength()
920         {
921             return 1;
922         }
923 
924         /** {@inheritDoc} */
925         @Override
926         public Node getNamedItemNS(final String namespaceURI, final String localName) throws DOMException
927         {
928             return null;
929         }
930 
931         /** {@inheritDoc} */
932         @Override
933         public Node setNamedItemNS(final Node arg) throws DOMException
934         {
935             return null;
936         }
937 
938         /** {@inheritDoc} */
939         @Override
940         public Node removeNamedItemNS(final String namespaceURI, final String localName) throws DOMException
941         {
942             return null;
943         }
944 
945     }
946 
947 }