Class SpecGenerator


  • public class SpecGenerator
    extends Object

    Generates a HUTN spec in a LIFO manner. ClassObjects are generated using #generateTopLevelClassObject(String) and #generateContainedClassObject(String, String).

    Before generating any ClassObjects, the generator must first be initialised using initialise() or initialise(String).

    To nest class objects, first use a call to #generateTopLevelClassObject(String) and then add levels of nesting with #generateContainedClassObject(String).

    A call to stopGeneratingCurrentClassObject() completes the generation of the current class object. Furthermore, the next class object to be generated will have the same parent as the last class object to be generated.

    Example: To generate the following structure:

      Family {
        members: Person { dog: Dog {} }, Person {}
      }
    the following calls would be made:
      initialise("families");
      generateTopLevelClassObject("Family");
        generateContainedClassObject("Person");
          generateContainedClassObject("Dog");
          stopGeneratingCurrentClassObject(); // Dog
        stopGeneratingCurrentClassObject(); // Person
        generateContainedClassObject("Person");
        stopGeneratingCurrentClassObject();
      stopGeneratingCurrentClassObject(); // Family
    The last two lines are optional, if no further ClassObjects are to be generated.

    Author:
    lrose
    • Constructor Detail

      • SpecGenerator

        public SpecGenerator()
    • Method Detail

      • getSpec

        public Spec getSpec()
      • initialise

        public void initialise()
      • initialise

        public void initialise​(String nsUri)
      • generateTopLevelClassObject

        public void generateTopLevelClassObject​(String identifier,
                                                String type,
                                                int lineNumber)
      • generateContainedClassObject

        public void generateContainedClassObject​(String containingFeature,
                                                 String identifier,
                                                 int lineNumber)
        Generates a new ClassObject whose type is determined by inspecting the class of the parent ClassObject. If no feature with the name specified can be found in the class of the parent ClassObject, the newly generated ClassObject will have type "UnknownType".
        Parameters:
        containingFeature - - the name of the feature in the parent ClassObject that will contain the newly generated
        identifier - - the identifier for the ClassObject to be created. Identifiers are used when adding values to reference slots. null is allowed, but this will create a ClassObject that cannot be referenced. ClassObject.
      • generateContainedClassObject

        public void generateContainedClassObject​(String containingFeature,
                                                 String identifier,
                                                 String type,
                                                 int lineNumber)

        Generates a new ClassObject with the type specified. The newly generated ClassObject will be placed in a ContainmentSlot, with the feature specified, of the parent ClassObject.

        If the parent ClassObject contains an existing ContainmentSlot with the feature specified, the newly generated ClassObject will be added to the values of that slot. Otherwise, a new ContainmentSlot with the feature specified will be created.

        Parameters:
        type - - the type of ClassObject to be generated.
        containingFeature - - the name of the feature in the parent ClassObject that will contain the newly generated ClassObject.
        identifier - - the identifier for the ClassObject to be created. Identifiers are used when adding values to reference slots. null is allowed, but this will create a ClassObject that cannot be referenced.
        lineNumber - - the line number of the generated ClassObject
      • getCurrentClassObject

        public ClassObject getCurrentClassObject()
      • hasCurrentClassObject

        public boolean hasCurrentClassObject()
      • stopGeneratingCurrentClassObject

        public void stopGeneratingCurrentClassObject()
      • stopGeneratingAndDeleteCurrentClassObject

        public void stopGeneratingAndDeleteCurrentClassObject()
      • addAttributeValue

        public void addAttributeValue​(String featureName,
                                      String value,
                                      int lineNumber)