Package org.geotools.xml.schema

Examples of org.geotools.xml.schema.SimpleType


                parent.encode(element, value, output, hints);
            } else {
                output.startElement(element.getNamespace(), element.getName(), null);
                Type type=element.getType();
                if( type instanceof SimpleType ){
                    SimpleType simple=(SimpleType) type;
                    simple.encode(element, value, output, hints);
                }else if (type instanceof ComplexType) {
                    ComplexType complex = (ComplexType) type;
                    Element[] children = complex.getChildElements();
                    boolean found=false;
                    for (int i = 0; i < children.length; i++) {
View Full Code Here


import org.xml.sax.SAXException;

public class XSISimpleTypesTest extends TestCase {

    public void testParseDate() throws Exception {
        SimpleType dateBinding = XSISimpleTypes.Date.getInstance();

        Element element = null;
        Attributes attrs = null;
        Map hints = null;
        ElementValue[] value;
        Date expected;
        String sval;
        Object actual;

        sval = "2012-02-14";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Date.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "2012-02-14Z";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Date.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "2011-10-24T10:53:24.200Z";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Date.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "10:53:24.255+03:00";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        try {
            dateBinding.getValue(element, value, attrs, hints);
        } catch (SAXException e) {
            assertTrue(true);
        }
    }
View Full Code Here

            assertTrue(true);
        }
    }

    public void testParseDateTime() throws Exception {
        SimpleType dateTimeBinding = XSISimpleTypes.DateTime.getInstance();

        Element element = null;
        Attributes attrs = null;
        Map hints = null;
        ElementValue[] value;
        java.util.Date expected;
        String sval;
        Object actual;

        sval = "2012-02-14";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateTimeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Timestamp.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "2012-02-14Z";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateTimeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Timestamp.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "2011-10-24T10:53:24.200Z";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateTimeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Timestamp.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "2011-10-24T00:00:00.200+03:00";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = dateTimeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Timestamp.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "10:53:24.255+03:00";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        try {
            dateTimeBinding.getValue(element, value, attrs, hints);
        } catch (SAXException e) {
            assertTrue(true);
        }
    }
View Full Code Here

            assertTrue(true);
        }
    }

    public void testParseTime() throws Exception {
        SimpleType timeBinding = XSISimpleTypes.Time.getInstance();

        Element element = null;
        Attributes attrs = null;
        Map hints = null;
        ElementValue[] value;
        java.util.Date expected;
        String sval;
        Object actual;

        sval = "10:53:24Z";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = timeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Time.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "10:53:24-03:00";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = timeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Time.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "10:53:24.255+03:00";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        actual = timeBinding.getValue(element, value, attrs, hints);
        assertNotNull(actual);
        expected = Converters.convert(sval, java.sql.Time.class);
        assertEquals(expected.getClass().getName() + "[" + expected + "] : "
                + actual.getClass().getName() + "[" + actual + "]", expected, actual);

        sval = "2012-02-14";
        value = new ElementValue[] { new ElementValueGT(null, sval) };
        try {
            timeBinding.getValue(element, value, attrs, hints);
        } catch (SAXException e) {
            assertTrue(true);
        }
    }
View Full Code Here

        if (s.getImports() != null) {
            Schema[] ss = s.getImports();

            for( int i = 0; (ss != null) && (i < ss.length); i++ ) {
                if (!targets.contains(ss[i].getTargetNamespace())) {
                    SimpleType st = lookUpSimpleType(localName, ss[i], targets);

                    if (st != null) {
                        return st;
                    }
                }
View Full Code Here

                    Schema s = (Schema) it.next();
                    String ns = s.getTargetNamespace().toString();

                    String prefixLookup = prefixCache != null ? (String) prefixCache.get(ns) : null;
                    if (prefix1 == null || prefixLookup == null || prefix1.equals(prefixLookup)) {
                        SimpleType st = lookUpSimpleType(localName, s, new TreeSet());
                        if (st != null) {
                            return st;
                        }
                    }
                }
            }
        }

        if (simpleTypes != null) {
            it = simpleTypes.iterator();

            while( it.hasNext() ) {
                Object o = it.next();

                if (o instanceof SimpleTypeHandler) {
                    SimpleTypeHandler sst = (SimpleTypeHandler) o;

                    if (localName.equalsIgnoreCase(sst.getName())) {
                        return sst.compress(this);
                    }
                } else {
                    SimpleType sst = (SimpleType) o;

                    if (localName.equalsIgnoreCase(sst.getName())) {
                        return sst;
                    }
                }
            }
        }

        SimpleType sti = XSISimpleTypes.find(localName);

        if (sti != null) {
            return sti;
        }
