FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
epicsCoreJava/normativeTypesJava/src/org/epics/nt/NTURI.java at master · shroffk/epicsCoreJava · GitHub
shroffk
epicsCoreJava
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
epicsCoreJava
/
normativeTypesJava
/
src
/
org
/
epics
/
nt
/
NTURI.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
318 lines (285 loc) · 9.03 KB
Breadcrumbs
epicsCoreJava
/
normativeTypesJava
/
src
/
org
/
epics
/
nt
/
NTURI.java
Copy path
File metadata and controls
318 lines (285 loc) · 9.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
package
org
.
epics
.
nt
;
import
org
.
epics
.
pvdata
.
pv
.
Field
;
import
org
.
epics
.
pvdata
.
pv
.
Scalar
;
import
org
.
epics
.
pvdata
.
pv
.
ScalarType
;
import
org
.
epics
.
pvdata
.
pv
.
Structure
;
import
org
.
epics
.
pvdata
.
pv
.
PVField
;
import
org
.
epics
.
pvdata
.
pv
.
PVScalar
;
import
org
.
epics
.
pvdata
.
pv
.
PVScalarArray
;
import
org
.
epics
.
pvdata
.
pv
.
PVStructure
;
import
org
.
epics
.
pvdata
.
pv
.
PVString
;
import
org
.
epics
.
pvdata
.
pv
.
PVStringArray
;
import
org
.
epics
.
pvdata
.
property
.
PVTimeStamp
;
import
org
.
epics
.
pvdata
.
property
.
PVAlarm
;
/**
* Wrapper class for NTURI.
*
* @author dgh
*/
public
class
NTURI
{
public
static
final
String
URI
=
"epics:nt/NTURI:1.0"
;
/**
* Creates an NTURI wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTURI
* and if so returns an NTURI which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTURI instance on success, null otherwise
*/
public
static
NTURI
wrap
(
PVStructure
pvStructure
)
{
if
(!
isCompatible
(
pvStructure
))
return
null
;
return
wrapUnsafe
(
pvStructure
);
}
/**
* Creates an NTURI wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTURI or is non-null.
*
* @param structure the PVStructure to be wrapped
* @return NTURI instance
*/
public
static
NTURI
wrapUnsafe
(
PVStructure
structure
)
{
return
new
NTURI
(
structure
);
}
/**
* Returns whether the specified Structure reports to be a compatible NTURI.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTURI through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test.
* @return (false,true) if (is not, is) a compatible NTURI.
*/
public
static
boolean
is_a
(
Structure
structure
)
{
return
NTUtils
.
is_a
(
structure
.
getID
(),
URI
);
}
/**
* Returns whether the specified PVStructure reports to be a compatible NTURI.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTURI through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test.
* @return (false,true) if (is not, is) a compatible NTURI.
*/
public
static
boolean
is_a
(
PVStructure
pvStructure
)
{
return
is_a
(
pvStructure
.
getStructure
());
}
/**
* Returns whether the specified Structure is compatible with NTURI.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTURI through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if (is not, is) a compatible NTURI
*/
public
static
boolean
isCompatible
(
Structure
structure
)
{
if
(
structure
==
null
)
return
false
;
Scalar
schemeField
=
structure
.
getField
(
Scalar
.
class
,
"scheme"
);
if
(
schemeField
==
null
)
return
false
;
if
(
schemeField
.
getScalarType
() !=
ScalarType
.
pvString
)
return
false
;
Scalar
pathField
=
structure
.
getField
(
Scalar
.
class
,
"path"
);
if
(
pathField
==
null
)
return
false
;
if
(
pathField
.
getScalarType
() !=
ScalarType
.
pvString
)
return
false
;
Field
field
=
structure
.
getField
(
"authority"
);
if
(
field
!=
null
)
{
Scalar
authorityField
=
structure
.
getField
(
Scalar
.
class
,
"authority"
);
if
(
authorityField
==
null
||
authorityField
.
getScalarType
() !=
ScalarType
.
pvString
)
return
false
;
}
field
=
structure
.
getField
(
"query"
);
if
(
field
!=
null
)
{
Structure
queryField
=
structure
.
getField
(
Structure
.
class
,
"query"
);
if
(
queryField
==
null
)
return
false
;
try
{
// check fields are scalars and int/double/string
Field
[]
queryFields
=
queryField
.
getFields
();
for
(
Field
f
:
queryFields
)
{
ScalarType
t
= ((
Scalar
)
f
).
getScalarType
();
switch
(
t
)
{
case
pvString
:
case
pvDouble
:
case
pvInt
:
break
;
default
:
return
false
;
}
}
}
catch
(
ClassCastException
e
) {
return
false
; }
}
return
true
;
}
/**
* Returns whether the specified PVStructure is compatible with NTURI.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTURI through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if (is not, is) a compatible NTURI
*/
public
static
boolean
isCompatible
(
PVStructure
pvStructure
)
{
if
(
pvStructure
==
null
)
return
false
;
return
isCompatible
(
pvStructure
.
getStructure
());
}
/**
* Returns whether the wrapped PVStructure is a valid NTURI.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTURI.
*/
public
boolean
isValid
()
{
return
true
;
}
/**
* Creates an NTURI builder instance.
*
* @return builder instance.
*/
public
static
NTURIBuilder
createBuilder
()
{
return
new
NTURIBuilder
();
}
/**
* Returns the PVStructure wrapped by this instance.
*
* @return the PVStructure wrapped by this instance
*/
public
PVStructure
getPVStructure
()
{
return
pvNTURI
;
}
/**
* Returns the scheme field.
*
* @return the scheme field
*/
public
PVString
getScheme
()
{
return
pvNTURI
.
getSubField
(
PVString
.
class
,
"scheme"
);
}
/**
* Returns the authority field.
*
* @return the authority field or null if no such field
*/
public
PVString
getAuthority
()
{
return
pvNTURI
.
getSubField
(
PVString
.
class
,
"authority"
);
}
/**
* Returns the path field.
*
* @return the path field
*/
public
PVString
getPath
()
{
return
pvNTURI
.
getSubField
(
PVString
.
class
,
"path"
);
}
/**
* Returns the query field.
*
* @return the query field or null if no such field
*/
public
PVStructure
getQuery
()
{
return
pvQuery
;
}
/**
* Returns the names of the query fields for the URI.
* For each name, calling getQueryField should return
* the query field, which should not be null.
*
* @return the query field names
*/
public
String
[]
getQueryNames
()
{
if
(
pvQuery
==
null
)
return
new
String
[
0
];
return
pvQuery
.
getStructure
().
getFieldNames
();
}
/**
* Returns the query subfield with the specified name.
*
* @param name the name of the requested field
* @return the query subfield or null if the subfield does not exist
*/
public
PVScalar
getQueryField
(
String
name
)
{
PVField
pvField
=
pvQuery
.
getSubField
(
name
);
if
(
PVScalar
.
class
.
isInstance
(
pvField
))
return
(
PVScalar
)(
pvField
);
else
return
null
;
}
/**
* Returns the query subfield with the specified name and
* of a specified type (e.g. PVString).
*
* @param <T> the expected type of the query field
* @param c class object modeling the class T (must be PVString, PVDouble or PVInt)
* @param name the name of the query field
* @return the query subfield or null if the subfield does not exist
* or the field is not of <code>c</code> type
*/
public
<
T
extends
PVScalar
>
T
getQueryField
(
Class
<
T
>
c
,
String
name
)
{
PVField
pvField
=
pvQuery
.
getSubField
(
name
);
if
(
c
.
isInstance
(
pvField
))
return
c
.
cast
(
pvField
);
else
return
null
;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public
String
toString
()
{
return
getPVStructure
().
toString
();
}
/**
* Constructor.
*
* @param pvStructure the PVStructure to be wrapped
*/
NTURI
(
PVStructure
pvStructure
)
{
pvNTURI
=
pvStructure
;
pvQuery
=
pvNTURI
.
getSubField
(
PVStructure
.
class
,
"query"
);
}
private
PVStructure
pvNTURI
;
private
PVStructure
pvQuery
;
}
Back
|
FazBrowse Home
|
New Git URL