public Field createField ( final MathRandom random , final Element element , final String characterSetId ) { Field field = null ; Element fieldElement = null ; Element fieldRefElement = element . getChild ( XMLTags . FIELD_REF ) ; if ( fieldRefElement != null ) { fieldElement = getElementFinder ( element ) . findElementById ( fieldRefElement ) ; } else { fieldElement = element . getChild ( XMLTags . FIELD ) ; } checkState ( fieldElement != null , "Could not find a Field tag or FieldRef tag" ) ; Class < ? extends Field > classObject = null ; try { classObject = getClassObject ( fieldElement ) ; Constructor < ? extends Field > constructor = classObject . getConstructor ( new Class [ ] { MathRandom . class , Element . class , String . class } ) ; field = constructor . newInstance ( new Object [ ] { random , fieldElement , characterSetId } ) ; } catch ( Exception e ) { throw new IllegalStateException ( "Could not initialise object of class " + classObject , e ) ; } return field ; }
Searches for the Field Child tag in the specified element or takes the Field_Ref Tag and generates a new field instance based on the tag data . So this method has to be called with an element as parameter that contains a field or a field_ref element respectively .