[udig-commits] svn - r6462 - udig/trunk/gml/src/schema/handlers
dzwiers at svn.geotools.org
dzwiers at svn.geotools.org
Wed Jun 16 16:39:58 PDT 2004
Author: dzwiers
Date: 2004-06-16 16:39:57 -0700 (Wed, 16 Jun 2004)
New Revision: 6462
Modified:
udig/trunk/gml/src/schema/handlers/AttributeGroupHandler.java
udig/trunk/gml/src/schema/handlers/AttributeHandler.java
udig/trunk/gml/src/schema/handlers/SchemaHandler.java
udig/trunk/gml/src/schema/handlers/SimpleTypeHandler.java
Log:
backup
Modified: udig/trunk/gml/src/schema/handlers/AttributeGroupHandler.java
===================================================================
--- udig/trunk/gml/src/schema/handlers/AttributeGroupHandler.java 2004-06-16 20:38:15 UTC (rev 6461)
+++ udig/trunk/gml/src/schema/handlers/AttributeGroupHandler.java 2004-06-16 23:39:57 UTC (rev 6462)
@@ -26,8 +26,6 @@
import schema.Attribute;
import schema.AttributeGroup;
-import schema.Schema;
-import schema.SimpleType;
import schema.XSIElementHandler;
import java.util.HashSet;
@@ -243,7 +241,7 @@
return ref;
}
private AttributeGroup cache = null;
- protected AttributeGroup compress(SimpleType[] simpleTypes, Schema[] schemas){
+ protected AttributeGroup compress(SchemaHandler parent){
if(cache != null)
return cache;
AttributeGroupDefault agd = new AttributeGroupDefault();
@@ -258,10 +256,10 @@
while(i.hasNext()){
Object o = i.next();
if(o instanceof AttributeHandler){
- h.add(((AttributeHandler)o).compress(simpleTypes,schemas));
+ h.add(((AttributeHandler)o).compress(parent));
}else{
AttributeGroupHandler agh = (AttributeGroupHandler)o;
- AttributeGroup ag = agh.compress(simpleTypes,schemas);
+ AttributeGroup ag = agh.compress(parent);
if(ag!=null && ag.getAttributes()!=null){
Attribute[] aa = ag.getAttributes();
for(int j=0;j<aa.length;j++)
Modified: udig/trunk/gml/src/schema/handlers/AttributeHandler.java
===================================================================
--- udig/trunk/gml/src/schema/handlers/AttributeHandler.java 2004-06-16 20:38:15 UTC (rev 6461)
+++ udig/trunk/gml/src/schema/handlers/AttributeHandler.java 2004-06-16 23:39:57 UTC (rev 6462)
@@ -25,10 +25,8 @@
import org.xml.sax.SAXNotRecognizedException;
import schema.Attribute;
-import schema.Schema;
import schema.SimpleType;
import schema.XSIElementHandler;
-import schema.xsi.XSISimpleTypes;
/**
@@ -317,7 +315,7 @@
}
private Attribute cache = null;
- protected Attribute compress(SimpleType[] simpleTypes, Schema[] schemas){
+ protected Attribute compress(SchemaHandler parent){
if(cache != null)
return cache;
@@ -331,23 +329,11 @@
// a.form = form; TODO add form support?
if(simpleType!=null){
- a.simpleType = simpleType.compress();
+ a.simpleType = simpleType.compress(parent);
}else{
if(type != null && (!"".equals(type))){
// look it up --- find it
-
- for(int i=0;i<simpleTypes.length && a.simpleType == null;i++)
- if(type.equals(simpleTypes[i].getName()))
- a.simpleType = simpleTypes[i];
-
- SimpleType st = XSISimpleTypes.find(type);
- if(st!=null)
- a.simpleType = st;
- for(int j=0;j<schemas.length && a.simpleType == null;j++){
- for(int i=0;i<schemas[j].getSimpleTypes().length && a.simpleType == null;i++)
- if(type.equals(schemas[j].getSimpleTypes()[i].getName()))
- a.simpleType = schemas[j].getSimpleTypes()[i];
- }
+ a.simpleType = parent.lookUpSimpleType(type);
}
}
cache = a;
Modified: udig/trunk/gml/src/schema/handlers/SchemaHandler.java
===================================================================
--- udig/trunk/gml/src/schema/handlers/SchemaHandler.java 2004-06-16 20:38:15 UTC (rev 6461)
+++ udig/trunk/gml/src/schema/handlers/SchemaHandler.java 2004-06-16 23:39:57 UTC (rev 6462)
@@ -20,7 +20,6 @@
*/
package schema.handlers;
-import org.dom4j.ElementHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -34,6 +33,8 @@
import schema.SchemaFactory;
import schema.SimpleType;
import schema.XSIElementHandler;
+import schema.xsi.XSISimpleTypes;
+
import java.net.URI;
import java.util.Arrays;
import java.util.HashSet;
@@ -61,7 +62,124 @@
* @version $Id$
*/
public class SchemaHandler extends XSIElementHandler{
- public static final String namespaceURI = "http://www.w3.org/2001/XMLSchema";
+ private static class DefaultSchema implements Schema{
+ boolean attributeFormDefault,elementFormDefault;
+ String id,name,targetNamespace,version;
+ int finalDefault, blockDefault;
+ URI[] URIs;
+ Schema[] imports;
+ SimpleType[] simpleTypes;
+ ComplexType[] complexTypes;
+ AttributeGroup[] attributeGroups;
+ Attribute[] attributes;
+ Element[] elements;
+ Group[] groups;
+
+ /**
+ * @return Returns the attributeFormDefault.
+ */
+ public boolean isAttributeFormDefault() {
+ return attributeFormDefault;
+ }
+ /**
+ * @return Returns the attributeGroups.
+ */
+ public AttributeGroup[] getAttributeGroups() {
+ return attributeGroups;
+ }
+ /**
+ * @return Returns the attributes.
+ */
+ public Attribute[] getAttributes() {
+ return attributes;
+ }
+ /**
+ * @return Returns the blockDefault.
+ */
+ public int getBlockDefault() {
+ return blockDefault;
+ }
+ /**
+ * @return Returns the complexTypes.
+ */
+ public ComplexType[] getComplexTypes() {
+ return complexTypes;
+ }
+ /**
+ * @return Returns the elementFormDefault.
+ */
+ public boolean isElementFormDefault() {
+ return elementFormDefault;
+ }
+ /**
+ * @return Returns the elements.
+ */
+ public Element[] getElements() {
+ return elements;
+ }
+ /**
+ * @return Returns the finalDefault.
+ */
+ public int getFinalDefault() {
+ return finalDefault;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public String getId() {
+ return id;
+ }
+ /**
+ * @return Returns the imports.
+ */
+ public Schema[] getImports() {
+ return imports;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @return Returns the simpleTypes.
+ */
+ public SimpleType[] getSimpleTypes() {
+ return simpleTypes;
+ }
+ /**
+ * @return Returns the targetNamespace.
+ */
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+ /**
+ * @return Returns the uRIs.
+ */
+ public URI[] getURIs() {
+ return URIs;
+ }
+ /**
+ * @return Returns the version.
+ */
+ public String getVersion() {
+ return version;
+ }
+ /**
+ * @return Returns the groups.
+ */
+ public Group[] getGroups() {
+ return groups;
+ }
+ /* (non-Javadoc)
+ * @see schema.Schema#includesURI(java.net.URI)
+ */
+ public boolean includesURI(URI uri) {
+ return Arrays.binarySearch(URIs,uri)>=0;
+ }
+ }
+
+ public static final String namespaceURI = "http://www.w3.org/2001/XMLSchema";
public final static String LOCALNAME = "schema";
private String id;
private String targetNamespace;
@@ -357,7 +475,7 @@
// TODO redefines?
// should do over-writing here
- //build schema object ... thDefaultwill be thrown out
+ //build schema object ... be thrown out
DefaultSchema schema = new DefaultSchema();
schema.attributeFormDefault = attributeFormDefault;
schema.elementFormDefault = elementFormDefault;
@@ -374,160 +492,75 @@
schema.simpleTypes = new SimpleType[simpleTypes.size()];
i=0;it=simpleTypes.iterator();
+ SimpleTypeHandler[] simplehandlers = (SimpleTypeHandler[])simpleTypes.toArray(new SimpleTypeHandler[simpleTypes.size()]);
while(it.hasNext()){
SimpleTypeHandler ct = (SimpleTypeHandler)it.next();
- schema.simpleTypes[i++] = ct.getSimpleType();
+ schema.simpleTypes[i++] = ct.compress(this);
}
schema.attributeGroups = new AttributeGroup[attributeGroups.size()];
i=0;it=attributeGroups.iterator();
while(it.hasNext()){
AttributeGroupHandler agh = (AttributeGroupHandler)it.next();
- schema.attributeGroups[i++] = agh.compress(schema.simpleTypes,schema.imports);
+ schema.attributeGroups[i++] = agh.compress(this);
}
schema.attributes = new Attribute[attributes.size()];
i=0;it=attributes.iterator();
while(it.hasNext()){
AttributeHandler ag = (AttributeHandler)it.next();
- schema.attributes[i++] = ag.compress(schema.simpleTypes,schema.imports);
+ schema.attributes[i++] = ag.compress(this);
}
schema.complexTypes = new ComplexType[complexTypes.size()];
i=0;it=complexTypes.iterator();
while(it.hasNext()){
ComplexTypeHandler ct = (ComplexTypeHandler)it.next();
- schema.complexTypes[i++] = ct.getComplexType();
+ schema.complexTypes[i++] = ct.compress(this);
}
schema.elements = new Element[elements.size()];
i=0;it=elements.iterator();
while(it.hasNext()){
ElementTypeHandler ct = (ElementTypeHandler)it.next();
- schema.elements[i++] = ct.getElement();
+ schema.elements[i++] = ct.compress(this);
}
schema.groups = new Group[groups.size()];
i=0;it=groups.iterator();
while(it.hasNext()){
GroupHandler ct = (GroupHandler)it.next();
- schema.groups[i++] = ct.getGroup();
+ schema.groups[i++] = ct.compress(this);
}
return schema;
}
- private static class DefaultSchema implements Schema{
- AttributeGroup[] attributeGroups;
- Attribute[] attributes;
- int blockDefault,finalDefault;
- ComplexType[] complexTypes;
- Element[] elements;
- Group[] groups;
- String version;
- boolean attributeFormDefault, elementFormDefault;;
- Schema[] imports;
- SimpleType[] simpleTypes;
- String targetNamespace,id;
- URI[] URIs;
+ protected SimpleType lookUpSimpleType(String qName){
- public boolean includesURI(URI uri) {
- if (URIs == null) {
- URIs = new URI[0];
- }
- return Arrays.binarySearch(URIs,uri)>=0;
- }
-
- /**
- * @return Returns the attributeFormDefault.
- */
- public boolean isAttributeFormDefault() {
- return attributeFormDefault;
+ // TODO add qName support ... ie prefix mappings
+ // for now just strip it ...
+ qName = qName.substring(qName.indexOf(":")+1);
+
+ SimpleType st = null;
+ Iterator it = simpleTypes.iterator();
+ while(it.hasNext()){
+ SimpleTypeHandler sst = (SimpleTypeHandler)it.next();
+ if(qName.equals(sst.getName()))
+ st = sst.compress(this);
}
- /**
- * @return Returns the attributeGroups.
- */
- public AttributeGroup[] getAttributeGroups() {
- return attributeGroups;
+
+ SimpleType sti = XSISimpleTypes.find(qName);
+ if(st!=null && st == null)
+ st = sti;
+ it = imports.iterator();
+ while(it.hasNext()){
+ Schema s = (Schema)it.next();
+ for(int i=0;i<s.getSimpleTypes().length && st == null;i++)
+ if(qName.equals(s.getSimpleTypes()[i].getName()))
+ st = s.getSimpleTypes()[i];
}
- /**
- * @return Returns the attributes.
- */
- public Attribute[] getAttributes() {
- return attributes;
- }
- /**
- * @return Returns the blockDefault.
- */
- public int getBlockDefault() {
- return blockDefault;
- }
- /**
- * @return Returns the complexTypes.
- */
- public ComplexType[] getComplexTypes() {
- return complexTypes;
- }
- /**
- * @return Returns the elementFormDefault.
- */
- public boolean isElementFormDefault() {
- return elementFormDefault;
- }
- /**
- * @return Returns the elements.
- */
- public Element[] getElements() {
- return elements;
- }
- /**
- * @return Returns the finalDefault.
- */
- public int getFinalDefault() {
- return finalDefault;
- }
- /**
- * @return Returns the groups.
- */
- public Group[] getGroups() {
- return groups;
- }
- /**
- * @return Returns the id.
- */
- public String getId() {
- return id;
- }
- /**
- * @return Returns the imports.
- */
- public Schema[] getImports() {
- return imports;
- }
- /**
- * @return Returns the simpleTypes.
- */
- public SimpleType[] getSimpleTypes() {
- return simpleTypes;
- }
- /**
- * @return Returns the targetNamespace.
- */
- public String getTargetNamespace() {
- return targetNamespace;
- }
- /**
- * @return Returns the uRIs.
- */
- public URI[] getURIs() {
- return URIs;
- }
- /**
- * @return Returns the version.
- */
- public String getVersion() {
- return version;
- }
+ return st;
}
private void addSchema(Schema s){
Modified: udig/trunk/gml/src/schema/handlers/SimpleTypeHandler.java
===================================================================
--- udig/trunk/gml/src/schema/handlers/SimpleTypeHandler.java 2004-06-16 20:38:15 UTC (rev 6461)
+++ udig/trunk/gml/src/schema/handlers/SimpleTypeHandler.java 2004-06-16 23:39:57 UTC (rev 6462)
@@ -20,6 +20,13 @@
*/
package schema.handlers;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -262,13 +269,16 @@
return name;
}
private SimpleType cache;
- protected SimpleType compress(){
+ protected SimpleType compress(SchemaHandler parent){
+ if(cache!=null)
+ return cache;
DefaultSimpleType dst = new DefaultSimpleType();
dst.finaL = finaL;
dst.id = id;
dst.name = name;
dst.nameSpace = namespace;
- dst.setup(child);
+ dst.setup(child,parent);
+ cache = dst;
return dst;
}
@@ -300,23 +310,219 @@
return nameSpace;
}
- void setup(Object child){
+ private SimpleType[] children = null;
+ private boolean isUnion = false;
+ private boolean isList = false;
+ private FacetHandler[] constraints;
+
+ void setup(Object child,SchemaHandler parent){
throw new RuntimeException("Should not be here ... child is one of the other three types.");
}
- void setup(RestrictionHandler rest){
- null
+ void setup(RestrictionHandler rest,SchemaHandler parent){
+ if(rest.getChild()!=null){
+ children = new SimpleType[1];
+ children[0] = ((SimpleTypeHandler)rest.getChild()).compress(parent);
+ }else{
+ // find this rest.getBase()
+ children = new SimpleType[1];
+ children[0] = parent.lookUpSimpleType(rest.getBase());
+ }
+
+ if(rest.getConstraints()!=null){
+ constraints = (FacetHandler[])rest.getConstraints().toArray(new FacetHandler[0]);
+ }
}
- void setup(ListHandler lst){
- null
+ void setup(ListHandler lst,SchemaHandler parent){
+ isList = true;
+
+ if(lst.getSimpleType()!=null){
+ children = new SimpleType[1];
+ children[0] = (lst.getSimpleType()).compress(parent);
+ }else{
+ // find this rest.getBase()
+ children = new SimpleType[1];
+ children[0] = parent.lookUpSimpleType(lst.getItemType());
+ }
}
- void setup(UnionHandler union){
- null
+ void setup(UnionHandler union,SchemaHandler parent){
+ isUnion = true;
+ List l = new LinkedList();
+ if(union.getMemberTypes()!=null){
+ String[] qNames = union.getMemberTypes().split("\\s");
+ for(int i=0;i<qNames.length;i++)
+ l.add(parent.lookUpSimpleType(qNames[i]));
+ }
+ if(union.getSimpleTypes()!=null){
+ Iterator i = union.getSimpleTypes().iterator();
+ while(i.hasNext()){
+ l.add(((SimpleTypeHandler)i.next()).compress(parent));
+ }
+ }
+ children = (SimpleType[])l.toArray(children);
}
/* (non-Javadoc)
* @see schema.Type#getValue(java.lang.Object, org.xml.sax.Attributes)
*/
public Object getValue(Object value, Attributes attrs) throws SAXException {
- return null.;
+ if(isUnion)
+ return getUnionValue(value,attrs);
+ if(isList)
+ return getListValue(value,attrs);
+ return getRestValue(value,attrs);
}
+
+ private Object getUnionValue(Object value, Attributes attrs) throws SAXException {
+ if(children == null)
+ return null;
+ for(int i=0;i<children.length;i++){
+ Object o = children[i].getValue(value,attrs);
+ if(o!=null)
+ return o;
+ }
+ return null;
+ }
+
+ private Object getListValue(Object value, Attributes attrs) throws SAXException {
+ if(children==null || children[0] == null)
+ return null;
+ String[] vals = ((String)value).split("\\s");
+ List l = new LinkedList();
+ for(int i=0;i<vals.length;i++)
+ l.add(children[0].getValue(vals[i],attrs));
+ return l;
+ }
+
+ private Object getRestValue(Object value, Attributes attrs) throws SAXException {
+ if(children==null || children[0] == null)
+ return null;
+ if(constraints==null)
+ return null;
+ if(constraints.length == 0)
+ return children[0].getValue(value,attrs);
+ String val = (String)value;
+ if(constraints[0].getType() == FacetHandler.ENUMERATION){
+ for(int i=0;i<constraints.length;i++){
+ if(val.equals(constraints[i].getValue()))
+ return children[0].getValue(value,attrs);
+ }
+ return null;
+ }else{
+ Number nval = null;
+ Date dval = null;
+ String sval = val;
+
+ Object o = children[0].getValue(value,attrs);
+ if(o instanceof Number){
+ nval = (Number)o;
+ }
+ if(o instanceof Date){
+ dval = (Date)o;
+ }
+
+ // check each constraint
+ for(int i=0;i<constraints.length;i++){
+ switch (constraints[i].getType()) {
+ case FacetHandler.ENUMERATION:
+ throw new SAXException("cannot have enumerations mixed with other facets.");
+ case FacetHandler.FRACTIONDIGITS:
+ int decimals = val.length()-val.indexOf(".");
+ int maxDec = Integer.parseInt(constraints[i].getValue());
+ if(decimals>maxDec)
+ throw new SAXException("Too many decimal places");
+ break;
+ case FacetHandler.LENGTH:
+ int maxLength = Integer.parseInt(constraints[i].getValue());
+ if(val.length()!=maxLength)
+ throw new SAXException("Too long places");
+ break;
+ case FacetHandler.MAXEXCLUSIVE:
+ if(nval != null){
+ Double max = Double.valueOf(constraints[i].getValue());
+ if(nval.doubleValue()>max.doubleValue())
+ throw new SAXException("Too large a value");
+ }
+ if(dval != null){
+ Date max;
+ try {
+ max = DateFormat.getDateTimeInstance().parse(constraints[i].getValue());
+ } catch (ParseException e) {
+ throw new SAXException(e);
+ }
+ if(dval.after(max))
+ throw new SAXException("Too large a value");
+ }
+ break;
+ case FacetHandler.MAXINCLUSIVE:
+ if(nval != null){
+ Double max = Double.valueOf(constraints[i].getValue());
+ if(nval.doubleValue()>=max.doubleValue())
+ throw new SAXException("Too large a value");
+ }
+ if(dval != null){
+ Date max;
+ try{
+ max = DateFormat.getDateTimeInstance().parse(constraints[i].getValue());
+ } catch (ParseException e) {
+ throw new SAXException(e);
+ }
+ if(dval.compareTo(max)>0)
+ throw new SAXException("Too large a value");
+ }
+ case FacetHandler.MAXLENGTH:
+ maxLength = Integer.parseInt(constraints[i].getValue());
+ if(val.length()>maxLength)
+ throw new SAXException("Too long places");
+ break;
+ case FacetHandler.MINEXCLUSIVE:
+ if(nval != null){
+ Double max = Double.valueOf(constraints[i].getValue());
+ if(nval.doubleValue()<max.doubleValue())
+ throw new SAXException("Too large a value");
+ }
+ if(dval != null){
+ Date max;
+ try{
+ max = DateFormat.getDateTimeInstance().parse(constraints[i].getValue());
+ } catch (ParseException e) {
+ throw new SAXException(e);
+ }
+ if(dval.before(max))
+ throw new SAXException("Too large a value");
+ }
+ case FacetHandler.MININCLUSIVE:
+ if(nval != null){
+ Double max = Double.valueOf(constraints[i].getValue());
+ if(nval.doubleValue()<=max.doubleValue())
+ throw new SAXException("Too large a value");
+ }
+ if(dval != null){
+ Date max;
+ try{
+ max = DateFormat.getDateTimeInstance().parse(constraints[i].getValue());
+ } catch (ParseException e) {
+ throw new SAXException(e);
+ }
+ if(dval.compareTo(max)<0)
+ throw new SAXException("Too large a value");
+ }
+ case FacetHandler.MINLENGTH:
+ maxLength = Integer.parseInt(constraints[i].getValue());
+ if(val.length()<maxLength)
+ throw new SAXException("Too short places");
+ break;
+ case FacetHandler.PATTERN:
+ if(val.split(constraints[i].getValue()).length != 1)
+ throw new SAXException("Does not match pattern");
+ break;
+ case FacetHandler.TOTALDIGITS:
+ maxLength = Integer.parseInt(constraints[i].getValue())+1;
+ if(val.length()>maxLength)
+ throw new SAXException("Too many digits");
+ break;
+ }
+ }
+ return o;
+ }
+ }
}
}
More information about the udig-commits
mailing list