- \r
- /**\r
- * Get tag by name.\r
- * \r
- * @param fieldName component name\r
- * @return component index or <code>null</code> if one does not exist\r
- */\r
- public Integer getComponentIndex(String fieldName) {\r
- for (int i=0; i<components.length; i++)\r
- if (components[i].name.equals(fieldName)) return i;\r
- return null;\r
- }\r
- \r
- /**\r
- * Get tag by name.\r
- * \r
- * @param fieldName component name\r
- * @return component index or -1 if one does not exist\r
- */\r
- public int getComponentIndex2(String fieldName) {\r
- for (int i=0; i<components.length; i++)\r
- if (components[i].name.equals(fieldName)) return i;\r
- return -1;\r
- }\r
- \r
-\r
- /**\r
- * Get component Datatype by field name\r
- * @param fieldName\r
- * @return datatype or <code>null</code>\r
- */\r
- public Datatype getComponentType(String fieldName) {\r
- int index = getComponentIndex2(fieldName);\r
- if (index<0) return null;\r
- return components[index].type;\r
- }\r
- \r
- /**\r
- * Get component by name.\r
- * \r
- * @param fieldName component name\r
- * @return component or <code>null</code> if one does not exist\r
- */\r
- public Component getComponent(String fieldName) {\r
- for (Component c : components)\r
- if (c.name.equals(fieldName)) return c;\r
- return null;\r
- }\r
-\r
- @Override\r
- public Datatype getComponentType(int index) {\r
- return components[index].type; \r
- }\r
- \r
- /**\r
- * UnionType is enumeration if all its components are empty records\r
- * @return true if enumeration type\r
- */\r
- public boolean isEnumeration() {\r
- boolean isEnum = true;\r
- for (Component c : components) isEnum &= c.type.equals( Datatypes.VOID );\r
- return isEnum;\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <T extends Datatype> T getChildType(ChildReference reference) throws ReferenceException {\r
- if (reference==null) return (T) this;\r
- \r
- if (reference instanceof LabelReference) {\r
- LabelReference lr = (LabelReference) reference;\r
- int tag = getComponentIndex( lr.label );\r
- \r
- if (tag<0 && lr.label.equals("uv")) {\r
- throw new ReferenceException("Cannot get component reference without an instance");\r
- }\r
- \r
- return components[tag].type.getChildType(reference.getChildReference()); \r
- }\r
- \r
- if (reference instanceof ComponentReference) {\r
- throw new ReferenceException("Cannot get component reference without an instance");\r
- }\r
- \r
- if (reference instanceof IndexReference) {\r
- IndexReference ir = (IndexReference) reference;\r
- int tag = ir.index;\r
- if (tag<0 || tag>=getComponentCount()) throw new ReferenceException("Tag index out of bounds");\r
- return components[tag].type.getChildType(reference.getChildReference());\r
- }\r
- \r
- if (reference instanceof NameReference) {\r
- NameReference nr = (NameReference) reference;\r
- int tag = getComponentIndex2( nr.name );\r
- if (tag<0) throw new ReferenceException("Tag by name \""+nr.name+"\" is not found");\r
- return components[tag].type.getChildType(reference.getChildReference());\r
- }\r
- \r
- throw new ReferenceException(reference.getClass()+" is not a reference of UnionType");\r
- }\r
+
+ /**
+ * Get tag by name.
+ *
+ * @param fieldName component name
+ * @return component index or <code>null</code> if one does not exist
+ */
+ public Integer getComponentIndex(String fieldName) {
+ for (int i=0; i<components.length; i++)
+ if (components[i].name.equals(fieldName)) return i;
+ return null;
+ }
+
+ /**
+ * Get tag by name.
+ *
+ * @param fieldName component name
+ * @return component index or -1 if one does not exist
+ */
+ public int getComponentIndex2(String fieldName) {
+ for (int i=0; i<components.length; i++)
+ if (components[i].name.equals(fieldName)) return i;
+ return -1;
+ }
+
+
+ /**
+ * Get component Datatype by field name
+ * @param fieldName
+ * @return datatype or <code>null</code>
+ */
+ public Datatype getComponentType(String fieldName) {
+ int index = getComponentIndex2(fieldName);
+ if (index<0) return null;
+ return components[index].type;
+ }
+
+ /**
+ * Get component by name.
+ *
+ * @param fieldName component name
+ * @return component or <code>null</code> if one does not exist
+ */
+ public Component getComponent(String fieldName) {
+ for (Component c : components)
+ if (c.name.equals(fieldName)) return c;
+ return null;
+ }
+
+ @Override
+ public Datatype getComponentType(int index) {
+ return components[index].type;
+ }
+
+ /**
+ * UnionType is enumeration if all its components are empty records
+ * @return true if enumeration type
+ */
+ public boolean isEnumeration() {
+ boolean isEnum = true;
+ for (Component c : components) isEnum &= c.type.equals( Datatypes.VOID );
+ return isEnum;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Datatype> T getChildType(ChildReference reference) throws ReferenceException {
+ if (reference==null) return (T) this;
+
+ if (reference instanceof LabelReference) {
+ LabelReference lr = (LabelReference) reference;
+ int tag = getComponentIndex( lr.label );
+
+ if (tag<0 && lr.label.equals("uv")) {
+ throw new ReferenceException("Cannot get component reference without an instance");
+ }
+
+ return components[tag].type.getChildType(reference.getChildReference());
+ }
+
+ if (reference instanceof ComponentReference) {
+ throw new ReferenceException("Cannot get component reference without an instance");
+ }
+
+ if (reference instanceof IndexReference) {
+ IndexReference ir = (IndexReference) reference;
+ int tag = ir.index;
+ if (tag<0 || tag>=getComponentCount()) throw new ReferenceException("Tag index out of bounds");
+ return components[tag].type.getChildType(reference.getChildReference());
+ }
+
+ if (reference instanceof NameReference) {
+ NameReference nr = (NameReference) reference;
+ int tag = getComponentIndex2( nr.name );
+ if (tag<0) throw new ReferenceException("Tag by name \""+nr.name+"\" is not found");
+ return components[tag].type.getChildType(reference.getChildReference());
+ }
+
+ throw new ReferenceException(reference.getClass()+" is not a reference of UnionType");
+ }