0001: /*
0002: * Geotools2 - OpenSource mapping toolkit
0003: * http://geotools.org
0004: * (C) 2002, Geotools Project Managment Committee (PMC)
0005: *
0006: * This library is free software; you can redistribute it and/or
0007: * modify it under the terms of the GNU Lesser General Public
0008: * License as published by the Free Software Foundation;
0009: * version 2.1 of the License.
0010: *
0011: * This library is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * Lesser General Public License for more details.
0015: *
0016: */
0017: package org.geotools.xml.gml;
0018:
0019: import java.io.IOException;
0020: import java.net.URI;
0021: import java.net.URISyntaxException;
0022: import java.util.Arrays;
0023: import java.util.Collections;
0024: import java.util.Map;
0025: import java.util.logging.Level;
0026:
0027: import org.geotools.xml.PrintHandler;
0028: import org.geotools.xml.schema.Attribute;
0029: import org.geotools.xml.schema.AttributeGroup;
0030: import org.geotools.xml.schema.AttributeValue;
0031: import org.geotools.xml.schema.ComplexType;
0032: import org.geotools.xml.schema.Element;
0033: import org.geotools.xml.schema.ElementValue;
0034: import org.geotools.xml.schema.Facet;
0035: import org.geotools.xml.schema.Group;
0036: import org.geotools.xml.schema.Schema;
0037: import org.geotools.xml.schema.SimpleType;
0038: import org.geotools.xml.schema.Type;
0039: import org.geotools.xml.schema.impl.AttributeValueGT;
0040: import org.geotools.xml.schema.impl.FacetGT;
0041: import org.geotools.xml.xLink.XLinkSchema;
0042: import org.geotools.xml.xsi.XSISimpleTypes;
0043: import org.xml.sax.Attributes;
0044: import org.xml.sax.SAXException;
0045:
0046: /**
0047: * <p>
0048: * This class represents a hard coded, java interpreted version of the GML
0049: * 2.1.2 schema. Instances of this class should be prefered for use over a
0050: * parsed instance as this class will create real instances for elements
0051: * who's types correspond to types defined in this schema.
0052: * </p>
0053: *
0054: * @author dzwiers www.refractions.net
0055: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/gml/GMLSchema.java $
0056: */
0057: public class GMLSchema implements Schema {
0058: /** GML target namespace */
0059: public static final URI NAMESPACE = makeURI("http://www.opengis.net/gml");
0060:
0061: // static attribute set
0062: private static Attribute[] attributes = AttributeList.attributes1;
0063:
0064: // static complexType set
0065: private static ComplexType[] complexTypes = loadComplexTypes();
0066:
0067: // static element set
0068: private static Element[] elements = loadElements();
0069:
0070: // static attribute group set
0071: private static AttributeGroup[] attributeGroups = { new GMLAssociationAttributeGroup(), };
0072:
0073: // static simpleType set
0074: private static SimpleType[] simpleTypes = { new GMLNullType(), };
0075: private static Schema instance = new GMLSchema();
0076:
0077: /**
0078: * Creates a new GMLSchema object.
0079: */
0080: private GMLSchema() {
0081: // no op constructor
0082: }
0083:
0084: public static void setLogLevel(Level l) {
0085: GMLComplexTypes.logger.setLevel(l);
0086: FCBuffer.logger.setLevel(l);
0087: }
0088:
0089: /**
0090: * @see schema.Schema#getAttributeGroups()
0091: */
0092: public AttributeGroup[] getAttributeGroups() {
0093: return attributeGroups;
0094: }
0095:
0096: /**
0097: * @see schema.Schema#getAttributes()
0098: */
0099: public Attribute[] getAttributes() {
0100: return attributes;
0101: }
0102:
0103: /**
0104: * @see schema.Schema#getBlockDefault()
0105: */
0106: public int getBlockDefault() {
0107: return NONE;
0108: }
0109:
0110: /*
0111: * used to load the static class variable containing the set of complexTypes
0112: * associated with the GML Schema
0113: */
0114: private static final ComplexType[] loadComplexTypes() {
0115: ComplexType[] complexTypes1 = new ComplexType[31];
0116: complexTypes1[0] = GMLComplexTypes.AbstractGeometryType
0117: .getInstance();
0118: complexTypes1[1] = GMLComplexTypes.AbstractGeometryCollectionBaseType
0119: .getInstance();
0120: complexTypes1[2] = GMLComplexTypes.GeometryAssociationType
0121: .getInstance();
0122: complexTypes1[3] = GMLComplexTypes.PointMemberType
0123: .getInstance();
0124: complexTypes1[4] = GMLComplexTypes.LineStringMemberType
0125: .getInstance();
0126: complexTypes1[5] = GMLComplexTypes.PolygonMemberType
0127: .getInstance();
0128: complexTypes1[6] = GMLComplexTypes.LinearRingMemberType
0129: .getInstance();
0130: complexTypes1[7] = GMLComplexTypes.PointType.getInstance();
0131: complexTypes1[8] = GMLComplexTypes.LineStringType.getInstance();
0132: complexTypes1[9] = GMLComplexTypes.LinearRingType.getInstance();
0133: complexTypes1[10] = GMLComplexTypes.BoxType.getInstance();
0134: complexTypes1[11] = GMLComplexTypes.PolygonType.getInstance();
0135: complexTypes1[12] = GMLComplexTypes.GeometryCollectionType
0136: .getInstance();
0137: complexTypes1[13] = GMLComplexTypes.MultiPointType
0138: .getInstance();
0139: complexTypes1[14] = GMLComplexTypes.MultiLineStringType
0140: .getInstance();
0141: complexTypes1[15] = GMLComplexTypes.MultiPolygonType
0142: .getInstance();
0143: complexTypes1[16] = GMLComplexTypes.CoordType.getInstance();
0144: complexTypes1[17] = GMLComplexTypes.CoordinatesType
0145: .getInstance();
0146: complexTypes1[18] = GMLComplexTypes.AbstractFeatureType
0147: .getInstance();
0148: complexTypes1[19] = GMLComplexTypes.AbstractFeatureCollectionsBaseType
0149: .getInstance();
0150: complexTypes1[20] = GMLComplexTypes.AbstractFeatureCollectionType
0151: .getInstance();
0152: complexTypes1[21] = GMLComplexTypes.GeometryPropertyType
0153: .getInstance();
0154: complexTypes1[22] = GMLComplexTypes.FeatureAssociationType
0155: .getInstance();
0156: complexTypes1[23] = GMLComplexTypes.BoundingShapeType
0157: .getInstance();
0158: complexTypes1[24] = GMLComplexTypes.PointPropertyType
0159: .getInstance();
0160: complexTypes1[25] = GMLComplexTypes.PolygonPropertyType
0161: .getInstance();
0162: complexTypes1[26] = GMLComplexTypes.LineStringPropertyType
0163: .getInstance();
0164: complexTypes1[27] = GMLComplexTypes.MultiPointPropertyType
0165: .getInstance();
0166: complexTypes1[28] = GMLComplexTypes.MultiLineStringPropertyType
0167: .getInstance();
0168: complexTypes1[29] = GMLComplexTypes.MultiPolygonPropertyType
0169: .getInstance();
0170: complexTypes1[30] = GMLComplexTypes.MultiGeometryPropertyType
0171: .getInstance();
0172:
0173: return complexTypes1;
0174: }
0175:
0176: /**
0177: * @see schema.Schema#getComplexTypes()
0178: */
0179: public ComplexType[] getComplexTypes() {
0180: return complexTypes;
0181: }
0182:
0183: /** GMLSchema.getInstance().getElements()[GMLSchema.BOX] */
0184: public static final int BOX = 41;
0185:
0186: /*
0187: * Used to load the set of elements stored in the static class variable
0188: * representing the element set in the GML Schema
0189: */
0190: private static final Element[] loadElements() {
0191: Element[] elements1 = new Element[48];
0192:
0193: elements1[0] = new GMLElement("_Feature",
0194: GMLComplexTypes.AbstractFeatureType.getInstance(), 1,
0195: 1, true, null); // gml:AbstractFeatureType
0196: elements1[1] = new GMLElement("featureCollection",
0197: GMLComplexTypes.AbstractFeatureCollectionType
0198: .getInstance(), 1, 1, true, elements1[0]); // gml:AbstractFeatureCollectionType
0199: elements1[2] = new GMLElement("featureMember",
0200: GMLComplexTypes.FeatureAssociationType.getInstance(),
0201: 1, 1, false, null); // gml:FeatureAssociationType
0202: elements1[3] = new GMLElement("_geometryProperty",
0203: GMLComplexTypes.GeometryAssociationType.getInstance(),
0204: 1, 1, true, null); // gml:GeometryAssociationType
0205: elements1[4] = new GMLElement("geometryProperty",
0206: GMLComplexTypes.GeometryAssociationType.getInstance(),
0207: 1, 1, false, null); // gml:GeometryAssociationType
0208: elements1[5] = new GMLElement("boundedBy",
0209: GMLComplexTypes.BoundingShapeType.getInstance(), 1, 1,
0210: false, null); // gml:BoundingShapeType
0211: elements1[6] = new GMLElement("pointProperty",
0212: GMLComplexTypes.PointPropertyType.getInstance(), 1, 1,
0213: false, elements1[3]); // gml:PointPropertyType
0214: elements1[7] = new GMLElement("polygonProperty",
0215: GMLComplexTypes.PolygonPropertyType.getInstance(), 1,
0216: 1, false, elements1[3]); // gml:PolygonPropertyType
0217: elements1[8] = new GMLElement("lineStringProperty",
0218: GMLComplexTypes.LineStringPropertyType.getInstance(),
0219: 1, 1, false, elements1[3]); // gml:LineStringPropertyType
0220: elements1[9] = new GMLElement("multiPointProperty",
0221: GMLComplexTypes.MultiPointPropertyType.getInstance(),
0222: 1, 1, false, elements1[3]); // gml:MultiPointPropertyType
0223: elements1[10] = new GMLElement("multiLineStringProperty",
0224: GMLComplexTypes.MultiLineStringPropertyType
0225: .getInstance(), 1, 1, false, elements1[3]); // gml:MultiLineStringPropertyType
0226: elements1[11] = new GMLElement("multiPolygonProperty",
0227: GMLComplexTypes.MultiPolygonPropertyType.getInstance(),
0228: 1, 1, false, elements1[3]); // gml:MultiPolygonPropertyType
0229: elements1[12] = new GMLElement(
0230: "multiGeometryProperty",
0231: GMLComplexTypes.MultiGeometryPropertyType.getInstance(),
0232: 1, 1, false, elements1[3]); // gml:MultiGeometryPropertyType
0233: elements1[13] = new GMLElement("location",
0234: GMLComplexTypes.PointPropertyType.getInstance(), 1, 1,
0235: false, elements1[6]); // gml:PointPropertyType
0236: elements1[14] = new GMLElement("centerOf",
0237: GMLComplexTypes.PointPropertyType.getInstance(), 1, 1,
0238: false, elements1[6]); // gml:PointPropertyType
0239: elements1[15] = new GMLElement("position",
0240: GMLComplexTypes.PointPropertyType.getInstance(), 1, 1,
0241: false, elements1[6]); // gml:PointPropertyType
0242: elements1[16] = new GMLElement("extentOf",
0243: GMLComplexTypes.PolygonPropertyType.getInstance(), 1,
0244: 1, false, elements1[7]); // gml:PolygonPropertyType
0245: elements1[17] = new GMLElement("coverage",
0246: GMLComplexTypes.PolygonPropertyType.getInstance(), 1,
0247: 1, false, elements1[7]); // gml:PolygonPropertyType
0248: elements1[18] = new GMLElement("edgeOf",
0249: GMLComplexTypes.LineStringPropertyType.getInstance(),
0250: 1, 1, false, elements1[8]); // gml:LineStringPropertyType
0251: elements1[19] = new GMLElement("centerLineOf",
0252: GMLComplexTypes.LineStringPropertyType.getInstance(),
0253: 1, 1, false, elements1[8]); // gml:LineStringPropertyType
0254: elements1[20] = new GMLElement("multiLocation",
0255: GMLComplexTypes.MultiPointPropertyType.getInstance(),
0256: 1, 1, false, elements1[9]); // gml:MultiPointPropertyType
0257: elements1[21] = new GMLElement("multiCenterOf",
0258: GMLComplexTypes.MultiPointPropertyType.getInstance(),
0259: 1, 1, false, elements1[9]); // gml:MultiPointPropertyType
0260: elements1[22] = new GMLElement("multiPosition",
0261: GMLComplexTypes.MultiPointPropertyType.getInstance(),
0262: 1, 1, false, elements1[9]); // gml:MultiPointPropertyType
0263: elements1[23] = new GMLElement("multiCenterLineOf",
0264: GMLComplexTypes.MultiLineStringPropertyType
0265: .getInstance(), 1, 1, false, elements1[10]); // gml:MultiLineStringPropertyType
0266: elements1[24] = new GMLElement("multiEdgeOf",
0267: GMLComplexTypes.MultiLineStringPropertyType
0268: .getInstance(), 1, 1, false, elements1[10]); // gml:MultiLineStringPropertyType
0269: elements1[25] = new GMLElement("multiCoverage",
0270: GMLComplexTypes.MultiPolygonPropertyType.getInstance(),
0271: 1, 1, false, elements1[11]); // gml:MultiPolygonPropertyType
0272: elements1[26] = new GMLElement("multiExtentOf",
0273: GMLComplexTypes.MultiPolygonPropertyType.getInstance(),
0274: 1, 1, false, elements1[11]); // gml:MultiPolygonPropertyType
0275: elements1[28] = new GMLElement("name", XSISimpleTypes.String
0276: .getInstance(), 1, 1, false, null); //xs:string
0277: elements1[27] = new GMLElement("description",
0278: XSISimpleTypes.String.getInstance(), 1, 1, false, null); //xs:string
0279: elements1[29] = new GMLElement("_Geometry",
0280: GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
0281: 1, true, null); // gml:AbstractGeometryType
0282: elements1[30] = new GMLElement("GeometryCollection",
0283: GMLComplexTypes.GeometryCollectionType.getInstance(),
0284: 1, 1, true, elements1[29]); // gml:GeometryCollectionType
0285: elements1[31] = new GMLElement("geometryMember",
0286: GMLComplexTypes.GeometryAssociationType.getInstance(),
0287: 1, 1, false, null); // gml:GeometryAssociationType
0288: elements1[32] = new GMLElement("pointMember",
0289: GMLComplexTypes.PointMemberType.getInstance(), 1, 1,
0290: false, elements1[31]); // gml:PointMemberType
0291: elements1[33] = new GMLElement("lineStringMember",
0292: GMLComplexTypes.PointMemberType.getInstance(), 1, 1,
0293: false, elements1[31]); // gml:PointMemberType
0294: elements1[34] = new GMLElement("polygonMember",
0295: GMLComplexTypes.PointMemberType.getInstance(), 1, 1,
0296: false, elements1[31]); // gml:PointMemberType
0297: elements1[35] = new GMLElement("outerBoundaryIs",
0298: GMLComplexTypes.LinearRingMemberType.getInstance(), 1,
0299: 1, false, null); // gml:LinearRingMemberType
0300: elements1[36] = new GMLElement("innerBoundaryIs",
0301: GMLComplexTypes.LinearRingMemberType.getInstance(), 1,
0302: 1, false, null); // gml:LinearRingMemberType
0303: elements1[37] = new GMLElement("Point",
0304: GMLComplexTypes.PointType.getInstance(), 1, 1, false,
0305: elements1[29]); // gml:PointType
0306: elements1[38] = new GMLElement("LineString",
0307: GMLComplexTypes.LineStringType.getInstance(), 1, 1,
0308: false, elements1[29]); // gml:LineStringType
0309: elements1[39] = new GMLElement("LinearRing",
0310: GMLComplexTypes.LinearRingType.getInstance(), 1, 1,
0311: false, elements1[29]); // gml:LinearRingType
0312: elements1[40] = new GMLElement("Polygon",
0313: GMLComplexTypes.PolygonType.getInstance(), 1, 1, false,
0314: elements1[29]); // gml:PolygonType
0315: elements1[BOX] = new GMLElement("Box", GMLComplexTypes.BoxType
0316: .getInstance(), 1, 1, false, null); // gml:BoxType
0317: elements1[42] = new GMLElement("MultiGeometry",
0318: GMLComplexTypes.GeometryCollectionType.getInstance(),
0319: 1, 1, false, elements1[29]); // gml:GeometryCollectionType
0320: elements1[43] = new GMLElement("MultiPoint",
0321: GMLComplexTypes.MultiPointType.getInstance(), 1, 1,
0322: false, elements1[29]); // gml:MultiPointType
0323: elements1[44] = new GMLElement("MultiLineString",
0324: GMLComplexTypes.MultiLineStringType.getInstance(), 1,
0325: 1, false, elements1[29]); // gml:MultiLineStringType
0326: elements1[45] = new GMLElement("MultiPolygon",
0327: GMLComplexTypes.MultiPolygonType.getInstance(), 1, 1,
0328: false, elements1[29]); // gml:MultiPolygonType
0329: elements1[46] = new GMLElement("coord",
0330: GMLComplexTypes.CoordType.getInstance(), 1, 1, false,
0331: null); // gml:CoordType
0332: elements1[47] = new GMLElement("coordinates",
0333: GMLComplexTypes.CoordinatesType.getInstance(), 1, 1,
0334: false, null); // gml:CoordinatesType
0335:
0336: return elements1;
0337: }
0338:
0339: /**
0340: * @see schema.Schema#isElementFormDefault()
0341: */
0342: public boolean isElementFormDefault() {
0343: return true;
0344: }
0345:
0346: /**
0347: * @see schema.Schema#getElements()
0348: */
0349: public Element[] getElements() {
0350: return elements;
0351: }
0352:
0353: /**
0354: * @see schema.Schema#getFinalDefault()
0355: */
0356: public int getFinalDefault() {
0357: return NONE;
0358: }
0359:
0360: /**
0361: * @see schema.Schema#getGroups()
0362: */
0363: public Group[] getGroups() {
0364: return new Group[0];
0365: }
0366:
0367: /**
0368: * @see schema.Schema#getId()
0369: */
0370: public String getId() {
0371: return null;
0372: }
0373:
0374: private static Schema[] imports = new Schema[] { XLinkSchema
0375: .getInstance() };
0376:
0377: /**
0378: * @see schema.Schema#getImports()
0379: */
0380: public Schema[] getImports() {
0381: return imports;
0382: }
0383:
0384: /**
0385: * @see schema.Schema#getSimpleTypes()
0386: */
0387: public SimpleType[] getSimpleTypes() {
0388: return simpleTypes;
0389: }
0390:
0391: /**
0392: * @see schema.Schema#getTargetNamespace()
0393: */
0394: public URI getTargetNamespace() {
0395: return NAMESPACE;
0396: }
0397:
0398: public URI getURI() {
0399: return NAMESPACE;
0400: }
0401:
0402: /**
0403: * @see schema.Schema#getVersion()
0404: */
0405: public String getVersion() {
0406: return "2.1.2";
0407: }
0408:
0409: private static URI makeURI(String s) {
0410: try {
0411: return new URI(s);
0412: } catch (URISyntaxException e) {
0413: // do nothing
0414: return null;
0415: }
0416: }
0417:
0418: /**
0419: * @see schema.Schema#includesURI(java.net.URI)
0420: */
0421: public boolean includesURI(URI uri) {
0422: // if (uri.toString().toLowerCase().endsWith("geometry.xsd")
0423: // || uri.toString().toLowerCase().endsWith("feature.xsd")) {
0424: // return true;
0425: // }
0426: //
0427: // return false;
0428: // this is a spec ... we never want the def modified.
0429: // TODO see if this affects printing
0430: return true;
0431: }
0432:
0433: /**
0434: * @see schema.Schema#isAttributeFormDefault()
0435: */
0436: public boolean isAttributeFormDefault() {
0437: return false;
0438: }
0439:
0440: /**
0441: * @see org.geotools.xml.schema.Schema#getPrefix()
0442: */
0443: public String getPrefix() {
0444: return "gml";
0445: }
0446:
0447: /**
0448: * @see org.geotools.xml.schema.Schema#getInstance()
0449: */
0450: public static Schema getInstance() {
0451: return instance;
0452: }
0453:
0454: static class AttributeList {
0455: static final Attribute[] attributes1 = { new GMLAttribute(
0456: "remoteSchema", XSISimpleTypes.AnyURI.getInstance()), };
0457: }
0458:
0459: /**
0460: * <p>
0461: * Adds some common information and functionality to a base element to be
0462: * used by the GMLSchema. The remaining data will be configured upon
0463: * creation.
0464: * </p>
0465: *
0466: * @author dzwiers
0467: *
0468: * @see Element
0469: */
0470: static class GMLElement implements Element {
0471: // default visibily to remove the set* methods ... this class is
0472: // only package visible
0473: boolean abstracT = false;
0474: int max;
0475: int min;
0476: String name;
0477: Type type;
0478: Element substitutionGroup;
0479:
0480: /*
0481: * Should never be called
0482: */
0483: private GMLElement() {
0484: // no op constructor
0485: }
0486:
0487: /**
0488: * Configures the Element for this particular GML instance. The
0489: * following params match schema definition attributes found in an
0490: * element declaration. Those missing have been hard coded for the gml
0491: * Schema.
0492: *
0493: * @param name
0494: * @param type
0495: * @param min
0496: * @param max
0497: * @param abstracT
0498: * @param substitutionGroup
0499: */
0500: public GMLElement(String name, Type type, int min, int max,
0501: boolean abstracT, Element substitutionGroup) {
0502: this .abstracT = abstracT;
0503: this .max = max;
0504: this .min = min;
0505: this .name = name;
0506: this .type = type;
0507: this .substitutionGroup = substitutionGroup;
0508: }
0509:
0510: /**
0511: * Creates a clone using the new min/max occurences.
0512: *
0513: * @param element
0514: * @param min
0515: * @param max
0516: */
0517: public GMLElement(GMLElement element, int min, int max) {
0518: this .abstracT = element.isAbstract();
0519: this .max = max;
0520: this .min = min;
0521: this .name = element.getName();
0522: this .type = element.getType();
0523: this .substitutionGroup = element.getSubstitutionGroup();
0524: }
0525:
0526: /**
0527: * @see org.geotools.xml.xsi.ElementGrouping#findChildElement(java.lang.String)
0528: */
0529: public Element findChildElement(String name1) {
0530: if (this .name != null) {
0531: if (this .name.equals(name1)) {
0532: return this ;
0533: }
0534: }
0535:
0536: return null;
0537: }
0538:
0539: /**
0540: * @see org.geotools.xml.xsi.ElementGrouping#getGrouping()
0541: */
0542: public int getGrouping() {
0543: return ELEMENT;
0544: }
0545:
0546: /**
0547: * @see schema.Element#isAbstract()
0548: */
0549: public boolean isAbstract() {
0550: return abstracT;
0551: }
0552:
0553: /**
0554: * @see schema.Element#getBlock()
0555: */
0556: public int getBlock() {
0557: return Schema.NONE;
0558: }
0559:
0560: /**
0561: * @see schema.Element#getDefault()
0562: */
0563: public String getDefault() {
0564: return null;
0565: }
0566:
0567: /**
0568: * @see schema.Element#getFinal()
0569: */
0570: public int getFinal() {
0571: return Schema.NONE;
0572: }
0573:
0574: /**
0575: * @see schema.Element#getFixed()
0576: */
0577: public String getFixed() {
0578: return null;
0579: }
0580:
0581: /**
0582: * @see schema.Element#isForm()
0583: */
0584: public boolean isForm() {
0585: return false;
0586: }
0587:
0588: /**
0589: * @see schema.Element#getId()
0590: */
0591: public String getId() {
0592: return null;
0593: }
0594:
0595: /**
0596: * @see schema.Element#getMaxOccurs()
0597: */
0598: public int getMaxOccurs() {
0599: return max;
0600: }
0601:
0602: /**
0603: * @see schema.Element#getMinOccurs()
0604: */
0605: public int getMinOccurs() {
0606: return min;
0607: }
0608:
0609: /**
0610: * @see schema.Element#getName()
0611: */
0612: public String getName() {
0613: return name;
0614: }
0615:
0616: /**
0617: * @see schema.Element#isNillable()
0618: */
0619: public boolean isNillable() {
0620: return false;
0621: }
0622:
0623: /**
0624: * @see schema.Element#getSubstitutionGroup()
0625: */
0626: public Element getSubstitutionGroup() {
0627: return substitutionGroup;
0628: }
0629:
0630: /**
0631: * @see schema.Element#getType()
0632: */
0633: public Type getType() {
0634: return type;
0635: }
0636:
0637: /**
0638: * @see schema.Element#getNamespace()
0639: */
0640: public URI getNamespace() {
0641: return GMLSchema.NAMESPACE;
0642: }
0643:
0644: public Element findChildElement(String localName,
0645: URI namespaceURI) {
0646: if (this .name != null) {
0647: if (this .name.equals(localName)
0648: && getNamespace().equals(namespaceURI)) {
0649: return this ;
0650: }
0651: }
0652:
0653: return null;
0654: }
0655: }
0656:
0657: /**
0658: * <p>
0659: * This abstract class represents some default and constant values
0660: * associated with a GML complexType.
0661: * </p>
0662: *
0663: * @author dzwiers
0664: *
0665: * @see ComplexType
0666: */
0667: static abstract class GMLComplexType implements ComplexType {
0668: /**
0669: * @see schema.ComplexType#getBlock()
0670: */
0671: public int getBlock() {
0672: return Schema.NONE;
0673: }
0674:
0675: /**
0676: * @see schema.ComplexType#getFinal()
0677: */
0678: public int getFinal() {
0679: return Schema.NONE;
0680: }
0681:
0682: /**
0683: * @see schema.ComplexType#getId()
0684: */
0685: public String getId() {
0686: return null;
0687: }
0688:
0689: /**
0690: * @see schema.ComplexType#isMixed()
0691: */
0692: public boolean isMixed() {
0693: return false;
0694: }
0695:
0696: /**
0697: * @see schema.ComplexType#getNamespace()
0698: */
0699: public URI getNamespace() {
0700: return GMLSchema.NAMESPACE;
0701: }
0702:
0703: /*
0704: * included here to deal generically with a GML complexType ...
0705: * part of the singleton pattern.
0706: */
0707: static GMLComplexType getInstance() {
0708: return null;
0709: }
0710:
0711: /**
0712: * @see schema.ComplexType#isDerived()
0713: */
0714: public boolean isDerived() {
0715: return false;
0716: }
0717:
0718: /**
0719: * @see schema.ComplexType#getParent()
0720: */
0721: public Type getParent() {
0722: return null;
0723: }
0724:
0725: /**
0726: * @see org.geotools.xml.schema.ComplexType#cache()
0727: */
0728: public boolean cache(Element e, Map m) {
0729: return true;
0730: }
0731: }
0732:
0733: /**
0734: * <p>
0735: * An instance of this class represents a GML attribute. This
0736: * implementation contains some constant data pertinent to the GML Schema,
0737: * and some configurable data depending on the GML attribute being
0738: * represented.
0739: * </p>
0740: *
0741: * @author dzwiers
0742: *
0743: * @see Attribute
0744: */
0745: static class GMLAttribute implements Attribute {
0746: // package visible class variable, used to avoid set* methods
0747: String name;
0748: String def = null;
0749: SimpleType simpleType;
0750: int use = Attribute.OPTIONAL;
0751:
0752: /*
0753: * Should never be called
0754: */
0755: private GMLAttribute() {
0756: // no op constructor
0757: }
0758:
0759: /**
0760: * Creates a GML attribute based on the name and type provided.
0761: *
0762: * @param name
0763: * @param simpleType
0764: */
0765: public GMLAttribute(String name, SimpleType simpleType) {
0766: this .name = name;
0767: this .simpleType = simpleType;
0768: }
0769:
0770: /**
0771: * Creates a GML attribute based on the name, use and type provided.
0772: *
0773: * @param name
0774: * @param simpleType
0775: * @param use
0776: */
0777: public GMLAttribute(String name, SimpleType simpleType, int use) {
0778: this .name = name;
0779: this .simpleType = simpleType;
0780: this .use = use;
0781: }
0782:
0783: /**
0784: * Creates a GML attribute based on the name, use, default and type
0785: * provided.
0786: *
0787: * @param name
0788: * @param simpleType
0789: * @param use
0790: * @param def
0791: */
0792: public GMLAttribute(String name, SimpleType simpleType,
0793: int use, String def) {
0794: this .name = name;
0795: this .simpleType = simpleType;
0796: this .use = use;
0797: this .def = def;
0798: }
0799:
0800: /**
0801: * @see schema.Attribute#getNameSpace()
0802: */
0803: public URI getNamespace() {
0804: return GMLSchema.NAMESPACE;
0805: }
0806:
0807: /**
0808: * @see schema.Attribute#getDefault()
0809: */
0810: public String getDefault() {
0811: return def;
0812: }
0813:
0814: /**
0815: * @see schema.Attribute#getFixed()
0816: */
0817: public String getFixed() {
0818: return null;
0819: }
0820:
0821: /**
0822: * @see schema.Attribute#isForm()
0823: */
0824: public boolean isForm() {
0825: return false;
0826: }
0827:
0828: /**
0829: * @see schema.Attribute#getId()
0830: */
0831: public String getId() {
0832: return null;
0833: }
0834:
0835: /**
0836: * @see schema.Attribute#getName()
0837: */
0838: public String getName() {
0839: return name;
0840: }
0841:
0842: /**
0843: * @see schema.Attribute#getUse()
0844: */
0845: public int getUse() {
0846: return use;
0847: }
0848:
0849: /**
0850: * @see schema.Attribute#getSimpleType()
0851: */
0852: public SimpleType getSimpleType() {
0853: return simpleType;
0854: }
0855: }
0856:
0857: /**
0858: * <p>
0859: * This implementation of an Attribute Group represents the GML Association
0860: * Attribute Group as specified in the GML Schema.
0861: * </p>
0862: *
0863: * @author dzwiers
0864: *
0865: * @see AttributeGroup
0866: */
0867: static class GMLAssociationAttributeGroup implements AttributeGroup {
0868: // package visible attribute set
0869: static final Attribute[] attributes1 = { new GMLAttribute(
0870: "remoteSchema", XSISimpleTypes.AnyURI.getInstance()), };
0871:
0872: // package visible child declaration
0873: static final AttributeGroup child = XLinkSchema.SimpleLink
0874: .getInstance();
0875:
0876: /**
0877: * @see schema.Attribute#getNameSpace()
0878: */
0879: public URI getNamespace() {
0880: return GMLSchema.NAMESPACE;
0881: }
0882:
0883: /**
0884: * @see schema.AttributeGroup#getAnyAttributeNameSpace()
0885: */
0886: public String getAnyAttributeNameSpace() {
0887: return child.getAnyAttributeNameSpace();
0888: }
0889:
0890: /**
0891: * @see schema.Schema#getAttributes()
0892: */
0893: public Attribute[] getAttributes() {
0894: return attributes1;
0895: }
0896:
0897: /**
0898: * @see schema.AttributeGroup#getId()
0899: */
0900: public String getId() {
0901: return null;
0902: }
0903:
0904: /**
0905: * @see schema.AttributeGroup#getName()
0906: */
0907: public String getName() {
0908: return "AssociationAttributeGroup";
0909: }
0910: }
0911:
0912: /**
0913: * <p>
0914: * This class represents the GML NullType declaration of a simple type.
0915: * </p>
0916: *
0917: * @author dzwiers
0918: *
0919: * @see SimpleType
0920: */
0921: static class GMLNullType implements SimpleType {
0922: /**
0923: * @see schema.SimpleType#getNamespace()
0924: */
0925: public URI getNamespace() {
0926: return GMLSchema.NAMESPACE;
0927: }
0928:
0929: /**
0930: * @see org.geotools.xml.xsi.Type#getParent()
0931: */
0932: public Type getParent() {
0933: return null;
0934: }
0935:
0936: /**
0937: * @see schema.SimpleType#getFinal()
0938: */
0939: public int getFinal() {
0940: return Schema.NONE;
0941: }
0942:
0943: /**
0944: * @see schema.SimpleType#getId()
0945: */
0946: public String getId() {
0947: return null;
0948: }
0949:
0950: /**
0951: * @see schema.SimpleType#getName()
0952: */
0953: public String getName() {
0954: return "NullType";
0955: }
0956:
0957: /**
0958: * @see schema.Type#getValue(java.lang.String)
0959: */
0960: public Object getValue(Element element, ElementValue[] value,
0961: Attributes attr, Map hints) throws SAXException {
0962: if ((value == null) || (value.length != 1)
0963: || (value[0].getValue() == null)) {
0964: return null;
0965: }
0966:
0967: if (!(value[0].getValue() instanceof String)) {
0968: throw new SAXException(
0969: "SimpleTypes can only evaluate Strings");
0970: }
0971:
0972: String text = (String) value[0].getValue();
0973: text = text.trim();
0974:
0975: final String[] enumeration = { "inapplicable", "unknown",
0976: "unavailable", "missing" };
0977:
0978: if (contains(enumeration, text)) {
0979: return value[0].getValue();
0980: }
0981:
0982: throw new SAXException(
0983: "The value passed in to gml:NullType was not one of the allowable enumerated values."); //unacceptable result
0984: }
0985:
0986: private boolean contains(String[] enumeration, String text) {
0987: for (int i = 0; i < enumeration.length; i++) {
0988: if (enumeration[i].equalsIgnoreCase(text))
0989: return true;
0990: }
0991: return false;
0992: }
0993:
0994: /**
0995: * @see org.geotools.xml.xsi.Type#getInstanceType()
0996: */
0997: public Class getInstanceType() {
0998: return String.class;
0999: }
1000:
1001: /**
1002: * @see org.geotools.xml.schema.SimpleType#toAttribute(org.geotools.xml.schema.Attribute,
1003: * java.lang.Object, java.util.Map)
1004: */
1005: public AttributeValue toAttribute(Attribute attribute,
1006: Object value, Map hints) {
1007: final String[] enumeration = { "inapplicable", "unknown",
1008: "unavailable", "missing" };
1009:
1010: if (Arrays.binarySearch(enumeration, value) < 0) {
1011: // not found
1012: return new AttributeValueGT(attribute, null);
1013: }
1014:
1015: return new AttributeValueGT(attribute, value.toString());
1016: }
1017:
1018: /**
1019: * @see org.geotools.xml.schema.SimpleType#canCreateAttributes(org.geotools.xml.schema.Attribute,
1020: * java.lang.Object, java.util.Map)
1021: */
1022: public boolean canCreateAttributes(Attribute attribute,
1023: Object value, Map hints) {
1024: final String[] enumeration = { "inapplicable", "unknown",
1025: "unavailable", "missing" };
1026:
1027: return Arrays.binarySearch(enumeration, value) < 0;
1028: }
1029:
1030: /**
1031: * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1032: * java.lang.Object, java.util.Map)
1033: */
1034: public boolean canEncode(Element element, Object value,
1035: Map hints) {
1036: final String[] enumeration = { "inapplicable", "unknown",
1037: "unavailable", "missing" };
1038:
1039: return Arrays.binarySearch(enumeration, value) < 0;
1040: }
1041:
1042: /**
1043: * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1044: * java.lang.Object, org.geotools.xml.PrintHandler,
1045: * java.util.Map)
1046: */
1047: public void encode(Element element, Object value,
1048: PrintHandler output, Map hints) throws IOException {
1049: output.startElement(element.getNamespace(), element
1050: .getName(), null);
1051: output.characters(value.toString());
1052: output
1053: .endElement(element.getNamespace(), element
1054: .getName());
1055: }
1056:
1057: /**
1058: * @see org.geotools.xml.schema.SimpleType#getChildType()
1059: */
1060: public int getChildType() {
1061: return RESTRICTION;
1062: }
1063:
1064: /**
1065: * @see org.geotools.xml.schema.SimpleType#getParents()
1066: */
1067: public SimpleType[] getParents() {
1068: return new SimpleType[] { XSISimpleTypes.String
1069: .getInstance(), };
1070: }
1071:
1072: /**
1073: * @see org.geotools.xml.schema.SimpleType#getFacets()
1074: */
1075: public Facet[] getFacets() {
1076: return new Facet[] {
1077: new FacetGT(Facet.ENUMERATION, "inapplicable"),
1078: new FacetGT(Facet.ENUMERATION, "unknown"),
1079: new FacetGT(Facet.ENUMERATION, "unavailable"),
1080: new FacetGT(Facet.ENUMERATION, "missing"), };
1081: }
1082:
1083: /**
1084: * @see org.geotools.xml.schema.Type#findChildElement(java.lang.String)
1085: */
1086: public Element findChildElement(String name) {
1087: return null; // will never happen
1088: }
1089: }
1090:
1091: /**
1092: * Returns the implementation hints. The default implementation returns en empty map.
1093: */
1094: public Map getImplementationHints() {
1095: return Collections.EMPTY_MAP;
1096: }
1097: }
|