Class PropFactory


  • public class PropFactory
    extends java.lang.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 Summary

      Fields 
      Modifier and TypeFieldDescription
      static intCLIENT
      The application type: CLIENT = 0.
      static intEDITOR
      The application type: EDITOR = 2.
      static intSERVER
      The application type: SERVER = 1.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      PropFactory​(int programType)
      Constructs the property factory with the default class loader.
      PropFactory​(int programType, java.lang.ClassLoader classLoader)
      Constructs the property factory.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      java.util.HashMap<java.lang.String,​java.lang.String>createClientClassNameMap​(boolean jsClient)
      Creates the map used to replace server/editor class names with client ones.
      org.w3c.dom.DocumentcreateDocument​(PropCnr pc)
      Creates a Document from a property container.
      java.util.HashMap<java.lang.String,​java.lang.String>createEditorServerClassNameMap()
      Creates the map used to replace class names for communication between the editor and the server.
      GProp<?>createProp​(java.lang.String tag, Atom atom)
      Creates a generic property with the specified tag name and atom.
      PropMgrcreatePropertyManager​(int application, java.util.Map<java.lang.String,​java.lang.String> classNameMapper)
      Creates a Property Manager for the application type.
      protected java.net.URLgetFile​(java.lang.String fn)
      Maps a file name into a File object in the class path.
      IPluginDescriptor<?>[]getLoadedPlugins()
      Gets a list of the loaded Server plug-in descriptors.
      java.util.List<IPluginDescriptor<?>>getLoadedPlugins​(java.lang.String names)
      Gets a list of the loaded Server plug-in descriptors.
      intgetProgramType()
      Gets the program type: 0=CLIENT, 1=SERVER or 2=EDITOR.
      java.lang.Class<? extends GProp<?>>getPropClass​(java.lang.String className)
      Gets the property class from a class name.
      booleanisPlugInRegistered​(java.lang.String name)
      Registers a plug-in.
      voidloadPropDefinitions()
      Loads the "schema/base-properties.xml" file using the "schema/property-definition-1.0.xsd" schema.
      GProp<?>loadPropTree​(GProp<?> parent, org.w3c.dom.Element element)
      Creates the GProp tree from an Element.
      PropCnrloadPropTree​(PropMgr propertyManager, java.io.File file, boolean setPropMgrToProps)
      Loads a property tree from an XML file.
      PropCnrloadPropTree​(PropMgr propertyManager, java.lang.String fileName, java.io.InputStream in, boolean setPropMgrToProps)
      Loads a property tree from an XML file.
      PropCnrloadPropTree​(PropMgr propertyManager, org.w3c.dom.Document document, boolean setPropMgrToProps)
      Loads a property tree from an XML document.
      static voidprocessQueryDesignerProps​(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.
      voidregisterPlugIn​(java.lang.String name, java.net.URL url, java.lang.ClassLoader classLoader, IPluginDescriptor<?> serverPluginDescriptor)
      Registers a plug-in.
      static voidsetDesignerInterface​(IPropFactory designerInterface)
      Assigns the Designer factory interface.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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,
                           java.lang.ClassLoader classLoader)
        Constructs the property factory.
        Parameters:
        programType - Value indicating what program type is running, CLIENT, SERVER or EDITOR.
        classLoader - The class loader.
    • Method Detail

      • getProgramType

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

        public java.lang.Class<? extends GProp<?>> getPropClass​(java.lang.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 java.net.URL getFile​(java.lang.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 java.io.IOException
        Loads the "schema/base-properties.xml" file using the "schema/property-definition-1.0.xsd" schema.
        Throws:
        java.io.IOException - for load errors.
      • loadPropTree

        public PropCnr loadPropTree​(PropMgr propertyManager,
                                    java.io.File file,
                                    boolean setPropMgrToProps)
                             throws java.io.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:
        java.io.IOException - for file errors.
        PropException - for property errors.
      • loadPropTree

        public PropCnr loadPropTree​(PropMgr propertyManager,
                                    java.lang.String fileName,
                                    java.io.InputStream in,
                                    boolean setPropMgrToProps)
                             throws java.io.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:
        java.io.IOException - for file errors.
        PropException - for property errors.
      • loadPropTree

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

        public GProp<?> loadPropTree​(GProp<?> parent,
                                     org.w3c.dom.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 java.util.HashMap<java.lang.String,​java.lang.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 java.util.HashMap<java.lang.String,​java.lang.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 org.w3c.dom.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:
        java.lang.IllegalStateException - If the factory does not match the run mode, i.e. Designer or Server (Client is not allowed).
      • isPlugInRegistered

        public boolean isPlugInRegistered​(java.lang.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​(java.lang.String name,
                                   java.net.URL url,
                                   java.lang.ClassLoader classLoader,
                                   IPluginDescriptor<?> serverPluginDescriptor)
                            throws java.io.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:
        java.io.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 java.util.List<IPluginDescriptor<?>> getLoadedPlugins​(java.lang.String names)
                                                              throws java.io.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:
        java.io.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,
                                             java.util.Map<java.lang.String,​java.lang.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​(java.lang.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.