jkesselm 02/05/03 07:44:40
Modified: java/src/org/apache/xml/dtm/ref Tag: Xalan3
ExpandedNameTable.java
java/src/org/apache/xml/dtm/ref/xni2dtm Tag: Xalan3
XNI2DTM.java
Log:
Xalan3 PSVI changes: Lighter-weight storage for PSVI datatype. Schema
type first seen is now stored as part of the ExpandedName. In many cases
all instances of the same node have the same type and this should suffice.
In some cases tthe actual type may be locally overridden (schema
derived types), and XNI2DTM will record an exception into a simple
"sparse vector".
Storage improved. DTM construction speed improved. Schema type
retrieval speed adversely impacted but -- one hopes -- not significantly.
Of course right now Xerces' schema-validator burns so many cycles
that our own efficiency or lack thereof is completely moot... but we
assume they'll be improving that over time.
Revision Changes Path
No revision
No revision
1.3.10.4 +21 -3
xml-xalan/java/src/org/apache/xml/dtm/ref/ExpandedNameTable.java
Index: ExpandedNameTable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/ExpandedNameTable.java,v
retrieving revision 1.3.10.3
retrieving revision 1.3.10.4
diff -u -r1.3.10.3 -r1.3.10.4
--- ExpandedNameTable.java 1 May 2002 19:41:59 -0000 1.3.10.3
+++ ExpandedNameTable.java 3 May 2002 14:44:40 -0000 1.3.10.4
@@ -287,7 +287,7 @@
public final Object getSchemaType(int ExpandedNameID)
{
ExtendedType etype = (ExtendedType)m_extendedTypes.elementAt
(ExpandedNameID);
- return etype.schemaType;
+ return (etype.schemaType==ExtendedType.NULL_SCHEMATYPE) ? null :
etype.schemaType;
}
/**
@@ -297,7 +297,9 @@
* @param ExpandedNameID an ID that represents an expanded-name.
* @param schemaType a schema type object -- probably an XNI PSVI type.
* @return false if previously set to something different
- * (as determined by Object.equals), otherwise true.
+ * (as determined by Object.equals), otherwise true. False can
+ * be used as a hint that we should record a type override for this
+ * node.
*/
public final boolean setSchemaType(int ExpandedNameID, Object schemaType)
{
@@ -305,7 +307,7 @@
Object oldtype=etype.schemaType;
if(oldtype==null)
{
- etype.schemaType=schemaType;
+ etype.schemaType=(schemaType==null) ? ExtendedType.NULL_SCHEMATYPE :
schemaType;
return true;
}
else return oldtype.equals(schemaType);
@@ -321,6 +323,22 @@
String namespace;
String localName;
Object schemaType=null; // Default, for XNI PSVI support
+
+ /** We need a value other than NULL which can be used to indicate that
+ the default (first-seen) schemaType really is null rather than
+ not-yet-established. This singleton is a bit of a kluge, but it
+ does the job...
+
+ %REVIEW%
+ This is mostly an issue because I implemented XNI2DTM as a subclass
+ of SAX2DTM and tried to leverage the existing code -- which means
+ we're trying to set the default type _after_ the ExpandedNameTable
+ entry has been constructed. Architecturally, it'd be better to
+ pass this info into the ctor, but that'd require a more
+ substantial rewrite of XNI2DTM.addNode (more code duplication).
+ Worth reconsidering.
+ */
+ public static final String NULL_SCHEMATYPE="NULL_SCHEMATYPE";
ExtendedType (int nodetype, String namespace, String localName)
{
No revision
No revision
1.2.2.5 +91 -29
xml-xalan/java/src/org/apache/xml/dtm/ref/xni2dtm/Attic/XNI2DTM.java
Index: XNI2DTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/xni2dtm/Attic/XNI2DTM.java,v
retrieving revision 1.2.2.4
retrieving revision 1.2.2.5
diff -u -r1.2.2.4 -r1.2.2.5
--- XNI2DTM.java 2 May 2002 19:43:05 -0000 1.2.2.4
+++ XNI2DTM.java 3 May 2002 14:44:40 -0000 1.2.2.5
@@ -123,7 +123,9 @@
/** %OPT% %REVIEW% PROTOTYPE: Schema Type information, datatype as
instantiated.
* See discussion in addNode */
- protected Vector m_actualType=null;
+ // protected Vector m_actualType=null;
+ protected SparseVector m_schemaTypeOverride=new SparseVector();
+
/**
* If we're building the model incrementally on demand, we need to
@@ -212,14 +214,13 @@
if(actualType != null)
{
- if(m_actualType==null)
- {
- m_actualType=new Vector();
- // m_expectedType=new Vector(); // %REVIEW% OBSOLETE?
-
- }
- m_actualType.setElementAt(actualType,identity);
- // m_expectedType.setElementAt(expectedType,identity); //
%REVIEW% OBSOLETE?
+ // Try to record as default for this nodetype
+ if(!m_expandedNameTable.setSchemaType(m_exptype.elementAt(identity),
+ actualType)
+ )
+ {
+ m_schemaTypeOverride.addElement(identity,actualType);
+ }
}
return identity;
@@ -241,7 +242,10 @@
if(identity!=DTM.NULL)
{
- XSTypeDecl
actualType=(XSTypeDecl)m_actualType.elementAt(identity);
+ XSTypeDecl
actualType=(XSTypeDecl)m_schemaTypeOverride.elementAt(identity);
+ if(actualType==null)
+
actualType=(XSTypeDecl)m_expandedNameTable.getSchemaType(m_exptype.elementAt(identity));
+
if(actualType!=null)
{
String nsuri=actualType.getTargetNamespace();
@@ -272,7 +276,9 @@
if(identity!=DTM.NULL)
{
- XSTypeDecl
actualType=(XSTypeDecl)m_actualType.elementAt(identity);
+ XSTypeDecl
actualType=(XSTypeDecl)m_schemaTypeOverride.elementAt(identity);
+ if(actualType==null)
+
actualType=(XSTypeDecl)m_expandedNameTable.getSchemaType(m_exptype.elementAt(identity));
if(actualType!=null)
{
return actualType.getTargetNamespace();
@@ -297,7 +303,9 @@
if(identity!=DTM.NULL)
{
- XSTypeDecl
actualType=(XSTypeDecl)m_actualType.elementAt(identity);
+ XSTypeDecl
actualType=(XSTypeDecl)m_schemaTypeOverride.elementAt(identity);
+ if(actualType==null)
+
actualType=(XSTypeDecl)m_expandedNameTable.getSchemaType(m_exptype.elementAt(identity));
if(actualType!=null)
{
return actualType.getTypeName();
@@ -322,7 +330,9 @@
if(identity!=DTM.NULL)
{
- XSTypeDecl
actualType=(XSTypeDecl)m_actualType.elementAt(identity);
+ XSTypeDecl
actualType=(XSTypeDecl)m_schemaTypeOverride.elementAt(identity);
+ if(actualType==null)
+
actualType=(XSTypeDecl)m_expandedNameTable.getSchemaType(m_exptype.elementAt(identity));
if(actualType!=null)
return actualType.derivedFrom(namespace,localname);
}
@@ -344,7 +354,10 @@
if(identity==DTM.NULL)
return XSequence.EMPTY;
- XSTypeDecl actualType=(XSTypeDecl)m_actualType.elementAt(identity);
+ XSTypeDecl
actualType=(XSTypeDecl)m_schemaTypeOverride.elementAt(identity);
+ if(actualType==null)
+
actualType=(XSTypeDecl)m_expandedNameTable.getSchemaType(m_exptype.elementAt(identity));
+
if(actualType==null)
return XSequence.EMPTY;
@@ -844,9 +857,7 @@
// Augs might be null if schema support not turned on in parser.
// Shouldn't arise in final operation (?); may arise during debugging
-
XSTypeDecl actualType=null;
-
if(augs!=null)
{
// Extract Experimental Xerces PSVI data
@@ -889,8 +900,7 @@
// Experimental Xerces PSVI data
Augmentations attrAugs=attributes.getAugmentations(i);
AttributePSVImpl
attrPSVI=(AttributePSVImpl)attrAugs.getItem(org.apache.xerces.impl.Constants.ATTRIBUTE_PSVI);
- XSTypeDecl actualAttrType =
- (attrPSVI==null) ? null : attrPSVI.getTypeDefinition();
+ XSTypeDecl actualAttrType=(attrPSVI==null) ? null :
attrPSVI.getTypeDefinition();
org.apache.xerces.impl.xs.XSAttributeDecl expectedAttrDecl= //
%REVIEW% Obsolete?
(attrPSVI==null) ? null : attrPSVI.getAttributeDecl();
expectedType=(expectedAttrDecl==null) ? actualAttrType :
expectedAttrDecl.fType;
@@ -935,6 +945,7 @@
String declURL = "http://www.w3.org/XML/1998/namespace";
exName = m_expandedNameTable.getExpandedTypeID(null, prefix,
DTM.NAMESPACE_NODE);
int val = m_valuesOrPrefixes.stringToIndex(declURL);
+ // %REVIEW% I don't _think_ we need datatype on namespaces...?
prev = addNode(DTM.NAMESPACE_NODE, exName, elemNode,
prev, val, false);
m_pastFirstElement=true;
@@ -953,6 +964,7 @@
int val = m_valuesOrPrefixes.stringToIndex(declURL);
+ // %REVIEW% I don't _think_ we need datatype on namespaces...?
prev = addNode(DTM.NAMESPACE_NODE, exName, elemNode,
prev, val, false);
}
@@ -1012,11 +1024,10 @@
// Experimental Xerces PSVI data
Augmentations attrAugs=attributes.getAugmentations(i);
AttributePSVImpl
attrPSVI=(AttributePSVImpl)attrAugs.getItem(org.apache.xerces.impl.Constants.ATTRIBUTE_PSVI);
- XSTypeDecl actualAttrType =
- (attrPSVI==null) ? null : attrPSVI.getTypeDefinition();
-
+ XSTypeDecl actualAttrType=(attrPSVI==null) ? null :
attrPSVI.getTypeDefinition();
+
prev = addNode(nodeType, exName, elemNode, prev, val,
- false,actualAttrType);
+ false, actualAttrType);
}
if (DTM.NULL != prev)
@@ -1067,13 +1078,6 @@
", localname: " + element.localpart + ", qname:
"+element.rawname);
try
- /** %OPT% %REVIEW% PROTOTYPE: Schema Type information, datatype as
declared.
- * See discussion in addNode
- * NOTE that the 3/28/03 query datamodel no longer records the
type-as-declared,
- * so this field can probably be eliminated!
- * */
- //protected Vector m_expectedType=null; // %REVIEW% OBSOLETE?
-
{
super.endElement(element.uri,element.localpart,element.rawname);
}
@@ -1694,5 +1698,63 @@
throw new SAXException(UNEXPECTED+"endDTD");
}
+
+ /** Defined internally for the moment.
+
+ %REVIEW% FIRST DRAFT: Binary search
+
+ %REVIEW% We really do need a more global solution... though
+ keeping it here would let us change the Objects in the API to
+ XSTypeDecl, avoiding a cast when retrieving. (Do we care?)
+ */
+ class SparseVector
+ {
+ int[] m_index=new int[64];
+ Object[] m_value=new Object[64];
+ int last=0;
+
+ /** ASSUMPTION: Elements will be added in index order, though
+ indices may be skipped.
+ */
+ void addElement(int index,Object value)
+ {
+ if(last>=m_index.length)
+ {
+ int[] i=new int[last+64];
+ System.arraycopy(m_index,0,i,0,last);
+ m_index=i;
+ Object[] v=new Object[last+64];
+ System.arraycopy(m_value,0,v,0,last);
+ m_value=v;
+ }
+ m_index[last]=index;
+ m_value[last]=value;
+ ++last;
+ }
+
+ Object elementAt(int index)
+ {
+ int i = 0;
+ int first = 0;
+ int last = m_index.length - 1;
+
+ while (first <= last) {
+ i = (first + last) / 2;
+ int test = index-m_index[i];
+ if(test == 0) {
+ return m_value[i]; // Found an entry!
+ }
+ else if (test < 0) {
+ last = i - 1; // looked too late
+ }
+ else {
+ first = i + 1; // looked too early
+ }
+ }
+
+ return null; // not found
+ }
+
+ } // SparseArray
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]