[jboss-svn-commits] JBL Code SVN: r31559 - labs/jbossrules/branches/camel_jaxb_marshaller2-lucaz/drools-pipeline/drools-transformer-jaxb/src/main/java/org/drools/runtime/pipeline/impl.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Feb 10 16:05:37 EST 2010


Author: baunax
Date: 2010-02-10 16:05:36 -0500 (Wed, 10 Feb 2010)
New Revision: 31559

Modified:
   labs/jbossrules/branches/camel_jaxb_marshaller2-lucaz/drools-pipeline/drools-transformer-jaxb/src/main/java/org/drools/runtime/pipeline/impl/ResultTranslator.java
Log:
don't beautify the xml 

Modified: labs/jbossrules/branches/camel_jaxb_marshaller2-lucaz/drools-pipeline/drools-transformer-jaxb/src/main/java/org/drools/runtime/pipeline/impl/ResultTranslator.java
===================================================================
--- labs/jbossrules/branches/camel_jaxb_marshaller2-lucaz/drools-pipeline/drools-transformer-jaxb/src/main/java/org/drools/runtime/pipeline/impl/ResultTranslator.java	2010-02-10 21:04:53 UTC (rev 31558)
+++ labs/jbossrules/branches/camel_jaxb_marshaller2-lucaz/drools-pipeline/drools-transformer-jaxb/src/main/java/org/drools/runtime/pipeline/impl/ResultTranslator.java	2010-02-10 21:05:36 UTC (rev 31559)
@@ -27,79 +27,63 @@
 
 public class ResultTranslator {
 
-	private DocumentBuilder documentBuilder;
-	private Transformer transformer;
+//	private DocumentBuilder documentBuilder;
+//	private Transformer transformer;
 
-	public ResultTranslator() {
-		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
-		documentBuilderFactory.setNamespaceAware(true);
-		documentBuilderFactory.setValidating(true); 
-		documentBuilderFactory.setExpandEntityReferences(true);
-		try {
-			documentBuilder = documentBuilderFactory.newDocumentBuilder();
-		} catch (ParserConfigurationException e) {
-			throw new RuntimeException("Result Transformer Exception");
-		}
+	public ResultTranslator() {}
 
-		try {
-			transformer = TransformerFactory.newInstance().newTransformer();
-			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-		} catch (TransformerConfigurationException e) {
-			throw new RuntimeException("Result Transformer Exception");
-		} catch (TransformerFactoryConfigurationError e) {
-			throw new RuntimeException("Result Transformer Exception");
-		}
-	}
-
 	public String transform( ExecutionResultImpl executionResult, Marshaller marshaller ) throws JAXBException, TransformerException{
 
-		Document document = documentBuilder.newDocument();
-		marshaller.marshal(executionResult, document);
-
-		Element results = document.createElement("results");
-		Map<String, Object> executionResults = executionResult.getResults();
-		for (String key : executionResults.keySet()) {
-			Object object = executionResults.get(key);
-			if (object==null) {
-				executionResults.remove(key);
-				continue;
-			}
-			Element result = null;
-			if (object instanceof ArrayList<?>) {
-				result = makeObjects(marshaller, document, (List<Object>) object);
-			}
-			else {
-				result = makeObject(marshaller, document, object);
-			}
-			result.setAttribute("identifier", key);
-			results.appendChild(result);
-		}
-		addElements(results, document, executionResults.size());
-
-		results = document.createElement("fact-handles");
-		Map<String, Object> factHandlesResult = executionResult.getFactHandles();
-		for (String key : factHandlesResult.keySet()) {
-			Object object = factHandlesResult.get(key);
-			Element factHandles = document.createElement("nil");
-			Element result = null;
-			if (object instanceof ArrayList<?>) {
-				result = makeObjects(marshaller, document, (List<Object>) object);
-			}
-			else {
-				result = makeObject(marshaller, document, object);
-			}
-			Node factHandle = factHandles.getFirstChild();
-			results.appendChild(result);
-			Node identifierAttribute = document.createAttribute("identifier");
-			identifierAttribute.setNodeValue(key);
-			result.getAttributes().setNamedItem(identifierAttribute);
-		}
-		addElements(results, document, factHandlesResult.size());
-
-		return convertDocumentToString(document);
+//		Document document = documentBuilder.newDocument();
+		
+		StringWriter writer = new StringWriter();
+		marshaller.marshal(executionResult, writer);
+		return writer.toString();
+//		
+//		Element results = document.createElement("results");
+//		Map<String, Object> executionResults = executionResult.getResults();
+//		for (String key : executionResults.keySet()) {
+//			Object object = executionResults.get(key);
+//			if (object==null) {
+//				executionResults.remove(key);
+//				continue;
+//			}
+//			Element result = null;
+//			if (object instanceof ArrayList<?>) {
+//				result = makeObjects(marshaller, document, (List<Object>) object);
+//			}
+//			else {
+//				result = makeObject(marshaller, document, object);
+//			}
+//			result.setAttribute("identifier", key);
+//			results.appendChild(result);
+//		}
+//		addElements(results, document, executionResults.size());
+//
+//		results = document.createElement("fact-handles");
+//		Map<String, Object> factHandlesResult = executionResult.getFactHandles();
+//		for (String key : factHandlesResult.keySet()) {
+//			Object object = factHandlesResult.get(key);
+//			Element factHandles = document.createElement("nil");
+//			Element result = null;
+//			if (object instanceof ArrayList<?>) {
+//				result = makeObjects(marshaller, document, (List<Object>) object);
+//			}
+//			else {
+//				result = makeObject(marshaller, document, object);
+//			}
+//			Node factHandle = factHandles.getFirstChild();
+//			results.appendChild(result);
+//			Node identifierAttribute = document.createAttribute("identifier");
+//			identifierAttribute.setNodeValue(key);
+//			result.getAttributes().setNamedItem(identifierAttribute);
+//		}
+//		addElements(results, document, factHandlesResult.size());
+//
+//		return convertDocumentToString(document);
 	}
 	
-	public Element makeObjects(Marshaller marshaller, Document document, List<Object> objects) throws JAXBException {
+	private Element makeObjects(Marshaller marshaller, Document document, List<Object> objects) throws JAXBException {
 		Element result = document.createElement("result");
 		for (Object object : objects) {
 			Element element = document.createElement("element");
@@ -109,7 +93,7 @@
 		return result;
 	}
 	
-	public Element makeObject(Marshaller marshaller, Document document, Object object) throws JAXBException {
+	private Element makeObject(Marshaller marshaller, Document document, Object object) throws JAXBException {
 		Element result = document.createElement("result");
 		marshaller.marshal(object, result);
 		return result;
@@ -170,10 +154,10 @@
 		}
 	}
 
-	private String convertDocumentToString(Document document) throws TransformerException {
-		StreamResult streamResult = new StreamResult(new StringWriter());
-		transformer.transform(new DOMSource(document), streamResult);
-		return streamResult.getWriter().toString();
-	}
+//	private String convertDocumentToString(Document document) throws TransformerException {
+//		StreamResult streamResult = new StreamResult(new StringWriter());
+//		transformer.transform(new DOMSource(document), streamResult);
+//		return streamResult.getWriter().toString();
+//	}
 
 }



More information about the jboss-svn-commits mailing list