Commits

Anonymous committed bcf5c69

Introduce IXFormParserFactory and implementation. Change XFormUtils to use the factory. Change XFormParser to have protected bind parsing methods to allow for overriding the parsing (equivalent to old IXFormBindHanlder capability).

Comments (0)

Files changed (4)

core/src/org/javarosa/xform/parse/IXFormParserFactory.java

+package org.javarosa.xform.parse;
+
+import java.io.Reader;
+
+import org.kxml2.kdom.Document;
+
+/**
+ * Interface for class factory for creating an XFormParser.
+ * Supports experimental extensions of XFormParser.
+ * 
+ * @author mitchellsundt@gmail.com
+ *
+ */
+public interface IXFormParserFactory {
+	public XFormParser getXFormParser(Reader reader);
+	
+	public XFormParser getXFormParser(Document doc);
+	
+	public XFormParser getXFormParser(Reader form, Reader instance);
+	
+	public XFormParser getXFormParser(Document form, Document instance);
+
+}

core/src/org/javarosa/xform/parse/XFormParser.java

 		}
 		return false;
 	}
-
-	private void parseBind (Element e) {
-		DataBinding binding  = new DataBinding();
-		
-		Vector usedAtts = new Vector();
+	
+	protected DataBinding processStandardBindAttributes( Vector usedAtts, Element e) {
 		usedAtts.addElement(ID_ATTR);
 		usedAtts.addElement(NODESET_ATTR);
 		usedAtts.addElement("type");
 		usedAtts.addElement("calculate");
 		usedAtts.addElement("preload");
 		usedAtts.addElement("preloadParams");
+
+		DataBinding binding  = new DataBinding();
+		
 		
 		binding.setId(e.getAttributeValue("", ID_ATTR));
 
 
 		binding.setPreload(e.getAttributeValue(NAMESPACE_JAVAROSA, "preload"));
 		binding.setPreloadParams(e.getAttributeValue(NAMESPACE_JAVAROSA, "preloadParams"));
+		
+		return binding;
+	}
 
+	protected void parseBind (Element e) {
+		Vector usedAtts = new Vector();
+
+		DataBinding binding = processStandardBindAttributes( usedAtts, e);
+		
 		//print unused attribute warning message for parent element
 		if(XFormUtils.showUnusedAttributeWarning(e, usedAtts)){
 			System.out.println(XFormUtils.unusedAttWarning(e, usedAtts));
 		return r;
 	}
 	
-	private void addBinding (DataBinding binding) {
+	protected void addBinding (DataBinding binding) {
 		bindings.addElement(binding);
 		
 		if (binding.getId() != null) {

core/src/org/javarosa/xform/parse/XFormParserFactory.java

+package org.javarosa.xform.parse;
+
+import java.io.Reader;
+
+import org.kxml2.kdom.Document;
+
+/**
+ * Class factory for creating an XFormParser.
+ * Supports experimental extensions of XFormParser.
+ * 
+ * @author mitchellsundt@gmail.com
+ *
+ */
+public class XFormParserFactory implements IXFormParserFactory {
+
+	public XFormParserFactory() {
+	}
+	
+	public XFormParser getXFormParser(Reader reader) {
+		return new XFormParser(reader);
+	}
+	
+	public XFormParser getXFormParser(Document doc) {
+		return new XFormParser(doc);
+	}
+	
+	public XFormParser getXFormParser(Reader form, Reader instance) {
+		return new XFormParser(form, instance);
+	}
+	
+	public XFormParser getXFormParser(Document form, Document instance) {
+		return new XFormParser(form, instance);
+	}
+
+}

core/src/org/javarosa/xform/util/XFormUtils.java

 import org.javarosa.core.model.FormDef;
 import org.javarosa.core.util.externalizable.DeserializationException;
 import org.javarosa.core.util.externalizable.ExtUtil;
+import org.javarosa.xform.parse.IXFormParserFactory;
 import org.javarosa.xform.parse.XFormParser;
+import org.javarosa.xform.parse.XFormParserFactory;
 import org.kxml2.kdom.Element;
 
 /**
  * @author Clayton Sims
  *
  */
-public class XFormUtils {
+public class XFormUtils {
+	private static IXFormParserFactory _factory = new XFormParserFactory();
+	
+	public static IXFormParserFactory setXFormParserFactory(IXFormParserFactory factory) {
+		IXFormParserFactory oldFactory = _factory;
+		_factory = factory;
+		return oldFactory;
+	}
+	
 	public static FormDef getFormFromResource (String resource) {
 		InputStream is = System.class.getResourceAsStream(resource);
 		if (is == null) {
 		}
 		
 		try {
-			return new XFormParser(isr).parse();
+			return _factory.getXFormParser(isr).parse();
 		} finally {
 			try {
 				isr.close();