Revision: 529
Author:
aal...@gmail.com
Date: Tue May 19 18:43:18 2015 UTC
Log: closes issue 162. in addition to fixing the attributeidentity
problem for the typed bridge, we *also* defer creating attribute identity
until and unless we actually need it (we need it to associate with type
annotations, so typed bridge only). this should have the side effect of
significantly improving performance (particularly multithreaded
performance) in the untyped api.
https://code.google.com/p/genxdm/source/detail?r=529
Modified:
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/AxiomFragmentBuilder.java
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/AxiomModel.java
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/enhanced/AxiomSequenceBuilder.java
=======================================
---
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/AxiomFragmentBuilder.java
Mon May 18 14:25:43 2015 UTC
+++
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/AxiomFragmentBuilder.java
Tue May 19 18:43:18 2015 UTC
@@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.WeakHashMap;
import javax.xml.XMLConstants;
@@ -32,7 +31,6 @@
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMProcessingInstruction;
import org.apache.axiom.om.OMText;
-import org.genxdm.bridgekit.misc.StringToURIParser;
import org.genxdm.exceptions.GenXDMException;
import org.genxdm.exceptions.IllegalNullArgumentException;
import org.genxdm.exceptions.PreCondition;
@@ -74,9 +72,8 @@
if (ids != null) // only null if we don't have a
document. *shrug*
ids.put(value, element);
}
-
+ typedNode = attribute;
element.addAttribute(attribute);
- nodeId = AxiomModel.attributeIdentity(attribute, true);
}
else
{
@@ -221,7 +218,7 @@
currentNode = element;
}
- nodeId = currentNode;
+ typedNode = currentNode;
}
public void text(String data)
@@ -285,9 +282,9 @@
return factory;
}
- public Object lastNodeId()
+ public Object lastTypedNode()
{
- return nodeId;
+ return typedNode;
}
public OMDocument docNode()
@@ -325,7 +322,8 @@
protected ArrayList<Object> nodes = new ArrayList<Object>();
protected Object currentNode;
protected OMDocument docNode;
- protected Object nodeId;
protected OMDocument documentNode;
protected boolean ignoreComments;
+
+ private Object typedNode;
}
=======================================
---
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/AxiomModel.java
Mon May 18 14:25:43 2015 UTC
+++
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/AxiomModel.java
Tue May 19 18:43:18 2015 UTC
@@ -1259,7 +1259,7 @@
if (node instanceof OMAttribute)
{
final OMAttribute attr = (OMAttribute)node;
- return attributeIdentity(attr, false);
+ return attributeIdentity(attr);
}
if (node instanceof OMNamespace)
return new NamespaceIdentity((OMNamespace)node);
@@ -1417,9 +1417,9 @@
}
// done as static so that the fragmentbuilder can use the only map
that we want to have around.
- static AttributeIdentity attributeIdentity(OMAttribute attr, boolean
isNew)
+ static public AttributeIdentity attributeIdentity(OMAttribute attr)
{
- AttributeIdentity id = isNew ? null : attributes.get(attr);
+ AttributeIdentity id = attributes.get(attr);
if (id == null)
{
id = new AttributeIdentity(attr);
@@ -1427,6 +1427,13 @@
}
return id;
}
+
+ static public AttributeIdentity createAttributeIdentity(OMAttribute
attr)
+ {
+ AttributeIdentity id = new AttributeIdentity(attr);
+ attributes.put(attr, id);
+ return id;
+ }
/**
* Determines whether the cancellation, xmlns="", is required to
ensure correct semantics.
=======================================
---
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/enhanced/AxiomSequenceBuilder.java
Wed Feb 20 20:55:34 2013 UTC
+++
/trunk/project/bridge.axiom/src/main/java/org/genxdm/bridge/axiom/enhanced/AxiomSequenceBuilder.java
Tue May 19 18:43:18 2015 UTC
@@ -21,8 +21,10 @@
import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMFactory;
import org.genxdm.bridge.axiom.AxiomFragmentBuilder;
+import org.genxdm.bridge.axiom.AxiomModel;
import org.genxdm.bridgekit.atoms.XmlAtom;
import org.genxdm.bridgekit.tree.TypeAnnotator;
import org.genxdm.exceptions.GenXDMException;
@@ -43,7 +45,8 @@
public void attribute(final String namespaceURI, final String localName,
final String prefix, final List<? extends XmlAtom> value, final QName type)
{
attribute(namespaceURI, localName, prefix,
bridge.getC14NString(value), /*map from schema to dtd?*/
DtdAttributeKind.CDATA);
- types.annotate(base.docNode(), base.lastNodeId(), type);
+ Object nodeId =
AxiomModel.createAttributeIdentity((OMAttribute)base.lastTypedNode());
+ types.annotate(base.docNode(), nodeId, type);
}
@@ -117,7 +120,7 @@
public void startElement(final String namespaceURI, final String
localName, final String prefix, final QName type)
{
startElement(namespaceURI, localName, prefix);
- types.annotate(base.docNode(), base.lastNodeId(), type);
+ types.annotate(base.docNode(), base.lastTypedNode(), type);
}
public void text(final List<? extends XmlAtom> value)