1717
1818import static com .rusticisoftware .tincan .InteractionType .getByString ;
1919
20+ import java .net .URI ;
2021import java .net .URISyntaxException ;
2122import java .util .ArrayList ;
2223import java .util .Iterator ;
4142public class ActivityDefinition extends JSONBase {
4243 private LanguageMap name ;
4344 private LanguageMap description ;
44- private String type ;
45+ private URI type ;
4546 private Extensions extensions ;
4647 private InteractionType interactionType ;
4748 private ArrayList <String > correctResponsesPattern ;
@@ -51,12 +52,13 @@ public class ActivityDefinition extends JSONBase {
5152 private ArrayList <InteractionComponent > target ;
5253 private ArrayList <InteractionComponent > steps ;
5354
55+
5456 public ActivityDefinition (JsonNode jsonNode ) throws URISyntaxException {
5557 this ();
5658
5759 JsonNode typeNode = jsonNode .path ("type" );
5860 if (! typeNode .isMissingNode ()) {
59- this .setType (typeNode .textValue ());
61+ this .setType (new URI ( typeNode .textValue () ));
6062 }
6163
6264 JsonNode nameNode = jsonNode .path ("name" );
@@ -84,60 +86,48 @@ public ActivityDefinition(JsonNode jsonNode) throws URISyntaxException {
8486 JsonNode correctResponsesPatternNode = jsonNode .path ("correctResponsesPattern" );
8587 if (! correctResponsesPatternNode .isMissingNode ()) {
8688 this .correctResponsesPattern = new ArrayList <String >();
87-
88- Iterator it = correctResponsesPatternNode .elements ();
89- while (it .hasNext ()) {
90- this .correctResponsesPattern .add (((JsonNode ) it .next ()).textValue ());
89+ for (JsonNode element : correctResponsesPatternNode ) {
90+ this .correctResponsesPattern .add (element .textValue ());
9191 }
9292 }
9393
9494 JsonNode choicesNode = jsonNode .path ("choices" );
9595 if (! choicesNode .isMissingNode ()) {
9696 this .choices = new ArrayList <InteractionComponent >();
97-
98- Iterator it = choicesNode .elements ();
99- while (it .hasNext ()) {
100- this .choices .add (new InteractionComponent ((JsonNode ) it .next ()));
97+ for (JsonNode element : choicesNode ) {
98+ this .choices .add (new InteractionComponent (element ));
10199 }
102100 }
103101
104102 JsonNode scaleNode = jsonNode .path ("scale" );
105103 if (! scaleNode .isMissingNode ()) {
106104 this .scale = new ArrayList <InteractionComponent >();
107-
108- Iterator it = scaleNode .elements ();
109- while (it .hasNext ()) {
110- this .scale .add (new InteractionComponent ((JsonNode ) it .next ()));
105+ for (JsonNode element : scaleNode ) {
106+ this .scale .add (new InteractionComponent (element ));
111107 }
112108 }
113109
114110 JsonNode sourceNode = jsonNode .path ("source" );
115111 if (! sourceNode .isMissingNode ()) {
116112 this .source = new ArrayList <InteractionComponent >();
117-
118- Iterator it = sourceNode .elements ();
119- while (it .hasNext ()) {
120- this .source .add (new InteractionComponent ((JsonNode ) it .next ()));
113+ for (JsonNode element : sourceNode ) {
114+ this .source .add (new InteractionComponent (element ));
121115 }
122116 }
123117
124118 JsonNode targetNode = jsonNode .path ("target" );
125119 if (! targetNode .isMissingNode ()) {
126120 this .target = new ArrayList <InteractionComponent >();
127-
128- Iterator it = targetNode .elements ();
129- while (it .hasNext ()) {
130- this .target .add (new InteractionComponent ((JsonNode ) it .next ()));
121+ for (JsonNode element : targetNode ) {
122+ this .target .add (new InteractionComponent (element ));
131123 }
132124 }
133125
134126 JsonNode stepsNode = jsonNode .path ("steps" );
135127 if (! stepsNode .isMissingNode ()) {
136128 this .steps = new ArrayList <InteractionComponent >();
137-
138- Iterator it = stepsNode .elements ();
139- while (it .hasNext ()) {
140- this .steps .add (new InteractionComponent ((JsonNode ) it .next ()));
129+ for (JsonNode element : stepsNode ) {
130+ this .steps .add (new InteractionComponent (element ));
141131 }
142132 }
143133 }
@@ -165,7 +155,7 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
165155 node .put ("description" , this .getDescription ().toJSONNode (version ));
166156 }
167157 if (this .type != null ) {
168- node .put ("type" , this .getType ());
158+ node .put ("type" , this .getType (). toString () );
169159 }
170160 if (this .extensions != null ) {
171161 node .put ("extensions" , this .getExtensions ().toJSONNode (version ));
@@ -244,4 +234,12 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
244234 }
245235 return node ;
246236 }
237+
238+ public void setType (URI type ) {
239+ this .type = type ;
240+ }
241+
242+ public void setType (String type ) throws URISyntaxException {
243+ this .setType (new URI (type ));
244+ }
247245}
0 commit comments