-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTML31Parser.java
More file actions
2861 lines (2721 loc) · 93.2 KB
/
RTML31Parser.java
File metadata and controls
2861 lines (2721 loc) · 93.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2006, Astrophysics Research Institute, Liverpool John Moores University.
This file is part of org.estar.rtml.
org.estar.rtml is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
org.estar.rtml is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with org.estar.rtml; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// RTML31Parser.java
// $Header: /space/home/eng/cjm/cvs/org_estar_rtml/RTML31Parser.java,v 1.8 2013-01-14 11:04:37 cjm Exp $
package org.estar.rtml;
import java.io.*;
import java.text.*;
import java.util.*;
import java.net.URL;
import java.net.MalformedURLException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.DOMException;
import org.estar.astrometry.*;
/**
* This class provides the capability of parsing an RTML3.1 document into a DOM tree, using JAXP.
* The resultant DOM tree is traversed, and relevant eSTAR data extracted.
* Extends RTMLParser to make use of methods common to this and RTML22Parser (parseIntegerNode etc), even though
* this subclass is created as part of the RTMLParser's parsing.
* @author Chris Mottram
* @version $Revision$
*/
public class RTML31Parser extends RTMLParser
{
/**
* Revision control system version id.
*/
public final static String RCSID = "$Id$";
/**
* Default constructor.
*/
public RTML31Parser()
{
super();
}
/**
* Method to parse the RTML node.
* @param rtmlNode The XML DOM node for the RTML tag node.
* @param rtmlDocument The RTMLDocument instance to fill with the parsed data.
* @return An instance of RTMLDocument, containing the data in the document.
* @exception RTMLException Thrown if a strange child is in the node,
* or the score/completion time fails to parse.
* @exception ParseException Thrown if parsing the time stamp fails.
* @see RTMLDocument#setVersion
* @see RTMLDocument#setMode
* @see RTMLIntelligentAgent
* @see #parseDeviceNode
* @see #parseScheduleNode
* @see #parseScoringNode
* @see #parseProjectNode
* @see #parseHistoryNode
* @see #parseTelescopeNode
*/
protected void parseRTMLNode(Node rtmlNode,RTMLDocument rtmlDocument) throws RTMLException,
ParseException
{
RTMLObservation observation = null;
RTMLIntelligentAgent intelligenAgent = null;
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
String uid = null;
String version = null;
String mode = null;
String uriString = null;
// check current XML node is correct
if(rtmlNode.getNodeType() != Node.ELEMENT_NODE)
throw new RTMLException(this.getClass().getName()+":parseRTMLNode:Illegal Node:"+rtmlNode);
if(rtmlNode.getNodeName() != "RTML")
{
throw new RTMLException(this.getClass().getName()+":parseRTMLNode:Illegal Node Name:"+
rtmlNode.getNodeName());
}
// go through attribute list
attributeList = rtmlNode.getAttributes();
// check version
attributeNode = attributeList.getNamedItem("version");
version = attributeNode.getNodeValue();
if(version == null)
throw new RTMLException(this.getClass().getName()+":parseRTMLNode:Version was null.");
rtmlDocument.setVersion(version);
if(version.equals(RTMLDocument.RTML_VERSION_31) == false)
{
throw new RTMLException(this.getClass().getName()+":parseRTMLNode:Unsupported Version:"+
version);
}
// uid
attributeNode = attributeList.getNamedItem("uid");
uid = attributeNode.getNodeValue();
rtmlDocument.setUId(uid);
// mode = type in RTML 2.2
attributeNode = attributeList.getNamedItem("mode");
mode = attributeNode.getNodeValue();
rtmlDocument.setMode(mode);
// RTML 3.1 has Observation inside Schedule!
//observation = new RTMLObservation();
//rtmlDocument.addObservation(observation);
// go through child nodes
childList = rtmlNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Device")
parseDeviceNode(rtmlDocument,childNode);
else if(childNode.getNodeName() == "History")
parseHistoryNode(rtmlDocument,childNode);
else if(childNode.getNodeName() == "Project")
parseProjectNode(rtmlDocument,childNode);
else if(childNode.getNodeName() == "RespondTo")
{
uriString = parseStringNode("RespondTo",childNode);
intelligenAgent = new RTMLIntelligentAgent();
intelligenAgent.setUri(uriString);
rtmlDocument.setIntelligentAgent(intelligenAgent);
}
else if(childNode.getNodeName() == "Schedule")
parseScheduleNode(rtmlDocument,childNode);
else if(childNode.getNodeName() == "Scoring")
parseScoringNode(rtmlDocument,childNode);
else if(childNode.getNodeName() == "Target")
parseTargetNode(rtmlDocument,childNode);
else if(childNode.getNodeName() == "Telescope")
parseTelescopeNode(rtmlDocument,childNode);
else
System.err.println("parseRTMLNode:ELEMENT:"+childNode);
}
else if(childNode.getNodeType() == Node.TEXT_NODE)
{
}
}
}
// private methods
/**
* Internal method to parse a History node.
* @param rtmlDocument The document to add the History to.
* @param historyNode The XML DOM node for the History tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @exception ParseException Thrown if parsing the time stamp fails.
*/
private void parseHistoryNode(RTMLDocument rtmlDocument,Node historyNode) throws RTMLException, ParseException
{
Node childNode;
NodeList childList;
// check current XML node is correct
if(historyNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseHistoryNode:Illegal Node:"+
historyNode);
}
if(historyNode.getNodeName() != "History")
{
throw new RTMLException(this.getClass().getName()+":parseHistoryNode:Illegal Node Name:"+
historyNode.getNodeName());
}
// add history node
RTMLHistory history = new RTMLHistory();
// go through child nodes
childList = historyNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Entry")
parseHistoryEntryNode(history, childNode);
else
System.err.println("parseHistoryNode:ELEMENT:"+childNode);
}
}
// Set history in RTML document.
rtmlDocument.setHistory(history);
}
/**
* Internal method to parse a History Entry node.
* @param history The History to add the Entry to.
* @param entryNode The XML DOM node for the Entry tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @exception ParseException Thrown if parsing the time stamp fails.
* @see #parseStringNode
* @see #parseIntegerNode
* @see #parseRejectionNode
*/
private void parseHistoryEntryNode(RTMLHistory history,Node entryNode) throws RTMLException, ParseException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
RTMLHistoryEntry entry = null;
String timeStamp = null;
// check current XML node is correct
if(entryNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseHistoryEntryNode:Illegal Node:"+
entryNode);
}
if(entryNode.getNodeName() != "Entry")
{
throw new RTMLException(this.getClass().getName()+":parseHistoryEntryNode:Illegal Node Name:"+
entryNode.getNodeName());
}
// create entry node
entry = new RTMLHistoryEntry();
// go through attribute list
attributeList = entryNode.getAttributes();
// timeStamp
attributeNode = attributeList.getNamedItem("timeStamp");
timeStamp = attributeNode.getNodeValue();
entry.setTimeStamp(timeStamp);
// go through child nodes
childList = entryNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Agent")
{
parseAgentNode(entry,childNode);
}
else if(childNode.getNodeName() == "Description")
entry.setDescription(parseStringNode("Description",childNode));
else if(childNode.getNodeName() == "Error")
entry.setError(parseStringNode("Error",childNode));
else if(childNode.getNodeName() == "Rejection")
parseRejectionNode(entry,childNode);
else if(childNode.getNodeName() == "Version")
entry.setVersion(parseIntegerNode(childNode));
else
System.err.println("parseHistoryEntryNode:ELEMENT:"+childNode);
}
}
// add entry to history
history.addEntry(entry);
}
/**
* Internal method to parse an Agent node.
* @param entry The history entry to add the agent to.
* @param agentNode The XML DOM node for the Agent tag node.
* @exception RTMLException Thrown if a strange child is in the node.
*/
private void parseAgentNode(RTMLHistoryEntry entry,Node agentNode)
throws RTMLException
{
RTMLIntelligentAgent intelligentAgent = null;
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(agentNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseAgentNode:Illegal Node:"+
agentNode);
}
if(agentNode.getNodeName() != "Agent")
{
throw new RTMLException(this.getClass().getName()+
":parseAgentNode:Illegal Node Name:"+
agentNode.getNodeName());
}
// add intelligentAgent node
intelligentAgent = new RTMLIntelligentAgent();
// go through attribute list
attributeList = agentNode.getAttributes();
// name
attributeNode = attributeList.getNamedItem("name");
if(attributeNode != null)
intelligentAgent.setId(attributeNode.getNodeValue());
else
intelligentAgent.setId(null);
// uri
attributeNode = attributeList.getNamedItem("uri");
if(attributeNode != null)
intelligentAgent.setUri(attributeNode.getNodeValue());
else
intelligentAgent.setUri(null);
// hostname/port not used in RTML3.1
intelligentAgent.setHostname(null);
intelligentAgent.setPort(0);
// set intelligentAgent in history entry.
entry.setAgent(intelligentAgent);
}
/**
* Internal method to parse an Rejection node.
* @param entry The history entry to add the rejection information to.
* @param rejectionNode The XML DOM node for the Rejection tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseStringNode
* @see org.estar.rtml.RTMLHistoryEntry#setRejectionReason
* @see org.estar.rtml.RTMLHistoryEntry#setRejectionDescription
*/
private void parseRejectionNode(RTMLHistoryEntry entry,Node rejectionNode) throws RTMLException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(rejectionNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseRejectionNode:Illegal Node:"+
rejectionNode);
}
if(rejectionNode.getNodeName() != "Rejection")
{
throw new RTMLException(this.getClass().getName()+
":parseRejectionNode:Illegal Node Name:"+
rejectionNode.getNodeName());
}
// go through attribute list
attributeList = rejectionNode.getAttributes();
// name
attributeNode = attributeList.getNamedItem("reason");
if(attributeNode != null)
entry.setRejectionReason(attributeNode.getNodeValue());
// go through child nodes
childList = rejectionNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Description")
entry.setRejectionDescription(parseStringNode("Description",childNode));
else
System.err.println("parseRejectionNode:ELEMENT:"+childNode);
}
}
}
/**
* Internal method to parse an Contact node. In RTML 3.1a, these are contained within a Project node,
* but as the document object model reflects RTML 2.2 the RTMLContact is in the top level RTMLDocument.
* @param rtmlDocument The document to add the Contact to.
* @param contactNode The XML DOM node for the Contact tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseRTMLAttributes
* @see #parseStringNode
* @see #parseNodeAttribute
* @see #parseCommunicationNode
*/
private void parseContactNode(RTMLDocument rtmlDocument,Node contactNode) throws RTMLException
{
NamedNodeMap attributeList = null;
Node childNode;
NodeList childList;
// check current XML node is correct
if(contactNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseContactNode:Illegal Node:"+
contactNode);
}
if(contactNode.getNodeName() != "Contact")
{
throw new RTMLException(this.getClass().getName()+":parseContactNode:Illegal Node Name:"+
contactNode.getNodeName());
}
// add contact node
RTMLContact contact = new RTMLContact();
// go through attribute list
attributeList = contactNode.getAttributes();
// get standard RTML attributes id,ref,uref
parseRTMLAttributes(contact,attributeList);
// go through child nodes
childList = contactNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Username")
contact.setUser(parseStringNode("Username",childNode));
else if(childNode.getNodeName() == "Name")
contact.setName(parseStringNode("Name",childNode));
else if(childNode.getNodeName() == "Institution")
contact.setInstitution(parseNodeAttribute("Institution",childNode,"name"));
else if(childNode.getNodeName() == "Communication")
parseCommunicationNode(contact, childNode);
else
System.err.println("parseContactNode:ELEMENT:"+childNode);
}
}
// Set contact in RTML document.
rtmlDocument.setContact(contact);
}
/**
* Internal method to parse a Communication node.
* @param contact The contact to add the communication data to.
* @param communicationNode The XML DOM node for the Communication tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseStringNode
*/
private void parseCommunicationNode(RTMLContact contact,Node communicationNode) throws RTMLException
{
URL url = null;
NamedNodeMap attributeList = null;
Node childNode;
NodeList childList;
String urlString = null;
// check current XML node is correct
if(communicationNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseCommunicationNode:Illegal Node:"+
communicationNode);
}
if(communicationNode.getNodeName() != "Communication")
{
throw new RTMLException(this.getClass().getName()+":parseCommunicationNode:Illegal Node Name:"+
communicationNode.getNodeName());
}
// go through child nodes
childList = communicationNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "AddressLine")
contact.setAddress(parseStringNode("AddressLine",childNode));
else if(childNode.getNodeName() == "Telephone")
contact.setTelephone(parseStringNode("Telephone",childNode));
else if(childNode.getNodeName() == "Fax")
contact.setFax(parseStringNode("Fax",childNode));
else if(childNode.getNodeName() == "Email")
contact.setEmail(parseStringNode("Email",childNode));
else if(childNode.getNodeName() == "Uri")
{
urlString = parseStringNode("Uri",childNode);
try
{
url = new URL(urlString);
}
catch(MalformedURLException e)
{
throw new RTMLException(this.getClass().getName()+
":parseCommunicationNode:Illegal URL ["+
urlString+"]", e);
}
contact.setUrl(url);
}
else
System.err.println("parseCommunicationNode:ELEMENT:"+childNode);
}
}
}
/**
* Internal method to parse an Project node.
* @param rtmlDocument The document to add the Project to.
* @param projectNode The XML DOM node for the Project tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseContactNode
* @see #parseRTMLAttributes
*/
private void parseProjectNode(RTMLDocument rtmlDocument,Node projectNode) throws RTMLException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(projectNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseProjectNode:Illegal Node:"+
projectNode);
}
if(projectNode.getNodeName() != "Project")
{
throw new RTMLException(this.getClass().getName()+":parseProjectNode:Illegal Node Name:"+
projectNode.getNodeName());
}
// add project node
RTMLProject project = new RTMLProject();
// go through attribute list
attributeList = projectNode.getAttributes();
// get standard RTML attributes id,ref,uref
parseRTMLAttributes(project,attributeList);
// name
attributeNode = attributeList.getNamedItem("ProjectID");
if(attributeNode != null)
project.setProject(attributeNode.getNodeValue());
else
project.setProject(null);
// go through child nodes
childList = projectNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Contact")
parseContactNode(rtmlDocument, childNode);
else
System.err.println("parseProjectNode:ELEMENT:"+childNode);
}
}
// Set project in RTML document.
rtmlDocument.setProject(project);
}
/**
* Internal method to parse a Telescope node.
* @param rtmlDocument The document to add the Telescope to.
* @param telescopeNode The XML DOM node for the Telescope tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseRTMLAttributes
* @see #parseApertureNode
* @see #parseStringNode
* @see #parseTelescopeLocationNode
* @see org.estar.rtml.RTMLTelescope
* @see org.estar.rtml.RTMLTelescope#setName
* @see org.estar.rtml.RTMLTelescope#setFocalRatio
* @see org.estar.rtml.RTMLDocument#setTelescope
*/
private void parseTelescopeNode(RTMLDocument rtmlDocument,Node telescopeNode) throws RTMLException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(telescopeNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseTelescopeNode:Illegal Node:"+
telescopeNode);
}
if(telescopeNode.getNodeName() != "Telescope")
{
throw new RTMLException(this.getClass().getName()+":parseTelescopeNode:Illegal Node Name:"+
telescopeNode.getNodeName());
}
// add project node
RTMLTelescope telescope = new RTMLTelescope();
// go through attribute list
attributeList = telescopeNode.getAttributes();
// get standard RTML attributes id,ref,uref
parseRTMLAttributes(telescope,attributeList);
// name
attributeNode = attributeList.getNamedItem("name");
if(attributeNode != null)
telescope.setName(attributeNode.getNodeValue());
else
telescope.setName(null);
// go through child nodes
childList = telescopeNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Aperture")
parseApertureNode(telescope,childNode);
else if(childNode.getNodeName() == "FocalLength")
parseFocalLengthNode(telescope,childNode);
else if(childNode.getNodeName() == "FocalRatio")
telescope.setFocalRatio(parseStringNode("FocalRatio",childNode));
else if(childNode.getNodeName() == "Location")
parseTelescopeLocationNode(telescope,childNode);
else
System.err.println("parseTelescopeNode:ELEMENT:"+childNode);
}
}
// Set telescope in RTML document.
rtmlDocument.setTelescope(telescope);
}
/**
* Internal method to parse an Aperture node.
* @param telescope The instance of Telescope to set the aperture data for.
* @param apertureNode The XML DOM node for the Aperture tag node.
* @exception RTMLException Thrown if a strange child is in the node, or a parse error occurs.
* @exception NumberFormatException Thrown if parsing the aperture value fails.
* @see org.estar.rtml.RTMLTelescope#setApertureUnits
* @see org.estar.rtml.RTMLTelescope#setApertureType
* @see org.estar.rtml.RTMLTelescope#setAperture(java.lang.String)
*/
private void parseApertureNode(RTMLTelescope telescope, Node apertureNode)
throws RTMLException, NumberFormatException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(apertureNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException
(this.getClass().getName()+":parseApertureNode:Illegal Node:"+apertureNode);
}
if(apertureNode.getNodeName() != "Aperture")
{
throw new RTMLException
(this.getClass().getName()+":parseApertureNode:Illegal Node Aperture:"+
apertureNode.getNodeName());
}
// go through attribute list
attributeList = apertureNode.getAttributes();
// units
attributeNode = attributeList.getNamedItem("units");
if(attributeNode != null)
telescope.setApertureUnits(attributeNode.getNodeValue());
else
telescope.setApertureUnits(null);
// type
attributeNode = attributeList.getNamedItem("type");
if(attributeNode != null)
telescope.setApertureType(attributeNode.getNodeValue());
else
telescope.setApertureType("geometric"); // default is geometric
// go through child nodes
childList = apertureNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.TEXT_NODE)
{
if(childNode.getNodeValue() != null)
{
// ensure it is not all whitespace
if(childNode.getNodeValue().trim().length() > 0)
{
telescope.setAperture(childNode.getNodeValue());
}
}
}
}
}
/**
* Internal method to parse an FocalLength node.
* @param telescope The instance of Telescope to set the focal length data for.
* @param focalLengthNode The XML DOM node for the FocalLength tag node.
* @exception RTMLException Thrown if a strange child is in the node, or a parse error occurs.
* @exception NumberFormatException Thrown if parsing the focal length value fails.
* @see org.estar.rtml.RTMLTelescope#setFocalLengthUnits
* @see org.estar.rtml.RTMLTelescope#setFocalLength(java.lang.String)
*/
private void parseFocalLengthNode(RTMLTelescope telescope, Node focalLengthNode)
throws RTMLException, NumberFormatException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(focalLengthNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException
(this.getClass().getName()+":parseFocalLengthNode:Illegal Node:"+focalLengthNode);
}
if(focalLengthNode.getNodeName() != "FocalLength")
{
throw new RTMLException
(this.getClass().getName()+":parseFocalLengthNode:Illegal Node FocalLength:"+
focalLengthNode.getNodeName());
}
// go through attribute list
attributeList = focalLengthNode.getAttributes();
// units
attributeNode = attributeList.getNamedItem("units");
if(attributeNode != null)
telescope.setFocalLengthUnits(attributeNode.getNodeValue());
else
telescope.setFocalLengthUnits(null);
// go through child nodes
childList = focalLengthNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.TEXT_NODE)
{
if(childNode.getNodeValue() != null)
{
// ensure it is not all whitespace
if(childNode.getNodeValue().trim().length() > 0)
{
telescope.setFocalLength(childNode.getNodeValue());
}
}
}
}
}
/**
* Internal method to parse an Telescope Location node.
* @param telescope The telescope to add the Location data to.
* @param locationNode The XML DOM node for the Location tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseStringNode
* @see org.estar.rtml.RTMLTelescopeLocation
* @see org.estar.rtml.RTMLTelescopeLocation#setName
* @see org.estar.rtml.RTMLTelescopeLocation#setLongitude
* @see org.estar.rtml.RTMLTelescopeLocation#setLatitude
* @see org.estar.rtml.RTMLTelescopeLocation#setAltitude
* @see org.estar.rtml.RTMLTelescope#setLocation
*/
private void parseTelescopeLocationNode(RTMLTelescope telescope,Node locationNode) throws RTMLException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(locationNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseTelescopeLocationNode:Illegal Node:"+
locationNode);
}
if(locationNode.getNodeName() != "Location")
{
throw new RTMLException(this.getClass().getName()+
":parseTelescopeLocationNode:Illegal Node Name:"+
locationNode.getNodeName());
}
// add location data to telescope
RTMLTelescopeLocation location = new RTMLTelescopeLocation();
// go through attribute list
attributeList = locationNode.getAttributes();
// get standard RTML attributes id,ref,uref
parseRTMLAttributes(location,attributeList);
// name
attributeNode = attributeList.getNamedItem("name");
if(attributeNode != null)
location.setName(attributeNode.getNodeValue());
else
location.setName(null);
// go through child nodes
childList = locationNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "EastLongitude")
location.setLongitude(parseStringNode("EastLongitude",childNode));
else if(childNode.getNodeName() == "Latitude")
location.setLatitude(parseStringNode("Latitude",childNode));
else if(childNode.getNodeName() == "Height")
location.setAltitude(parseStringNode("Height",childNode));
else
System.err.println("parseTelescopeLocationNode:ELEMENT:"+childNode);
}
}
// Set location in telescope.
telescope.setLocation(location);
}
/**
* Internal method to parse a Device node.
* @param rtmlDeviceHolder The object to add the device to - either an instance of RTMLDocument or
* RTMLObservation.
* @param deviceNode The XML DOM node for the Device tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseSetupNode
* @see #parseRTMLAttributes
* @see #parseStringNode
*/
private void parseDeviceNode(RTMLDeviceHolder rtmlDeviceHolder,Node deviceNode)
throws RTMLException
{
RTMLDevice device = null;
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(deviceNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseDeviceNode:Illegal Node:"+
deviceNode);
}
if(deviceNode.getNodeName() != "Device")
{
throw new RTMLException(this.getClass().getName()+
":parseDeviceNode:Illegal Node Name:"+
deviceNode.getNodeName());
}
// add Device node
device = new RTMLDevice();
// go through attribute list
attributeList = deviceNode.getAttributes();
// get standard RTML attributes id,ref,uref
parseRTMLAttributes(device,attributeList);
// type
attributeNode = attributeList.getNamedItem("type");
if(attributeNode != null)
device.setType(attributeNode.getNodeValue());
// name
attributeNode = attributeList.getNamedItem("name");
if(attributeNode != null)
device.setName(attributeNode.getNodeValue());
// go through child nodes
childList = deviceNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Setup")
parseSetupNode(device,childNode);
else if(childNode.getNodeName() == "SpectralRegion")
device.setSpectralRegion(parseStringNode("SpectralRegion",childNode));
else
System.err.println("parseDeviceNode:ELEMENT:"+childNode);
}
}
// set device in device holder (RTML document/RTML Observation).
rtmlDeviceHolder.setDevice(device);
}
/**
* Internal method to parse a Setup node (inside a Device node).
* @param device The RTMLDevice instance to add the setup data to.
* @param setupNode The XML DOM node for the Setup tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseFilterNode
* @see #parseDetectorNode
* @see #parseGratingNode
* @see #parseHalfWavePlateSubDeviceNode
*/
private void parseSetupNode(RTMLDevice device,Node setupNode)
throws RTMLException
{
NamedNodeMap attributeList = null;
Node childNode,attributeNode;
NodeList childList;
// check current XML node is correct
if(setupNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseSetupNode:Illegal Node:"+
setupNode);
}
if(setupNode.getNodeName() != "Setup")
{
throw new RTMLException(this.getClass().getName()+
":parseSetupNode:Illegal Node Name:"+
setupNode.getNodeName());
}
// go through child nodes
childList = setupNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Detector")
parseDetectorNode(device,childNode);
else if(childNode.getNodeName() == "Filter")
parseFilterNode(device,childNode);
else if(childNode.getNodeName() == "Grating")
parseGratingNode(device,childNode);
else if(childNode.getNodeName() == "Device")
parseHalfWavePlateSubDeviceNode(device,childNode);
else
System.err.println("parseSetupNode:ELEMENT:"+childNode);
}
}
}
/**
* Internal method to parse a Filter node.
* @param device The device to add the filter to.
* @param filterNode The XML DOM node for the Filter tag node.
* @exception RTMLException Thrown if a strange child is in the node.
*/
private void parseFilterNode(RTMLDevice device,Node filterNode)
throws RTMLException
{
RTMLGrating grating = null;
NamedNodeMap attributeList = null;
Node childNode,attributeNode,centerNode;
NodeList childList;
// check current XML node is correct
if(filterNode.getNodeType() != Node.ELEMENT_NODE)
{
throw new RTMLException(this.getClass().getName()+":parseFilterNode:Illegal Node:"+
filterNode);
}
if(filterNode.getNodeName() != "Filter")
{
throw new RTMLException(this.getClass().getName()+
":parseFilterNode:Illegal Node Name:"+
filterNode.getNodeName());
}
// go through attribute list
attributeList = filterNode.getAttributes();
// type
attributeNode = attributeList.getNamedItem("type");
if(attributeNode != null)
device.setFilterType(attributeNode.getNodeValue());
// go through child nodes
childList = filterNode.getChildNodes();
for(int i = 0; i < childList.getLength(); i++)
{
childNode = childList.item(i);
if(childNode.getNodeType() == Node.ELEMENT_NODE)
{
if(childNode.getNodeName() == "Center")
{
centerNode = childNode;
// currently used to respresent central wavelength of spectrograph.
// This is wrong!
if(device.getGrating() != null)
grating = device.getGrating();
else
grating = new RTMLGrating();
// go through attribute list
attributeList = centerNode.getAttributes();
// wavelengthUnits
attributeNode = attributeList.getNamedItem("units");
if(attributeNode != null)
grating.setWavelengthUnits(attributeNode.getNodeValue());
// wavelength is double value of node
grating.setWavelength(parseDoubleNode(centerNode));
// set grating in device.
device.setGrating(grating);
}
else
System.err.println("parseFilterNode:ELEMENT:"+childNode);
}
}
}
/**
* Internal method to parse a Detector node.
* @param device The device to add the detector to.
* @param detectorNode The XML DOM node for the Detector tag node.
* @exception RTMLException Thrown if a strange child is in the node.
* @see #parseBinningNode
* @see #parseGainNode
*/
private void parseDetectorNode(RTMLDevice device,Node detectorNode)
throws RTMLException
{
RTMLDetector detector = null;
NamedNodeMap attributeList = null;