Imported GNU Classpath 0.90
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r111942
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/* AnyAttribute.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import gnu.xml.validation.datatype.Annotation;
|
||||
|
||||
/**
|
||||
* An attribute wildcard.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class AnyAttribute
|
||||
{
|
||||
|
||||
static final int STRICT = 0;
|
||||
static final int LAX = 1;
|
||||
static final int SKIP = 2;
|
||||
|
||||
final String namespace;
|
||||
|
||||
final int processContents;
|
||||
|
||||
Annotation annotation;
|
||||
|
||||
AnyAttribute(String namespace, int processContents)
|
||||
{
|
||||
this.namespace = namespace;
|
||||
this.processContents = processContents;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/* AttributeDeclaration.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import gnu.xml.validation.datatype.Annotation;
|
||||
import gnu.xml.validation.datatype.SimpleType;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* An XML Schema attribute declaration schema component.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class AttributeDeclaration
|
||||
{
|
||||
|
||||
static final int NONE = 0;
|
||||
static final int DEFAULT = 1;
|
||||
static final int FIXED = 2;
|
||||
|
||||
/**
|
||||
* The scope of this attribute declaration (global or local).
|
||||
*/
|
||||
final boolean scope;
|
||||
|
||||
/**
|
||||
* The constraint type.
|
||||
* One of NONE, DEFAULT, FIXED.
|
||||
*/
|
||||
final int type;
|
||||
|
||||
/**
|
||||
* The value constraint.
|
||||
*/
|
||||
final String value;
|
||||
|
||||
/**
|
||||
* The name of the attribute to which this declaration refers.
|
||||
*/
|
||||
final QName name;
|
||||
|
||||
/**
|
||||
* The type definition corresponding to this attribute.
|
||||
*/
|
||||
final SimpleType datatype;
|
||||
|
||||
/**
|
||||
* The annotation associated with this attribute declaration, if any.
|
||||
*/
|
||||
final Annotation annotation;
|
||||
|
||||
AttributeDeclaration(boolean scope, int type, String value, QName name,
|
||||
SimpleType datatype, Annotation annotation)
|
||||
{
|
||||
this.scope = scope;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
this.datatype = datatype;
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/* AttributeUse.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
/**
|
||||
* An XML Schema attribute use schema component.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class AttributeUse
|
||||
{
|
||||
|
||||
/**
|
||||
* Whether the attribute is required.
|
||||
*/
|
||||
final boolean required;
|
||||
|
||||
/**
|
||||
* The constraint type.
|
||||
* One of NONE, DEFAULT, FIXED.
|
||||
*/
|
||||
final int type;
|
||||
|
||||
/**
|
||||
* The value constraint.
|
||||
*/
|
||||
final String value;
|
||||
|
||||
/**
|
||||
* The name of the attribute to which this declaration refers.
|
||||
*/
|
||||
final AttributeDeclaration declaration;
|
||||
|
||||
AttributeUse(boolean required, int type, String value,
|
||||
AttributeDeclaration declaration)
|
||||
{
|
||||
this.required = required;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.declaration = declaration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/* ComplexType.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import javax.xml.namespace.QName;
|
||||
import gnu.xml.validation.datatype.Type;
|
||||
|
||||
/**
|
||||
* A complex type definition.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class ComplexType
|
||||
extends Type
|
||||
{
|
||||
|
||||
/**
|
||||
* Either a simple type definition or a complex type definition.
|
||||
*/
|
||||
QName baseType;
|
||||
|
||||
/**
|
||||
* Either EXTENSION or RESTRICTION.
|
||||
*/
|
||||
int derivationMethod;
|
||||
|
||||
/**
|
||||
* A subset of {EXTENSION, RESTRICTION}.
|
||||
*/
|
||||
final int finality;
|
||||
|
||||
final boolean isAbstract;
|
||||
|
||||
Set attributeUses;
|
||||
|
||||
AnyAttribute attributeWildcard;
|
||||
|
||||
/**
|
||||
* One of EMPTY, SIMPLE, MIXED, or ELEMENT_ONLY.
|
||||
*/
|
||||
int contentType;
|
||||
|
||||
/**
|
||||
* A simple type definition or a Particle.
|
||||
*/
|
||||
Object contentModel;
|
||||
|
||||
final int prohibitedSubstitutions;
|
||||
|
||||
Set annotations;
|
||||
|
||||
ComplexType(QName name,
|
||||
boolean isAbstract,
|
||||
int prohibitedSubstitutions,
|
||||
int finality)
|
||||
{
|
||||
super(name);
|
||||
this.isAbstract = isAbstract;
|
||||
this.prohibitedSubstitutions = prohibitedSubstitutions;
|
||||
this.finality = finality;
|
||||
attributeUses = new LinkedHashSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/* ElementDeclaration.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import gnu.xml.validation.datatype.Annotation;
|
||||
import gnu.xml.validation.datatype.Type;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* An XML Schema element declaration schema component.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class ElementDeclaration
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the element to which this declaration refers.
|
||||
*/
|
||||
final QName name;
|
||||
|
||||
/**
|
||||
* The type definition corresponding to this element.
|
||||
*/
|
||||
Type datatype;
|
||||
|
||||
/**
|
||||
* The scope of this schema component.
|
||||
* One of GLOBAL, LOCAL, or ABSENT.
|
||||
*/
|
||||
final int scope;
|
||||
|
||||
/**
|
||||
* If scope is LOCAL, the parent element definition.
|
||||
*/
|
||||
final ElementDeclaration parent;
|
||||
|
||||
/**
|
||||
* The constraint type.
|
||||
* One of NONE, DEFAULT, FIXED.
|
||||
*/
|
||||
final int type;
|
||||
|
||||
/**
|
||||
* The value constraint.
|
||||
*/
|
||||
final String value;
|
||||
|
||||
final boolean nillable;
|
||||
|
||||
// TODO identity-constraint definitions
|
||||
|
||||
final QName substitutionGroup;
|
||||
|
||||
final int substitutionGroupExclusions;
|
||||
|
||||
final int disallowedSubstitutions;
|
||||
|
||||
final boolean isAbstract;
|
||||
|
||||
/**
|
||||
* The annotation associated with this attribute declaration, if any.
|
||||
*/
|
||||
Annotation annotation;
|
||||
|
||||
ElementDeclaration(QName name,
|
||||
Type datatype,
|
||||
int scope, ElementDeclaration parent,
|
||||
int type, String value,
|
||||
boolean nillable,
|
||||
QName substitutionGroup,
|
||||
int substitutionGroupExclusions,
|
||||
int disallowedSubstitutions,
|
||||
boolean isAbstract)
|
||||
{
|
||||
this.name = name;
|
||||
this.datatype = datatype;
|
||||
this.scope = scope;
|
||||
this.parent = parent;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.nillable = nillable;
|
||||
this.substitutionGroup = substitutionGroup;
|
||||
this.substitutionGroupExclusions = substitutionGroupExclusions;
|
||||
this.disallowedSubstitutions = disallowedSubstitutions;
|
||||
this.isAbstract = isAbstract;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Particle.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
/**
|
||||
* Container for element content.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class Particle
|
||||
{
|
||||
|
||||
final Integer minOccurs;
|
||||
final Integer maxOccurs;
|
||||
|
||||
final Object term;
|
||||
|
||||
Particle(Integer minOccurs, Integer maxOccurs, Object term)
|
||||
{
|
||||
this.minOccurs = minOccurs;
|
||||
this.maxOccurs = maxOccurs;
|
||||
this.term = term;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/* ValidationException.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* An XML Schema validation rule violation.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class ValidationException
|
||||
extends SAXParseException
|
||||
{
|
||||
|
||||
ValidationException(String message, Locator locator)
|
||||
{
|
||||
super(message, locator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/* XMLSchema.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.Validator;
|
||||
import javax.xml.validation.ValidatorHandler;
|
||||
|
||||
/**
|
||||
* An XML Schema schema.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class XMLSchema
|
||||
extends Schema
|
||||
{
|
||||
|
||||
static final int FINAL_NONE = 0x00;
|
||||
static final int FINAL_EXTENSION = 0x01;
|
||||
static final int FINAL_RESTRICTION = 0x02;
|
||||
static final int FINAL_LIST = 0x04;
|
||||
static final int FINAL_UNION = 0x08;
|
||||
static final int FINAL_ALL = 0x0f;
|
||||
|
||||
static final int BLOCK_NONE = 0x00;
|
||||
static final int BLOCK_EXTENSION = 0x01;
|
||||
static final int BLOCK_RESTRICTION = 0x02;
|
||||
static final int BLOCK_SUBSTITUTION = 0x04;
|
||||
static final int BLOCK_ALL = 0x07;
|
||||
|
||||
static final int GLOBAL = 0x00;
|
||||
static final int LOCAL = 0x01;
|
||||
static final int ABSENT = 0x02;
|
||||
|
||||
static final int CONSTRAINT_NONE = 0x00;
|
||||
static final int CONSTRAINT_DEFAULT = 0x01;
|
||||
static final int CONSTRAINT_FIXED = 0x02;
|
||||
|
||||
static final int CONTENT_EMPTY = 0x00;
|
||||
static final int CONTENT_SIMPLE = 0x01;
|
||||
static final int CONTENT_MIXED = 0x02;
|
||||
static final int CONTENT_ELEMENT_ONLY = 0x03;
|
||||
|
||||
final String targetNamespace;
|
||||
final String version;
|
||||
final int finalDefault;
|
||||
final int blockDefault;
|
||||
final boolean attributeFormQualified;
|
||||
final boolean elementFormQualified;
|
||||
|
||||
/**
|
||||
* The element declarations in this schema.
|
||||
*/
|
||||
final Map elementDeclarations;
|
||||
|
||||
/**
|
||||
* The attribute declarations in this schema.
|
||||
*/
|
||||
final Map attributeDeclarations;
|
||||
|
||||
/**
|
||||
* The type declarations in this schema.
|
||||
*/
|
||||
final Map types;
|
||||
|
||||
XMLSchema(String targetNamespace, String version,
|
||||
int finalDefault, int blockDefault,
|
||||
boolean attributeFormQualified,
|
||||
boolean elementFormQualified)
|
||||
{
|
||||
this.targetNamespace = targetNamespace;
|
||||
this.version = version;
|
||||
this.finalDefault = finalDefault;
|
||||
this.blockDefault = blockDefault;
|
||||
this.attributeFormQualified = attributeFormQualified;
|
||||
this.elementFormQualified = elementFormQualified;
|
||||
elementDeclarations = new LinkedHashMap();
|
||||
attributeDeclarations = new LinkedHashMap();
|
||||
types = new LinkedHashMap();
|
||||
}
|
||||
|
||||
public Validator newValidator()
|
||||
{
|
||||
// TODO
|
||||
//return new XMLSchemaValidator(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
public ValidatorHandler newValidatorHandler()
|
||||
{
|
||||
// TODO
|
||||
//return new XMLSchemaValidatorHandler(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/* XMLSchemaAttributeTypeInfo.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import org.w3c.dom.TypeInfo;
|
||||
import gnu.xml.validation.datatype.SimpleType;
|
||||
|
||||
/**
|
||||
* Attribute type information provided by validation against an XML Schema.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class XMLSchemaAttributeTypeInfo
|
||||
extends XMLSchemaTypeInfo
|
||||
{
|
||||
|
||||
final XMLSchema schema;
|
||||
final AttributeDeclaration decl;
|
||||
final SimpleType type;
|
||||
boolean id;
|
||||
final boolean specified;
|
||||
|
||||
XMLSchemaAttributeTypeInfo(XMLSchema schema, AttributeDeclaration decl,
|
||||
boolean specified)
|
||||
{
|
||||
this.schema = schema;
|
||||
this.decl = decl;
|
||||
this.specified = specified;
|
||||
type = (decl == null) ? null : decl.datatype;
|
||||
}
|
||||
|
||||
public String getTypeName()
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return "CDATA";
|
||||
}
|
||||
return type.name.getLocalPart();
|
||||
}
|
||||
|
||||
public String getTypeNamespace()
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return type.name.getNamespaceURI();
|
||||
}
|
||||
|
||||
public boolean isDerivedFrom(String typeNamespace, String typeName,
|
||||
int derivationMethod)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return simpleTypeIsDerivedFrom(type, typeNamespace, typeName,
|
||||
derivationMethod);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,844 @@
|
||||
/* XMLSchemaBuilder.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import gnu.xml.validation.datatype.Annotation;
|
||||
import gnu.xml.validation.datatype.AtomicSimpleType;
|
||||
import gnu.xml.validation.datatype.ListSimpleType;
|
||||
import gnu.xml.validation.datatype.SimpleType;
|
||||
import gnu.xml.validation.datatype.Type;
|
||||
import gnu.xml.validation.datatype.UnionSimpleType;
|
||||
|
||||
/**
|
||||
* Parses an XML Schema DOM tree, constructing a compiled internal
|
||||
* representation.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class XMLSchemaBuilder
|
||||
{
|
||||
|
||||
XMLSchema schema;
|
||||
final DatatypeLibrary typeLibrary;
|
||||
|
||||
XMLSchemaBuilder()
|
||||
{
|
||||
final String ns = XMLConstants.W3C_XML_SCHEMA_NS_URI;
|
||||
typeLibrary = new DatatypeLibraryLoader().createDatatypeLibrary(ns);
|
||||
}
|
||||
|
||||
void parseSchema(Node node)
|
||||
throws DatatypeException
|
||||
{
|
||||
String uri = node.getNamespaceURI();
|
||||
String name = node.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
node.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("schema".equals(name))
|
||||
{
|
||||
NamedNodeMap attrs = node.getAttributes();
|
||||
String targetNamespace = getAttribute(attrs, "targetNamespace");
|
||||
String version = getAttribute(attrs, "version");
|
||||
String fd = getAttribute(attrs, "finalDefault");
|
||||
int finalDefault = parseFullDerivationSet(fd);
|
||||
String bd = getAttribute(attrs, "blockDefault");
|
||||
int blockDefault = parseBlockSet(bd);
|
||||
String afd = getAttribute(attrs, "attributeFormDefault");
|
||||
boolean attributeFormQualified = "qualified".equals(afd);
|
||||
String efd = getAttribute(attrs, "elementFormDefault");
|
||||
boolean elementFormQualified = "qualified".equals(efd);
|
||||
schema = new XMLSchema(targetNamespace, version,
|
||||
finalDefault, blockDefault,
|
||||
attributeFormQualified,
|
||||
elementFormQualified);
|
||||
for (Node child = node.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
parseTopLevelElement(child);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// TODO throw schema exception
|
||||
}
|
||||
|
||||
void parseTopLevelElement(Node node)
|
||||
throws DatatypeException
|
||||
{
|
||||
String uri = node.getNamespaceURI();
|
||||
String name = node.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
node.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("element".equals(name))
|
||||
{
|
||||
ElementDeclaration ed =
|
||||
(ElementDeclaration) parseElement(node, null);
|
||||
schema.elementDeclarations.put(ed.name, ed);
|
||||
// TODO
|
||||
}
|
||||
else if ("attribute".equals(name))
|
||||
{
|
||||
AttributeDeclaration ad =
|
||||
(AttributeDeclaration) parseAttribute(node, true);
|
||||
schema.attributeDeclarations.put(ad.name, ad);
|
||||
// TODO
|
||||
}
|
||||
else if ("type".equals(name))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if ("group".equals(name))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if ("attributeGroup".equals(name))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if ("notation".equals(name))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if ("identityConstraint".equals(name))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
// TODO throw schema exception
|
||||
}
|
||||
|
||||
Object parseAttribute(Node node, boolean scope)
|
||||
throws DatatypeException
|
||||
{
|
||||
NamedNodeMap attrs = node.getAttributes();
|
||||
String def = getAttribute(attrs, "default");
|
||||
String fixed = getAttribute(attrs, "fixed");
|
||||
int constraintType = AttributeDeclaration.NONE;
|
||||
String constraintValue = null;
|
||||
if (def != null)
|
||||
{
|
||||
constraintType = AttributeDeclaration.DEFAULT;
|
||||
constraintValue = def;
|
||||
}
|
||||
else if (fixed != null)
|
||||
{
|
||||
constraintType = AttributeDeclaration.FIXED;
|
||||
constraintValue = fixed;
|
||||
}
|
||||
// TODO form = (qualified | unqualified)
|
||||
String attrName = getAttribute(attrs, "name");
|
||||
String attrNamespace = getAttribute(attrs, "targetNamespace");
|
||||
String ref = getAttribute(attrs, "ref");
|
||||
String use = getAttribute(attrs, "use");
|
||||
String type = getAttribute(attrs, "type");
|
||||
SimpleType datatype = (type == null) ? null :
|
||||
parseSimpleType(asQName(type, node));
|
||||
Annotation annotation = null;
|
||||
for (Node child = node.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
annotation = parseAnnotation(child);
|
||||
}
|
||||
else if ("simpleType".equals(name))
|
||||
{
|
||||
datatype = parseSimpleType(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO throw schema exception
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scope)
|
||||
{
|
||||
return new AttributeDeclaration(scope,
|
||||
constraintType,
|
||||
constraintValue,
|
||||
new QName(attrNamespace, attrName),
|
||||
datatype,
|
||||
annotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean required = "required".equals(use);
|
||||
// TODO ref
|
||||
AttributeDeclaration decl = (ref == null) ?
|
||||
new AttributeDeclaration(scope,
|
||||
AttributeDeclaration.NONE,
|
||||
null,
|
||||
new QName(attrNamespace, attrName),
|
||||
datatype,
|
||||
annotation) :
|
||||
/*schema.getAttributeDeclaration(ref)*/ null;
|
||||
return new AttributeUse(required,
|
||||
constraintType,
|
||||
constraintValue,
|
||||
decl);
|
||||
}
|
||||
}
|
||||
|
||||
int parseFullDerivationSet(String value)
|
||||
{
|
||||
int ret = XMLSchema.FINAL_NONE;
|
||||
if ("#all".equals(value))
|
||||
{
|
||||
ret = XMLSchema.FINAL_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(value, " ");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken();
|
||||
if ("extension".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_EXTENSION;
|
||||
}
|
||||
else if ("restriction".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_RESTRICTION;
|
||||
}
|
||||
else if ("list".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_LIST;
|
||||
}
|
||||
else if ("union".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_UNION;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int parseSimpleTypeDerivationSet(String value)
|
||||
{
|
||||
int ret = XMLSchema.FINAL_NONE;
|
||||
if ("#all".equals(value))
|
||||
{
|
||||
ret = XMLSchema.FINAL_LIST |
|
||||
XMLSchema.FINAL_UNION |
|
||||
XMLSchema.FINAL_RESTRICTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(value, " ");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken();
|
||||
if ("list".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_LIST;
|
||||
}
|
||||
else if ("union".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_UNION;
|
||||
}
|
||||
else if ("restriction".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_RESTRICTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int parseComplexTypeDerivationSet(String value)
|
||||
{
|
||||
int ret = XMLSchema.FINAL_NONE;
|
||||
if ("#all".equals(value))
|
||||
{
|
||||
ret = XMLSchema.FINAL_EXTENSION | XMLSchema.FINAL_RESTRICTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(value, " ");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken();
|
||||
if ("extension".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_EXTENSION;
|
||||
}
|
||||
else if ("restriction".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.FINAL_RESTRICTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int parseBlockSet(String value)
|
||||
{
|
||||
int ret = XMLSchema.BLOCK_NONE;
|
||||
if ("#all".equals(value))
|
||||
{
|
||||
ret = XMLSchema.BLOCK_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(value, " ");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken();
|
||||
if ("extension".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.BLOCK_EXTENSION;
|
||||
}
|
||||
else if ("restriction".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.BLOCK_RESTRICTION;
|
||||
}
|
||||
else if ("substitution".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.BLOCK_SUBSTITUTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int parseComplexTypeBlockSet(String value)
|
||||
{
|
||||
int ret = XMLSchema.BLOCK_NONE;
|
||||
if ("#all".equals(value))
|
||||
{
|
||||
ret = XMLSchema.BLOCK_EXTENSION | XMLSchema.BLOCK_RESTRICTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(value, " ");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken();
|
||||
if ("extension".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.BLOCK_EXTENSION;
|
||||
}
|
||||
else if ("restriction".equals(token))
|
||||
{
|
||||
ret |= XMLSchema.BLOCK_RESTRICTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object parseElement(Node node, ElementDeclaration parent)
|
||||
throws DatatypeException
|
||||
{
|
||||
NamedNodeMap attrs = node.getAttributes();
|
||||
Integer minOccurs = null;
|
||||
Integer maxOccurs = null;
|
||||
Node parentNode = node.getParentNode();
|
||||
boolean notTopLevel = !"schema".equals(parentNode.getLocalName());
|
||||
if (notTopLevel)
|
||||
{
|
||||
String ref = getAttribute(attrs, "ref");
|
||||
if (ref != null)
|
||||
{
|
||||
minOccurs = getOccurrence(getAttribute(attrs, "minOccurs"));
|
||||
maxOccurs = getOccurrence(getAttribute(attrs, "maxOccurs"));
|
||||
// TODO resolve top-level element declaration
|
||||
ElementDeclaration ad = null;
|
||||
return new Particle(minOccurs, maxOccurs, ad);
|
||||
}
|
||||
}
|
||||
String elementName = getAttribute(attrs, "name");
|
||||
String elementNamespace = getAttribute(attrs, "targetNamespace");
|
||||
String type = getAttribute(attrs, "type");
|
||||
Type datatype = (type != null) ?
|
||||
parseSimpleType(asQName(type, node)) : null;
|
||||
int scope = (parent == null) ?
|
||||
XMLSchema.GLOBAL :
|
||||
XMLSchema.LOCAL;
|
||||
String def = getAttribute(attrs, "default");
|
||||
String fixed = getAttribute(attrs, "fixed");
|
||||
int constraintType = AttributeDeclaration.NONE;
|
||||
String constraintValue = null;
|
||||
if (def != null)
|
||||
{
|
||||
constraintType = AttributeDeclaration.DEFAULT;
|
||||
constraintValue = def;
|
||||
}
|
||||
else if (fixed != null)
|
||||
{
|
||||
constraintType = AttributeDeclaration.FIXED;
|
||||
constraintValue = fixed;
|
||||
}
|
||||
String sg = getAttribute(attrs, "substitutionGroup");
|
||||
QName substitutionGroup = QName.valueOf(sg);
|
||||
String sgPrefix = substitutionGroup.getPrefix();
|
||||
if (sgPrefix != null && !"".equals(sgPrefix))
|
||||
{
|
||||
String sgName = substitutionGroup.getLocalPart();
|
||||
String sgNamespace = node.lookupNamespaceURI(sgPrefix);
|
||||
substitutionGroup = new QName(sgNamespace, sgName);
|
||||
}
|
||||
|
||||
String block = getAttribute(attrs, "block");
|
||||
int substitutionGroupExclusions = (block == null) ?
|
||||
schema.blockDefault :
|
||||
parseBlockSet(block);
|
||||
String final_ = getAttribute(attrs, "final");
|
||||
int disallowedSubstitutions = (final_ == null) ?
|
||||
schema.finalDefault :
|
||||
parseFullDerivationSet(final_);
|
||||
|
||||
boolean nillable = "true".equals(getAttribute(attrs, "nillable"));
|
||||
boolean isAbstract = "true".equals(getAttribute(attrs, "abstract"));
|
||||
|
||||
if (notTopLevel)
|
||||
{
|
||||
minOccurs = getOccurrence(getAttribute(attrs, "minOccurs"));
|
||||
maxOccurs = getOccurrence(getAttribute(attrs, "maxOccurs"));
|
||||
String form = getAttribute(attrs, "form");
|
||||
if (form != null)
|
||||
{
|
||||
if ("qualified".equals(form))
|
||||
{
|
||||
elementNamespace = schema.targetNamespace;
|
||||
}
|
||||
}
|
||||
else if (schema.elementFormQualified)
|
||||
{
|
||||
elementNamespace = schema.targetNamespace;
|
||||
}
|
||||
}
|
||||
ElementDeclaration ed =
|
||||
new ElementDeclaration(new QName(elementNamespace, elementName),
|
||||
datatype,
|
||||
scope, parent,
|
||||
constraintType, constraintValue,
|
||||
nillable,
|
||||
substitutionGroup,
|
||||
substitutionGroupExclusions,
|
||||
disallowedSubstitutions,
|
||||
isAbstract);
|
||||
|
||||
for (Node child = node.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
ed.annotation = parseAnnotation(child);
|
||||
}
|
||||
else if ("simpleType".equals(name) && datatype == null)
|
||||
{
|
||||
ed.datatype = parseSimpleType(child);
|
||||
}
|
||||
else if ("complexType".equals(name) && datatype == null)
|
||||
{
|
||||
ed.datatype = parseComplexType(child, ed);
|
||||
}
|
||||
else
|
||||
{
|
||||
// throw schema exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (notTopLevel)
|
||||
{
|
||||
return new Particle(minOccurs, maxOccurs, ed);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ed;
|
||||
}
|
||||
}
|
||||
|
||||
Integer getOccurrence(String value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return new Integer(1);
|
||||
}
|
||||
else if ("unbounded".equals(value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Integer(value);
|
||||
}
|
||||
}
|
||||
|
||||
SimpleType parseSimpleType(QName typeName)
|
||||
throws DatatypeException
|
||||
{
|
||||
SimpleType type = (SimpleType) schema.types.get(typeName);
|
||||
if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(typeName.getNamespaceURI()))
|
||||
return null;
|
||||
String localName = typeName.getLocalPart();
|
||||
return (SimpleType) typeLibrary.createDatatype(localName);
|
||||
}
|
||||
|
||||
SimpleType parseSimpleType(Node simpleType)
|
||||
throws DatatypeException
|
||||
{
|
||||
NamedNodeMap attrs = simpleType.getAttributes();
|
||||
String typeFinal = getAttribute(attrs, "final");
|
||||
if (typeFinal == null)
|
||||
{
|
||||
Node schema = simpleType.getParentNode();
|
||||
while (schema != null && !"schema".equals(schema.getLocalName()))
|
||||
{
|
||||
schema = schema.getParentNode();
|
||||
}
|
||||
if (schema != null)
|
||||
{
|
||||
NamedNodeMap schemaAttrs = schema.getAttributes();
|
||||
typeFinal = getAttribute(schemaAttrs, "finalDefault");
|
||||
}
|
||||
}
|
||||
int typeFinality = parseSimpleTypeDerivationSet(typeFinal);
|
||||
QName typeName = asQName(getAttribute(attrs, "name"), simpleType);
|
||||
int variety = 0;
|
||||
Set facets = new LinkedHashSet();
|
||||
int fundamentalFacets = 0; // TODO
|
||||
SimpleType baseType = null; // TODO
|
||||
Annotation annotation = null;
|
||||
// TODO use DatatypeBuilder
|
||||
for (Node child = simpleType.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
annotation = parseAnnotation(child);
|
||||
}
|
||||
else if ("restriction".equals(name))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if ("list".equals(name))
|
||||
{
|
||||
variety = SimpleType.LIST;
|
||||
// TODO
|
||||
}
|
||||
else if ("union".equals(name))
|
||||
{
|
||||
variety = SimpleType.UNION;
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SimpleType(typeName, variety, facets, fundamentalFacets,
|
||||
baseType, annotation);
|
||||
}
|
||||
|
||||
Type parseComplexType(Node complexType, ElementDeclaration parent)
|
||||
throws DatatypeException
|
||||
{
|
||||
NamedNodeMap attrs = complexType.getAttributes();
|
||||
QName typeName = asQName(getAttribute(attrs, "name"), complexType);
|
||||
boolean isAbstract = "true".equals(getAttribute(attrs, "abstract"));
|
||||
String block = getAttribute(attrs, "block");
|
||||
int prohibitedSubstitutions = (block == null) ?
|
||||
schema.blockDefault :
|
||||
parseComplexTypeBlockSet(block);
|
||||
String final_ = getAttribute(attrs, "final");
|
||||
int finality = (final_ == null) ?
|
||||
schema.finalDefault :
|
||||
parseComplexTypeDerivationSet(final_);
|
||||
ComplexType type = new ComplexType(typeName, isAbstract,
|
||||
prohibitedSubstitutions, finality);
|
||||
boolean mixed = "true".equals(getAttribute(attrs, "mixed"));
|
||||
for (Node child = complexType.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("simpleContent".equals(name))
|
||||
{
|
||||
parseSimpleContent(child, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mixed)
|
||||
{
|
||||
type.contentType = XMLSchema.CONTENT_MIXED;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
void parseSimpleContent(Node simpleContent, ComplexType type)
|
||||
throws DatatypeException
|
||||
{
|
||||
for (Node child = simpleContent.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
type.annotations.add(parseAnnotation(child));
|
||||
}
|
||||
else if ("restriction".equals(name))
|
||||
{
|
||||
type.derivationMethod = XMLSchema.FINAL_RESTRICTION;
|
||||
parseRestriction(child, type);
|
||||
}
|
||||
else if ("extension".equals(name))
|
||||
{
|
||||
type.derivationMethod = XMLSchema.FINAL_EXTENSION;
|
||||
parseExtension(child, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parseRestriction(Node restriction, ComplexType type)
|
||||
throws DatatypeException
|
||||
{
|
||||
NamedNodeMap attrs = restriction.getAttributes();
|
||||
String base = getAttribute(attrs, "base");
|
||||
QName baseType = asQName(base, restriction);
|
||||
SimpleType simpleType = null;
|
||||
for (Node child = restriction.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
type.annotations.add(parseAnnotation(child));
|
||||
}
|
||||
else if ("simpleType".equals(name))
|
||||
{
|
||||
type.contentType = XMLSchema.CONTENT_SIMPLE;
|
||||
simpleType = parseSimpleType(child);
|
||||
}
|
||||
else if ("minExclusive".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("minInclusive".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("maxExclusive".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("maxInclusive".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("totalDigits".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("fractionDigits".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("length".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("minLength".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("maxLength".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("enumeration".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("whiteSpace".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("pattern".equals(name))
|
||||
{
|
||||
}
|
||||
else if ("attribute".equals(name))
|
||||
{
|
||||
AttributeUse use =
|
||||
(AttributeUse) parseAttribute(child, false);
|
||||
schema.attributeDeclarations.put(use.declaration.name,
|
||||
use.declaration);
|
||||
type.attributeUses.add(use);
|
||||
}
|
||||
else if ("attributeGroup".equals(name))
|
||||
{
|
||||
NamedNodeMap agAttrs = child.getAttributes();
|
||||
String ref = getAttribute(agAttrs, "ref");
|
||||
QName ag = asQName(ref, child);
|
||||
type.attributeUses.add(ag);
|
||||
}
|
||||
else if ("anyAttribute".equals(name))
|
||||
{
|
||||
type.attributeWildcard = parseAnyAttribute(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parseExtension(Node extension, ComplexType type)
|
||||
throws DatatypeException
|
||||
{
|
||||
NamedNodeMap attrs = extension.getAttributes();
|
||||
String base = getAttribute(attrs, "base");
|
||||
QName baseType = asQName(base, extension);
|
||||
for (Node child = extension.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
type.annotations.add(parseAnnotation(child));
|
||||
}
|
||||
else if ("attribute".equals(name))
|
||||
{
|
||||
AttributeUse use =
|
||||
(AttributeUse) parseAttribute(child, false);
|
||||
schema.attributeDeclarations.put(use.declaration.name,
|
||||
use.declaration);
|
||||
type.attributeUses.add(use);
|
||||
}
|
||||
else if ("attributeGroup".equals(name))
|
||||
{
|
||||
NamedNodeMap agAttrs = child.getAttributes();
|
||||
String ref = getAttribute(agAttrs, "ref");
|
||||
QName ag = asQName(ref, child);
|
||||
type.attributeUses.add(ag);
|
||||
}
|
||||
else if ("anyAttribute".equals(name))
|
||||
{
|
||||
type.attributeWildcard = parseAnyAttribute(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnyAttribute parseAnyAttribute(Node node)
|
||||
{
|
||||
NamedNodeMap attrs = node.getAttributes();
|
||||
String namespace = getAttribute(attrs, "namespace");
|
||||
String pc = getAttribute(attrs, "processContents");
|
||||
int processContents = AnyAttribute.STRICT;
|
||||
if ("lax".equals(pc))
|
||||
{
|
||||
processContents = AnyAttribute.LAX;
|
||||
}
|
||||
else if ("skip".equals(pc))
|
||||
{
|
||||
processContents = AnyAttribute.SKIP;
|
||||
}
|
||||
AnyAttribute ret = new AnyAttribute(namespace, processContents);
|
||||
for (Node child = node.getFirstChild(); child != null;
|
||||
child = child.getNextSibling())
|
||||
{
|
||||
String uri = child.getNamespaceURI();
|
||||
String name = child.getLocalName();
|
||||
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) &&
|
||||
child.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if ("annotation".equals(name))
|
||||
{
|
||||
ret.annotation = parseAnnotation(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Annotation parseAnnotation(Node node)
|
||||
{
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getAttribute(NamedNodeMap attrs, String name)
|
||||
{
|
||||
Node attr = attrs.getNamedItem(name);
|
||||
return (attr == null) ? null : attr.getNodeValue();
|
||||
}
|
||||
|
||||
private static QName asQName(String text, Node resolver)
|
||||
{
|
||||
QName name = QName.valueOf(text);
|
||||
String prefix = name.getPrefix();
|
||||
if (prefix != null && prefix.length() > 0)
|
||||
{
|
||||
String uri = resolver.lookupNamespaceURI(prefix);
|
||||
name = new QName(uri, name.getLocalPart());
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/* XMLSchemaElementTypeInfo.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import org.w3c.dom.TypeInfo;
|
||||
import gnu.xml.validation.datatype.SimpleType;
|
||||
import gnu.xml.validation.datatype.Type;
|
||||
|
||||
/**
|
||||
* Element type information provided by validation against an XML Schema.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class XMLSchemaElementTypeInfo
|
||||
extends XMLSchemaTypeInfo
|
||||
{
|
||||
|
||||
final XMLSchema schema;
|
||||
final ElementDeclaration decl;
|
||||
final Type type;
|
||||
boolean nil;
|
||||
|
||||
XMLSchemaElementTypeInfo(XMLSchema schema, ElementDeclaration decl,
|
||||
Type type)
|
||||
{
|
||||
this.schema = schema;
|
||||
this.decl = decl;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTypeName()
|
||||
{
|
||||
return type.name.getLocalPart();
|
||||
}
|
||||
|
||||
public String getTypeNamespace()
|
||||
{
|
||||
return type.name.getNamespaceURI();
|
||||
}
|
||||
|
||||
public boolean isDerivedFrom(String typeNamespace, String typeName,
|
||||
int derivationMethod)
|
||||
{
|
||||
if (type instanceof SimpleType)
|
||||
{
|
||||
SimpleType simpleType = (SimpleType) type;
|
||||
return simpleTypeIsDerivedFrom(simpleType, typeNamespace, typeName,
|
||||
derivationMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/* XMLSchemaSchemaFactory.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Schema factory for W3C XML Schema schemata.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
public class XMLSchemaSchemaFactory
|
||||
extends SchemaFactory
|
||||
{
|
||||
|
||||
LSResourceResolver resourceResolver;
|
||||
|
||||
public LSResourceResolver getResourceResolver()
|
||||
{
|
||||
return resourceResolver;
|
||||
}
|
||||
|
||||
public void setResourceResolver(LSResourceResolver resourceResolver)
|
||||
{
|
||||
this.resourceResolver = resourceResolver;
|
||||
}
|
||||
|
||||
public boolean isSchemaLanguageSupported(String schemaLanguage)
|
||||
{
|
||||
return XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schemaLanguage);
|
||||
}
|
||||
|
||||
public Schema newSchema()
|
||||
throws SAXException
|
||||
{
|
||||
// TODO
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Schema newSchema(Source[] schemata)
|
||||
throws SAXException
|
||||
{
|
||||
if (schemata == null || schemata.length != 1)
|
||||
throw new IllegalArgumentException("must specify one source");
|
||||
// TODO multiple sources
|
||||
try
|
||||
{
|
||||
Document doc = getDocument(schemata[0]);
|
||||
XMLSchemaBuilder builder = new XMLSchemaBuilder();
|
||||
builder.parseSchema(doc);
|
||||
return builder.schema;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SAXException e2 = new SAXException(e.getMessage());
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
catch (DatatypeException e)
|
||||
{
|
||||
SAXException e2 = new SAXException(e.getMessage());
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
private static Document getDocument(Source source)
|
||||
throws SAXException, IOException
|
||||
{
|
||||
if (source instanceof DOMSource)
|
||||
{
|
||||
Node node = ((DOMSource) source).getNode();
|
||||
if (node != null && node instanceof Document)
|
||||
return (Document) node;
|
||||
}
|
||||
String url = source.getSystemId();
|
||||
try
|
||||
{
|
||||
InputSource input = new InputSource(url);
|
||||
if (source instanceof StreamSource)
|
||||
{
|
||||
StreamSource streamSource = (StreamSource) source;
|
||||
input.setByteStream(streamSource.getInputStream());
|
||||
input.setCharacterStream(streamSource.getReader());
|
||||
}
|
||||
if (input.getByteStream() == null &&
|
||||
input.getCharacterStream() == null &&
|
||||
url != null)
|
||||
input.setByteStream(new URL(url).openStream());
|
||||
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
|
||||
f.setNamespaceAware(true);
|
||||
f.setCoalescing(true);
|
||||
f.setExpandEntityReferences(true);
|
||||
f.setIgnoringComments(true);
|
||||
f.setIgnoringElementContentWhitespace(true);
|
||||
DocumentBuilder b = f.newDocumentBuilder();
|
||||
return b.parse(input);
|
||||
}
|
||||
catch (ParserConfigurationException e)
|
||||
{
|
||||
SAXException e2 = new SAXException(e.getMessage());
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* XMLSchemaTypeInfo.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import org.w3c.dom.TypeInfo;
|
||||
import gnu.xml.validation.datatype.SimpleType;
|
||||
|
||||
/**
|
||||
* Abstract superclass providing simple type derivation.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
abstract class XMLSchemaTypeInfo
|
||||
implements TypeInfo
|
||||
{
|
||||
|
||||
protected boolean simpleTypeIsDerivedFrom(SimpleType simpleType,
|
||||
String typeNamespace,
|
||||
String typeName,
|
||||
int derivationMethod)
|
||||
{
|
||||
switch (derivationMethod)
|
||||
{
|
||||
case TypeInfo.DERIVATION_RESTRICTION:
|
||||
SimpleType baseType = simpleType.baseType;
|
||||
while (baseType != null)
|
||||
{
|
||||
if (baseType.name.getNamespaceURI().equals(typeNamespace) &&
|
||||
baseType.name.getLocalPart().equals(typeName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
baseType = baseType.baseType;
|
||||
}
|
||||
break;
|
||||
// TODO other methods
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/* XMLSchemaTypeInfoProvider.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import javax.xml.validation.TypeInfoProvider;
|
||||
import org.w3c.dom.TypeInfo;
|
||||
|
||||
/**
|
||||
* TypeInfo provider for XML Schema validator handler.
|
||||
* This simply delegates to the handler. It wouldn't be required if
|
||||
* TypeInfoProvider were an interface instead of an abstract class.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class XMLSchemaTypeInfoProvider
|
||||
extends TypeInfoProvider
|
||||
{
|
||||
|
||||
final XMLSchemaValidatorHandler handler;
|
||||
|
||||
XMLSchemaTypeInfoProvider(XMLSchemaValidatorHandler handler)
|
||||
{
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public TypeInfo getElementTypeInfo()
|
||||
{
|
||||
return handler.getElementTypeInfo();
|
||||
}
|
||||
|
||||
public TypeInfo getAttributeTypeInfo(int index)
|
||||
{
|
||||
return handler.getAttributeTypeInfo(index);
|
||||
}
|
||||
|
||||
public boolean isIdAttribute(int index)
|
||||
{
|
||||
return handler.isIdAttribute(index);
|
||||
}
|
||||
|
||||
public boolean isSpecified(int index)
|
||||
{
|
||||
return handler.isSpecified(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/* XMLSchemaValidator.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.validation.Validator;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* JAXP validator for an XML Schema.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class XMLSchemaValidator
|
||||
extends Validator
|
||||
{
|
||||
|
||||
final XMLSchema schema;
|
||||
|
||||
ErrorHandler errorHandler;
|
||||
LSResourceResolver resourceResolver;
|
||||
|
||||
XMLSchemaValidator(XMLSchema schema)
|
||||
{
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
}
|
||||
|
||||
public void validate(Source source, Result result)
|
||||
throws SAXException, IOException
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public ErrorHandler getErrorHandler()
|
||||
{
|
||||
return errorHandler;
|
||||
}
|
||||
|
||||
public void setErrorHandler(ErrorHandler errorHandler)
|
||||
{
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public LSResourceResolver getResourceResolver()
|
||||
{
|
||||
return resourceResolver;
|
||||
}
|
||||
|
||||
public void setResourceResolver(LSResourceResolver resourceResolver)
|
||||
{
|
||||
this.resourceResolver = resourceResolver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,394 @@
|
||||
/* XMLSchemaValidatorHandler.java --
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package gnu.xml.validation.xmlschema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.validation.TypeInfoProvider;
|
||||
import javax.xml.validation.ValidatorHandler;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
|
||||
import org.w3c.dom.TypeInfo;
|
||||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.Attributes2Impl;
|
||||
import org.xml.sax.helpers.NamespaceSupport;
|
||||
import gnu.xml.validation.datatype.SimpleType;
|
||||
import gnu.xml.validation.datatype.Type;
|
||||
|
||||
/**
|
||||
* Streaming validator.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
final class XMLSchemaValidatorHandler
|
||||
extends ValidatorHandler
|
||||
{
|
||||
|
||||
final XMLSchema schema;
|
||||
final TypeInfoProvider typeInfoProvider;
|
||||
final NamespaceSupport namespaceSupport;
|
||||
final DatatypeLibrary typeLibrary;
|
||||
Locator loc;
|
||||
ContentHandler contentHandler;
|
||||
ErrorHandler errorHandler;
|
||||
LSResourceResolver resourceResolver;
|
||||
final LinkedList context; // element context
|
||||
final ArrayList attributes; // attribute context;
|
||||
|
||||
XMLSchemaValidatorHandler(XMLSchema schema)
|
||||
{
|
||||
this.schema = schema;
|
||||
typeInfoProvider = new XMLSchemaTypeInfoProvider(this);
|
||||
namespaceSupport = new NamespaceSupport();
|
||||
context = new LinkedList();
|
||||
attributes = new ArrayList();
|
||||
final String ns = XMLConstants.W3C_XML_SCHEMA_NS_URI;
|
||||
typeLibrary = new DatatypeLibraryLoader().createDatatypeLibrary(ns);
|
||||
}
|
||||
|
||||
public ContentHandler getContentHandler()
|
||||
{
|
||||
return contentHandler;
|
||||
}
|
||||
|
||||
public void setContentHandler(ContentHandler contentHandler)
|
||||
{
|
||||
this.contentHandler = contentHandler;
|
||||
}
|
||||
|
||||
public ErrorHandler getErrorHandler()
|
||||
{
|
||||
return errorHandler;
|
||||
}
|
||||
|
||||
public void setErrorHandler(ErrorHandler errorHandler)
|
||||
{
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public LSResourceResolver getResourceResolver()
|
||||
{
|
||||
return resourceResolver;
|
||||
}
|
||||
|
||||
public void setResourceResolver(LSResourceResolver resourceResolver)
|
||||
{
|
||||
this.resourceResolver = resourceResolver;
|
||||
}
|
||||
|
||||
public TypeInfoProvider getTypeInfoProvider()
|
||||
{
|
||||
return typeInfoProvider;
|
||||
}
|
||||
|
||||
TypeInfo getElementTypeInfo()
|
||||
{
|
||||
return (XMLSchemaElementTypeInfo) context.getFirst();
|
||||
}
|
||||
|
||||
TypeInfo getAttributeTypeInfo(int index)
|
||||
{
|
||||
return (XMLSchemaAttributeTypeInfo) attributes.get(index);
|
||||
}
|
||||
|
||||
boolean isIdAttribute(int index)
|
||||
{
|
||||
XMLSchemaAttributeTypeInfo typeInfo =
|
||||
(XMLSchemaAttributeTypeInfo) attributes.get(index);
|
||||
return typeInfo.id;
|
||||
}
|
||||
|
||||
boolean isSpecified(int index)
|
||||
{
|
||||
XMLSchemaAttributeTypeInfo typeInfo =
|
||||
(XMLSchemaAttributeTypeInfo) attributes.get(index);
|
||||
return typeInfo.specified;
|
||||
}
|
||||
|
||||
public void setDocumentLocator(Locator locator)
|
||||
{
|
||||
loc = locator;
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.setDocumentLocator(locator);
|
||||
}
|
||||
}
|
||||
|
||||
public void startDocument()
|
||||
throws SAXException
|
||||
{
|
||||
namespaceSupport.reset();
|
||||
context.clear();
|
||||
attributes.clear();
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.startDocument();
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocument()
|
||||
throws SAXException
|
||||
{
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.endDocument();
|
||||
}
|
||||
}
|
||||
|
||||
public void startPrefixMapping(String prefix, String uri)
|
||||
throws SAXException
|
||||
{
|
||||
namespaceSupport.declarePrefix(prefix, uri);
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.startPrefixMapping(prefix, uri);
|
||||
}
|
||||
}
|
||||
|
||||
public void endPrefixMapping(String prefix)
|
||||
throws SAXException
|
||||
{
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.endPrefixMapping(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName,
|
||||
Attributes atts)
|
||||
throws SAXException
|
||||
{
|
||||
namespaceSupport.pushContext();
|
||||
QName name = new QName(uri, localName);
|
||||
ElementDeclaration decl =
|
||||
(ElementDeclaration) schema.elementDeclarations.get(name);
|
||||
// Validation Rule: Element Locally Valid (Element)
|
||||
String xsiType =
|
||||
atts.getValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
|
||||
xsiType = xsiType.trim(); // normalise
|
||||
String xsiNil =
|
||||
atts.getValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil");
|
||||
Type type = decl.datatype;
|
||||
if (xsiType.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Type specifiedType = resolveType(xsiType);
|
||||
// TODO 4.3
|
||||
type = specifiedType;
|
||||
}
|
||||
catch (DatatypeException e) // 4.1, 4.2
|
||||
{
|
||||
ValidationException e2 =
|
||||
new ValidationException("Can't resolve type " + xsiType,
|
||||
loc);
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
XMLSchemaElementTypeInfo typeInfo =
|
||||
new XMLSchemaElementTypeInfo(schema, decl, type);
|
||||
if (decl == null) // 1
|
||||
{
|
||||
throw new ValidationException("No declaration for " + name, loc);
|
||||
}
|
||||
if (decl.isAbstract) // 2
|
||||
{
|
||||
throw new ValidationException("Declaration for " + name +
|
||||
" is abstract", loc);
|
||||
}
|
||||
if (xsiNil.length() > 0)
|
||||
{
|
||||
if (!decl.nillable) // 3.1
|
||||
{
|
||||
throw new ValidationException("Declaration for " + name +
|
||||
" is nillable but xsi:nil present",
|
||||
loc);
|
||||
}
|
||||
else if ("true".equals(xsiNil)) // 3.2
|
||||
{
|
||||
typeInfo.nil = true;
|
||||
if (decl.type == XMLSchema.CONSTRAINT_FIXED) // 3.2.2
|
||||
{
|
||||
throw new ValidationException("Declaration for " + name +
|
||||
" is fixed but xsi:nil is true",
|
||||
loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO 5, 6, 7
|
||||
|
||||
// parent
|
||||
if (!context.isEmpty())
|
||||
{
|
||||
XMLSchemaElementTypeInfo parent =
|
||||
(XMLSchemaElementTypeInfo) context.getFirst();
|
||||
if (parent.nil) // Element Locally Valid (Element) 3.2.1
|
||||
{
|
||||
throw new ValidationException("Parent of " + qName +
|
||||
" is declared xsi:nil", loc);
|
||||
}
|
||||
// TODO
|
||||
}
|
||||
context.addFirst(typeInfo);
|
||||
// attributes
|
||||
int len = atts.getLength();
|
||||
Attributes2Impl atts2 = new Attributes2Impl();
|
||||
int count = 0;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
String attUri = atts.getURI(i);
|
||||
String attLocalName = atts.getLocalName(i);
|
||||
String attQName = atts.getQName(i);
|
||||
String attValue = atts.getValue(i);
|
||||
|
||||
if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(attUri))
|
||||
{
|
||||
continue; // ?
|
||||
}
|
||||
|
||||
QName attName = new QName(attUri, attLocalName);
|
||||
AttributeDeclaration attDecl =
|
||||
(AttributeDeclaration) schema.attributeDeclarations.get(attName);
|
||||
boolean declared = (attDecl != null);
|
||||
|
||||
String attType = (attDecl != null) ?
|
||||
attDecl.datatype.toString() : "CDATA";
|
||||
XMLSchemaAttributeTypeInfo attTypeInfo =
|
||||
new XMLSchemaAttributeTypeInfo(schema, attDecl, true);
|
||||
attributes.add(attTypeInfo);
|
||||
|
||||
atts2.addAttribute(attUri, attLocalName, attQName, attType, attValue);
|
||||
atts2.setDeclared(count, declared);
|
||||
atts2.setSpecified(count, true);
|
||||
count++;
|
||||
}
|
||||
// add defaulted attributes to atts2
|
||||
// TODO
|
||||
// atts2.setSpecified(count, false);
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.startElement(uri, localName, qName, atts2);
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localName, String qName)
|
||||
throws SAXException
|
||||
{
|
||||
// TODO check all required have been seen
|
||||
context.removeFirst();
|
||||
attributes.clear();
|
||||
namespaceSupport.popContext();
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.endElement(uri, localName, qName);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException
|
||||
{
|
||||
XMLSchemaElementTypeInfo parent =
|
||||
(XMLSchemaElementTypeInfo) context.getFirst();
|
||||
if (parent.nil) // Element Locally Valid (Element) 3.2.1
|
||||
{
|
||||
throw new ValidationException(parent.decl.name.toString() +
|
||||
" is declared xsi:nil",
|
||||
loc);
|
||||
}
|
||||
// TODO
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.characters(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void ignorableWhitespace(char[] ch, int start, int length)
|
||||
throws SAXException
|
||||
{
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.ignorableWhitespace(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void processingInstruction(String target, String data)
|
||||
throws SAXException
|
||||
{
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.processingInstruction(target, data);
|
||||
}
|
||||
}
|
||||
|
||||
public void skippedEntity(String name)
|
||||
throws SAXException
|
||||
{
|
||||
if (contentHandler != null)
|
||||
{
|
||||
contentHandler.skippedEntity(name);
|
||||
}
|
||||
}
|
||||
|
||||
Type resolveType(String value)
|
||||
throws DatatypeException
|
||||
{
|
||||
QName name = QName.valueOf(value);
|
||||
String prefix = name.getPrefix();
|
||||
String localName = name.getLocalPart();
|
||||
if (prefix != null && prefix.length() > 0)
|
||||
{
|
||||
String uri = namespaceSupport.getURI(prefix);
|
||||
if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri))
|
||||
return null;
|
||||
}
|
||||
if ("anyType".equals(localName))
|
||||
return Type.ANY_TYPE;
|
||||
return (SimpleType) typeLibrary.createDatatype(localName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user