/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.geotools.wfs.bindings;

import java.math.BigInteger;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.geotools.xml.Node;


/**
 * Utility class to be used by bindings.
 *
 * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
 *
 */
public class WFSBindingUtils {
    /**
     * Sets the service feature of the object passed in.
     * <p>
     * The service value is retreived as an attribute from the node, if
     * <code>null</code>, the default "WFS" is used.
     * </p>
     * @param object An object which contains a feature named "service"
     * @param node The parse node.
     */
    public static void service(EObject object, Node node) {
        String service = (String) node.getAttributeValue("service");

        if (service == null) {
            service = "WFS";
        }

        set(object, "service", service);
    }

    /**
     * Sets the version feature of the object passed in.
     * <p>
     * The version value is retreived as an attribute from the node, if
     * <code>null</code>, the default "1.0.0" is used.
     * </p>
     * @param object An object which contains a feature named "version"
     * @param node The parse node.
     */
    public static void version(EObject object, Node node) {
        String version = (String) node.getAttributeValue("version");

        if (version == null) {
            version = "1.0.0";
        }

        set(object, "version", version);
    }

    /**
     * Sets the outputFormat feature of the object passed in.
     * <p>
     * The outputFormat value is retreived as an attribute from the node, if
     * <code>null</code>, the default <code>default</code> is used.
     * </p>
     * @param object An object which contains a feature named "version"
     * @param node The parse node.
     */
    public static void outputFormat(EObject object, Node node, String defalt) {
        String outputFormat = (String) node.getAttributeValue("outputFormat");

        if (outputFormat == null) {
            outputFormat = defalt;
        }

        set(object, "outputFormat", outputFormat);
    }

    static void set(EObject object, String featureName, Object value) {
        EStructuralFeature feature = object.eClass().getEStructuralFeature(featureName);

        if (feature != null) {
            object.eSet(feature, value);
        }
    }

    /**
     * @param value A number
     *
     * @return The number as a {@link BigInteger}.
     */
    public static BigInteger asBigInteger(Number number) {
        if (number == null) {
            return null;
        }

        if (number instanceof BigInteger) {
            return (BigInteger) number;
        }

        return BigInteger.valueOf(number.longValue());
    }
}

@@ -1,178 +1,637 @@
 /* 
-Copyright (c
+   GeoTools - The Open Source Java GIS Toolkit%0A *    http://geotools.org%0A *%0A *    (C
 ) 20
-01 - 2007 TOPP - www.openplans.org. All right
+12, Open Source Geospatial Foundation (OSGeo)%0A *%0A *    This library i
 s 
+f
 re
-served.%0A * This code is licensed under the GPL 2.0 license, availible at the root%0A * application directory
+e software; you can redistribute it and/or%0A *    modify it under the terms of the GNU Lesser General Public%0A *    License as published by the Free Software Foundation;%0A *    version 2.1 of the License.%0A *%0A *    This library is distributed in the hope that it will be useful,%0A *    but WITHOUT ANY WARRANTY; without even the implied warranty of%0A *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A *    Lesser General Public License for more details
 .%0A *

Correct header, content provided by Gabriel in 2012