Class WfXMLObject

java.lang.Object
com.groiss.wfxml.WfXMLObject
Direct Known Subclasses:
WfXMLForm, WfXMLNote, WfXMLWebLink

public abstract class WfXMLObject extends Object
WfXMLObject and its subclasses are used to easily access, modify and create DMSObject objects and to do a transformation to and from XML.
Therefore the hierarchical structure of these WfXML classes is similar to the structure of the DMSObject interface and its subinterfaces.

The mapping between WfXMLObject objects and DMSObject objects works like this:
As you can see, the same naming scheme has been used, so it's easy to keep that mapping in mind.
Let's take a look on what you can do with WfXMLObject objects:

  1. First, you can create WfXMLObject objects in three different ways:
    • You can create a new and empty WfXMLObject with one of the subclasses' constructors.
    • You can create a WfXMLObject out of an existing DMSObject. There are two possible ways to do that. If you know the exact type of DMSObject that you have, then you should use a constructor of the corresponding WfXML class. If you don't know the exact type, you can use the static createInstance(DMSObject) method of this class (WfXMLObject) to create the right WfXMLObject out of your DMSObject.
    • And you can create a WfXMLObject out of a JDOM Element object, which typically has been created using one of the WfXMLObject subclasses (but of course, the XML structure can also come from somewhere else). If you know which type of WfXMLObject the Element holds, you can use a constructor of the corresponding subclass again. If you don't know the type, you should take the static createInstance(Element) method for that purpose.
    • Examples:
      WfXMLNote myNote = new WfXMLNote("About this", "This is the WfXMLObject class", "gerhard", false);
      WfXMLObject myObject = WfXMLObject.createInstance(someDMSObject);
      WfXMLForm myForm = new WfXMLForm(anyDMSForm);
  2. Once you have a WfXMLObject, you can modify it with various methods (change name/id/etc.; add and change content, fields, and so on).
  3. When you created and changed a WfXMLObject according to your needs, you can do two things with it:
    • You can create DMSObject objects out of the WfXMLObject by calling the createDMSObject(User) method.
    • And you can use the WfXMLObject to update an existing DMSObject with the fill(com.groiss.dms.DMSObject, com.groiss.org.User) method.
    • So, using the objects created above, you could do:
      DMSObject aNewDMSObject = myObject.createDMSObject("gerhard"); (note, that you don't need to know the type of WfXMLObject at all...)
      myObject.fill(existingDMSObject, aUser);
      myForm.setField("subject", "Whatever you want");
      myForm.attachNote(myNote);
      DMSForm newDMSForm = myForm.createDMSObject(null);
  • Field Details

  • Constructor Details

    • WfXMLObject

      protected WfXMLObject()
      This default constructor is called implicitly when one of the subclasses is instanciated. It creates a collection object for storing attached notes.
  • Method Details

    • createInstance

      public static WfXMLObject createInstance(org.apache.xmlbeans.XmlObject elem)
    • getUserId

      public String getUserId()
      Get the id of the user who should be used to create a DMSObject out of this WfXMLObject.
      Returns:
      The id of the user who should be used to create the document, or null if no user has been specified.
    • getUser

      public User getUser()
      Returns a User object representing the user who will be used to create a DMSObject out of this WfXMLObject. If null is returned, the defined user was not found on the system.
      Returns:
      A User object of the user who should create this object or null if the user is not available.
    • getUser

      protected User getUser(User defaultUser)
      This method tries to get a user defined in this WfXMLObject. If there is no user, it simply returns the defaultUser that you passed in to the method. As this is usually performed quite often, this method is useful.
      Parameters:
      defaultUser - You can provide a default user here. If no user is found in the WfXMLObject object, you will get this default user back. Mind: if you pass null and no user is found, you will get null back.
      Returns:
      The user defined in this WfXMLObject, or defaultUser (whatever you passed in to this method) if no user is set in this object.
    • setUserId

      public void setUserId(String userId)
      Set a user (by its id), who will be used when a DMSObject is created out of this WfXMLObject.
      Parameters:
      userId - The id of the user who you want to set as document creator. You can set this to null if you want to remove a previously set user.
    • createInstance

      public static WfXMLObject createInstance(DMSObject obj) throws Exception
      Use this method to create a WfXMLObject out of a DMSObject. You don't need to care about which type of DMSObject you pass in to this method, it will always return the right type of WfXMLObject.
      obj should be one of the following:
      Parameters:
      obj - A DMSObject of which you want to create a WfXMLObject.
      Returns:
      A WfXMLObject with the data of the DMSObject or null if obj was non of the above mentioned types.
      Throws:
      Exception - if creating the object fails.
    • createDMSObject

      public abstract DMSObject createDMSObject(User defaultCreator) throws Exception
      This method creates a DMSObject out of a WfXMLObject. Depending on the type of WfXMLObject, the right DMSObject will be created.
      For example: if you call createDMSObject on a WfXMLForm, you can cast the result to DMSForm.
      Parameters:
      defaultCreator - This optional parameter defines a default creator who will be used for creating the DMSObject, if no particular user is defined in the WfXMLObject. You can set this parameter to null in case you don't want to provide a default creator.
      Returns:
      The resulting DMSObject.
      Throws:
      Exception - if creating the object fails.
    • fill

      public abstract void fill(DMSObject object, User defaultCreator) throws Exception
      This method is used for updating existing DMSObject objects with data from WfXMLObject objects. Each subclass implements this method and handles the task of filling existing objects with data and updating them to the database.
      Parameters:
      object - The object that has to be filled.
      defaultCreator - If any new object must be created, a creator is required. In case that the WfXMLObject objects themselves don't contain users, it is useful to provide a default creator here.
      Throws:
      Exception - if updating the object fails.
    • getName

      public abstract String getName()
      Returns the name of this WfXMLObject.
      Returns:
      The name as String.
    • getXMLObject

      public abstract org.apache.xmlbeans.XmlObject getXMLObject()