You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by xm...@xml.apache.org on 2004/04/28 02:16:02 UTC

[Apache XMLBeans Wiki] New: PrePostSetFeature

   Date: 2004-04-27T17:16:02
   Editor: 63.120.159.29 <>
   Wiki: Apache XMLBeans Wiki
   Page: PrePostSetFeature
   URL: http://wiki.apache.org/xmlbeans/PrePostSetFeature

   no comment

New Page:

##language:en
== 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
     * `org.apache.xmlbeans.impl.config.PrePostExtension.OPERATION_INSERT` - for creating a new internal value
     * `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.

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org