001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.geoserver.wfs.xml.v1_0_0;
006:
007: import org.eclipse.emf.ecore.EObject;
008: import org.eclipse.emf.ecore.EStructuralFeature;
009: import org.geotools.xml.Node;
010: import java.math.BigInteger;
011:
012: /**
013: * Utility class to be used by bindings.
014: *
015: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
016: *
017: */
018: public class WFSBindingUtils {
019: /**
020: * Sets the service feature of the object passed in.
021: * <p>
022: * The service value is retreived as an attribute from the node, if
023: * <code>null</code>, the default "WFS" is used.
024: * </p>
025: * @param object An object which contains a feature named "service"
026: * @param node The parse node.
027: */
028: public static void service(EObject object, Node node) {
029: String service = (String) node.getAttributeValue("service");
030:
031: if (service == null) {
032: service = "WFS";
033: }
034:
035: set(object, "service", service);
036: }
037:
038: /**
039: * Sets the version feature of the object passed in.
040: * <p>
041: * The version value is retreived as an attribute from the node, if
042: * <code>null</code>, the default "1.0.0" is used.
043: * </p>
044: * @param object An object which contains a feature named "version"
045: * @param node The parse node.
046: */
047: public static void version(EObject object, Node node) {
048: String version = (String) node.getAttributeValue("version");
049:
050: if (version == null) {
051: version = "1.0.0";
052: }
053:
054: set(object, "version", version);
055: }
056:
057: /**
058: * Sets the outputFormat feature of the object passed in.
059: * <p>
060: * The outputFormat value is retreived as an attribute from the node, if
061: * <code>null</code>, the default <code>default</code> is used.
062: * </p>
063: * @param object An object which contains a feature named "version"
064: * @param node The parse node.
065: */
066: public static void outputFormat(EObject object, Node node,
067: String defalt) {
068: String outputFormat = (String) node
069: .getAttributeValue("outputFormat");
070:
071: if (outputFormat == null) {
072: outputFormat = defalt;
073: }
074:
075: set(object, "outputFormat", outputFormat);
076: }
077:
078: static void set(EObject object, String featureName, Object value) {
079: EStructuralFeature feature = object.eClass()
080: .getEStructuralFeature(featureName);
081:
082: if (feature != null) {
083: object.eSet(feature, value);
084: }
085: }
086:
087: /**
088: * @param value A number
089: *
090: * @return The number as a {@link BigInteger}.
091: */
092: public static BigInteger asBigInteger(Number number) {
093: if (number == null) {
094: return null;
095: }
096:
097: if (number instanceof BigInteger) {
098: return (BigInteger) number;
099: }
100:
101: return BigInteger.valueOf(number.longValue());
102: }
103: }
|