You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/09/20 23:48:55 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 XSCMAny.java XSCMBinOp.java XSCMUniOp.java XSCMLeaf.java
neilg 01/09/20 14:48:55
Added: java/src/org/apache/xerces/impl/v2 XSCMAny.java
XSCMBinOp.java XSCMUniOp.java XSCMLeaf.java
Log:
files to support DFAContentModel (a.k.a. XSDFACM).
Revision Changes Path
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/XSCMAny.java
Index: XSCMAny.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2;
import org.apache.xerces.impl.validation.models.CMNode;
import org.apache.xerces.impl.validation.models.CMStateSet;
/**
* Content model any node.
*
* @author Neil Graham, IBM
* @version $$
*/
public class XSCMAny
extends CMNode {
//
// Data
//
/**
* The any content model type. This value is one of the following:
* XSParticleDecl.PARTICLE_WILDCARD
*/
private int fType;
/**
* URI of the any content model. This value is set if the type is
* XSParticleDecl.PARTICLE_WILDCARD.
*/
private String fURI;
/**
* Part of the algorithm to convert a regex directly to a DFA
* numbers each leaf sequentially. If its -1, that means its an
* epsilon node. Zero and greater are non-epsilon positions.
*/
private int fPosition = -1;
//
// Constructors
//
/** Constructs a content model any. */
public XSCMAny(int type, String uri, int position) {
super(type);
// Store the information
fType = type;
fURI = uri;
fPosition = position;
}
//
// Package methods
//
final int getType() {
return fType;
}
final String getURI() {
return fURI;
}
final int getPosition() {
return fPosition;
}
final void setPosition(int newPosition) {
fPosition = newPosition;
}
//
// CMNode methods
//
// package
public boolean isNullable() {
// Leaf nodes are never nullable unless its an epsilon node
return (fPosition == -1);
}
public String toString() {
StringBuffer strRet = new StringBuffer();
strRet.append("(");
strRet.append("##any:uri=");
strRet.append(fURI);
strRet.append(')');
if (fPosition >= 0) {
strRet.append
(
" (Pos:"
+ new Integer(fPosition).toString()
+ ")"
);
}
return strRet.toString();
}
// protected
protected void calcFirstPos(CMStateSet toSet) {
// If we are an epsilon node, then the first pos is an empty set
if (fPosition == -1)
toSet.zeroBits();
// Otherwise, its just the one bit of our position
else
toSet.setBit(fPosition);
}
protected void calcLastPos(CMStateSet toSet) {
// If we are an epsilon node, then the last pos is an empty set
if (fPosition == -1)
toSet.zeroBits();
// Otherwise, its just the one bit of our position
else
toSet.setBit(fPosition);
}
} // class XSCMAny
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/XSCMBinOp.java
Index: XSCMBinOp.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENCEUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2;
import org.apache.xerces.impl.validation.models.CMNode;
import org.apache.xerces.impl.validation.models.CMStateSet;
/**
*
* Content model Bin-Op node.
*
* @author Neil Graham, IBM
* @version $$
*/
public class XSCMBinOp extends CMNode {
// -------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------
public XSCMBinOp(int type, CMNode leftNode, CMNode rightNode)
{
super(type);
// Insure that its one of the types we require
if ((type() != XSParticleDecl.PARTICLE_CHOICE)
&& (type() != XSParticleDecl.PARTICLE_SEQUENCE)) {
throw new RuntimeException("ImplementationMessages.VAL_BST");
}
// Store the nodes and init any data that needs it
fLeftChild = leftNode;
fRightChild = rightNode;
}
// -------------------------------------------------------------------
// Package, final methods
// -------------------------------------------------------------------
final CMNode getLeft() {
return fLeftChild;
}
final CMNode getRight() {
return fRightChild;
}
// -------------------------------------------------------------------
// Package, inherited methods
// -------------------------------------------------------------------
public boolean isNullable() {
//
// If its an alternation, then if either child is nullable then
// this node is nullable. If its a concatenation, then both of
// them have to be nullable.
//
if (type() == XSParticleDecl.PARTICLE_CHOICE)
return (fLeftChild.isNullable() || fRightChild.isNullable());
else if (type() == XSParticleDecl.PARTICLE_SEQUENCE)
return (fLeftChild.isNullable() && fRightChild.isNullable());
else
throw new RuntimeException("ImplementationMessages.VAL_BST");
}
// -------------------------------------------------------------------
// Protected, inherited methods
// -------------------------------------------------------------------
protected void calcFirstPos(CMStateSet toSet) {
if (type() == XSParticleDecl.PARTICLE_CHOICE) {
// Its the the union of the first positions of our children.
toSet.setTo(fLeftChild.firstPos());
toSet.union(fRightChild.firstPos());
}
else if (type() == XSParticleDecl.PARTICLE_SEQUENCE) {
//
// If our left child is nullable, then its the union of our
// children's first positions. Else is our left child's first
// positions.
//
toSet.setTo(fLeftChild.firstPos());
if (fLeftChild.isNullable())
toSet.union(fRightChild.firstPos());
}
else {
throw new RuntimeException("ImplementationMessages.VAL_BST");
}
}
protected void calcLastPos(CMStateSet toSet) {
if (type() == XSParticleDecl.PARTICLE_CHOICE) {
// Its the the union of the first positions of our children.
toSet.setTo(fLeftChild.lastPos());
toSet.union(fRightChild.lastPos());
}
else if (type() == XSParticleDecl.PARTICLE_SEQUENCE) {
//
// If our right child is nullable, then its the union of our
// children's last positions. Else is our right child's last
// positions.
//
toSet.setTo(fRightChild.lastPos());
if (fRightChild.isNullable())
toSet.union(fLeftChild.lastPos());
}
else {
throw new RuntimeException("ImplementationMessages.VAL_BST");
}
}
// -------------------------------------------------------------------
// Private data members
//
// fLeftChild
// fRightChild
// These are the references to the two nodes that are on either
// side of this binary operation.
// -------------------------------------------------------------------
private CMNode fLeftChild;
private CMNode fRightChild;
} // XSCMBinOp
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/XSCMUniOp.java
Index: XSCMUniOp.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2;
import org.apache.xerces.impl.validation.models.CMNode;
import org.apache.xerces.impl.validation.models.CMStateSet;
/**
*
* Content model Uni-Op node.
*
* @author Neil Graham, IBM
* @version $$
*/
public class XSCMUniOp extends CMNode {
// -------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------
public XSCMUniOp(int type, CMNode childNode) {
super(type);
// Insure that its one of the types we require
if ((type() != XSParticleDecl.PARTICLE_ZERO_OR_ONE)
&& (type() != XSParticleDecl.PARTICLE_ZERO_OR_MORE)
&& (type() != XSParticleDecl.PARTICLE_ONE_OR_MORE)) {
throw new RuntimeException("ImplementationMessages.VAL_UST");
}
// Store the node and init any data that needs it
fChild = childNode;
}
// -------------------------------------------------------------------
// Package, final methods
// -------------------------------------------------------------------
final CMNode getChild() {
return fChild;
}
// -------------------------------------------------------------------
// Package, inherited methods
// -------------------------------------------------------------------
public boolean isNullable() {
//
// For debugging purposes, make sure we got rid of all non '*'
// repetitions. Otherwise, '*' style nodes are always nullable.
//
if (type() == XSParticleDecl.PARTICLE_ONE_OR_MORE)
return fChild.isNullable();
else
return true;
}
// -------------------------------------------------------------------
// Protected, inherited methods
// -------------------------------------------------------------------
protected void calcFirstPos(CMStateSet toSet) {
// Its just based on our child node's first pos
toSet.setTo(fChild.firstPos());
}
protected void calcLastPos(CMStateSet toSet) {
// Its just based on our child node's last pos
toSet.setTo(fChild.lastPos());
}
// -------------------------------------------------------------------
// Private data members
//
// fChild
// This is the reference to the one child that we have for this
// unary operation.
// -------------------------------------------------------------------
private CMNode fChild;
} // XSCMUniOp
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/XSCMLeaf.java
Index: XSCMLeaf.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2;
import org.apache.xerces.impl.validation.models.CMNode;
import org.apache.xerces.impl.validation.models.CMStateSet;
/**
* Content model leaf node.
*
* @author Neil Graham, IBM
* @version $$
*/
public class XSCMLeaf
extends CMNode {
//
// Data
//
/** This is the element that this leaf represents. */
private XSElementDecl fElement = null;
/**
* Part of the algorithm to convert a regex directly to a DFA
* numbers each leaf sequentially. If its -1, that means its an
* epsilon node. Zero and greater are non-epsilon positions.
*/
private int fPosition = -1;
//
// Constructors
//
/** Constructs a content model leaf. */
public XSCMLeaf(XSElementDecl element, int position) {
super(XSParticleDecl.PARTICLE_ELEMENT);
// Store the element index and position
fElement = element;
fPosition = position;
}
/** Constructs a content model leaf. */
public XSCMLeaf(XSElementDecl element) {
super(XSParticleDecl.PARTICLE_ELEMENT);
// Store the element index and position
fElement = element;
}
//
// Package methods
//
final XSElementDecl getElement() {
return fElement;
}
final int getPosition() {
return fPosition;
}
final void setPosition(int newPosition) {
fPosition = newPosition;
}
//
// CMNode methods
//
// package
public boolean isNullable() {
// Leaf nodes are never nullable unless its an epsilon node
return (fPosition == -1);
}
public String toString() {
StringBuffer strRet = new StringBuffer(fElement.toString());
strRet.append(" (");
strRet.append(fElement.fTargetNamespace);
strRet.append(',');
strRet.append(fElement.fName);
strRet.append(')');
if (fPosition >= 0) {
strRet.append
(
" (Pos:"
+ new Integer(fPosition).toString()
+ ")"
);
}
return strRet.toString();
}
// protected
protected void calcFirstPos(CMStateSet toSet) {
// If we are an epsilon node, then the first pos is an empty set
if (fPosition == -1)
toSet.zeroBits();
// Otherwise, its just the one bit of our position
else
toSet.setBit(fPosition);
}
protected void calcLastPos(CMStateSet toSet) {
// If we are an epsilon node, then the last pos is an empty set
if (fPosition == -1)
toSet.zeroBits();
// Otherwise, its just the one bit of our position
else
toSet.setBit(fPosition);
}
} // class XSCMLeaf
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org