View Full Code Here

    public static SimpleType find(java.lang.String type) {
        if (m == null) {
            load();
        }

        SimpleType r = (SimpleType) m.get(type);

        return r;
    }
View Full Code Here

        // assuming strings and class values will not conflict
        if (m == null) {
            load();
        }

        SimpleType r = (SimpleType) m.get(type);

        return r;
    }
View Full Code Here

        switch (simpleType.getChildType()) {
        case SimpleType.RESTRICTION:

            // determine whether to print or reference the child st
            SimpleType st = simpleType.getParents()[0];
            ai = null;

            if (schema.getTargetNamespace().equals(st.getNamespace())) {
                if ((st.getName() != null) && (st.getName() != "")) {
                    SimpleType[] sts = schema.getSimpleTypes();

                    if (sts != null) {
                        for (int i = 0; i < sts.length; i++)
                            if (st.getName().equals(sts[i].getName())) {
                                ai = new AttributesImpl();
                                ai.addAttribute("", "base", "", "QName",
                                    st.getName());
                            }
                    }
                }
            } else {
                ai = new AttributesImpl();
                XSISAXHandler.setLogLevel(logger.getLevel());
                Schema s = SchemaFactory.getInstance(st.getNamespace());
                ai.addAttribute("", "base", "", "QName",
                    s.getPrefix() + ":" + st.getName());
            }

            ph.startElement(XSISimpleTypes.NAMESPACE, "restriction", ai);

            if (ai == null) {
                writeSimpleType(st, schema, ph, hints);
            }

            Facet[] facets = simpleType.getFacets();

            if (facets != null) {
                for (int i = 0; i < facets.length; i++)
                    writeFacet(facets[i], ph);
            }

            ph.endElement(XSISimpleTypes.NAMESPACE, "restriction");

            break;

        case SimpleType.LIST:

            // determine whether to print or reference the child st
            st = simpleType.getParents()[0];
            ai = null;

            if (schema.getTargetNamespace().equals(st.getNamespace())) {
                if ((st.getName() != null) && (st.getName() != "")) {
                    SimpleType[] sts = schema.getSimpleTypes();

                    if (sts != null) {
                        for (int i = 0; i < sts.length; i++)
                            if (st.getName().equals(sts[i].getName())) {
                                ai = new AttributesImpl();
                                ai.addAttribute("", "itemType", "", "QName",
                                    st.getName());
                            }
                    }
                }
            } else {
                ai = new AttributesImpl();

                Schema s = SchemaFactory.getInstance(st.getNamespace());
                ai.addAttribute("", "itemType", "", "QName",
                    s.getPrefix() + ":" + st.getName());
            }

            ph.startElement(XSISimpleTypes.NAMESPACE, "list", ai);

            if (ai == null) {
                writeSimpleType(st, schema, ph, hints);
            }

            ph.endElement(XSISimpleTypes.NAMESPACE, "list");

            break;

        case SimpleType.UNION:

            // determine whether to print or reference the child st
            SimpleType[] sts = simpleType.getParents();
            String memberTypes = null;
            List childTs = new LinkedList();

            if (sts != null) {
                for (int j = 0; j < sts.length; j++) {
                    st = sts[j];

                    if (schema.getTargetNamespace().equals(st.getNamespace())) {
                        boolean found = false;

                        if ((st.getName() != null) && (st.getName() != "")) {
                            SimpleType[] sts2 = schema.getSimpleTypes();

                            if (sts2 != null) {
                                for (int i = 0; i < sts2.length; i++)
                                    if (st.getName().equals(sts2[i].getName())) {
                                        found = true;

                                        if (memberTypes == null) {
                                            memberTypes = st.getName();
                                        } else {
                                            memberTypes += (" " + st.getName());
                                        }
                                    }
                            }
                        }

                        if (!found) {
                            childTs.add(st);
                        }
                    } else {
                        ai = new AttributesImpl();

                        Schema s = SchemaFactory.getInstance(st.getNamespace());

                        if (memberTypes == null) {
                            memberTypes = s.getPrefix() + ":" + st.getName();
                        } else {
                            memberTypes += (" " + s.getPrefix() + ":"
                            + st.getName());
                        }
                    }
                }
            }
View Full Code Here

        if (cache != null) {
            return cache;
        }

        // a.form = form; TODO add form support?
        SimpleType st = null;
        String name1 = this.name;
        String def1 = this.def;
        String fixed1 = this.fixed;
        int use1 = this.use;
View Full Code Here

TOP

Related Classes of org.geotools.xml.schema.SimpleType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.