Class XMLControlElement

java.lang.Object
org.opensourcephysics.controls.XMLNode
org.opensourcephysics.controls.XMLControlElement
All Implemented Interfaces:
Control, XMLControl, XMLProperty

public final class XMLControlElement extends XMLNode implements XMLControl
This is a basic xml control for storing data.
Version:
1.0
Author:
Douglas Brown
  • Field Details

    • ALWAYS_DECRYPT

      public static final int ALWAYS_DECRYPT
      See Also:
    • PASSWORD_DECRYPT

      public static final int PASSWORD_DECRYPT
      See Also:
    • NEVER_DECRYPT

      public static final int NEVER_DECRYPT
      See Also:
    • compactArraySize

      public static int compactArraySize
    • encoding

      protected static String encoding
    • theClass

      protected Class<?> theClass
    • counts

      protected Map<String,Integer> counts
    • object

      protected Object object
    • level

      protected int level
    • input

      protected BufferedReader input
    • output

      protected BufferedWriter output
    • canWrite

      public boolean canWrite
    • valid

      protected boolean valid
    • readFailed

      protected boolean readFailed
    • version

      protected String version
    • doctype

      protected String doctype
    • loader

      public XML.ObjectLoader loader
  • Constructor Details

    • XMLControlElement

      public XMLControlElement()
      Constructs an empty control for the Object class.
    • XMLControlElement

      public XMLControlElement(Class<?> type)
      Constructs an empty control for the specified class.
      Parameters:
      type - the class.
    • XMLControlElement

      public XMLControlElement(Object obj)
      Constructs and loads a control with the specified object.
      Parameters:
      obj - the object.
    • XMLControlElement

      public XMLControlElement(XMLProperty parent)
      Constructs a control with the specified parent.
      Parameters:
      parent - the parent.
    • XMLControlElement

      public XMLControlElement(File xmlFile)
      BH we need to read the File object directly, as it will have the data in it already.
      Parameters:
      xmlFile -
    • XMLControlElement

      public XMLControlElement(String input)
      Constructs a control and reads the specified input. Input may be a file name or an xml string
      Parameters:
      input - the input string
    • XMLControlElement

      public XMLControlElement(XMLControl control)
      Constructs a copy of the specified XMLControl.
      Parameters:
      control - the XMLControl to copy.
  • Method Details

    • getBasepath

      public String getBasepath()
      Specified by:
      getBasepath in interface XMLControl
    • setBasepath

      public void setBasepath(String basepath)
      Specified by:
      setBasepath in interface XMLControl
    • getData

      public Object getData()
      see TrackerPanel.Loader
      Returns:
      the TrackerIO.AsyncLoader if a Tracker object
    • setLockValues

      public void setLockValues(boolean lock)
      Locks the control's interface. Values sent to the control will not update the display until the control is unlocked. Not implemented.
      Specified by:
      setLockValues in interface Control
      Parameters:
      lock - boolean
    • setValue

      public void setValue(String name, boolean value)
      Sets a property with the specified name and boolean value.
      Specified by:
      setValue in interface Control
      Parameters:
      name - the name
      value - the boolean value
    • setValue

      public void setValue(String name, double value)
      Sets a property with the specified name and double value.
      Specified by:
      setValue in interface Control
      Parameters:
      name - the name
      value - the double value
    • setValue

      public void setValue(String name, int value)
      Sets a property with the specified name and int value.
      Specified by:
      setValue in interface Control
      Parameters:
      name - the name
      value - the int value
    • setValue

      public void setValue(String name, Object obj)
      Sets a property with the specified name and object value.
      Specified by:
      setValue in interface Control
      Parameters:
      name - the name
      obj - the object
    • setValue

      public void setValue(String name, double[] val, int decimalPlaces)
      Specified by:
      setValue in interface Control
    • setValue

      public void setValue(String name, Object obj, boolean writeNullFinalElement)
      Sets a property with the specified name and object value.
      Parameters:
      name - the name
      obj - the object
      writeNullFinalElement - true to write a final null array element (if needed)
    • getBoolean

      public boolean getBoolean(String name)
      Gets the boolean value of the specified named property.
      Specified by:
      getBoolean in interface Control
      Parameters:
      name - the name
      Returns:
      the boolean value, or false if none found
    • getDouble

      public double getDouble(String name)
      Gets the double value of the specified named property.
      Specified by:
      getDouble in interface Control
      Parameters:
      name - the name
      Returns:
      the double value, or Double.NaN if none found
    • getInt

      public int getInt(String name)
      Gets the int value of the specified named property.
      Specified by:
      getInt in interface Control
      Parameters:
      name - the name
      Returns:
      the int value, or Integer.MIN_VALUE if none found
    • getString

      public String getString(String name)
      Gets the string value of the specified named property.
      Specified by:
      getString in interface Control
      Parameters:
      name - the name
      Returns:
      the string value, or null if none found
    • getObject

      public Object getObject(String name)
      Gets the object value of the specified named property. "framedata" arrays will be adjusted only during loading, not export, and only if needed. In that case, this.data will be TrackerIO.AsyncLoader
      Specified by:
      getObject in interface Control
      Parameters:
      name - the name
      Returns:
      the object, or null if not found
    • getPropertyNames

      public Collection<String> getPropertyNames()
      Gets the set of property names.
      Specified by:
      getPropertyNames in interface Control
      Returns:
      a set of names
    • getPropertyNamesRaw

      public Collection<String> getPropertyNamesRaw()
      Description copied from interface: Control
      Gets the names of all properties stored in this control.
      Specified by:
      getPropertyNamesRaw in interface Control
      Returns:
      the actual property list
    • getPropertyType

      public int getPropertyType(String name)
      Gets the type of the specified property. Returns null if the property is not found.
      Specified by:
      getPropertyType in interface XMLControl
      Parameters:
      name - the property name
      Returns:
      the type
    • setPassword

      public void setPassword(String pass)
      Sets the password. Files are encrypted when the password is non-null.
      Parameters:
      pass - the password or phrase
    • getPassword

      public String getPassword()
      Gets the password.
      Returns:
      the password
    • setDecryptPolicy

      public void setDecryptPolicy(int policy)
      Sets the decryption policy.
      Parameters:
      policy - the decryption policy: NEVER_DECRYPT, PASSWORD_DECRYPT or ALWAYS_DECRYPT
    • readAsync

      public void readAsync(String name, Function<String,Void> whenDone)
    • processReader

      protected void processReader(String name, Resource res, BufferedReader in, Function<String,Void> whenDone)
      Read this file resource
      Parameters:
      name -
      res -
      in -
      whenDone - will be passed a File[] array or null
    • read

      public String read(String fileName)
      Reads data into this control from a named source.
      Specified by:
      read in interface XMLControl
      Parameters:
      fileName - the name
      Returns:
      the path of the opened document or null if failed
    • readXML

      public void readXML(String xml)
      Reads the control from an xml string.
      Specified by:
      readXML in interface XMLControl
      Parameters:
      xml - the xml string
    • read

      public void read(Reader in)
      Reads the control from a Reader, setting readFailed if there are any problems.
      Specified by:
      read in interface XMLControl
      Parameters:
      in - the Reader
    • readForClass

      public String readForClass(String name, Class<?> type)
      Reads data into this control from a named source if the source specifies the same class as the current className. BH: never called
      Parameters:
      name - the name
      type - the class
      Returns:
      the path of the opened document or null if failed
    • readXMLForClass

      public boolean readXMLForClass(String xml, Class<?> type)
      Reads this control from an xml string if the xml specifies the same class as the current className. Utilized in org.colos.ejs.library.Simulation
      Parameters:
      xml - the xml string
      type - the class
      Returns:
      true if successfully read
    • failedToRead

      public boolean failedToRead()
      Returns true if the most recent read operation failed.
      Specified by:
      failedToRead in interface XMLControl
      Returns:
      true if the most recent read operation failed
    • write

      public String write(String fileName)
      Writes this control as an xml file with the specified name.
      Specified by:
      write in interface XMLControl
      Parameters:
      fileName - the file name
      Returns:
      the path of the saved document or null if failed
    • write

      public void write(Writer out)
      Writes this control to a Writer.
      Specified by:
      write in interface XMLControl
      Parameters:
      out - the Writer
    • writeDocType

      public void writeDocType(Writer out)
      Writes the DTD to a Writer.
      Parameters:
      out - the Writer
    • toXML

      public String toXML()
      Returns this control as an xml string.
      Specified by:
      toXML in interface XMLControl
      Returns:
      the xml string
    • setValid

      public void setValid(boolean valid)
      Sets the valid property.
      Parameters:
      valid - true to write the DTD and DocType
    • isValid

      public boolean isValid()
      Gets the valid property. When true, this writes the DTD and defines the DocType when writing an xml document. Note: the presence or absense of the DocType header and DTD has no effect on the read() methods--this will always read a well-formed osp document and ignore a non-osp document.
      Returns:
      true if this is valid
    • setVersion

      public void setVersion(String vers)
      Sets the version.
      Parameters:
      vers - the version data
    • getVersion

      public String getVersion()
      Gets the version. May return null.
      Returns:
      the version
    • setDoctype

      public void setDoctype(String name)
      Sets the doctype. Not yet implemented since only one doctype is defined.
      Parameters:
      name - the doctype resource name
    • getDoctype

      public String getDoctype()
      Gets the doctype. May return null.
      Returns:
      the doctype
    • setObjectClass

      public void setObjectClass(Class<?> type)
      Sets the class of the object for which this element stores data.
      Parameters:
      type - the Class of the object
    • getObjectClass

      public Class<?> getObjectClass()
      Gets the class of the object for which this element stores data.
      Specified by:
      getObjectClass in interface XMLControl
      Returns:
      the Class of the object
    • getObjectClassName

      public String getObjectClassName()
      Gets the name of the object class for which this element stores data.
      Specified by:
      getObjectClassName in interface XMLControl
      Returns:
      the object class name
    • saveObject

      public void saveObject(Object obj)
      Saves an object's data in this element.
      Specified by:
      saveObject in interface XMLControl
      Parameters:
      obj - the object to save.
    • loadObject

      public Object loadObject(Object obj)
      BH! THIS METHOD COULD FAIL IN JAVASCRIPT because importAll is false 111 references !!! Loads an object with data from this element. This asks the user for approval and review before importing data from mismatched classes.
      Specified by:
      loadObject in interface XMLControl
      Parameters:
      obj - the object to load
      Returns:
      the loaded object
    • loadObject

      public Object loadObject(Object obj, Object data)
      Specified by:
      loadObject in interface XMLControl
    • loadObject

      public Object loadObject(Object obj, boolean autoImport)
      BH! THIS METHOD WILL FAIL IN JAVASCRIPT when autoImport is false (not called in OSP or Tracker?) Loads an object with data from this element. This asks the user to review data from mismatched classes before importing it.
      Parameters:
      obj - the object to load
      autoImport - true to automatically import data from mismatched classes
      Returns:
      the loaded object
    • loadObject

      public Object loadObject(Object obj, boolean autoImport, boolean importAll)
      Loads an object with data from this element. false for BOTH parameters autoImport and importAll will FAIL IN JAVASCRIPT
      Parameters:
      obj - the object to load
      autoImport - true to automatically import data from mismatched classes
      importAll - true to import all importable data
      Returns:
      the loaded object
    • clearValues

      public void clearValues()
      Clears all properties.
      Specified by:
      clearValues in interface Control
    • println

      public void println(String s)
      Method required by the Control interface.
      Specified by:
      println in interface Control
      Parameters:
      s - the string
    • println

      public void println()
      Method required by the Control interface.
      Specified by:
      println in interface Control
    • print

      public void print(String s)
      Method required by the Control interface.
      Specified by:
      print in interface Control
      Parameters:
      s - the string
    • clearMessages

      public void clearMessages()
      Method required by the Control interface.
      Specified by:
      clearMessages in interface Control
    • calculationDone

      public void calculationDone(String s)
      Method required by the Control interface.
      Specified by:
      calculationDone in interface Control
      Parameters:
      s - the string
    • getPropertyName

      public String getPropertyName()
      Gets the property name.
      Specified by:
      getPropertyName in interface XMLProperty
      Returns:
      a name
    • getPropertyClass

      public Class<?> getPropertyClass()
      Gets the property class.
      Specified by:
      getPropertyClass in interface XMLProperty
      Returns:
      the class
    • getLevel

      public int getLevel()
      Gets the level of this property relative to the root.
      Specified by:
      getLevel in interface XMLProperty
      Returns:
      a non-negative integer
    • getPropertyContent

      public List<Object> getPropertyContent()
      Gets the property content of this control.
      Specified by:
      getPropertyContent in interface XMLProperty
      Returns:
      a list of XMLProperties
    • getPropsRaw

      public List<XMLProperty> getPropsRaw()
      Gets the property content of this control.
      Specified by:
      getPropsRaw in interface XMLControl
      Returns:
      a list of XMLProperties
    • getChildControl

      public XMLControl getChildControl(String name)
      Gets the named XMLControl child of this property. May return null.
      Specified by:
      getChildControl in interface XMLProperty
      Parameters:
      name - the property name
      Returns:
      the XMLControl
    • getChildControls

      public XMLControl[] getChildControls()
      Gets the XMLControl children of this property. The returned array has length for type "object" = 1, "collection" and "array" = 0+, other types = 0.
      Specified by:
      getChildControls in interface XMLProperty
      Returns:
      an XMLControl array
    • getRootControl

      public XMLControlElement getRootControl()
      Gets the root control.
      Returns:
      the root control
    • addNumbering

      public String addNumbering(String name)
      Appends numbering to a specified name. Increments the number each time this is called for the same name.
      Parameters:
      name - the name
      Returns:
      the name with appended numbering
    • toString

      public String toString()
      Returns the string xml representation.
      Overrides:
      toString in class Object
      Returns:
      the string xml representation
    • getObjects

      public <T> List<T> getObjects(Class<T> type)
      Returns a list of objects of a specified class within this control.
      Parameters:
      type - the Class
      Returns:
      the list of objects
    • getObjects

      public <T> List<T> getObjects(Class<T> type, boolean useChooser)
      Returns a list of objects of a specified class within this control.
      Parameters:
      type - the Class
      useChooser - true to allow user to choose
      Returns:
      the list of objects
    • clone

      public Object clone()
      Returns a copy of this control.
      Overrides:
      clone in class Object
      Returns:
      a clone
    • getAdjustedFrameData

      public static Object getAdjustedFrameData(Object o, Object data)
      For Tracker, tap into TrackerIO.asyncLoader to check to see if this FrameData needs so be adjusted based on the VideoControl property "frameshift".
      Parameters:
      o -
      data -
      Returns:
    • getClassName

      public static String getClassName(String xml)
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • dispose

      public void dispose()