/*
* GeoTools - The Open Source Java GIS Tookit
* http://geotools.org
*
* (C) 2006-2008, Open Source Geospatial Foundation (OSGeo)
*
* This file is hereby placed into the Public Domain. This means anyone is
* free to do whatever they wish with this file. Use it well and enjoy!
*/
package org.geotools.po.bindings;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.geotools.xml.*;
import org.geotools.po.Items;
import org.geotools.po.ObjectFactory;
import org.geotools.po.Items.Item;
import javax.xml.namespace.QName;
/**
* Binding object for the type http://www.geotools.org/po:Items.
*
* <p>
* <pre>
* <code>
* <xsd:complexType name="Items">
* <xsd:sequence>
* <xsd:element maxOccurs="unbounded" minOccurs="0" name="item">
* <xsd:complexType>
* <xsd:sequence>
* <xsd:element name="productName" type="xsd:string"/>
* <xsd:element name="quantity">
* <xsd:simpleType>
* <xsd:restriction base="xsd:positiveInteger">
* <xsd:maxExclusive value="100"/>
* </xsd:restriction>
* </xsd:simpleType>
* </xsd:element>
* <xsd:element name="USPrice" type="xsd:decimal"/>
* <xsd:element minOccurs="0" ref="comment"/>
* <xsd:element minOccurs="0" name="shipDate" type="xsd:date"/>
* </xsd:sequence>
* <xsd:attribute name="partNum" type="SKU" use="required"/>
* </xsd:complexType>
* </xsd:element>
* </xsd:sequence>
* </xsd:complexType>
*
* </code>
* </pre>
* </p>
*
* @generated
*
* @source $URL$
*/
public class ItemsBinding extends AbstractComplexBinding {
ObjectFactory factory;
public ItemsBinding( ObjectFactory factory ) {
this.factory = factory;
}
/**
* @generated
*/
public QName getTarget() {
return PO.Items;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public Class getType() {
return Items.class;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public Object parse(ElementInstance instance, Node node, Object value)
throws Exception {
//create the items collection
Items items = factory.createItems();
//for each item element, turn the map into an item
List itemElements = node.getChildValues( "item" );
for ( Iterator i = itemElements.iterator(); i.hasNext(); ) {
Map map = (Map) i.next();
//create the item
Item item = factory.createItemsItem();
item.setProductName( (String) map.get( "productName") );
item.setQuantity( (BigInteger) map.get( "quantity" ) );
item.setUSPrice( (BigDecimal) map.get( "USPrice" ) );
item.setComment( (String) map.get( "comment" ) );
item.setPartNum( (String) map.get( "partNum" ) );
//add the item
items.getItem().add( item );
}
return items;
}
}