<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
<document>
    <header>
        <title>Methods for Types Generated From Schema</title>
    </header>
    <body>
        <section>
            <title>Methods for Types Generated From Schema</title>

            <p>As you may have seen in <a href="site:gettingstarted">Getting
                Started with XMLBeans</a>, you use the types generated from schema to access
                XML instances based on the schema. If you're familiar with the JavaBeans technology,
                the conventions used in the generated API will be recognizable.
            </p>
            <p>In general, elements and attributes are treated as "properties"
                in the JavaBeans sense. In other words, as you would with JavaBeans properties,
                you manipulate parts of the XML through accessor methods such as getCustomer()
                (where you have a "customer" element), setId(String) (where you
                have an "id" attribute), and so on. However, because schema structures
                can be somewhat complex, XMLBeans provides several other method styles for
                handling those structures in XML instances.
            </p>
        </section>
        <section>
            <title>Prototypes for Methods in Generated Interfaces</title>
            <p>Several methods are generated for each element or attribute within the
                complex type. This topic lists each method that could be generated for a
                given element or attribute.
            </p>
            <p>Note that whether or not a given method is generated is based on how the
                element or attribute is defined in schema. For example, a customer element
                definition with a <strong>maxOccurs</strong> attribute value
                of 1 will result in a getCustomer method, but not a getCustomerArray method
                &#8212; after all, only one customer element is possible in an instance
                document.
            </p>
            <p>Note, too, that there may be two sets of parallel methods: one whose prototype
                starts with an "x". An "x" method such as xgetName or
                xsetName would be generated for elements or attribute whose type is a simple
                type. A simple type may be one of the 44 built-in simple types or may be
                a restriction in schema of one of those built-in types. Of course, an attribute
                will always be of a simple type. For built-in simple types, an "x"
                method will get or set one of the types provided with XMLBeans, such as
                <strong>
                    <a href="ext:api/stable/XmlString">XmlString</a>
                </strong>
                ,
                <strong>
                    <a href="ext:api/stable/XmlInteger">XmlInteger</a>
                </strong>
                ,
                <strong>
                    <a href="ext:api/stable/XmlGDay">XmlGDay</a>
                </strong>
                ,
                and so on. For derived types, the "x" method will get or set a
                generated type.
            </p>
        </section>
        <section>
            <title>Single Occurrence Methods</title>
            <p>Methods generated for elements or attributes that allow a single occurrence.
                An element is singular if it was declared with maxOccurs="1".
                An attribute is singular if it was not declared with use="prohibited".
            </p>
            <source><![CDATA[
                Type getFoo()
                void setFoo(Type newValue)
            ]]></source>
            <p>Returns or sets the value of Foo. Generated when Foo is an attribute,
                or is an element that can occur only once as a child.
            </p>
            <source><![CDATA[
                XmlType xgetFoo()
                void xsetFoo(XmlType newValue)
            ]]></source>
            <p>Returns or sets the value of Foo as an XMLBean simple type. These methods
                are generated if Foo's type is defined in schema as a simpleType.
            </p>
            <source><![CDATA[
                boolean isNilFoo()
                void setNilFoo()
            ]]></source>
            <p>Determines or specifies whether the Foo element is nil (in other words,
                "null" in schema terms), meaning it can be empty. A nil element
                looks something like this:
            </p>
            <source><![CDATA[<foo/>]]></source>
            <p>These methods are only generated when an element type is declared as
                nillable in schema &#8212; it has a nillable="true" attribute.
            </p>
            <source><![CDATA[XmlType addNewFoo()]]></source>
            <p>Adds a new Foo as an XMLBean simple to the document, or returns Foo's
                value if one exists already.
            </p>
            <source><![CDATA[
                boolean isSetFoo()
                void unSetFoo()
            ]]></source>
            <p>Determines whether the Foo element or attribute exists in the document;
                removes Foo. These methods are generated for elements and attributes that
                are optional. In schema, and optional element has an
                <strong>minOccurs</strong>
                attribute set to "0"; an optional attribute has a
                <strong>use</strong>
                attribute set to "optional".
            </p>
        </section>
        <section>
            <title>Multiple Occurrence Methods</title>
            <p>Methods generated for elements that allow multiple occurrences.</p>
            <p>An element may occur multiple times if it has a
                <strong>maxOccurs</strong>
                attribute set to "unbounded" or greater than 1. Attributes can't
                occur multiple times.
            </p>

            <section>
                <title>Returns or sets all of the Foo elements.</title>
                <source><![CDATA[
                    Type[] getFooArray()
                    void setFooArray(Type[] newValue)

                    // Get an array of the all of the purchase-order elements item children.
                    Item[] items = myPO.getItemArray();
                ]]></source>
            </section>

            <section>
                <title>Returns or sets the Foo child element at the specified index.</title>
                <source><![CDATA[
                    Type getFooArray(int index)
                    void setFooArray(Type newValue, int index)

                    // Sets the value of the third item child element.
                    myPO.setItem(newItem, 2);
                ]]></source>
            </section>

            <section>
                <title>Returns the number of Foo child elements.</title>

                <source><![CDATA[
                    int sizeOfFooArray()

                    // Returns the number of item child elements.
                    int itemCount = myPO.sizeOfItemArray();
                ]]></source>
            </section>

            <section>
                <title>Removes the Foo child element at the specified index.</title>
                <source><![CDATA[
                    void removeFoo(int index)
                ]]></source>
            </section>

            <section>
                <title>Returns or sets all of the Foo elements as XMLBeans simple types.</title>
                <p>Generated only when the Foo element is defined as a simple type.</p>
                <source><![CDATA[
                    XmlType[] xgetFooArray()
                    void xsetFooArray(XmlType[] arrayOfNewValues)

                    /*
                     * Returns values of all the phone child elements of an employee element,
                     * where the phone element has been defined as xs:string.
                     */
                    XmlString[] empPhones = currentEmployee.xGetPhoneArray();
                ]]></source>
            </section>

            <section>
                <title>Returns or sets the Foo element at the specified index, using an XMLBeans
                    simple type value.
                </title>
                <p>Generated for an element defined as a simple type in schema.</p>
                <source><![CDATA[
                    XmlType xgetFooArray(int index)
                    void xsetFooArray(int index, XmlType newValue)
                ]]></source>
            </section>

            <section>
                <title>Inserts a new Foo at the specified index</title>
                <p>... returning an XMLBeans simple type representing the new element; returns the existing Foo if
                    there's already one at index.
                </p>
                <source><![CDATA[
                    void insertFoo(int index, FooType newValue)
                ]]></source>
            </section>

            <section>
                <title>Adds the specified Foo to the end of the list of Foo child elements.</title>
                <source><![CDATA[
                    void addFoo(FooType newValue)
                ]]></source>
            </section>

            <section>
                <title>Inserts the specified Foo child element at the specified index.</title>
                <source><![CDATA[
                    XmlType insertNewFoo(int index)
                ]]></source>
            </section>

            <section>
                <title>Adds a new Foo element to the end of the list</title>
                <p>... of Foo child elements, returning an XMLBeans simple type representing the newly added element.
                </p>
                <source><![CDATA[
                    XmlType addNewFoo()
                ]]></source>
            </section>

            <section>
                <title>Determines or specifies whether the Foo element at the specified index is nil.</title>
                <source><![CDATA[
                    boolean isNilFooArray(int index)
                    void setNilFooArray(int index)
                ]]></source>
            </section>
        </section>

        <section id="relatedtopics">
            <title>Related Topics</title>
            <p>
                <a href="GeneratedTypes.html">Java Types Generated
                    from User-Derived Schema Types
                </a>
            </p>
        </section>
    </body>
</document>