Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
    * JBoss, Home of Professional Open Source
    * Copyright 2005, JBoss Inc., and individual contributors as indicated
    * by the @authors tag. See the copyright.txt in the distribution for a
    * full listing of individual contributors.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
 package org.jboss.xb.binding;
 
All object model factories must implement this interface. Object model factories are used on unmarshalling to build an object graph that is a representation of the XML content unmarshalled.

Each object model factory must implement methods newRoot and completeRoot defined in this interface, plus a set of newChild, addChild and setValue methods that will be descovered by the framework at runtime with introspection.

The contract for methods discovered at runtime with introspection:

  • newChild methods
    This method is called by the framework on the object model factory when parsing of a new XML element started. Each newChild method must have five arguments:
    1. parent object of a concrete Java type (not java.lang.Object) for this new child
    2. instance of org.jboss.xml.binding.UnmarshallingContext
    3. namespace URI of the child XML element as java.lang.String
    4. local name of the child XML element as java.lang.String
    5. attributes of the child XML element as org.xml.sax.Attributes
    Each newChild() method returns either a new instance of the child object that represents the XML element with the namespace URI and local name (in this case, the child XML element is said to be accepted, i.e. should be represented in the object graph) or null if this child XML element should be ignored, i.e. not be represented in the object graph.

  • addChild methods
    This method is called on the object model factory by the framework when parsing of a child XML element completed. The arguments of the addChild() method are:
    1. parent object of a conrete Java type (not java.lang.Object) of the child
    2. child object of a concrete Java type (returned earlier by the newChild method that was called when parsing of this child XML element started)
    3. instance of org.jboss.xml.binding.UnmarshallingContext
    4. namespace URI for the child XML element as java.lang.String
    5. local name for the child XML element as java.lang.String
    When addChild method is called, the child object is supposed to be populated with all the data from the corresponding XML element. The child object now can be validated and added to the parent.

  • setValue methods
    This method is called on the object model factory by the framework when a new XML element with text content was parsed. The method must have four arguments:
    1. an object of a concrete Java type (not java.lang.Object) which was returned earlier by the newChild method (that was called when parsing of the parent XML element started) for which the value of an XML element was read
    2. instance of org.jboss.xml.binding.UnmarshallingContext
    3. namespace URI of the child XML element as java.lang.String
    4. local name of the child XML element as java.lang.String
    5. the value of the child XML element as java.lang.String
    In setValue method the object model factory is supposed to set the value on the field which represents the parsed XML element possibly converting the parsed XML element value to the field's Java type.

Author(s):
Alexey Loubyansky
Version:
$Revision: 1958 $
 
 public interface ObjectModelFactory
 {
   
This method is called by the framework and returns the root of the object graph.

If root argument is null, the factory is supposed to create and return a new one that is going to be the real root object of the graph or an object that will represent the root object during unmarshalling and which will be used to create the real root object when unmarshalling is complete in completeRoot if the real root object can't be created while its children are not available, e.g. no no-arg constructor or other reasons.

If root argument is not null (i.e. a user provided the root object through the org.jboss.xml.binding.Unmarshaller) then the factory could just return it as is or extract the real root from the root argument based on the namespace URI and local name if root argument wraps/contains the real root.

Parameters:
root an object that is the root or which contains the root of the object graph
ctx unmarshalling context
namespaceURI namespace URI of the root
localName local name of the root
attrs attributes of the root object
Returns:
the root of the object graph
   Object newRoot(Object rootUnmarshallingContext ctxString namespaceURIString localNameAttributes attrs);

   
This method is called by the framework when unmarshalling of the object graph completed. The method returns the root object of the object graph. If at the beginning of unmarshalling newRoot returned not the real root object but an object that represented the root during unmarshalling, the real root object should be created and returned.

Parameters:
root the object returned by newRoot at the beginning of unmarshalling
ctx unmarshalling context
namespaceURI namespace URI that corresponds to the root
localName local element name the root of the object graph is bound to
Returns:
the root of the object graph
   Object completeRoot(Object rootUnmarshallingContext ctxString namespaceURIString localName);
New to GrepCode? Check out our FAQ X