You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tsik-dev@ws.apache.org by ha...@apache.org on 2005/08/08 22:03:01 UTC
svn commit: r230871 [17/61] - in /incubator/tsik/trunk: ./ data/
data/schema/ resources/ resources/junit/ src/ src/org/ src/org/apache/
src/org/apache/tsik/ src/org/apache/tsik/c14n/
src/org/apache/tsik/c14n/elements/ src/org/apache/tsik/common/ src/or...
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/TimeDuration.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/TimeDuration.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/TimeDuration.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/TimeDuration.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,288 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.datatype;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+
+/**
+ * An interval of time, defined by XML Schema using a subset of ISO 8601.
+ *
+ */
+public class TimeDuration
+{
+ public static final TimeDuration ZERO
+ = new TimeDuration(1, 0, 0, 0, 0, 0, null);
+ public static final TimeDuration SECOND
+ = new TimeDuration(1, 0, 0, 0, 0, 0, 1, 0);
+ public static final TimeDuration MINUTE
+ = new TimeDuration(1, 0, 0, 0, 0, 1, null);
+ public static final TimeDuration HOUR
+ = new TimeDuration(1, 0, 0, 0, 1, 0, null);
+ public static final TimeDuration DAY
+ = new TimeDuration(1, 0, 0, 1, 0, 0, null);
+ public static final TimeDuration MONTH
+ = new TimeDuration(1, 0, 1, 0, 0, 0, null);
+ public static final TimeDuration YEAR
+ = new TimeDuration(1, 1, 0, 0, 0, 0, null);
+ public static final TimeDuration CENTURY
+ = new TimeDuration(1, 100, 0, 0, 0, 0, null);
+
+ private static final BigDecimal ZERO_DECIMAL = new BigDecimal(0);
+
+ private static final long SECOND_MILLIS = 1000L;
+ private static final long MINUTE_MILLIS = 1000L * 60;
+ private static final long HOUR_MILLIS = 1000L * 60 * 60;
+ private static final long DAY_MILLIS = 1000L * 60 * 60 * 24;
+
+ private int sign;
+ private int years;
+ private int months;
+ private int days;
+ private int hours;
+ private int minutes;
+ private BigDecimal seconds;
+
+ public TimeDuration(String fmt) throws ParseException
+ {
+ parse(fmt);
+ }
+
+ public TimeDuration(int sign, int years, int months, int days,
+ int hours, int minutes,
+ int seconds, int millis)
+ {
+ this(sign, years, months, days, hours, minutes,
+ BigDecimal.valueOf(seconds * 1000 + millis, 3));
+ }
+
+ public TimeDuration(int sign, int years, int months, int days,
+ int hours, int minutes,
+ BigDecimal decimalSeconds)
+ {
+ this.sign = (sign < 0) ? (-1) : 1;
+ this.years = years;
+ this.months = months;
+ this.days = days;
+ this.hours = hours;
+ this.minutes = minutes;
+ this.seconds = decimalSeconds;
+ if (this.seconds == null)
+ this.seconds = BigDecimal.valueOf(0);
+ }
+
+ public boolean equals(Object o)
+ {
+ TimeDuration other = (TimeDuration) o;
+
+ return sign == other.sign &&
+ years == other.years &&
+ months == other.months &&
+ days == other.days &&
+ hours == other.hours &&
+ minutes == other.minutes &&
+ seconds.compareTo(other.seconds) == 0;
+ }
+
+ public String toString()
+ {
+ return null; // TODO
+ }
+
+ public int getYears()
+ {
+ return years;
+ }
+
+ public int getMonths()
+ {
+ return months;
+ }
+
+ public int getDays()
+ {
+ return days;
+ }
+
+ public int getHours()
+ {
+ return hours;
+ }
+
+ public int getMinutes()
+ {
+ return minutes;
+ }
+
+ public int getSeconds()
+ {
+ return seconds.intValue();
+ }
+
+ public int getMillis()
+ {
+ return seconds.movePointRight(3).intValue() % 1000;
+ }
+
+ public BigDecimal getDecimalSeconds()
+ {
+ return seconds;
+ }
+
+ private void parse(String fmt) throws ParseException
+ {
+ /*
+ [+|-]P[<years>Y][<months>M][<days>D][T[<hours>H][<minutes>M][<seconds>S]]
+ */
+ TextInput input = new TextInput(fmt);
+ boolean gotOne = false;
+ int val;
+
+ sign = 1;
+ char c = input.current();
+ if (c == '+') {
+ input.advance();
+ } else if (c == '-') {
+ sign = -1;
+ input.advance();
+ }
+
+ input.getChar('P');
+
+ boolean gotYears = false;
+ boolean gotMonths = false;
+ boolean gotDays = false;
+ while (!input.eof() && input.current() != 'T') {
+ val = input.getInt();
+ c = input.current();
+ if (c == 'Y') {
+ if (gotYears || gotMonths || gotDays) input.error();
+ years = val;
+ gotYears = true;
+ } else if (c == 'M') {
+ if (gotMonths || gotDays) input.error();
+ months = val;
+ gotMonths = true;
+ } else if (c == 'D') {
+ if (gotDays) input.error();
+ days = val;
+ gotDays = true;
+ } else {
+ input.error();
+ }
+ input.advance();
+ gotOne = true;
+ }
+
+ if (!input.eof() && input.current() == 'T') {
+ gotOne = false; // require something after 'T'
+ boolean gotHours = false;
+ boolean gotMinutes = false;
+ boolean gotSeconds = false;
+ input.advance();
+ while (!input.eof()) {
+ val = input.getInt();
+ c = input.current();
+ if (c == '.') {
+ input.advance();
+ c = input.current();
+ StringBuffer decimal = new StringBuffer(20);
+ decimal.append(String.valueOf(val));
+ decimal.append('.');
+ while (c >= '0' && c <= '9') {
+ decimal.append(c);
+ input.advance();
+ c = input.current();
+ }
+ seconds = new BigDecimal(decimal.toString());
+ if (c != 'S') input.error();
+ }
+ if (c == 'H') {
+ if (gotHours || gotMinutes || gotSeconds) input.error();
+ hours = val;
+ gotHours = true;
+ } else if (c == 'M') {
+ if (gotMinutes || gotSeconds) input.error();
+ minutes = val;
+ gotMinutes = true;
+ } else if (c == 'S') {
+ if (gotSeconds) input.error();
+ if (seconds == null) {
+ seconds = new BigDecimal(val);
+ }
+ gotSeconds = true;
+ } else {
+ input.error();
+ }
+ input.advance();
+ gotOne = true;
+ }
+ }
+
+ if (!gotOne || !input.eof()) input.error();
+
+ if (seconds == null)
+ seconds = ZERO_DECIMAL;
+ }
+
+ /*
+ public BigDecimal getTotalYears()
+ {
+ return null;
+ }
+
+ public BigDecimal getTotalMonths()
+ {
+ return null;
+ }
+
+ public BigDecimal getTotalDays()
+ {
+ return null;
+ }
+
+ public BigDecimal getTotalHours()
+ {
+ return null;
+ }
+
+ public BigDecimal getTotalMinutes()
+ {
+ return null;
+ }
+
+ public BigDecimal getTotalSeconds()
+ {
+ return null;
+ }
+ */
+
+ /**
+ * Returns the time portion of the duration in milliseconds.
+ */
+ public BigDecimal getTotalMillis()
+ {
+ BigDecimal val = seconds.multiply(new BigDecimal(SECOND_MILLIS));
+ val = val.add(new BigDecimal(
+ days * DAY_MILLIS +
+ hours * HOUR_MILLIS +
+ minutes * MINUTE_MILLIS));
+ return val;
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/TimeDuration.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/package.html
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/package.html?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/package.html (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/package.html Mon Aug 8 12:58:58 2005
@@ -0,0 +1,8 @@
+<html>
+<!-- $Id: package.html,v 1.1 2002/08/30 14:53:19 mark Exp $ -->
+<body>
+
+(INTERNAL) May only be used by org.apache.tsik.xml.schema.* packages.
+
+</body>
+</html>
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/datatype/package.html
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AnyTypeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AnyTypeImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AnyTypeImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AnyTypeImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,193 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import java.util.Iterator;
+import org.apache.tsik.xml.schema.*;
+
+/**
+ * AnyTypeImpl is used as the root type of the entire type hierarchy (ur-type)
+ * whose name is anyType, as well as for a daughter class, anySimpleType, which
+ * is used as the root type for all simple types.
+ *
+ */
+class AnyTypeImpl extends TypeImpl
+ implements SimpleType, ComplexType, SchemaConstants
+{
+ private AnyTypeImpl anyTypeBase;
+ private boolean isComplexType;
+ private AttributeGroup attributes;
+ private Particle contentParticle;
+
+ /**
+ Construct "anyType" type
+ */
+ AnyTypeImpl(SchemaImpl schema)
+ {
+ super(null, schema.NS_XS, "anyType", schema);
+
+ anyTypeBase = this;
+ isComplexType = true;
+ WildcardImpl wildcard = new WildcardImpl(schema);
+ Particle part = new ParticleImpl(schema, 0, -1, wildcard);
+ ModelGroupImpl model = new ModelGroupImpl(schema, CO_SEQUENCE);
+ model.addItem(part);
+ contentParticle = new ParticleImpl(schema, 1, 1, model);
+ attributes = new AttributeGroupImpl(schema, wildcard);
+ }
+
+ /**
+ Construct "anySimpleType" type
+ */
+ AnyTypeImpl(AnyTypeImpl baseType, SchemaImpl schema)
+ {
+ super(null, schema.NS_XS, "anySimpleType", schema);
+
+ anyTypeBase = baseType;
+ isComplexType = false;
+ }
+
+ void readDefinition()
+ {
+ }
+
+ public boolean isSimpleType()
+ {
+ return true;
+ }
+
+ public boolean isComplexType()
+ {
+ return isComplexType;
+ }
+
+ public Type getBaseType()
+ {
+ return anyTypeBase;
+ }
+
+ // SimpleType
+
+ public short getVariety()
+ {
+ return SV_NONE;
+ }
+
+ public SimpleType getPrimitiveTypeDefinition()
+ {
+ return anyTypeBase;
+ }
+
+ public SimpleType getItemTypeDefinition()
+ {
+ return null;
+ }
+
+ public SimpleType[] getMemberTypeDefinitions()
+ {
+ return null;
+ }
+
+ public boolean isOrdered()
+ {
+ return false;
+ }
+
+ public boolean isBounded()
+ {
+ return false;
+ }
+
+ public boolean isNumeric()
+ {
+ return false;
+ }
+
+ public short getCardinality()
+ {
+ return SC_COUNTABLY_INFINITE;
+ }
+
+ public String toString(Object value)
+ {
+ return value.toString();
+ }
+
+ public Object valueOf(String data) throws Exception
+ {
+ return data;
+ }
+
+ public Object uncheckedValueOf(String data) throws Exception
+ {
+ return data;
+ }
+
+ public Iterator getFacets()
+ {
+ return null;
+ }
+
+ public Facet getFacet(short facetType, boolean searchSubtypes)
+ {
+ return null;
+ }
+
+ // ComplexType
+
+ public short getDerivationMethod()
+ {
+ return DM_RESTRICTION;
+ }
+
+ public boolean isFinal(short derivationMethod)
+ {
+ return false;
+ }
+
+ public boolean isProhibitedSubstitution(short derivationMethod)
+ {
+ return false;
+ }
+
+ public boolean isAbstract()
+ {
+ return false;
+ }
+
+ public AttributeGroup getAttributes()
+ {
+ return attributes;
+ }
+
+ public short getContentMode()
+ {
+ return CM_MIXED;
+ }
+
+ public SimpleType getSimpleContentType()
+ {
+ return null;
+ }
+
+ public Particle getContentParticle()
+ {
+ return contentParticle;
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AnyTypeImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeDeclarationImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeDeclarationImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeDeclarationImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeDeclarationImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,116 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.xml.schema.*;
+import org.w3c.dom.*;
+
+/**
+ * @see org.apache.tsik.xml.schema.AttributeDeclaration
+ *
+ */
+class AttributeDeclarationImpl extends SchemaComponentImpl
+ implements AttributeDeclaration
+{
+ private SimpleType typeDefinition;
+ private short constraintMode;
+ private String constraintValue;
+ private boolean isRequired;
+ private boolean isProhibited;
+
+ AttributeDeclarationImpl(Element declaration, String namespaceURI,
+ String localName, SchemaImpl schema)
+ {
+ super(declaration, namespaceURI, localName, SS_ATTRIBUTE, schema);
+ }
+
+ public SimpleType getTypeDefinition()
+ {
+ return typeDefinition;
+ }
+
+ public short getValueConstraintMode()
+ {
+ return constraintMode;
+ }
+
+ public String getValueConstraintValue()
+ {
+ return constraintValue;
+ }
+
+ boolean isRequired()
+ {
+ return isRequired;
+ }
+
+ boolean isProhibited()
+ {
+ return isProhibited;
+ }
+
+ void readDefinition()
+ {
+ // use undeclared (null) namespace if form is unqualified and
+ // attribute is not a global element
+ if (!SchemaImpl.parentIsSchema(declaration)) {
+ Attr node = declaration.getAttributeNode("form");
+ String attr = (node != null) ? node.getValue() :
+ schema.getSchemaAttribute(declaration,
+ "attributeFormDefault");
+ if (attr.length() == 0 || attr.equals("unqualified"))
+ namespaceURI = null;
+ }
+
+ String use = declaration.getAttribute("use");
+ String value = declaration.getAttribute("value");
+ if (use.equals("prohibited")) {
+ isProhibited = true;
+ } else if (value.length() == 0) {
+ constraintMode = VC_NONE;
+ isRequired = use.equals("required");
+ } else {
+ constraintMode = use.equals("fixed") ? VC_FIXED : VC_DEFAULT;
+ constraintValue = value;
+ }
+
+ String typeRef = declaration.getAttribute("type");
+ if (typeRef.length() > 0) {
+ Type type = schema.getType(declaration, typeRef);
+ if (type instanceof SimpleType)
+ typeDefinition = (SimpleType) type;
+ else
+ error(null, "attribute type must be simpleType", null, "type");
+ } else {
+ Element e = ops.firstElementChild(declaration);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ if (e == null) {
+ typeDefinition = schema.getAnySimpleType();
+ } else if (ops.matchName(e, schema.NS_XS, "simpleType")) {
+ SimpleTypeImpl type = new SimpleTypeImpl(e, null, null, schema);
+ type.readDefinition();
+ typeDefinition = type;
+ }
+ }
+
+ // TODO: identity constraints
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeDeclarationImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeGroupImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeGroupImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeGroupImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeGroupImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,182 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.xml.schema.*;
+import java.util.ArrayList;
+import java.util.List;
+import org.w3c.dom.*;
+
+/**
+ * @see org.apache.tsik.xml.schema.AttributeGroup
+ *
+ */
+class AttributeGroupImpl extends SchemaComponentBase implements AttributeGroup
+{
+ private ArrayList attributes;
+ private WildcardImpl wildcard;
+
+ /** declaration is next child to process, not the parent */
+ AttributeGroupImpl(Element declaration, SchemaImpl schema)
+ {
+ super(declaration, schema);
+ attributes = new ArrayList();
+ }
+
+ /** Construct attributes for "anyType" type */
+ AttributeGroupImpl(SchemaImpl schema, WildcardImpl wildcard)
+ {
+ super(null, schema);
+ attributes = new ArrayList();
+ this.wildcard = wildcard;
+ }
+
+// xxx
+ /*private AttributeGroupImpl(SchemaImpl schema, ArrayList attrs)
+ {
+ super(null, schema);
+ attributes = attrs;
+ }*/
+
+ public int getLength()
+ {
+ return attributes.size();
+ }
+
+ public AttributeDeclaration getItem(int index)
+ {
+ return (AttributeDeclaration) attributes.get(index);
+ }
+
+ public boolean isItemRequired(int index)
+ {
+ AttributeDeclarationImpl attr =
+ (AttributeDeclarationImpl) attributes.get(index);
+ return (attr != null && attr.isRequired());
+ }
+
+ public Wildcard getWildcard()
+ {
+ return wildcard;
+ }
+
+ void setWildcard(Wildcard newWildcard)
+ {
+ wildcard = (WildcardImpl) newWildcard;
+ }
+
+ void subtractProhibitedAttributes()
+ {
+ for (int i = 0; i < attributes.size(); i++) {
+
+ AttributeDeclarationImpl attr =
+ (AttributeDeclarationImpl) attributes.get(i);
+
+ if (attr.isProhibited()) {
+ attributes.remove(i);
+ }
+ }
+ }
+
+ /** ignores (does not replace) duplicates */
+ void unionAttributes(AttributeGroup others)
+ {
+ List list = ((AttributeGroupImpl) others).attributes;
+
+ for (int i = 0; i < list.size(); i++) {
+
+ AttributeDeclarationImpl attr =
+ (AttributeDeclarationImpl) list.get(i);
+
+ addAttribute(attr, true);
+ }
+ }
+
+ /** does not replace duplicates */
+ private void addAttribute(AttributeDeclarationImpl attr,
+ boolean allowDuplicates)
+ {
+ for (int i = 0; i < attributes.size(); i++) {
+
+ AttributeDeclarationImpl attr1 =
+ (AttributeDeclarationImpl) attributes.get(i);
+
+ if (attr1.nameEquals(attr)) {
+ if (allowDuplicates) {
+ // TODO: check for compatible types
+ return;
+ } else {
+ error(null, "duplicate attribute (" + attr.localName +
+ ", " + attr.namespaceURI + ")");
+ }
+ }
+ }
+ attributes.add(attr);
+ }
+
+ void readDefinition()
+ {
+ // declaration is next child to process, not the parent
+ Element e = declaration;
+ List groups = null;
+
+ while (e != null) {
+ if (ops.matchName(e, schema.NS_XS, "attribute")) {
+ AttributeDeclarationImpl attr;
+ String ref = e.getAttribute("ref");
+ if (ref.length() > 0) {
+ attr = schema.getAttribute(e, ref);
+ } else {
+ attr = new AttributeDeclarationImpl(e, null, null, schema);
+ attr.readDefinition();
+ }
+ addAttribute(attr, false);
+ } else if (ops.matchName(e, schema.NS_XS, "attributeGroup")) {
+ String ref = e.getAttribute("ref");
+ if (ref.length() == 0)
+ error(null, "ref required on nested attributeGroup");
+ AttributeGroupImpl group = schema.getAttributeGroup(e, ref);
+ if (groups == null)
+ groups = new ArrayList();
+ groups.add(group);
+ } else if (ops.matchName(e, schema.NS_XS, "anyAttribute")) {
+ wildcard = new WildcardImpl(e, schema);
+ wildcard.readDefinition();
+ }
+ e = ops.nextElementSibling(e);
+ }
+
+ if (groups != null) {
+ for (int i = 0; i < groups.size(); i++) {
+ AttributeGroupImpl group = (AttributeGroupImpl) groups.get(i);
+ unionAttributes(group);
+ Wildcard groupWildcard = group.getWildcard();
+ if (wildcard != null && groupWildcard != null) {
+ wildcard.intersectNamespaceConstraint(groupWildcard);
+ }
+ }
+ }
+
+ // TODO: spec ({attribute wildcard} in complexType) is not clear on
+ // what to do when there are wildcards in the nested groups but no
+ // wildcard at the top level; because when both are present they are to
+ // be intersected, we ommit a wildcard if one is not present at the
+ // top level; this is a best guess
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/AttributeGroupImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ComplexTypeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ComplexTypeImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ComplexTypeImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ComplexTypeImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,375 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.xml.schema.*;
+import org.w3c.dom.*;
+
+/**
+ * @see org.apache.tsik.xml.schema.ComplexType
+ *
+ */
+class ComplexTypeImpl extends TypeImpl implements ComplexType
+{
+ private short derivationMethod;
+ private boolean isAbstract;
+ private short prohibitedDerivationMethods;
+ private short prohibitedSubstitutionMethods;
+ private short contentMode;
+ private SimpleType simpleContentType;
+ private ParticleImpl contentParticle;
+ private AttributeGroupImpl attributes;
+
+ ComplexTypeImpl(Element declaration, String namespaceURI,
+ String localName, SchemaImpl schema)
+ {
+ super(declaration, namespaceURI, localName, schema);
+ }
+
+ public boolean isComplexType()
+ {
+ return true;
+ }
+
+ public short getDerivationMethod()
+ {
+ return derivationMethod;
+ }
+
+ public boolean isAbstract()
+ {
+ return isAbstract;
+ }
+
+ public boolean isFinal(short derivationMethod)
+ {
+ return (prohibitedDerivationMethods & derivationMethod) != 0;
+ }
+
+ public boolean isProhibitedSubstitution(short derivationMethod)
+ {
+ return (prohibitedSubstitutionMethods & derivationMethod) != 0;
+ }
+
+ public short getContentMode()
+ {
+ return contentMode;
+ }
+
+ public SimpleType getSimpleContentType()
+ {
+ return simpleContentType;
+ }
+
+ public Particle getContentParticle()
+ {
+ //contentParticle.resolve();
+ return contentParticle;
+ }
+
+ public AttributeGroup getAttributes()
+ {
+ return attributes;
+ }
+
+ void readDefinition()
+ {
+ // TODO: other attributes
+
+ isAbstract = "true".equals(declaration.getAttribute("abstract"));
+ prohibitedSubstitutionMethods =
+ parseDerivationMethods(declaration, "block", "blockDefault",
+ DM_EXTENSION | DM_RESTRICTION);
+ prohibitedDerivationMethods =
+ parseDerivationMethods(declaration, "final", "finalDefault",
+ DM_EXTENSION | DM_RESTRICTION);
+
+ Element e = ops.firstElementChild(declaration);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ if (e == null) {
+ derivationMethod = DM_RESTRICTION;
+ contentMode = CM_EMPTY;
+ attributes = new AttributeGroupImpl(schema, null);
+ } else if (ops.matchName(e, schema.NS_XS, "simpleContent")) {
+ parseSimpleContent(declaration, e);
+ } else if (ops.matchName(e, schema.NS_XS, "complexContent")) {
+ parseComplexContent(declaration, e);
+ } else {
+ // implied complexContent/restriction[@base='anyType']
+ parseImpliedComplexRestriction(declaration, e);
+ }
+ }
+
+ private void parseSimpleContent(Element complexType,
+ Element simpleContent)
+ {
+ Element e = ops.firstElementChild(simpleContent);
+ if (ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ if (ops.matchName(e, schema.NS_XS, "restriction")) {
+ parseSimpleRestriction(complexType, simpleContent, e);
+ } else if (ops.matchName(e, schema.NS_XS, "extension")) {
+ parseSimpleExtension(complexType, simpleContent, e);
+ }
+
+ contentMode = CM_SIMPLE;
+ }
+
+ private void parseSimpleRestriction(Element complexType,
+ Element complexContent,
+ Element restriction)
+ {
+ derivationMethod = DM_RESTRICTION;
+ parseSimpleBaseType(restriction, false);
+ SimpleTypeImpl stype = (SimpleTypeImpl) simpleContentType;
+
+ Element e = ops.firstElementChild(restriction);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ if (e != null && ops.matchName(e, schema.NS_XS, "simpleType")) {
+ stype = new SimpleTypeImpl(e, null, null, schema);
+ stype.readDefinition();
+ simpleContentType = stype;
+ e = ops.nextElementSibling(e);
+ }
+
+ attributes = new AttributeGroupImpl(e, schema);
+ attributes.readDefinition();
+
+ if (baseType.isComplexType()) {
+ ComplexType cbase = (ComplexType) baseType;
+ attributes.unionAttributes(cbase.getAttributes());
+ attributes.subtractProhibitedAttributes();
+
+ SimpleTypeImpl sbase = stype;
+ stype = new SimpleTypeImpl(schema);
+ stype.parseRestriction(e, sbase);
+ simpleContentType = stype;
+ } else {
+ if (attributes.getLength() > 0)
+ error(null,
+ "restriction attributes must extend complex base type",
+ complexType);
+ }
+ }
+
+ private void parseSimpleExtension(Element complexType,
+ Element complexContent,
+ Element extension)
+ {
+ derivationMethod = DM_EXTENSION;
+ parseSimpleBaseType(extension, true);
+
+ Element e = ops.firstElementChild(extension);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ attributes = new AttributeGroupImpl(e, schema);
+ attributes.readDefinition();
+
+ if (baseType.isComplexType()) {
+ ComplexType cbase = (ComplexType) baseType;
+ AttributeGroup baseAttributes = cbase.getAttributes();
+ attributes.unionAttributes(baseAttributes);
+ if (attributes.getWildcard() == null)
+ attributes.setWildcard(baseAttributes.getWildcard());
+ }
+ }
+
+ private void parseComplexContent(Element complexType,
+ Element complexContent)
+ {
+ Element e = ops.firstElementChild(complexContent);
+ if (ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+ if (ops.matchName(e, schema.NS_XS, "restriction")) {
+ parseComplexRestriction(complexType, complexContent, e);
+ } else if (ops.matchName(e, schema.NS_XS, "extension")) {
+ parseComplexExtension(complexType, complexContent, e);
+ }
+ }
+
+ private void parseComplexRestriction(Element complexType,
+ Element complexContent,
+ Element restriction)
+ {
+ derivationMethod = DM_RESTRICTION;
+ parseComplexBaseType(restriction);
+ ComplexType cbase = (ComplexType) baseType;
+
+ Element e = ops.firstElementChild(restriction);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ parseComplexChildren(e);
+ if (contentParticle == null) {
+ contentMode = CM_EMPTY;
+ } else {
+ contentMode = CM_ELEMENT_ONLY;
+ String attr = complexContent.getAttribute("mixed");
+ if (attr.length() > 0) {
+ if (attr.equals("true"))
+ contentMode = CM_MIXED;
+ } else {
+ if ("true".equals(complexType.getAttribute("mixed")))
+ contentMode = CM_MIXED;
+ }
+ }
+
+ //((SchemaComponentBase) cbase).resolve();
+
+ attributes.unionAttributes(cbase.getAttributes());
+ attributes.subtractProhibitedAttributes();
+ }
+
+ private void parseImpliedComplexRestriction(Element complexType,
+ Element child)
+ {
+ derivationMethod = DM_RESTRICTION;
+ baseType = schema.getAnyType();
+ ComplexType cbase = (ComplexType) baseType;
+
+ parseComplexChildren(child);
+ if (contentParticle == null)
+ contentMode = CM_EMPTY;
+ else if ("true".equals(complexType.getAttribute("mixed")))
+ contentMode = CM_MIXED;
+ else
+ contentMode = CM_ELEMENT_ONLY;
+
+ attributes.unionAttributes(cbase.getAttributes());
+ attributes.subtractProhibitedAttributes();
+ }
+
+ private void parseComplexChildren(Element child)
+ {
+ if (child != null) {
+ if (ops.matchName(child, schema.NS_XS, "group")) {
+ String ref = child.getAttribute("ref");
+ if (ref.length() == 0)
+ error(null, "nested <group> must have ref", child);
+ contentParticle = schema.getGroupParticle(child, ref);
+ } else if (ops.matchName(child, schema.NS_XS, "all") ||
+ ops.matchName(child, schema.NS_XS, "choice") ||
+ ops.matchName(child, schema.NS_XS, "sequence")) {
+ contentParticle = new ParticleImpl(child, schema);
+ contentParticle.readDefinition();
+ }
+ }
+
+ attributes = new AttributeGroupImpl(child, schema);
+ attributes.readDefinition();
+
+ if (contentParticle != null) {
+ //contentParticle.resolve(); // TODO ?
+ Term term = contentParticle.getTerm();
+ if (term.getTermType() == TT_MODEL_GROUP) {
+ ModelGroup group = (ModelGroup) term;
+ if (group.getLength() == 0) {
+ if (group.getCompositor() != CO_CHOICE ||
+ contentParticle.getMinOccurs() == 0) {
+ contentParticle = null; // is empty
+ }
+ }
+ }
+ }
+ }
+
+ private void parseComplexExtension(Element complexType,
+ Element complexContent,
+ Element extension)
+ {
+ derivationMethod = DM_EXTENSION;
+ parseComplexBaseType(extension);
+ ComplexType cbase = (ComplexType) baseType;
+
+ Element e = ops.firstElementChild(extension);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ parseComplexChildren(e);
+ if (contentParticle == null) {
+ contentMode = cbase.getContentMode();
+ contentParticle = (ParticleImpl) cbase.getContentParticle();
+ } else {
+ contentMode = CM_ELEMENT_ONLY;
+ String attr = complexContent.getAttribute("mixed");
+ if (attr.length() > 0) {
+ if (attr.equals("true"))
+ contentMode = CM_MIXED;
+ } else {
+ if ("true".equals(complexType.getAttribute("mixed")))
+ contentMode = CM_MIXED;
+ }
+ if (cbase.getContentMode() != CM_EMPTY) {
+ ModelGroupImpl seq = new ModelGroupImpl(schema, CO_SEQUENCE);
+ seq.addItem(cbase.getContentParticle());
+ seq.addItem(contentParticle);
+ contentParticle = new ParticleImpl(schema, 1, 1, seq);
+ }
+ }
+
+ AttributeGroup baseAttributes = cbase.getAttributes();
+ attributes.unionAttributes(baseAttributes);
+ if (attributes.getWildcard() == null)
+ attributes.setWildcard(baseAttributes.getWildcard());
+ }
+
+ private void parseComplexBaseType(Element elem)
+ {
+ String typeRef = elem.getAttribute("base");
+ if (typeRef.length() > 0) {
+ baseType = schema.getType(elem, typeRef);
+ if (baseType.isComplexType())
+ return;
+ else
+ error(null, "complexContent base must be complexType", elem);
+ } else {
+ error(null, "base attribute required", elem);
+ }
+ }
+
+ private void parseSimpleBaseType(Element elem, boolean isExtension)
+ {
+ String typeRef = elem.getAttribute("base");
+ if (typeRef.length() > 0) {
+ baseType = schema.getType(elem, typeRef);
+ if (baseType.isComplexType()) {
+ simpleContentType =
+ ((ComplexType) baseType).getSimpleContentType();
+ if (simpleContentType != null)
+ return;
+ } else {
+ if (isExtension) {
+ simpleContentType = (SimpleType) baseType;
+ return;
+ }
+ }
+ error(null,
+ "simpleContent base must be simple or complex with a simple base",
+ elem);
+ } else {
+ error(null, "base attribute required", elem);
+ }
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ComplexTypeImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/Dump.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/Dump.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/Dump.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/Dump.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,514 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.resource.ResourceFactory;
+import org.apache.tsik.xml.schema.*;
+import java.io.FileReader;
+import java.io.PrintStream;
+import java.util.Iterator;
+import java.util.Set;
+import org.w3c.dom.Document;
+
+/**
+ * Dumps to System.out a representation of the entire schema model.
+ * Used for debugging to make sure a model is complete and matches
+ * its XML representation.
+ *
+ */
+public class Dump implements SchemaConstants
+{
+ static String[] SS = new String[4];
+ static {
+ SS[SS_TYPE] = "SS_TYPE";
+ SS[SS_ELEMENT] = "SS_ELEMENT";
+ SS[SS_ATTRIBUTE] = "SS_ATTRIBUTE";
+ }
+ static String[] DM = new String[5];
+ static {
+ DM[DM_EXTENSION] = "DM_EXTENSION";
+ DM[DM_RESTRICTION] = "DM_RESTRICTION";
+ DM[DM_SUBSTITUTION] = "DM_SUBSTITUTION";
+ }
+ static String[] CM = new String[5];
+ static {
+ CM[CM_EMPTY] = "CM_EMPTY";
+ CM[CM_SIMPLE] = "CM_SIMPLE";
+ CM[CM_ELEMENT_ONLY] = "CM_ELEMENT_ONLY";
+ CM[CM_MIXED] = "CM_MIXED";
+ }
+ static String[] SV = new String[5];
+ static {
+ SV[SV_NONE] = "SV_NONE";
+ SV[SV_ATOMIC] = "SV_ATOMIC";
+ SV[SV_UNION] = "SV_UNION";
+ SV[SV_LIST] = "SV_LIST";
+ }
+ static String[] SC = new String[4];
+ static {
+ SC[SC_FINITE] = "SC_FINITE";
+ SC[SC_COUNTABLY_INFINITE] = "SC_COUNTABLY_INFINITE";
+ SC[SC_UNCOUNTABLY_INFINITE] = "SC_UNCOUNTABLY_INFINITE";
+ }
+ static String [] TT = new String[4];
+ static {
+ TT[TT_MODEL_GROUP] = "TT_MODEL_GROUP";
+ TT[TT_WILDCARD] = "TT_WILDCARD";
+ TT[TT_ELEMENT] = "TT_ELEMENT";
+ }
+ static String[] CO = new String[4];
+ static {
+ CO[CO_SEQUENCE] = "CO_SEQUENCE";
+ CO[CO_CHOICE] = "CO_CHOICE";
+ CO[CO_ALL] = "CO_ALL";
+ }
+ static String[] PC = new String[4];
+ static {
+ PC[PC_STRICT] = "PC_STRICT";
+ PC[PC_SKIP] = "PC_SKIP";
+ PC[PC_LAX] = "PC_LAX";
+ }
+ static String[] NC = new String[4];
+ static {
+ NC[NC_ANY] = "NC_ANY";
+ NC[NC_NOT] = "NC_NOT";
+ NC[NC_SET] = "NC_SET";
+ }
+ static String[] VC = new String[4];
+ static {
+ VC[VC_NONE] = "VC_NONE";
+ VC[VC_DEFAULT] = "VC_DEFAULT";
+ VC[VC_FIXED] = "VC_FIXED";
+ }
+ static String[] FACET = new String[16];
+ static {
+ FACET[Facet.LENGTH] = "length";
+ FACET[Facet.MIN_LENGTH] = "minLength";
+ FACET[Facet.MAX_LENGTH] = "maxLength";
+ FACET[Facet.PATTERN] = "pattern";
+ FACET[Facet.ENUMERATION] = "enumeration";
+ FACET[Facet.WHITE_SPACE] = "whiteSpace";
+ FACET[Facet.MAX_INCLUSIVE] = "maxInclusive";
+ FACET[Facet.MAX_EXCLUSIVE] = "maxExclusive";
+ FACET[Facet.MIN_INCLUSIVE] = "minInclusive";
+ FACET[Facet.MIN_EXCLUSIVE] = "minExclusive";
+ FACET[Facet.PRECISION] = "precision";
+ FACET[Facet.SCALE] = "scale";
+ FACET[Facet.ENCODING] = "encoding";
+ FACET[Facet.DURATION] = "duration";
+ FACET[Facet.PERIOD] = "period";
+ }
+
+ static PrintStream out = System.out;
+ static boolean dumpAll;
+ static Schema currentSchema;
+
+ public static void main(String[] args) throws Exception
+ {
+ int offset = 0;
+ int length = args.length;
+
+ if (args[0].equals("-a")) {
+ dumpAll = true;
+ offset++;
+ length--;
+ }
+
+ dump(load(args, offset, length));
+ }
+
+ public static Schema load(String[] args, int offset, int length)
+ throws Exception
+ {
+ Document[] docs = new Document[length];
+
+ for (int i = 0; i < length; i++) {
+ FileReader reader = new FileReader(args[i + offset]);
+ docs[i] = ResourceFactory.getXMLResource().parseXML(reader);
+ reader.close();
+ }
+
+ SchemaLoader loader = SchemaLoaderFactory.newLoader();
+ SchemaDocumentLoader docLoader
+ = SchemaDocumentLoaderFactory.newDocumentArrayLoader(docs);
+
+ Schema schema = loader.loadSchema(docLoader);
+
+ // force load of namespaces
+ for (int i = 0; i < docs.length; i++) {
+ String ns =
+ docs[i].getDocumentElement().getAttribute("targetNamespace");
+ if (ns.length() > 0) {
+ schema.getType(ns, "x");
+ }
+ }
+ return schema;
+ }
+
+ public static void dump(Schema schema)
+ throws Exception
+ {
+ String i = "";
+
+ currentSchema = schema;
+
+ out.println(i + "(all-types");
+ i = indent(i);
+ Iterator types = schema.getAllTypes();
+ while (types.hasNext()) {
+ Type type = (Type) types.next();
+ if (dumpAll || !NS_XS_2001.equals(type.getNamespaceURI()))
+ dumpType(i, type);
+ }
+ i = outdent(i);
+ out.println(i + ")");
+
+ out.println(i + "(all-elements");
+ i = indent(i);
+ Iterator elements = schema.getAllElements();
+ while (elements.hasNext()) {
+ ElementDeclaration elem = (ElementDeclaration) elements.next();
+ dumpElement(i, elem);
+ }
+ i = outdent(i);
+ out.println(i + ")");
+
+ out.println(i + "(all-attributes");
+ i = indent(i);
+ Iterator attrs = schema.getAllAttributes();
+ while (attrs.hasNext()) {
+ AttributeDeclaration attr = (AttributeDeclaration) attrs.next();
+ dumpAttribute(i, attr, false);
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static void dumpTypeRef(String i, Type type)
+ {
+ if (type.getLocalName() != null &&
+ type.getLocalName().length() > 0 &&
+ currentSchema.getType(type.getNamespaceURI(),
+ type.getLocalName()) != null) {
+ dumpBuiltinIdentifier(i, type, "type-ref");
+ } else {
+ dumpType(i, type);
+ }
+ }
+
+ static void dumpDerivationMethods(String i, String label,
+ boolean isRestriction,
+ boolean isExtension,
+ boolean isSubstitution)
+ {
+ String s = "";
+ if (isRestriction)
+ s += ' ' + DM[DM_RESTRICTION];
+ if (isExtension)
+ s += ' ' + DM[DM_EXTENSION];
+ if (isSubstitution)
+ s += ' ' + DM[DM_SUBSTITUTION];
+ if (s.length() == 0)
+ s = " none";
+ out.println(i + '(' + label + s + ')');
+ }
+
+ static void dumpType(String i, Type type)
+ {
+ if (type.isComplexType())
+ out.println(i + "(complex-type");
+ else
+ out.println(i + "(simple-type");
+ i = indent(i);
+ dumpComponent(i, type);
+ dumpBuiltinIdentifier(i, type.getBaseType(), "baseType");
+ if (type.isComplexType()) {
+ ComplexType ctype = (ComplexType) type;
+ out.println(i + "(derivationMethod " +
+ DM[ctype.getDerivationMethod()] + ")");
+ dumpDerivationMethods(i, "isFinal",
+ ctype.isFinal(DM_RESTRICTION),
+ ctype.isFinal(DM_EXTENSION),
+ ctype.isFinal(DM_SUBSTITUTION));
+ dumpDerivationMethods(i, "isProhibitedSubstitution",
+ ctype.isProhibitedSubstitution(DM_RESTRICTION),
+ ctype.isProhibitedSubstitution(DM_EXTENSION),
+ ctype.isProhibitedSubstitution(DM_SUBSTITUTION));
+ out.println(i + "(abstract " + ctype.isAbstract() + ")");
+ out.println(i + "(contentMode " + CM[ctype.getContentMode()] + ")");
+ if (ctype.getContentMode() == CM_SIMPLE)
+ dumpTypeRef(i, ctype.getSimpleContentType());
+ Particle part = ctype.getContentParticle();
+ if (part != null) {
+ dumpParticle(i, part);
+ }
+ dumpAttributeGroup(i, ctype.getAttributes());
+ } else {
+ SimpleType stype = (SimpleType) type;
+ out.println(i + "(variety " + SV[stype.getVariety()] + ")");
+ switch (stype.getVariety()) {
+ case SV_ATOMIC:
+ out.println(i + "(primitiveType " +
+ stype.getPrimitiveTypeDefinition().getLocalName() +
+ ")");
+ break;
+ case SV_LIST:
+ dumpBuiltinIdentifier(i, stype.getItemTypeDefinition(),
+ "itemType");
+ break;
+ case SV_UNION:
+ SimpleType[] memberTypes = stype.getMemberTypeDefinitions();
+ for (int j = 0; j < memberTypes.length; j++) {
+ dumpBuiltinIdentifier(i, memberTypes[j], "memberType");
+ }
+ break;
+ }
+ out.println(i + "(isOrdered " + stype.isOrdered() + ")");
+ out.println(i + "(isBounded " + stype.isBounded() + ")");
+ out.println(i + "(isNumeric " + stype.isNumeric() + ")");
+ out.println(i + "(cardinality " + SC[stype.getCardinality()] + ")");
+ Iterator it = stype.getFacets();
+ if(it != null) {
+ out.println(i + "(facets");
+ i = indent(i);
+ while(it.hasNext()) {
+ Facet f = (Facet) it.next();
+ out.println(i + "(" + FACET[f.getType()] + " " + f.getValue().toString() + (f.isFixed() ? " fixed" : "") + ")");
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ }
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static void dumpAttributeRef(String i, AttributeDeclaration attr,
+ boolean isRequired)
+ {
+ if (attr.getLocalName() != null &&
+ attr.getLocalName().length() > 0 &&
+ currentSchema.getType(attr.getNamespaceURI(),
+ attr.getLocalName()) != null) {
+ dumpBuiltinIdentifier(i, attr, "attr-ref");
+ } else {
+ dumpAttribute(i, attr, isRequired);
+ }
+ }
+
+ static void dumpAttribute(String i, AttributeDeclaration attr,
+ boolean isRequired)
+ {
+ out.println(i + "(attribute");
+ i = indent(i);
+ out.println(i + "(required " + isRequired +
+ ")");
+ dumpComponent(i, attr);
+ out.println(i + "(valueContraintMode " +
+ VC[attr.getValueConstraintMode()] + ")");
+ out.println(i + "(valueConstraintValue " +
+ attr.getValueConstraintValue() + ")");
+ dumpTypeRef(i, attr.getTypeDefinition());
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static void dumpAttributeGroup(String i, AttributeGroup attrs)
+ {
+ if (attrs != null) {
+ out.println(i + "(attributes");
+ i = indent(i);
+ for (int j = 0; j < attrs.getLength(); j++) {
+ dumpAttributeRef(i, attrs.getItem(j), attrs.isItemRequired(j));
+ }
+ Wildcard wildcard = attrs.getWildcard();
+ if (wildcard != null)
+ dumpWildcard(i, wildcard);
+ i = outdent(i);
+ out.println(i + ")");
+ } else {
+ out.println(i + "(attributes null)");
+ }
+ }
+
+ static void dumpBuiltinIdentifier(String i, SchemaComponent comp,
+ String label)
+ {
+ if (comp == null) {
+ out.println(i + "(" + label + " null)");
+ } else if (NS_XS_2001.equals(comp.getNamespaceURI())) {
+ out.println(i + "(" + label + " " + comp.getLocalName() + ")");
+ } else {
+ out.println(i + "(" + label);
+ i = indent(i);
+ dumpIdentifier(i, comp);
+ i = outdent(i);
+ out.println(i + ")");
+ }
+ }
+
+ static void dumpComponent(String i, SchemaComponent comp)
+ {
+ dumpIdentifier(i, comp);
+ out.println(i + "(componentType " + SS[comp.getComponentType()] + ")");
+ }
+
+ static void dumpIdentifier(String i, SchemaComponent comp)
+ {
+ out.println(i + "(name/uri " + comp.getLocalName() +
+ ' ' + comp.getNamespaceURI() + ")");
+ }
+
+ static void dumpParticle(String i, Particle part)
+ {
+ out.println(i + "(particle");
+ i = indent(i);
+ out.println(i + "(minOccurs " + part.getMinOccurs() + ")");
+ out.println(i + "(maxOccurs " + part.getMaxOccurs() + ")");
+ Term term = part.getTerm();
+ if (term != null) {
+ dumpTerm(i, term);
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static void dumpTerm(String i, Term term)
+ {
+ switch (term.getTermType()) {
+ case TT_MODEL_GROUP:
+ ModelGroup group = (ModelGroup) term;
+ dumpModelGroup(i, group);
+ break;
+ case TT_WILDCARD:
+ Wildcard wildcard = (Wildcard) term;
+ dumpWildcard(i, wildcard);
+ break;
+ case TT_ELEMENT:
+ ElementDeclaration elem = (ElementDeclaration) term;
+ dumpElement(i, elem);
+ break;
+ default:
+ out.println(i + "(unknown-term " + term.getTermType() + ")");
+ break;
+ }
+ }
+
+ static void dumpModelGroup(String i, ModelGroup group)
+ {
+ out.println(i + "(model-group");
+ i = indent(i);
+ // TODO: print group name?
+ out.println(i + "(compositor " + CO[group.getCompositor()] + ")");
+ out.println(i + "(particles");
+ i = indent(i);
+ for (int j = 0; j < group.getLength(); j++) {
+ dumpParticle(i, group.getItem(j));
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static void dumpWildcard(String i, Wildcard wildcard)
+ {
+ if (wildcard == null) {
+ out.println(i + "(wildcard null)");
+ return;
+ }
+ out.println(i + "(wildcard");
+ i = indent(i);
+ out.println(i + "(processContentsMode " +
+ PC[wildcard.getProcessContentsMode()] + ")");
+ out.println(i + "(namespaceContraintMode " +
+ NC[wildcard.getNamespaceConstraintMode()] + ")");
+ out.println(i + "(notNamespaceURI " +
+ wildcard.getNotNamespaceURI() + ")");
+ Set set = wildcard.getNamespaceSet();
+ if (set != null) {
+ out.println(i + "(namespaceSet");
+ i = indent(i);
+ Iterator uris = set.iterator();
+ while (uris.hasNext()) {
+ out.println(i + "(uri " + uris.next() + ")");
+ }
+ i = outdent(i);
+ out.println(i = ")");
+ } else {
+ out.println(i + "(namespaceSet null)");
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static void dumpElement(String i, ElementDeclaration elem)
+ {
+ out.println(i + "(element");
+ i = indent(i);
+ dumpComponent(i, elem);
+
+ dumpDerivationMethods(i, "isDisallowedSubstitution",
+ elem.isDisallowedSubstitution(DM_RESTRICTION),
+ elem.isDisallowedSubstitution(DM_EXTENSION),
+ elem.isDisallowedSubstitution(DM_SUBSTITUTION));
+ dumpDerivationMethods(i, "isSubstitutionGroupExclusion",
+ elem.isSubstitutionGroupExclusion(DM_RESTRICTION),
+ elem.isSubstitutionGroupExclusion(DM_EXTENSION),
+ elem.isSubstitutionGroupExclusion(DM_SUBSTITUTION));
+
+ ElementDeclaration head = elem.getSubstitutionGroupHead();
+ if (head != null) {
+ out.println(i + "(substitutionGroupHead");
+ i = indent(i);
+ dumpIdentifier(i, head);
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ Set members = elem.getSubstitutionGroupMembers();
+ if (members.size() > 1 || !members.contains(elem)) {
+ out.println(i + "(substitutionGroupMembers [except self]");
+ i = indent(i);
+ Iterator iter = members.iterator();
+ while (iter.hasNext()) {
+ ElementDeclaration next = (ElementDeclaration) iter.next();
+ if (next != elem)
+ dumpIdentifier(i, next);
+ }
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ dumpTypeRef(i, elem.getTypeDefinition());
+
+ i = outdent(i);
+ out.println(i + ")");
+ }
+
+ static String indent(String i)
+ {
+ return i + " ";
+ }
+
+ static String outdent(String i)
+ {
+ return i.substring(0, i.length() - 2);
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/Dump.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ElementDeclarationImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ElementDeclarationImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ElementDeclarationImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ElementDeclarationImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,158 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.xml.schema.*;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.w3c.dom.*;
+
+/**
+ * @see org.apache.tsik.xml.schema.ElementDeclaration
+ *
+ */
+class ElementDeclarationImpl extends SchemaComponentImpl
+ implements ElementDeclaration
+{
+ private TypeImpl typeDefinition;
+ private boolean isAbstract;
+ private short disallowedSubstitutions;
+ private short substitutionGroupExclusions;
+ private HashSet subGroupMembers;
+ private HashSet subGroupExpandedMembers;
+ private ElementDeclarationImpl subGroupHead;
+
+ ElementDeclarationImpl(Element declaration, String namespaceURI,
+ String localName, SchemaImpl schema)
+ {
+ super(declaration, namespaceURI, localName, SS_ELEMENT, schema);
+ subGroupMembers = new HashSet();
+ subGroupMembers.add(this);
+ }
+
+ public Type getTypeDefinition()
+ {
+ return typeDefinition;
+ }
+
+ public short getTermType()
+ {
+ return TT_ELEMENT;
+ }
+
+ public boolean isAbstract()
+ {
+ return isAbstract;
+ }
+
+ public boolean isDisallowedSubstitution(short derivationMethod)
+ {
+ return (disallowedSubstitutions & derivationMethod) != 0;
+ }
+
+ public boolean isSubstitutionGroupExclusion(short derivationMethod)
+ {
+ return (substitutionGroupExclusions & derivationMethod) != 0;
+ }
+
+ public ElementDeclaration getSubstitutionGroupHead()
+ {
+ return subGroupHead;
+ }
+
+ public Set getSubstitutionGroupMembers()
+ {
+ // assume this is called only after the complete
+ // model has been constructed
+
+ if (subGroupExpandedMembers == null) {
+ expandSubGroupMembers(subGroupMembers.iterator(), this);
+ if (subGroupExpandedMembers == null)
+ subGroupExpandedMembers = subGroupMembers;
+ }
+ return subGroupExpandedMembers;
+ }
+
+ void expandSubGroupMembers(Iterator members, ElementDeclaration except) {
+
+ while (members.hasNext()) {
+ ElementDeclarationImpl next =
+ (ElementDeclarationImpl) members.next();
+ if (next != except) {
+ if (subGroupExpandedMembers == null)
+ subGroupExpandedMembers = new HashSet();
+ subGroupExpandedMembers.add(next);
+ expandSubGroupMembers(next.subGroupMembers.iterator(), next);
+ }
+ }
+ }
+
+ void readDefinition()
+ {
+ // TODO: other element attributes
+
+ isAbstract = "true".equals(declaration.getAttribute("abstract"));
+ disallowedSubstitutions =
+ parseDerivationMethods(declaration, "block", "blockDefault",
+ DM_EXTENSION | DM_RESTRICTION | DM_SUBSTITUTION);
+ substitutionGroupExclusions =
+ parseDerivationMethods(declaration, "final", "finalDefault",
+ DM_EXTENSION | DM_RESTRICTION);
+
+ // use undeclared (null) namespace if form is unqualified and
+ // element is not a global element
+ if (!SchemaImpl.parentIsSchema(declaration)) {
+ Attr node = declaration.getAttributeNode("form");
+ String attr = (node != null) ? node.getValue() :
+ schema.getSchemaAttribute(declaration,
+ "elementFormDefault");
+ if (attr.length() == 0 || attr.equals("unqualified"))
+ namespaceURI = null;
+ }
+
+ String ref = declaration.getAttribute("substitutionGroup");
+ if (ref.length() > 0) {
+ subGroupHead = schema.getElement(declaration, ref);
+ subGroupHead.subGroupMembers.add(this);
+ }
+
+ ref = declaration.getAttribute("type");
+ if (ref.length() > 0) {
+ typeDefinition = schema.getType(declaration, ref);
+ } else {
+ Element e = ops.firstElementChild(declaration);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+
+ if (e == null) {
+ typeDefinition = schema.getAnyType();
+ } else if (ops.matchName(e, schema.NS_XS, "simpleType")) {
+ // TODO
+ } else if (ops.matchName(e, schema.NS_XS, "complexType")) {
+ typeDefinition =
+ new ComplexTypeImpl(e, null, null, schema);
+ typeDefinition.readDefinition();
+ }
+ }
+if (typeDefinition == null) throw new RuntimeException("xxx");
+
+ // TODO: identity constraints
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ElementDeclarationImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/FacetImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/FacetImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/FacetImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/FacetImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,446 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.xml.schema.*;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import org.w3c.dom.*;
+
+/**
+ * Facets are bound to a ValueType to allow a single implementation per facet
+ * to be used for multiple ValueTypes. For example, the minLength facet
+ * can be bound to the INTEGER or STRING ValueType, since it uses the ValueType
+ * to obtain the length of a value.
+ * <p>
+ * The facet's ValueType is sometimes used for the facet value and
+ * sometimes not. For example, it is the type of enumeration facet
+ * values, but not of minLength facet values since these are always
+ * integers. In any case, the ValueType always describes the type of
+ * values that are being validated.
+ *
+ * @see org.apache.tsik.xml.schema.Facet
+ *
+ */
+abstract class FacetImpl implements Facet
+{
+ protected short type;
+ protected Object value;
+ protected boolean isFixed;
+ protected ValueType valueType;
+
+ static FacetImpl newInstance(Element e, SimpleTypeImpl stype)
+ {
+ String schemaNS = stype.schema.NS_XS;
+ String data = e.getAttribute("value");
+ String name = stype.ops.getLocalName(e);
+ boolean isFixed = "true".equals(e.getAttribute("fixed"));
+ SimpleType longType = (SimpleTypeImpl)
+ stype.schema.getType(schemaNS, "long");
+ ValueType valueType = stype.getValueType();
+ Object value;
+
+ try {
+ if (name.equals("length")) {
+
+ value = longType.valueOf(data);
+ return new Length(value, isFixed, valueType);
+
+ } else if (name.equals("minLength")) {
+
+ value = longType.valueOf(data);
+ return new MinLength(value, isFixed, valueType);
+
+ } else if (name.equals("maxLength")) {
+
+ value = longType.valueOf(data);
+ return new MaxLength(value, isFixed, valueType);
+
+ } else if (name.equals("pattern")) {
+
+ FacetImpl otherFacet =
+ (FacetImpl) stype.getFacet(PATTERN, false);
+ if (otherFacet != null) {
+ otherFacet.appendValue(data);
+ return null;
+ }
+ return new Pattern(data, isFixed);
+
+ } else if (name.equals("enumeration")) {
+
+ value = getBaseTypeValue(stype, data);
+ FacetImpl otherFacet =
+ (FacetImpl) stype.getFacet(ENUMERATION, false);
+ if (otherFacet != null) {
+ otherFacet.appendValue(value);
+ return null;
+ }
+ return new Enumeration(value, isFixed, valueType);
+
+ } else if (name.equals("whiteSpace")) {
+
+ data = stype.ops.collapseWhiteSpace(data);
+ short v;
+ if (data.equals("preserve"))
+ v = SchemaConstants.WS_PRESERVE;
+ else if (data.equals("replace"))
+ v = SchemaConstants.WS_REPLACE;
+ else if (data.equals("preserve"))
+ v = SchemaConstants.WS_COLLAPSE;
+ else
+ throw new Error("invalid whiteSpace: " + data);
+ return new WhiteSpace(v, isFixed);
+
+ } else if (name.equals("maxInclusive")) {
+
+ value = getBaseTypeValue(stype, data);
+ return new MaxInclusive(value, isFixed, valueType);
+
+ } else if (name.equals("maxExclusive")) {
+
+ value = getBaseTypeValue(stype, data);
+ return new MaxExclusive(value, isFixed, valueType);
+
+ } else if (name.equals("minExclusive")) {
+
+ value = getBaseTypeValue(stype, data);
+ return new MinExclusive(value, isFixed, valueType);
+
+ } else if (name.equals("minInclusive")) {
+
+ value = getBaseTypeValue(stype, data);
+ return new MinInclusive(value, isFixed, valueType);
+
+ } else if ((name.equals("precision") &&
+ schemaNS == SchemaConstants.NS_XS_2000) ||
+ (name.equals("totalDigits") &&
+ schemaNS == SchemaConstants.NS_XS_2001)) {
+
+ Number longValue = (Number) longType.valueOf(data);
+ return new Precision(longValue, isFixed, valueType);
+
+ } else if ((name.equals("scale") &&
+ schemaNS == SchemaConstants.NS_XS_2000) ||
+ (name.equals("fractionDigits") &&
+ schemaNS == SchemaConstants.NS_XS_2001)) {
+
+ Number longValue = (Number) longType.valueOf(data);
+ return new Scale(longValue, isFixed, valueType);
+
+ } else if (name.equals("encoding") &&
+ schemaNS == SchemaConstants.NS_XS_2000) {
+
+ return new Encoding(data, isFixed);
+
+ // Never implemented for old spec, removed in current spec.
+ //} else if (name.equals("duration")) {
+ //} else if (name.equals("period")) {
+
+ } else {
+ throw new Error();
+ }
+ } catch (Exception ex) {
+ stype.schema.error(null, ex, e, null, null);
+ return null;
+ } catch (Error ex) {
+ stype.schema.error(null, ex, e, null, null);
+ return null;
+ } catch (Throwable ex) {
+ stype.schema.error(null, ex, e, null, null);
+ return null;
+ }
+ // 'return null' statements above never execute since a runtime
+ // exception is thrown by error()
+ }
+
+ private static Object getBaseTypeValue(SimpleTypeImpl stype, String data)
+ throws Exception
+ {
+ // another special case for the 'binary' type, since we can't in
+ // this case use it as a base type for conversion of facet values
+
+ SimpleTypeImpl sbase = (SimpleTypeImpl) stype.getBaseType();
+ if (stype.schema.NS_XS.equals(sbase.namespaceURI) &&
+ "binary".equals(sbase.localName)) {
+ return stype.getValueType().valueOf(data);
+ } else {
+ return sbase.valueOf(data);
+ }
+ }
+
+ protected FacetImpl(short type, Object value, boolean isFixed,
+ ValueType valueType)
+ {
+ this.type = type;
+ this.value = value;
+ this.isFixed = isFixed;
+ this.valueType = valueType;
+ }
+
+ public short getType()
+ {
+ return type;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ public boolean isFixed()
+ {
+ return isFixed;
+ }
+
+ boolean appendValue(Object newValue)
+ {
+ return false;
+ }
+
+ void bind()
+ {
+ }
+
+ abstract void validate(String data, Object value) throws Exception;
+
+ static class Length extends FacetImpl
+ {
+ Length(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(LENGTH, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (valueType.length(testValue) != ((Number) value).longValue())
+ throw new Exception("length " + value);
+ }
+ }
+
+ static class MinLength extends FacetImpl
+ {
+ MinLength(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(MIN_LENGTH, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (valueType.length(testValue) < ((Number) value).longValue())
+ throw new Exception("minLength " + value);
+ }
+ }
+
+ static class MaxLength extends FacetImpl
+ {
+ MaxLength(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(MAX_LENGTH, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (valueType.length(testValue) > ((Number) value).longValue())
+ throw new Exception("maxLength " + value);
+ }
+ }
+
+ static class Pattern extends FacetImpl
+ {
+ Pattern(String value, boolean isFixed)
+ {
+ super(PATTERN, value, isFixed, ValueType.STRING);
+ }
+
+ boolean appendValue(Object newValue)
+ {
+ value = ((String) value) + '|' + newValue;
+ return true;
+ }
+
+ void bind()
+ {
+ /*
+ GNU RE doesn't seem to work for the REs in the schema-schema, so it
+ is disabled until we get a different RE package.
+
+ try {
+ value = new RE((String) value);
+ } catch (REException e) {
+ throw new Error(e.toString());
+ }
+ */
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ /*
+ GNU RE doesn't seem to work for the REs in the schema-schema, so it
+ is disabled until we get a different RE package.
+
+ if (!((RE) value).isMatch(testData))
+ throw new Exception("pattern " + value + " doesn't match " + testData);
+ */
+ }
+ }
+
+ static class Enumeration extends FacetImpl
+ {
+ Enumeration(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(ENUMERATION, new ArrayList(), isFixed, valueType);
+ appendValue(value);
+ }
+
+ boolean appendValue(Object newValue)
+ {
+ ((List) value).add(newValue);
+ return true;
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ List list = (List) value;
+ int len = list.size();
+ for (int i = 0; i < len; i++) {
+ if (testValue.equals(list.get(i)))
+ return;
+ }
+ throw new Exception("enumeration " + value);
+ }
+ }
+
+ static class WhiteSpace extends ValueHolder
+ {
+ WhiteSpace(short value, boolean isFixed)
+ {
+ super(WHITE_SPACE, BigInteger.valueOf(value), isFixed,
+ ValueType.INTEGER);
+ }
+ }
+
+ static class MaxInclusive extends FacetImpl
+ {
+ MaxInclusive(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(MAX_INCLUSIVE, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (((Comparable) value).compareTo(testValue) < 0)
+ throw new Exception("maxInclusive " + value);
+ }
+ }
+
+ static class MaxExclusive extends FacetImpl
+ {
+ MaxExclusive(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(MAX_EXCLUSIVE, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (((Comparable) value).compareTo(testValue) <= 0)
+ throw new Exception("maxExclusive " + value);
+ }
+ }
+
+ static class MinExclusive extends FacetImpl
+ {
+ MinExclusive(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(MIN_EXCLUSIVE, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (((Comparable) value).compareTo(testValue) >= 0)
+ throw new Exception("minExclusive " + value);
+ }
+ }
+
+ static class MinInclusive extends FacetImpl
+ {
+ MinInclusive(Object value, boolean isFixed, ValueType valueType)
+ {
+ super(MIN_INCLUSIVE, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (((Comparable) value).compareTo(testValue) > 0)
+ throw new Exception("minInclusive " + value);
+ }
+ }
+
+ static class Precision extends FacetImpl
+ {
+ Precision(Number value, boolean isFixed, ValueType valueType)
+ {
+ super(PRECISION, null, isFixed, valueType);
+ BigInteger bint = BigInteger.valueOf(10);
+ this.value = bint.pow(value.intValue());
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (valueType.exceedsPrecision(testValue, (BigInteger) value))
+ throw new Exception("precision " + value);
+ }
+ }
+
+ static class Scale extends FacetImpl
+ {
+ Scale(Number value, boolean isFixed, ValueType valueType)
+ {
+ super(SCALE, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ if (valueType.getScale(testValue) != ((Number) value).intValue())
+ throw new Exception("scale " + value);
+ }
+ }
+
+ static class Encoding extends ValueHolder
+ {
+ Encoding(String value, boolean isFixed)
+ {
+ super(ENCODING, value, isFixed, ValueType.STRING);
+ }
+ }
+
+ static class ValueHolder extends FacetImpl
+ {
+ ValueHolder(short type, Object value, boolean isFixed,
+ ValueType valueType)
+ {
+ super(type, value, isFixed, valueType);
+ }
+
+ void validate(String testData, Object testValue) throws Exception
+ {
+ // no validation -- just holds a value
+ }
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/FacetImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ModelGroupImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ModelGroupImpl.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ModelGroupImpl.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ModelGroupImpl.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,93 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import org.apache.tsik.xml.schema.*;
+import java.util.ArrayList;
+import org.w3c.dom.*;
+
+/**
+ * @see org.apache.tsik.xml.schema.ModelGroup
+ *
+ */
+class ModelGroupImpl extends SchemaComponentBase implements ModelGroup
+{
+ private short compositor;
+ private ArrayList particles;
+
+ ModelGroupImpl(Element declaration, SchemaImpl schema)
+ {
+ super(declaration, schema);
+
+ particles = new ArrayList();
+ }
+
+ ModelGroupImpl(SchemaImpl schema, short newCompositor)
+ {
+ this(null, schema);
+
+ compositor = newCompositor;
+ }
+
+ public short getTermType()
+ {
+ return TT_MODEL_GROUP;
+ }
+
+ public short getCompositor()
+ {
+ return compositor;
+ }
+
+ public int getLength()
+ {
+ return particles.size();
+ }
+
+ public Particle getItem(int index)
+ {
+ return (Particle) particles.get(index);
+ }
+
+ void addItem(Particle part)
+ {
+ particles.add(part);
+ }
+
+ void readDefinition()
+ {
+ if (ops.matchName(declaration, schema.NS_XS, "sequence"))
+ compositor = CO_SEQUENCE;
+ else if (ops.matchName(declaration, schema.NS_XS, "choice"))
+ compositor = CO_CHOICE;
+ else if (ops.matchName(declaration, schema.NS_XS, "all"))
+ compositor = CO_ALL;
+
+ Element e = ops.firstElementChild(declaration);
+ if (e != null && ops.matchName(e, schema.NS_XS, "annotation"))
+ e = ops.nextElementSibling(e);
+ while (e != null) {
+ ParticleImpl part = new ParticleImpl(e, schema);
+ part.readDefinition();
+ if (part.getMinOccurs() != 0 || part.getMaxOccurs() != 0)
+ particles.add(part);
+ e = ops.nextElementSibling(e);
+ }
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/ModelGroupImpl.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/MyBigDecimal.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/MyBigDecimal.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/MyBigDecimal.java (added)
+++ incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/MyBigDecimal.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,48 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.xml.schema.loader;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Overrides BigDecimal.equals() so that values are considered equal if
+ * their mathematical values are equal, even if their scales are
+ * different. The fact that BigDecimal.equals() returns false when the
+ * scales are different seems to be a bug or at least a large
+ * inconsistency.
+ *
+ */
+class MyBigDecimal extends BigDecimal
+{
+ MyBigDecimal(BigInteger val)
+ {
+ super(val);
+ }
+
+ MyBigDecimal(String val)
+ {
+ super(val);
+ }
+
+ public boolean equals(Object object)
+ {
+ return compareTo((BigDecimal)object) == 0;
+ }
+}
Propchange: incubator/tsik/trunk/src/org/apache/tsik/xml/schema/loader/MyBigDecimal.java
------------------------------------------------------------------------------
svn:executable =
---------------------------------------------------------------------
To unsubscribe, e-mail: tsik-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tsik-dev-help@ws.apache.org