Class CMLBaseImpl

All Implemented Interfaces:
AbstractBase, CMLNode, Element, Node

public class CMLBaseImpl extends PMRElementImpl implements AbstractBase
The base class for all elementObjects mentioned in the Schema

Any CML element may have attributes:titleiddictRefconvention and convenience get/set methods are provided for allAn element (FOO) subclassed from a AbstractBase may be constructed in the following ways:FOO(). Creates a new empty element with null values of the attributes. Required for newInstance(), but use carefully since it has no tagName and no document associated with it.FOO(String tagName, CMLDocument document). Creates an empty element with null attribute names.FOO(org.w3c.dom.Element element). Creates a subclassed Element with the same attribute values as the input Element. Used when a DOM has been created with non-CML-aware software. The routine makeAndProcessSubclass(Element element) will replace the current Element with the appropriate CML subclass.FOO(String title, String id, String dictRef, String convention). Makes subclassed Element and sets attribute values.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Field Details

    • version

      protected String version
    • arraySyntax

      protected boolean arraySyntax
    • tool

      protected BaseTool tool
    • debug

      protected boolean debug
    • tagName

      protected String tagName
    • ownerDocument

      protected AbstractCMLDocument ownerDocument
  • Constructor Details

    • CMLBaseImpl

      public CMLBaseImpl()
      create a Node WITHOUT tagName OR document Use with care
    • CMLBaseImpl

      protected CMLBaseImpl(String tagName, AbstractCMLDocument document)
      used when creating new nodes in a DOM
    • CMLBaseImpl

      public CMLBaseImpl(String tagName, Document document)
  • Method Details

    • init

      protected void init()
    • getCMLDocument

      public AbstractCMLDocument getCMLDocument()
      Description copied from interface: AbstractBase
      get owner document as CMLDocument.
      Specified by:
      getCMLDocument in interface AbstractBase
      Returns:
      the document
    • getClassTagName

      public String getClassTagName()
    • addChild

      public void addChild(Element elem) throws CMLException
      content model

      adds a child to the element content. The elementName is checked for validity (but not its position in the list of children). It will always be added at the end. Therefore when building a DOM the author must ensure that all elements are added in correct order or must validate after addition. The count will be taken from the sum of the allowed children. Thus foo, bar, foo* will allow the addition of 1 bar and many foos.

      Parameters:
      elem - the element to add (identified by elementName not class)
      Throws:
      CMLException - element cannot be added (violates content model)
    • deleteChild

      public void deleteChild(Element elem) throws CMLException
      delete an element The element must have been previously created and present in the DOM
      Parameters:
      elem - element to be deleted.
      Throws:
      CMLException - element would leave invalid content
    • getFirstChild

      public Element getFirstChild(String elementName)
      gets the first Child of a given type (by elementName) This method will normally be used when there is a single child of this type
      Parameters:
      elementName -
      Returns:
      null if no elements of this type
    • getChildVector

      public Vector<Element> getChildVector(String elementName)
      gets a Vector of all child elements with this name
      Parameters:
      elementName -
      Returns:
      if no children an empty vector (not null) is returned
    • getChildList

      public Element[] getChildList(String elementName)
      gets a (typed) list of child elements with a given name
      Parameters:
      elementName -
      Returns:
      returns a zero length list if none found
    • appendChild

      public Node appendChild(Element elem) throws CMLException
      traps the addition of an child to the element content By default this will be routed to addChild() and org.w3c.dom.Node.appendChild(), but other element-specific stuff can be interposed (within the Cont
      Parameters:
      elem - the element to add (identified by elementName not class)
      Throws:
      CMLException - element cannot be added (violates content model)
    • getOrCreateChild

      public Element getOrCreateChild(String elemName) throws CMLException
      get a child of a given name If it doesn't exist, create and add it
      Specified by:
      getOrCreateChild in interface AbstractBase
      Parameters:
      elemName - the elementName to get/create (identified by elementName not class)
      Returns:
      the Element
      Throws:
      CMLException - element cannot be added (violates content model)
    • setContentValue

      public void setContentValue(String value)
      adds text content to an element should only be used for text-only or mixed content.
      Specified by:
      setContentValue in interface AbstractBase
      Parameters:
      value - the content
      Throws:
      CMLException - thrown by subclasses
    • getContentValue

      public String getContentValue()
      gets text content from an element should only be used for text-only or mixed content.
      Specified by:
      getContentValue in interface AbstractBase
      Returns:
      value the content; "" if none
      Throws:
      CMLException - thrown by subclasses
    • removeTextChildren

      public void removeTextChildren() throws CMLException
      removes whitespace nodes or throws any Exception for non-whitespace ones
      Specified by:
      removeTextChildren in interface AbstractBase
      Throws:
      CMLException - non-whitespace Text node
    • characters

      public void characters(SaxHandler saxHandler, String content) throws CMLException
      SAX2 parsing routine called from characters() callback NOT namespace aware
      Specified by:
      characters in interface AbstractBase
      Parameters:
      saxHandler - SaxHandler
      content - throws exception (probably application specific)
      Throws:
      CMLException
    • endElement

      public void endElement(SaxHandler saxHandler) throws CMLException
      SAX2 parsing routine called from endElement() callback NOT namespace aware
      Specified by:
      endElement in interface AbstractBase
      Parameters:
      saxHandler - Saxhandler throws exception (probably application specific)
      Throws:
      CMLException
    • startElement

      public void startElement(SaxHandler saxHandler, Attributes attributes) throws CMLException
      SAX2 parsing routine called from startElement() callback NOT namespace aware
      Specified by:
      startElement in interface AbstractBase
      Parameters:
      saxHandler - Saxhandler
      attributes - the attribute list throws exception (probably application specific)
      Throws:
      CMLException
    • setAttribute

      public void setAttribute(String name, String value)
      set attribute. do not use. may be called by autogenerated code. reroutes calls to attribute "elementContent" to setTextChild
      Specified by:
      setAttribute in interface AbstractBase
      Specified by:
      setAttribute in interface Element
      Overrides:
      setAttribute in class PMRElementImpl
      Parameters:
      name - The name of the attribute to create or alter.
      value - Value to set in string form.
    • addTextChild

      public void addTextChild(String value)
      addStringContent to Element

      if no Text child, creates one if Text child, resets value if existing non-Text children, no action

      Parameters:
      value - to add
      See Also:
    • setTextChild

      public void setTextChild(String value)
      addStringContent to Element

      if no Text child, creates one if Text child, resets value if existing non-Text children, no action

      Specified by:
      setTextChild in interface AbstractBase
      Parameters:
      value - to add
    • setDebug

      public void setDebug(boolean d)
      toggle debugging
      Specified by:
      setDebug in interface AbstractBase
      Parameters:
      d - debug
    • getDebug

      public boolean getDebug()
      debug status
      Specified by:
      getDebug in interface AbstractBase
      Returns:
      is debug set
    • debug

      protected void debug(String s)
      output string if debug set
      Parameters:
      s - string to output
    • setVersion

      public void setVersion(String v) throws CMLException
      set CML version

      1 or 2 at present (default 2)

      Specified by:
      setVersion in interface CMLNode
      Parameters:
      v - version
    • setArraySyntax

      public void setArraySyntax(boolean syntax)
      set array syntax

      set CML array syntax (default false)

      Specified by:
      setArraySyntax in interface CMLNode
      Parameters:
      syntax -
    • writeXML

      public void writeXML(Writer w, String control) throws CMLException, IOException
      write XML (allows for syntactic variants)
      Specified by:
      writeXML in interface CMLNode
      Parameters:
      w - - output
      control - - application specific string for example "CML1 array" or "CML2"
      Throws:
      IOException
      CMLException
    • writeXML

      public void writeXML(Writer w) throws CMLException, IOException
      write XML use current control (version and syntax)
      Specified by:
      writeXML in interface AbstractBase
      Specified by:
      writeXML in interface CMLNode
      Parameters:
      w - - output
      Throws:
      CMLException
      IOException
    • writeXML0

      public static void writeXML0(Element elem, Writer w, String control) throws IOException, CMLException
      Throws:
      IOException
      CMLException
    • outputChildren

      public static void outputChildren(Element elem, Writer w, String control) throws IOException, CMLException
      Throws:
      IOException
      CMLException
    • deepCopy

      public AbstractBase deepCopy()
      deep clones an element including subclassing.

      uses intermediate XML serialization object is owned by a new document all CML elements have correct subclass

      Specified by:
      deepCopy in interface AbstractBase
      Returns:
      the copied object
    • deepCopy

      public AbstractBase deepCopy(AbstractCMLDocument document)
      deep clones an element including subclassing

      uses intermediate XML serialization object is owned by document

      Specified by:
      deepCopy in interface AbstractBase
      Parameters:
      document - ownerDocument
      Returns:
      the copied object
    • getTool

      public BaseTool getTool()
      get tool.

      creates one if not already created do not use if subclass is known to compiler (use FooToolImpl.getTool(foo) instead)

      Specified by:
      getTool in interface AbstractBase
      Returns:
      the tool
    • getOrCreateTool

      public BaseTool getOrCreateTool()
      get or create tool.

      creates one if not already created should only be used when the subclass is not known to the compiler i.e. where an abstractBase is found

      Specified by:
      getOrCreateTool in interface AbstractBase
      Returns:
      the tool
    • setTool

      public void setTool(BaseTool t)
      set tool

      not user-callable

      Specified by:
      setTool in interface AbstractBase
      Parameters:
      t - tool
    • createToolClassName

      public static String createToolClassName(AbstractBase abstractBase)
      constructs a class name for tool

      at present converts some.where.bar.FooImpl to some.where.tool.FooToolImpl

      Parameters:
      abstractBase - class object
      Returns:
      class name
    • updateDelegates

      public void updateDelegates()
      update delegates. updates this delegates (content and attributes) then recurses through children
      Specified by:
      updateDelegates in interface AbstractBase
    • updateDOM

      public void updateDOM()
      update DOM. updates this DOM (content and attributes) then recurses through children
      Specified by:
      updateDOM in interface AbstractBase
    • updateDelegateContent

      public void updateDelegateContent()
      update delegate content.
      Specified by:
      updateDelegateContent in interface AbstractBase
    • updateDelegateAttributes

      public void updateDelegateAttributes()
      update delegate attributes.
      Specified by:
      updateDelegateAttributes in interface AbstractBase
    • updateDOMContent

      public void updateDOMContent()
      update DOM content.
      Specified by:
      updateDOMContent in interface AbstractBase
    • updateDOMAttributes

      public void updateDOMAttributes()
      update DOM attributes.
      Specified by:
      updateDOMAttributes in interface AbstractBase