forked from opencadc/caom2ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameResolverData.java
More file actions
144 lines (121 loc) · 4.99 KB
/
NameResolverData.java
File metadata and controls
144 lines (121 loc) · 4.99 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
/*
************************************************************************
**** C A N A D I A N A S T R O N O M Y D A T A C E N T R E *****
*
* (c) 2007. (c) 2007.
* National Research Council Conseil national de recherches
* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6
* All rights reserved Tous droits reserves
*
* NRC disclaims any warranties Le CNRC denie toute garantie
* expressed, implied, or statu- enoncee, implicite ou legale,
* tory, of any kind with respect de quelque nature que se soit,
* to the software, including concernant le logiciel, y com-
* without limitation any war- pris sans restriction toute
* ranty of merchantability or garantie de valeur marchande
* fitness for a particular pur- ou de pertinence pour un usage
* pose. NRC shall not be liable particulier. Le CNRC ne
* in any event for any damages, pourra en aucun cas etre tenu
* whether direct or indirect, responsable de tout dommage,
* special or general, consequen- direct ou indirect, particul-
* tial or incidental, arising ier ou general, accessoire ou
* from the use of the software. fortuit, resultant de l'utili-
* sation du logiciel.
*
**** C A N A D I A N A S T R O N O M Y D A T A C E N T R E *****
************************************************************************
*/
package ca.nrc.cadc.search.nameresolver;
import ca.nrc.cadc.astro.CoordUtil;
import ca.nrc.cadc.search.nameresolver.exception.ClientException;
import java.util.Properties;
/**
* Simple class to hold the results from a Name Resolver query.
*/
public class NameResolverData {
private static final String LF = "\n";
private double ra;
private double dec;
private String target;
private String coordsys;
private String service;
private String objectName;
private String objectType;
private String morphologyType;
private int time;
public NameResolverData(final Properties properties) throws ClientException {
this.ra = CoordUtil.raToDegrees(getProperty(properties, NameResolverDataKey.RA));
this.dec = CoordUtil.decToDegrees(getProperty(properties, NameResolverDataKey.DEC));
this.service = getProperty(properties, NameResolverDataKey.SERVICE);
this.coordsys = getProperty(properties, NameResolverDataKey.COORDSYS);
this.time = Integer.parseInt(getProperty(properties, NameResolverDataKey.TIME));
this.target = getProperty(properties, NameResolverDataKey.TARGET);
this.objectName = getProperty(properties, NameResolverDataKey.ONAME);
this.objectType = getProperty(properties, NameResolverDataKey.OTYPE);
this.morphologyType = getProperty(properties, NameResolverDataKey.MTYPE);
}
private String getProperty(final Properties properties, final NameResolverDataKey nameResolverDataKey)
throws ClientException {
if (properties.containsKey(nameResolverDataKey.getKeyLabel())) {
return properties.getProperty(nameResolverDataKey.getKeyLabel());
} else if (nameResolverDataKey.isRequired()) {
throw new ClientException(nameResolverDataKey.getKeyLabel() + " not found in query results.");
} else {
return null;
}
}
public NameResolverData(double ra, double dec, String target, String coordsys, String service,
String objectName, String objectType, String morphologyType, int time) {
this.ra = ra;
this.dec = dec;
this.target = target;
this.coordsys = coordsys;
this.service = service;
this.objectName = objectName;
this.objectType = objectType;
this.morphologyType = morphologyType;
this.time = time;
}
public double getRa() {
return ra;
}
public double getDec() {
return dec;
}
public String getTarget() {
return target;
}
public String getCoordsys() {
return coordsys;
}
public String getService() {
return service;
}
public String getObjectName() {
return objectName;
}
public String getObjectType() {
return objectType;
}
public String getMorphologyType() {
return morphologyType;
}
public int getTime() {
return time;
}
/**
* @return String representation of the object.
*/
@Override
public String toString() {
return "target=" + target + LF +
"service=" + service + LF +
"coordsys=" + coordsys + LF +
"ra=" + ra + LF +
"dec=" + dec + LF +
"oname=" + (objectName == null ? "" : objectName) + LF +
"otype=" + (objectType == null ? "" : objectType) + LF +
"mtype=" + (morphologyType == null ? "" : morphologyType) + LF +
"time=" + time + LF;
}
}