Author: thorsten
Date: Wed Sep 17 04:37:18 2008
New Revision: 696257
URL: http://svn.apache.org/viewvc?rev=696257&view=rev
Log:
Re-factoring the Structure implementation to implement the interface. Removing
hacks around data and contract resolving.
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java?rev=696257&r1=696256&r2=696257&view=diff
==============================================================================
---
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
(original)
+++
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
Wed Sep 17 04:37:18 2008
@@ -14,19 +14,22 @@
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventAllocator;
-import org.apache.forrest.dispatcher.DispatcherException;
import org.apache.forrest.dispatcher.api.Contract;
-import org.apache.forrest.dispatcher.helper.StAX;
+import org.apache.forrest.dispatcher.api.Resolver;
+import org.apache.forrest.dispatcher.api.Structurer;
+import org.apache.forrest.dispatcher.config.DispatcherBean;
+import org.apache.forrest.dispatcher.exception.DispatcherException;
+import org.apache.forrest.dispatcher.factories.ContractFactory;
+import org.apache.forrest.dispatcher.impl.helper.StAX;
import org.apache.forrest.dispatcher.utils.CommonString;
import org.xml.sax.InputSource;
-public class XMLStructurer extends StAX {
+public class XMLStructurer extends StAX implements Structurer {
public static final String NS = "http://apache.org/forrest/templates/2.0";
@@ -52,51 +55,29 @@
private static final Object CONTRACT_RESULT_XPATH = "xpath";
- private String format = "";
- private InputStream dataStream = null;
-
private String currentPath = "";
+
+ private Resolver resolver = null;
private boolean allowXmlProperties = false;
private LinkedHashMap<String, LinkedHashSet<XMLEvent>> resultTree = new
LinkedHashMap<String, LinkedHashSet<XMLEvent>>();
- public boolean isAllowXmlProperties() {
- return allowXmlProperties;
- }
-
- public void setAllowXmlProperties(boolean allowXmlProperties) {
- this.allowXmlProperties = allowXmlProperties;
- }
-
- private String contractUriPrefix = "";
- private String contractUriSufix = ".contract.xml";
-
- public String getContractUriPrefix() {
- return contractUriPrefix;
- }
-
- public void setContractUriPrefix(String contractUriPrefix) {
- this.contractUriPrefix = contractUriPrefix;
+ private ContractFactory contractRep =null;
+
+ public XMLStructurer(DispatcherBean config) {
+ this.contractRep = new ContractFactory(config);
+ this.resolver = config.getResolver();
+ this.allowXmlProperties = config.isAllowXmlProperties();
}
- public String getContractUriSufix() {
- return contractUriSufix;
- }
-
- public void setContractUriSufix(String contractUriSufix) {
- this.contractUriSufix = contractUriSufix;
- }
-
- public XMLStructurer(InputStream dataStream, String format) {
- this.format = format;
- this.dataStream = dataStream;
- }
-
- public BufferedInputStream execute() throws DispatcherException {
+ /*
+ * @see
org.apache.forrest.dispatcher.impl.Structurer#execute(java.io.InputStream,
java.lang.String)
+ */
+ public InputStream execute(InputStream structurerStream, String format)
throws DispatcherException {
BufferedInputStream stream = null;
try {
- XMLStreamReader reader = getReader(dataStream);
+ XMLStreamReader reader = getReader(structurerStream);
boolean process = true;
while (process) {
int event = reader.next();
@@ -141,6 +122,14 @@
throw new DispatcherException(e);
} catch (IOException e) {
throw new DispatcherException(e);
+ }finally{
+ if (null!=structurerStream){
+ try {
+ structurerStream.close();
+ } catch (IOException e) {
+ throw new DispatcherException(e);
+ };
+ }
}
return stream;
}
@@ -215,7 +204,7 @@
throws XMLStreamException, DispatcherException, IOException {
boolean process = true;
String elementName = null;
- String name = "", data = "";
+ String name = "", data= null;
// Get attribute names
for (int i = 0; i < reader.getAttributeCount(); i++) {
String localName = reader.getAttributeLocalName(i);
@@ -226,26 +215,12 @@
data = reader.getAttributeValue(i);
}
}
- /*
- * FIXME: TEMPORAL HACK ONLY Use source resolver/contract factory when
- * fixing this.
- *
- * Ignoring dataStream completely for now
- *
- * THIS ONLY WORKS FOR JUNIT ATM!!!
- */
- dataStream = null;
- Contract contract = new XSLContract(allowXmlProperties);
- InputStream xslStream = this.getClass().getResourceAsStream(
- this.contractUriPrefix + name + this.contractUriSufix);
- contract.initializeFromStream(xslStream);
- // closing stream
- if (xslStream != null) {
- xslStream.close();
- }
- /*
- * HACK END
- */
+ log.debug("data "+data);
+ InputStream dataStream=null;
+ if(null != data){
+ dataStream = resolver.resolve(data);
+ }
+ Contract contract = contractRep.resolve(name);
HashMap<String, ?> param = new HashMap();
while (process) {