You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2013/11/04 17:18:41 UTC
svn commit: r1538665 - in
/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima:
analysis_engine/impl/AnalysisEngineDescription_impl.java
resource/metadata/impl/MetaDataObject_impl.java
util/impl/SaxDeserializer_impl.java
Author: schor
Date: Mon Nov 4 16:18:41 2013
New Revision: 1538665
URL: http://svn.apache.org/r1538665
Log:
[UIMA-3404] [UIMA-239] [UIMA-2155] hand-merge comment changes and missing fix for SaxDeserializer_impl from branches/xmlComments.
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineDescription_impl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SaxDeserializer_impl.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineDescription_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineDescription_impl.java?rev=1538665&r1=1538664&r2=1538665&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineDescription_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineDescription_impl.java Mon Nov 4 16:18:41 2013
@@ -104,8 +104,10 @@ public class AnalysisEngineDescription_i
private FlowControllerDeclaration mFlowControllerDeclaration;
+ // This holds delegates after imports have been resolved (merged from xmlComments 1187355)
private Map<String, ResourceSpecifier> mDelegateAnalysisEngineSpecifiers = new LinkedHashMap<String, ResourceSpecifier>();
+ // This holds delegates as they come from reading the descriptor, may have import elements (unresolved) (merged from xmlComments 1187355)
private Map<String, MetaDataObject> mDelegateAnalysisEngineSpecifiersWithImports = new LinkedHashMap<String, MetaDataObject>();
private Map<String, Import> mProcessedImports = new HashMap<String, Import>();
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java?rev=1538665&r1=1538664&r2=1538665&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java Mon Nov 4 16:18:41 2013
@@ -77,11 +77,21 @@ import org.xml.sax.helpers.AttributesImp
*
* The implementation for getting and setting property values uses the JavaBeans introspection API.
* Therefore subclasses of this class must be valid JavaBeans and either use the standard naming
- * conventions for getters and setters or else provide a BeanInfo class. See <a
- * href="http://java.sun.com/docs/books/tutorial/javabeans/"> The Java Beans Tutorial</a> for more
+ * conventions for getters and setters. BeanInfo augmentation is ignored; the implementation here
+ * uses the flag IGNORE_ALL_BEANINFO. See <a href="http://java.sun.com/docs/books/tutorial/javabeans/">
+ * The Java Beans Tutorial</a> for more
* information.
*
+ * To support XML Comments, which can occur inbetween any sub-elements, including array values,
+ * the "data" for all objects is stored in a pair of ArrayLists; one holds the "name" of the slot,
+ * the other the value; comments are interspersed within this list where they occur.
*
+ * To the extent possible, this should be the *only* data storage used for the xml element.
+ * Subclasses should access these elements on demand. Data will be read into / written from this
+ * representation; Cloning will copy this information.
+ *
+ * For getters that need to do some special initial processing, a global flag will be set whenever
+ * this base code changes the underlying value.
*/
public abstract class MetaDataObject_impl implements MetaDataObject {
@@ -117,7 +127,8 @@ public abstract class MetaDataObject_imp
/**
* Returns a list of <code>NameClassPair</code> objects indicating the attributes of this object
- * and the Classes of the attributes' values. For primitive types, the wrapper classes will be
+ * and the String names of the Classes of the attributes' values.
+ * For primitive types, the wrapper classes will be
* returned (e.g. <code>java.lang.Integer</code> instead of int).
*
* Several subclasses override this, to add additional items to the list.
@@ -355,9 +366,8 @@ public abstract class MetaDataObject_imp
// now clone all values that are MetaDataObjects
List<NameClassPair> attrs = listAttributes();
- Iterator<NameClassPair> i = attrs.iterator();
- while (i.hasNext()) {
- String attrName = ((NameClassPair) i.next()).getName();
+ for (NameClassPair ncp : attrs) {
+ String attrName = ncp.getName();
Object val = getAttributeValue(attrName);
if (val instanceof MetaDataObject) {
Object clonedVal = ((MetaDataObject) val).clone();
@@ -927,6 +937,9 @@ public abstract class MetaDataObject_imp
* Initializes this object from its XML DOM representation. This method is typically called from
* the {@link XMLParser}.
*
+ * It is overridden by specific Java impl classes to provide additional
+ * defaulting (e.g. see AnalysisEngineDescription_impl)
+ *
* @param aElement
* the XML element that represents this object.
* @param aParser
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SaxDeserializer_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SaxDeserializer_impl.java?rev=1538665&r1=1538664&r2=1538665&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SaxDeserializer_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SaxDeserializer_impl.java Mon Nov 4 16:18:41 2013
@@ -38,6 +38,7 @@ import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
/**
* Reference implementation of {@link SaxDeserializer}.
@@ -62,6 +63,8 @@ public class SaxDeserializer_impl implem
private TransformerHandler mTransformerHandler;
+ private final boolean needsFix;
+
/**
* Creates a new SAX Deserializer.
*
@@ -75,14 +78,36 @@ public class SaxDeserializer_impl implem
mUimaXmlParser = aUimaXmlParser;
mOptions = aOptions;
+ TransformerHandler testTransformerHandler = null;
+ DOMResult testDomResult = new DOMResult();
+
// use a TransformerHandler to convert SAX events to DOM
try {
mTransformerHandler = transformerFactory.newTransformerHandler();
mDOMResult = new DOMResult();
mTransformerHandler.setResult(mDOMResult);
+
+ // set up a test for old buggy XALAN (2.6.0) impl
+ // see https://issues.apache.org/jira/browse/UIMA-2155
+ testTransformerHandler = transformerFactory.newTransformerHandler();
+ testTransformerHandler.setResult(testDomResult);
} catch (TransformerConfigurationException e) {
throw new UIMARuntimeException(e);
}
+
+ // test for old buggy XALAN (2.6.0) impl
+ // see https://issues.apache.org/jira/browse/UIMA-2155
+
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "xmlns", "xmlns", "CDATA", "http://some");
+ boolean nf = false;
+ try {
+ testTransformerHandler.startDocument();
+ testTransformerHandler.startElement("http://some", "test", "test", atts);
+ } catch (SAXException e) {
+ nf = true;
+ }
+ needsFix = nf;
}
/**
@@ -112,17 +137,7 @@ public class SaxDeserializer_impl implem
public XMLizable getObject() throws InvalidXMLException {
// COMMENT NODEs may be present, and getDocumentElement would skip it...
Node rootDomNode = ((Document) mDOMResult.getNode()).getDocumentElement();
-// NodeList children = mDOMResult.getNode().getChildNodes();
-// for (int i = 0; i < children.getLength(); i ++) {
-// System.out.format("Child: %s", children.item(i).getNodeName());
-// if (children.item(i) instanceof Text) {
-// String s = children.item(i).getTextContent();
-// for (int j = 0; j < s.length(); j++) {
-// System.out.format(" %d", s.codePointAt(j));
-// }
-// }
-// System.out.print("\n");
-// }
+
// build the object
XMLizable result = mUimaXmlParser.buildObject((Element) rootDomNode, mOptions);
@@ -219,8 +234,28 @@ public class SaxDeserializer_impl implem
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException {
// System.out.println("SaxDeserializer_impl::startElement("+namespaceURI+","+localName+","+qName+","+atts+")");
+ if (needsFix) {
+ mTransformerHandler.startElement(namespaceURI, localName, qName, fixNSbug(atts));
+ } else {
mTransformerHandler.startElement(namespaceURI, localName, qName, atts);
}
+ }
+
+ // bypass a bug in handling xmlns= attributes in some Javas impls,
+ // where it throws a org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
+ // confirmed happens on Java 1.6 Sun 6_22, but is OK on IBM Java 6
+
+ private Attributes fixNSbug(Attributes atts) {
+ // fix: scan the attributes for the attribute "xmlns" and if found, add the correct namespace for that attribute.
+ for (int i = 0; i < atts.getLength(); i++) {
+ if ("xmlns".equals(atts.getQName(i))){
+ AttributesImpl result = new AttributesImpl(atts); // make a copy of all the attributes, into an impl-neutral impl.
+ result.setURI(i, "http://www.w3.org/2000/xmlns/");
+ return result;
+ }
+ }
+ return atts;
+ }
/**
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)