Class PropFactory

java.lang.Object
com.iizix.prop.PropFactory

public class PropFactory extends Object
This class handles definitions of available properties, available as predefined or plug-in classes extending the GProp class. Processing of these properties classes is handled in different ways for the client, server and editor. The client has functionality towards Swing, the server for storing the properties in XML files, and the editor provides developer-functions for Eclipse.
Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • PropFactory

      public PropFactory(int programType)
      Constructs the property factory with the default class loader.
      Parameters:
      programType - Value indicating what program type is running, CLIENT, SERVER or EDITOR.
    • PropFactory

      public PropFactory(int programType, ClassLoader classLoader)
      Constructs the property factory.
      Parameters:
      programType - Value indicating what program type is running, CLIENT, SERVER or EDITOR.
      classLoader - The class loader.
  • Method Details

    • getProgramType

      public int getProgramType()
      Gets the program type: 0=CLIENT, 1=SERVER or 2=EDITOR.
    • getPropClass

      public Class<? extends GProp<?>> getPropClass(String className)
      Gets the property class from a class name.
      Parameters:
      className - The class name.
      Returns:
      The class, or null for not found.
    • getFile

      protected URL getFile(String fn)
      Maps a file name into a File object in the class path.
      Parameters:
      fn - The file name.
      Returns:
      null if not resolved.
    • loadPropDefinitions

      public void loadPropDefinitions() throws IOException
      Loads the "schema/base-properties.xml" file using the "schema/property-definition-1.0.xsd" schema.
      Throws:
      IOException - for load errors.
    • loadPropTree

      public PropCnr loadPropTree(PropMgr propertyManager, File file, boolean setPropMgrToProps) throws IOException, PropException
      Loads a property tree from an XML file.
      Parameters:
      propertyManager - The PropertyManager instance.
      file - The file to load.
      setPropMgrToProps - Flag to initialize the property manager to the properties.
      Returns:
      the property container.
      Throws:
      IOException - for file errors.
      PropException - for property errors.
    • loadPropTree

      public PropCnr loadPropTree(PropMgr propertyManager, String fileName, InputStream in, boolean setPropMgrToProps) throws IOException, PropException
      Loads a property tree from an XML file.
      Parameters:
      propertyManager - The PropertyManager instance.
      fileName - The file name for logging and error messages/logging.
      in - The input stream.
      setPropMgrToProps - Flag to initialize the property manager to the properties.
      Returns:
      the property container.
      Throws:
      IOException - for file errors.
      PropException - for property errors.
    • loadPropTree

      public PropCnr loadPropTree(PropMgr propertyManager, Document document, boolean setPropMgrToProps) throws IOException, PropException
      Loads a property tree from an XML document.
      Parameters:
      propertyManager - the PropertyManager instance.
      document - the Document.
      Returns:
      the property container.
      Throws:
      IOException - for file errors.
      PropException - for property errors.
    • loadPropTree

      public GProp<?> loadPropTree(GProp<?> parent, Element element) throws PropException
      Creates the GProp tree from an Element.
      Parameters:
      parent - the parent property.
      element - the Element for the tree.
      Returns:
      the property container.
      Throws:
      PropException - for property errors.
    • createClientClassNameMap

      public HashMap<String,String> createClientClassNameMap(boolean jsClient)
      Creates the map used to replace server/editor class names with client ones.
      Parameters:
      jsClient - The JavaScript client flag.
      Returns:
      Map the map of names.
    • createEditorServerClassNameMap

      public HashMap<String,String> createEditorServerClassNameMap()
      Creates the map used to replace class names for communication between the editor and the server.
      Returns:
      Map the map of names.
    • createDocument

      public Document createDocument(PropCnr pc)
      Creates a Document from a property container.

      Note: this only work for the Editor, an InternalError is thrown otherwise!

      Parameters:
      pc - The property container.
      Returns:
      The Document created.
      Throws:
      IllegalStateException - If the factory does not match the run mode, i.e. Designer or Server (Client is not allowed).
    • isPlugInRegistered

      public boolean isPlugInRegistered(String name)
      Registers a plug-in. A plug-in has an XML file that has the same format as the product-internal base definitions.
      Parameters:
      name - The plug-in name.
    • registerPlugIn

      public void registerPlugIn(String name, URL url, ClassLoader classLoader, IPluginDescriptor<?> serverPluginDescriptor) throws IOException
      Registers a plug-in. A plug-in has an XML file that has the same format as the product-internal base definitions.
      Parameters:
      name - The plug-in name.
      url - The file of the XML properties file for the plug-in.
      classLoader - Additional class loader if not null.
      serverPluginDescriptor - The Server plug-in descriptor, can be null only for "com.iizigo" plug-in name.
      Throws:
      IOException - for load errors.
    • getLoadedPlugins

      public IPluginDescriptor<?>[] getLoadedPlugins()
      Gets a list of the loaded Server plug-in descriptors.
      Returns:
      The list of plug-in descriptors.
    • getLoadedPlugins

      public List<IPluginDescriptor<?>> getLoadedPlugins(String names) throws IOException
      Gets a list of the loaded Server plug-in descriptors.
      Parameters:
      names - The plug-in name, e.g. "com.iizigo.db,com.iizigo.term,com.iizigo.ws".
      Returns:
      The list of plug-in descriptors.
      Throws:
      IOException - If a plug-in is not loaded. This exception is thrown in order to have the same exception as the exception thrown in the com.iizix.server.IAppLoader interface.
    • createPropertyManager

      public PropMgr createPropertyManager(int application, Map<String,String> classNameMapper)
      Creates a Property Manager for the application type.
      Parameters:
      application - The application type, EDITOR, SERVER or CLIENT.
      classNameMapper - A class name mapper array, may be null for none.
      Returns:
      An initialized Property Manager.
    • createProp

      public GProp<?> createProp(String tag, Atom atom)
      Creates a generic property with the specified tag name and atom.

      This method will throw an InternalError if the calling process is not the Editor.

      This method will throw an NullPointerException if the tag name is not found.

      Parameters:
      tag - The tag name in the property definition XML file.
      atom - The atom for the property.
    • setDesignerInterface

      public static void setDesignerInterface(IPropFactory designerInterface)
      Assigns the Designer factory interface.

      Note: this can only be done in the Designer ONCE.

    • processQueryDesignerProps

      public static void processQueryDesignerProps(PropReference ref, GEvent event)
      Requests processing of the method by the Designer factory interface, done when the PropReference gets the GEvent.PROP_QUERY_DESIGNER_PROPS event.
      Parameters:
      ref - The property reference instance.
      event - The event.