Differences between revisions 107 and 108
Revision 107 as of 2011-11-29 11:07:30
Size: 2897
Editor: SteveNewly
Comment:
Revision 108 as of 2011-12-19 22:14:02
Size: 2876
Editor: fx
Comment: remove sp@m
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
When the prepostset feature is enabled in a .xsdconfig file, pre and post calls to the handler will be generated at the beginning and at the end of all the setter methods of the specifyed xbeans.
When the prepostset feature is enabled in a .xsdconfig file, pre and post calls to the handler will be generated at the beginning and at the end of all the setter methods of the specifyed xbeans. 
Line 6: Line 7:
Line 17: Line 19:
Line 36: Line 39:
Line 37: Line 41:
Line 44: Line 47:
Line 50: Line 54:
        return true;         return true;  
Line 58: Line 62:
Line 59: Line 64:
Line 61: Line 65:
  * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_SET` - for set of an external value (example: Address address = Address.Factory.newInstance(); cust.setAddress(address); )
  * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_INSERT` - for creating a new internal value (example: Address address = cust.addNewAddress(); )
  * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_REMOVE` - for remove operations
    * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_SET` - for set of an external value (example: Address address = Address.Factory.newInstance(); cust.setAddress(address); )
    * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_INSERT` - for creating a new internal value (example: Address address = cust.addNewAddress(); )
     * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_REMOVE` - for remove operations
Line 65: Line 69:
 * `QName propertyName` - the QName of the property to be set  * `QName propertyName` - the ``QName of the property to be set
Line 70: Line 74:
Same [[http://vipdeal.info/pro|proactol reviews]] as building for ExtensionInterfacesFeature.
Same as building for ExtensionInterfacesFeature.

PrePostSetFeature

When the prepostset feature is enabled in a .xsdconfig file, pre and post calls to the handler will be generated at the beginning and at the end of all the setter methods of the specifyed xbeans.

Example

To enable this feature the .xsdconfig must contain the following:

<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
    <xb:extension for="*">
        <xb:prePostSet>
            <xb:staticHandler>myPackage.FooHandler</xb:staticHandler>
        </xb:prePostSet>
    </xb:extension>
</xb:config>

The extension element specifies a set of xbeans (see ExtensionInterfacesFeature), for this set of xbeans, in all the setter methods calls to the preSet and postSet handler methods will be generated.

    /**
     * Sets the "config" element
     */
    public void setConfig(org.apache.xml.xmlbeans.x2004.x02.xbean.config.ConfigDocument.Config config)
    {
        synchronized (monitor())
        {
            check_orphaned();
            if ( myPackage.FooHandler.preSet(...) )
            {
                ... store implementation code
            }
            myPackage.FooHandler.postSet(...);
        }
    }

The preSet method returns a boolean, if the result is:

  • true: the usual store code executes
  • false: the store code is skipped

If a handler that always returns false is used, it will prevent the modification of an xbean through setters.

Signature

The handler specified in the staticHandler element must have the following two static methods:

    public static boolean preSet(int opType, XmlObject xo, QName prop, boolean isAttr, int index)
    {
        ...
        return true;  
    }

    public static void postSet(int opType, XmlObject xo, QName propertyName, boolean isAttr, int index)
    {
        ...
    }

Where the parameters are:

  • int opType - the type of the set operation, valid values are:
    • org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_SET - for set of an external value (example: Address address = Address.Factory.newInstance(); cust.setAddress(address); )

    • org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_INSERT - for creating a new internal value (example: Address address = cust.addNewAddress(); )

    • org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_REMOVE - for remove operations

  • XmlObject xo - the XmlObject on which the setter was called

  • QName propertyName - the QName of the property to be set

  • boolean isAttr - true if property is an attribute, false if it's an element

  • int index - the index of the item to be set when the property allows several values (i.e. maxOccurs > 1 )

Building

Same as building for ExtensionInterfacesFeature.

PrePostSetFeature (last edited 2011-12-19 22:14:02 by fx)