[jboss-svn-commits] JBL Code SVN: r17011 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product: rosetta/src/org/jboss/internal/soa/esb/dependencies and 8 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Dec 4 08:15:19 EST 2007


Author: kevin.conner at jboss.com
Date: 2007-12-04 08:15:19 -0500 (Tue, 04 Dec 2007)
New Revision: 17011

Added:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/lib/ext/wstx-lgpl-3.2.1.jar
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ElementContent.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ParsingSupport.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/QNameHelper.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/StreamHelper.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_expected.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_source.xml
Removed:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/ognl-2.6.9.jar
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/stax-api-1.0.1.jar
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/wstx-lgpl-3.2.1.jar
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/xbean.jar
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/xstream-1.1.3.jar
Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/JBossESBPropertyService.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksService.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/build.xml
Log:
Incorporate property replacement: JBESB-1273

Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/lib/ext/wstx-lgpl-3.2.1.jar (from rev 16898, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/wstx-lgpl-3.2.1.jar)
===================================================================
(Binary files differ)

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java	2007-12-04 11:45:07 UTC (rev 17010)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -22,13 +22,13 @@
 
 package org.jboss.internal.soa.esb.dependencies;
 
-import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.net.URI;
+import java.io.InputStream;
 import java.net.URL;
-import java.util.Enumeration;
-import java.util.Hashtable;
 import java.util.Properties;
 
 import javax.naming.InitialContext;
@@ -36,6 +36,7 @@
 import org.apache.juddi.registry.rmi.JNDIRegistration;
 import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.util.PropertiesHelper;
+import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.system.ServiceMBeanSupport;
 import org.jboss.system.server.ServerConfig;
 import org.jboss.system.server.ServerConfigLocator;
@@ -43,8 +44,6 @@
 public class JuddiRMIService extends ServiceMBeanSupport implements JuddiRMIServiceMBean
 {
    private Logger logger = Logger.getLogger(this.getClass());
-   public static final String JBOSS_BIND_ADDRESS_TOKEN = "jboss.bind.address";
-   
    public static final String PROPNAME_JAVA_NAMING_FACTORY_INITIAL = "java.naming.factory.initial";
    public static final String PROPNAME_JAVA_NAMING_PROVIDER_URL = "java.naming.provider.url";
    public static final String PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS = "java.naming.factory.url.pkgs";
@@ -53,8 +52,6 @@
    private static final String JUDDI_PROPERTIES_RESOURCE_FILE = "esb.juddi.properties";
    private static final String JUDDI_PROPERTY_FILE_COMMENTS = "Auto generated property file, do not edit" ;
    
-   private Hashtable<String, String> tokenHash;
-   
    private String propertiesResourceFile ;
 
    public String getPropertiesResourceFile()
@@ -66,12 +63,6 @@
    {
       this.propertiesResourceFile = propertiesResourceFile;
    }
-
-   public void initializeTokenHash() {
-	   tokenHash = new Hashtable<String,String>();
-       String bindAddress = System.getProperty("jboss.bind.address");
-       tokenHash.put("${" + JBOSS_BIND_ADDRESS_TOKEN + "}", bindAddress);
-   }
    
    protected void startService() throws Exception
 	{
@@ -87,53 +78,42 @@
         }
         final File baseFile = new File(propertiesResourceFileVal) ;
 
-        final File xmlPropertyFile ;
+        final InputStream xmlPropertyIS ;
         if (baseFile.isAbsolute())
         {
-            xmlPropertyFile = baseFile;
+            xmlPropertyIS = new FileInputStream(baseFile);
         }
         else
         {
-            URL url = Thread.currentThread().getContextClassLoader().getResource(propertiesResourceFileVal);
-            URI uri = new URI(url.toString());
-            xmlPropertyFile = new File(uri) ;
+            final URL url = Thread.currentThread().getContextClassLoader().getResource(propertiesResourceFileVal);
+            xmlPropertyIS = url.openStream() ;
         }
+        final byte[] propertyFileContents ;
+        try {
+            final ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
+            XMLHelper.replaceSystemProperties(XMLHelper.getXMLStreamReader(xmlPropertyIS),
+                XMLHelper.getXMLStreamWriter(baos)) ;
+            propertyFileContents = baos.toByteArray() ;
+        } finally {
+            xmlPropertyIS.close() ;
+        }
+        
         final ServerConfig serverConfig = ServerConfigLocator.locate() ;
         final File dataDir = serverConfig.getServerDataDir() ;
         final File juddiPropertyFile = new File(dataDir, JUDDI_PROPERTIES_RESOURCE_FILE) ;
         
-        final Properties xmlProperties = PropertiesHelper.translateXMLToText(xmlPropertyFile, juddiPropertyFile, JUDDI_PROPERTY_FILE_COMMENTS) ;
-        System.setProperty("juddi.propertiesFile", juddiPropertyFile.getAbsolutePath());
-        System.setProperty("javax.xml.registry.ConnectionFactoryClass","org.apache.ws.scout.registry.ConnectionFactoryImpl");
-        
-        // Support token replacement
-        initializeTokenHash(); 
-        for (Enumeration e = xmlProperties.keys(); e.hasMoreElements();) {
-        	String key = (String) e.nextElement();
-        	String value = xmlProperties.getProperty(key);
-        	for (String tokenKey : tokenHash.keySet()) {
-        		String tokenValue = tokenHash.get(tokenKey);
-        		if (value.contains(tokenKey)) {
-        			value = value.replace(tokenKey, tokenValue);
-        			System.setProperty(key, value);
-        			xmlProperties.setProperty(key, value);
-        		}
-        	}	
-        }
-        
-        // Rewrite for token replacement
-        FileOutputStream rewritePropertyOS = new FileOutputStream(juddiPropertyFile) ;
+        final ByteArrayInputStream bais = new ByteArrayInputStream(propertyFileContents) ;
+        final FileOutputStream juddiPropertyOS = new FileOutputStream(juddiPropertyFile) ;
+        final Properties xmlProperties ;
         try {
-        	rewritePropertyOS = new FileOutputStream(juddiPropertyFile);
-            final BufferedOutputStream bos = new BufferedOutputStream(rewritePropertyOS) ;
-            xmlProperties.store(bos, JUDDI_PROPERTY_FILE_COMMENTS) ;
-            bos.flush() ;
+            xmlProperties = PropertiesHelper.translateXMLToText(bais, juddiPropertyOS, JUDDI_PROPERTY_FILE_COMMENTS) ;
         } finally {
-        	rewritePropertyOS.close();
+            juddiPropertyOS.close() ;
         }
+        System.setProperty("juddi.propertiesFile", juddiPropertyFile.getAbsolutePath());
+        System.setProperty("javax.xml.registry.ConnectionFactoryClass","org.apache.ws.scout.registry.ConnectionFactoryImpl");
         
         // Read properties from file and if they exist - pass them on to juddi as system properties
-        // Do not pass back the properties back if 
         String factoryInitial =  xmlProperties.getProperty(PROPNAME_JAVA_NAMING_FACTORY_INITIAL, null);
         String providerURL = xmlProperties.getProperty(PROPNAME_JAVA_NAMING_PROVIDER_URL, null); 
         String factoryURLPkgs = xmlProperties.getProperty(PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS, null);

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,229 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.jboss.internal.soa.esb.util.stax.ParsingSupport;
+import org.jboss.internal.soa.esb.util.stax.StreamHelper;
+import org.jboss.util.StringPropertyReplacer;
+
+/**
+ * Helper class for manipulating XML documents.
+ * 
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+public class XMLHelper
+{
+    /**
+     * The XML input factory.
+     */
+    private static final XMLInputFactory XML_INPUT_FACTORY = getXMLInputFactory() ;
+    /**
+     * The XML output factory.
+     */
+    private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance() ;
+
+    /**
+     * Get the XML stream reader.
+     * @param reader The input reader.
+     * @return The XML stream reader.
+     * @throws XMLStreamException For errors obtaining an XML stream reader.
+     */
+    public static XMLStreamReader getXMLStreamReader(final Reader reader)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLStreamReader(reader) ;
+    }
+
+    /**
+     * Get the XML stream reader.
+     * @param is The input stream.
+     * @return The XML stream reader.
+     * @throws XMLStreamException For errors obtaining an XML stream reader.
+     */
+    public static XMLStreamReader getXMLStreamReader(final InputStream is)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLStreamReader(is) ;
+    }
+
+    /**
+     * Get the XML stream reader.
+     * @param is The input stream.
+     * @param encoding The input stream encoding.
+     * @return The XML stream reader.
+     * @throws XMLStreamException For errors obtaining an XML stream reader.
+     */
+    public static XMLStreamReader getXMLStreamReader(final InputStream is, final String encoding)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLStreamReader(is, encoding) ;
+    }
+
+    /**
+     * Get the XML stream writer.
+     * @param writer The output writer.
+     * @return The XML stream writer.
+     * @throws XMLStreamException For errors obtaining an XML stream writer.
+     */
+    public static XMLStreamWriter getXMLStreamWriter(final Writer writer)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLStreamWriter(writer) ;
+    }
+
+    /**
+     * Get the XML stream writer.
+     * @param os The output stream.
+     * @return The XML stream writer.
+     * @throws XMLStreamException For errors obtaining an XML stream writer.
+     */
+    public static XMLStreamWriter getXMLStreamWriter(final OutputStream os)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLStreamWriter(os) ;
+    }
+
+    /**
+     * Get the XML stream writer.
+     * @param os The output stream.
+     * @param encoding The output stream encoding.
+     * @return The XML stream writer.
+     * @throws XMLStreamException For errors obtaining an XML stream writer.
+     */
+    public static XMLStreamWriter getXMLStreamWriter(final OutputStream os, final String encoding)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLStreamWriter(os, encoding) ;
+    }
+    
+    /**
+     * Replace system property values within the attribute values/text elements.
+     * @param streamReader The XML stream reader.
+     * @param streamWriter The XMl stream writer.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    public static void replaceSystemProperties(final XMLStreamReader streamReader,
+        final XMLStreamWriter streamWriter)
+        throws XMLStreamException
+    {
+        streamWriter.writeStartDocument() ;
+        
+        StreamHelper.skipToStartElement(streamReader) ;
+        final QName elementName = streamReader.getName() ;
+        final String uri = StreamHelper.writeStartElement(streamWriter, elementName) ;
+        
+        new SystemPropertyReplacementParser(streamReader, streamWriter) ;
+        
+        StreamHelper.writeEndElement(streamWriter, elementName.getPrefix(), uri) ;
+        
+        streamWriter.writeEndDocument() ;
+        streamWriter.flush() ;
+    }
+
+    /**
+     * Create the XML input factory.
+     * @return The XML input factory.
+     */
+    private static XMLInputFactory getXMLInputFactory()
+    {
+        final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance() ;
+        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE) ;
+        return xmlInputFactory ;
+    }
+    
+    /**
+     * The parser class used to perform system property replacement.
+     * @author kevin
+     */
+    private static final class SystemPropertyReplacementParser extends ParsingSupport
+    {
+        /**
+         * The output writer.
+         */
+        private final XMLStreamWriter out ;
+        
+        /**
+         * Construct the parser.
+         * @param in The XML input stream.
+         * @param out The XML output stream.
+         * @throws XMLStreamException For errors during parsing.
+         */
+        SystemPropertyReplacementParser(final XMLStreamReader in, final XMLStreamWriter out)
+            throws XMLStreamException
+        {
+            this.out = out ;
+            parse(in) ;
+        }
+        
+        /**
+         * Set the text value of this element.
+         * @param in The current input stream.
+         * @param value The text value of this element.
+         * @throws XMLStreamException For errors during parsing.
+         */
+        protected void putValue(final XMLStreamReader in, final String value)
+            throws XMLStreamException
+        {
+            out.writeCharacters(StringPropertyReplacer.replaceProperties(value)) ;
+        }
+        
+        /**
+         * Add the attribute value.
+         * @param in The current input stream.
+         * @param attributeName The qualified attribute name.
+         * @param attributeValue The qualified attribute value.
+         * @throws XMLStreamException For errors during parsing.
+         */
+        protected void putAttribute(final XMLStreamReader in,
+            final QName attributeName, final String attributeValue)
+            throws XMLStreamException
+        {
+            StreamHelper.writeAttribute(out, attributeName, StringPropertyReplacer.replaceProperties(attributeValue)) ;
+        }
+        
+        /**
+         * Add the element.
+         * @param in The current input stream.
+         * @param elementName The qualified element name.
+         * @throws XMLStreamException For errors during parsing.
+         */
+        protected void putElement(final XMLStreamReader in,
+            final QName elementName)
+            throws XMLStreamException
+        {
+            final String uri = StreamHelper.writeStartElement(out, elementName) ;
+            new SystemPropertyReplacementParser(in, out) ;
+            StreamHelper.writeEndElement(out, elementName.getPrefix(), uri) ;
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ElementContent.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ElementContent.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ElementContent.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util.stax;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Utility class providing support for all elements.
+ * @author kevin
+ */
+public abstract class ElementContent extends ParsingSupport
+{
+    /**
+     * Write the contents of the element.
+     * @param out The output stream.
+     * @throws XMLStreamException For errors during output.
+     */
+    public void writeContent(final XMLStreamWriter out)
+        throws XMLStreamException
+    {
+        writeAttributes(out) ;
+        writeChildContent(out) ;
+    }
+    
+    /**
+     * Write the attributes of the element.
+     * @param out The output stream.
+     * @throws XMLStreamException For errors during output.
+     */
+    protected void writeAttributes(final XMLStreamWriter out)
+        throws XMLStreamException
+    {
+    }
+    
+    /**
+     * Write the child content of the element.
+     * @param out The output stream.
+     * @throws XMLStreamException For errors during output.
+     */
+    protected void writeChildContent(final XMLStreamWriter out)
+        throws XMLStreamException
+    {
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ElementContent.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ParsingSupport.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ParsingSupport.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ParsingSupport.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util.stax;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Utility class providing support for parsing.
+ * @author kevin
+ */
+public abstract class ParsingSupport
+{
+    /**
+     * Is the configuration of this element valid?
+     * @return true if valid, false otherwise.
+     */
+    public boolean isValid()
+    {
+        return true ;
+    }
+    
+    /**
+     * Parse the contents of this element from the input stream.
+     * @param in The input stream.
+     */
+    protected final void parse(final XMLStreamReader in)
+        throws XMLStreamException
+    {
+        final int attributeCount = in.getAttributeCount() ;
+        for(int count = 0 ; count < attributeCount ; count++)
+        {
+            final QName attributeName = in.getAttributeName(count) ;
+            final String attributeValue = in.getAttributeValue(count) ;
+            putAttribute(in, attributeName, attributeValue) ;
+        }
+        
+        final QName name = in.getName() ;
+        boolean finished = false ;
+        
+        do
+        {
+            final int type = in.next() ;
+            switch(type)
+            {
+                case XMLStreamConstants.START_ELEMENT:
+                    final QName startElementName = in.getName() ;
+                    putElement(in, startElementName) ;
+                    in.require(XMLStreamConstants.END_ELEMENT, startElementName.getNamespaceURI(),
+                        startElementName.getLocalPart()) ;
+                    break ;
+                case XMLStreamConstants.END_ELEMENT:
+                    in.require(type, name.getNamespaceURI(), name.getLocalPart()) ;
+                    finished = true ;
+                    break ;
+                case XMLStreamConstants.CDATA:
+                case XMLStreamConstants.CHARACTERS:
+                    putValue(in, in.getText()) ;
+                    break ;
+                case XMLStreamConstants.COMMENT:
+                case XMLStreamConstants.DTD:
+                case XMLStreamConstants.ENTITY_DECLARATION:
+                case XMLStreamConstants.ENTITY_REFERENCE:
+                case XMLStreamConstants.SPACE:
+                case XMLStreamConstants.NOTATION_DECLARATION:
+                case XMLStreamConstants.PROCESSING_INSTRUCTION:
+                    // Ignore these
+                    break ;
+                case XMLStreamConstants.ATTRIBUTE:
+                case XMLStreamConstants.START_DOCUMENT:
+                case XMLStreamConstants.END_DOCUMENT:
+                case XMLStreamConstants.NAMESPACE:
+                    throw new XMLStreamException("Encountered unexpected event type: " + type) ;
+            }
+        }
+        while(!finished) ;
+    }
+    
+    /**
+     * Set the text value of this element.
+     * @param in The current input stream.
+     * @param value The text value of this element.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    protected void putValue(final XMLStreamReader in, final String value)
+        throws XMLStreamException
+    {
+    }
+    
+    /**
+     * Add the attribute value.
+     * @param in The current input stream.
+     * @param attributeName The qualified attribute name.
+     * @param attributeValue The qualified attribute value.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    protected void putAttribute(final XMLStreamReader in,
+        final QName attributeName, final String attributeValue)
+        throws XMLStreamException
+    {
+    }
+    
+    /**
+     * Add the element.
+     * @param in The current input stream.
+     * @param elementName The qualified element name.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    protected abstract void putElement(final XMLStreamReader in,
+        final QName elementName)
+        throws XMLStreamException ;
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/ParsingSupport.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/QNameHelper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/QNameHelper.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/QNameHelper.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util.stax;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+/**
+ * Helper class for manipulating QNames.
+ * @author kevin
+ */
+public class QNameHelper
+{
+    /**
+     * Return a qualified representation of the qname.
+     * @param qname The qname.
+     * @return The qualified name.
+     */
+    public static String toQualifiedName(final QName qname)
+    {
+        return toQualifiedName(qname.getPrefix(), qname.getLocalPart()) ;
+    }
+    
+    /**
+     * Return a qualified representation of the prefix and local name.
+     * @param prefix The prefix.
+     * @param localName The local name.
+     * @return The qualified name.
+     */
+    public static String toQualifiedName(final String prefix, final String localName)
+    {
+        if ((prefix == null) || (prefix.length() == 0))
+        {
+            return localName ;
+        }
+        else
+        {
+            return prefix + ":" + localName ;
+        }
+    }
+    
+    /**
+     * Return the qname represented by the qualified name.
+     * @param namespaceContext The namespace context.
+     * @param qualifiedName The qualified name.
+     * @return The qname.
+     */
+    public static QName toQName(final NamespaceContext namespaceContext, final String qualifiedName)
+    {
+        final int index = qualifiedName.indexOf(':') ;
+        if (index == -1)
+        {
+            return new QName(qualifiedName) ;
+        }
+        else
+        {
+            final String prefix = qualifiedName.substring(0, index) ;
+            final String localName = qualifiedName.substring(index+1) ;
+            
+            final String namespaceURI = getNormalisedValue(namespaceContext.getNamespaceURI(prefix)) ;
+            return new QName(namespaceURI, localName, prefix) ;
+        }
+    }
+
+    /**
+     * Get the normalised value of the string.
+     * @param value The string value.
+     * @return The normalised value.
+     */
+    public static String getNormalisedValue(final String value)
+    {
+        if (value == null)
+        {
+            return "" ;
+        }
+        else
+        {
+            return value ;
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/QNameHelper.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/StreamHelper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/StreamHelper.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/StreamHelper.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,366 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util.stax;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Helper class for Stream operations.
+ * @author kevin
+ */
+public class StreamHelper
+{
+    /**
+     * Pseudo namespace used to unbind a prefix.
+     */
+    private static final String UNBOUND_NAMESPACE = "http://www.jboss.com/stax/parsing/unboundnamespace" ;
+    
+    /**
+     * Write a start element with appropriate namespace declarations if necessary
+     * @param out The output stream.
+     * @param elementName The element name.
+     * @return The previous namespace if written, null otherwise.
+     * @throws XMLStreamException for errors during writing.
+     */
+    public static String writeStartElement(final XMLStreamWriter out, final QName elementName)
+        throws XMLStreamException
+    {
+        final String namespaceURI = QNameHelper.getNormalisedValue(elementName.getNamespaceURI()) ;
+        final String localName = elementName.getLocalPart() ;
+        
+        final NamespaceContext namespaceContext = out.getNamespaceContext() ;
+        final boolean writeNamespace = (namespaceContext.getPrefix(namespaceURI) == null) ;
+        
+        if (writeNamespace)
+        {
+            final String prefix = QNameHelper.getNormalisedValue(elementName.getPrefix()) ;
+            final String origNamespace = QNameHelper.getNormalisedValue(namespaceContext.getNamespaceURI(prefix)) ;
+            if (prefix.length() == 0)
+            {
+                out.setDefaultNamespace(namespaceURI) ;
+                out.writeStartElement(namespaceURI, localName) ;
+                out.writeDefaultNamespace(namespaceURI) ;
+            }
+            else
+            {
+                out.setPrefix(prefix, namespaceURI) ;
+                out.writeStartElement(namespaceURI, localName) ;
+                out.writeNamespace(prefix, namespaceURI) ;
+            }
+            return origNamespace ;
+        }
+        else
+        {
+            out.writeStartElement(namespaceURI, localName) ;
+            return null ;
+        }
+    }
+    
+    /**
+     * Write an end element removing the namespace binding if necessary
+     * @param out The output stream.
+     * @param prefix The element prefix.
+     * @param namespaceURI The previous binding for the prefix.
+     * @throws XMLStreamException for errors during writing.
+     */
+    public static void writeEndElement(final XMLStreamWriter out, final String prefix,
+        final String namespaceURI)
+        throws XMLStreamException
+    {
+        out.writeEndElement() ;
+        if (namespaceURI != null)
+        {
+            final String resetNamespace = (namespaceURI.length() == 0 ? UNBOUND_NAMESPACE : namespaceURI) ;
+            
+            if (prefix.length() == 0)
+            {
+                out.setDefaultNamespace(resetNamespace) ;
+            }
+            else
+            {
+                out.setPrefix(prefix, resetNamespace) ;
+            }
+        }
+    }
+    
+    /**
+     * Write the element to the stream.
+     * @param out The output stream.
+     * @param elementName The name of the element.
+     * @param elementContent The element contents.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeElement(final XMLStreamWriter out, final QName elementName,
+        final ElementContent elementContent)
+        throws XMLStreamException
+    {
+        final String origNamespace = writeStartElement(out, elementName) ;
+        elementContent.writeContent(out) ;
+        writeEndElement(out, elementName.getPrefix(), origNamespace) ;
+    }
+
+    /**
+     * Write the attributes to the stream.
+     * @param out The output stream.
+     * @param attributes The attributes.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeAttributes(final XMLStreamWriter out, final Map<QName, Object> attributes)
+        throws XMLStreamException
+    {
+        final Set<Map.Entry<QName, Object>> entrySet = attributes.entrySet() ;
+        final Iterator<Map.Entry<QName, Object>> entryIter = entrySet.iterator() ;
+        while(entryIter.hasNext())
+        {
+            final Map.Entry<QName, Object> entry = entryIter.next() ;
+            final QName name = (QName)entry.getKey() ;
+            final Object value = entry.getValue() ;
+            writeAttribute(out, name, value) ;
+        }
+    }
+    
+    /**
+     * Write the attribute to the stream.
+     * @param out The output stream.
+     * @param attributeName The attribute name.
+     * @param attributeValue The attribute value.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeAttribute(final XMLStreamWriter out, final QName attributeName,
+        final Object attributeValue)
+        throws XMLStreamException
+    {
+        if (attributeValue instanceof QName)
+        {
+            writeAttribute(out, attributeName, (QName)attributeValue) ;
+        }
+        else
+        {
+            writeAttribute(out, attributeName, attributeValue.toString()) ;
+        }
+    }
+    
+    /**
+     * Write the attribute to the stream.
+     * @param out The output stream.
+     * @param attributeName The attribute name.
+     * @param attributeValue The attribute value as a QName.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeAttribute(final XMLStreamWriter out, final QName attributeName,
+        final QName attributeValue)
+        throws XMLStreamException
+    {
+        final String namespaceURI = QNameHelper.getNormalisedValue(attributeValue.getNamespaceURI()) ;
+        if (namespaceURI.length() == 0)
+        {
+            writeAttribute(out, attributeName, attributeValue.getLocalPart()) ;
+        }
+        else
+        {
+            final NamespaceContext namespaceContext = out.getNamespaceContext() ;
+            final String origPrefix = namespaceContext.getPrefix(namespaceURI) ;
+            
+            if (origPrefix == null)
+            {
+                final String prefix = QNameHelper.getNormalisedValue(attributeValue.getPrefix()) ;
+                writeNamespace(out, prefix, namespaceURI) ;
+                writeAttribute(out, attributeName, QNameHelper.toQualifiedName(attributeValue)) ;
+            }
+            else
+            {
+                writeAttribute(out, attributeName, QNameHelper.toQualifiedName(origPrefix, attributeValue.getLocalPart())) ;
+            }
+        }
+    }
+    
+    /**
+     * Write the attribute to the stream.
+     * @param out The output stream.
+     * @param attributeName The attribute name.
+     * @param attributeValue The attribute value.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeAttribute(final XMLStreamWriter out, final QName attributeName,
+        final String attributeValue)
+        throws XMLStreamException
+    {
+        final String namespaceURI = QNameHelper.getNormalisedValue(attributeName.getNamespaceURI()) ;
+        final String localName = attributeName.getLocalPart() ;
+        
+        if (namespaceURI.length() == 0)
+        {
+            out.writeAttribute(localName, attributeValue) ;
+        }
+        else
+        {
+            final String prefix = QNameHelper.getNormalisedValue(attributeName.getPrefix()) ;
+            writeNamespace(out, prefix, namespaceURI) ;
+            out.writeAttribute(namespaceURI, localName, attributeValue) ;
+        }
+    }
+    
+    /**
+     * Write the QName to the stream as text.
+     * @param out The output stream.
+     * @param qName The qualified name.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeQualifiedName(final XMLStreamWriter out, final QName qName)
+        throws XMLStreamException
+    {
+        final String namespaceURI = QNameHelper.getNormalisedValue(qName.getNamespaceURI()) ;
+        
+        if (namespaceURI.length() == 0)
+        {
+            out.writeCharacters(QNameHelper.toQualifiedName(qName)) ;
+        }
+        else
+        {
+            final NamespaceContext namespaceContext = out.getNamespaceContext() ;
+            final String origPrefix = namespaceContext.getPrefix(namespaceURI) ;
+            
+            if (origPrefix == null)
+            {
+                final String prefix = QNameHelper.getNormalisedValue(qName.getPrefix()) ;
+                writeNamespace(out, prefix, namespaceURI) ;
+                out.writeCharacters(QNameHelper.toQualifiedName(qName)) ;
+            }
+            else
+            {
+                out.writeCharacters(QNameHelper.toQualifiedName(origPrefix, qName.getLocalPart())) ;
+            }
+        }
+    }
+    
+    /**
+     * Write the namespace if necessary.
+     * @param out The output stream.
+     * @param prefix The namespace prefix.
+     * @param namespaceURI The namespaceURI.
+     * @throws XMLStreamException Thrown for errors during writing.
+     */
+    public static void writeNamespace(final XMLStreamWriter out, final String prefix, final String namespaceURI)
+        throws XMLStreamException
+    {
+        final NamespaceContext namespaceContext = out.getNamespaceContext() ;
+            
+        final boolean writeNamespace = (namespaceContext.getPrefix(namespaceURI) == null) ;
+        if (writeNamespace)
+        {
+            out.setPrefix(prefix, namespaceURI) ;
+            out.writeNamespace(prefix, namespaceURI) ;
+        }
+    }
+
+    /**
+     * Make sure the stream is at the start of the next element.
+     * @param streamReader The current stream reader.
+     * @throws XMLStreamException For parsing errors.
+     */
+    public static void skipToNextStartElement(final XMLStreamReader streamReader)
+        throws XMLStreamException
+    {
+        if (streamReader.hasNext())
+        {
+            streamReader.nextTag() ;
+            if (streamReader.isEndElement())
+            {
+                throw new XMLStreamException("Unexpected end element: " + streamReader.getName()) ;
+            }
+        }
+        else
+        {
+            throw new XMLStreamException("Unexpected end of document reached") ;
+        }
+    }
+
+    /**
+     * Make sure the stream is at the start of an element.
+     * @param streamReader The current stream reader.
+     * @throws XMLStreamException For parsing errors.
+     */
+    public static void skipToStartElement(final XMLStreamReader streamReader)
+        throws XMLStreamException
+    {
+        while (!streamReader.isStartElement())
+        {
+            if (streamReader.hasNext())
+            {
+                streamReader.next() ;
+            }
+            else
+            {
+                throw new XMLStreamException("Unexpected end of document reached") ;
+            }
+        }
+    }
+
+    /**
+     * Check the next start tag is as expected.
+     * @param streamReader The stream reader.
+     * @param expected The expected qualified name.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    public static void checkNextStartTag(final XMLStreamReader streamReader, final QName expected)
+        throws XMLStreamException
+    {
+        skipToNextStartElement(streamReader) ;
+        checkTag(streamReader, expected) ;
+    }
+    
+    /**
+     * Compare the element tag with the expected qualified name.
+     * @param streamReader The current stream reader.
+     * @param expected The expected qualified name.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    public static void checkTag(final XMLStreamReader streamReader, final QName expected)
+        throws XMLStreamException
+    {
+        final QName elementName = streamReader.getName() ;
+        if (!expected.equals(elementName))
+        {
+            throw new XMLStreamException("Unexpected start element: " + elementName) ;
+        }
+    }
+
+    /**
+     * Check to see if the parent element is finished.
+     * @param streamReader The stream reader.
+     * @return true if it is finished, false otherwise.
+     * @throws XMLStreamException For errors during parsing.
+     */
+    public static boolean checkParentFinished(final XMLStreamReader streamReader)
+        throws XMLStreamException
+    {
+        return (streamReader.nextTag() == XMLStreamConstants.END_ELEMENT) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/stax/StreamHelper.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/JBossESBPropertyService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/JBossESBPropertyService.java	2007-12-04 11:45:07 UTC (rev 17010)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/JBossESBPropertyService.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -21,12 +21,19 @@
 package org.jboss.soa.esb.common;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.URL;
 
 import javax.transaction.Status;
 import javax.transaction.TransactionManager;
 
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.system.server.ServerConfig;
+import org.jboss.system.server.ServerConfigLocator;
 import org.jboss.tm.TransactionManagerLocator;
 
 /**
@@ -36,6 +43,11 @@
 public class JBossESBPropertyService extends ServiceMBeanSupport implements JBossESBPropertyServiceMBean
 {
     /**
+     * The name of the ESB property file.
+     */
+    private static final String ESB_PROPERTY_FILE = "jbossesb-properties.xml";
+    
+    /**
      * The current property file name.
      */
     private String propertyFile ;
@@ -67,14 +79,31 @@
     {
         if (propertyFile != null)
         {
-            final File propertyFile = new File(this.propertyFile) ;
-            if (propertyFile.isAbsolute())
-            {
-                System.setProperty(Environment.PROPERTIES_FILE, "abs://" + propertyFile.getAbsolutePath());
+            final File baseFile = new File(this.propertyFile) ;
+            final InputStream xmlPropertyIS ;
+            if (!baseFile.isAbsolute()) {
+                final URL resourceURL = Thread.currentThread().getContextClassLoader().getResource(propertyFile) ;
+                xmlPropertyIS = resourceURL.openStream() ;
+            } else {
+                xmlPropertyIS = new FileInputStream(baseFile) ;
             }
-            else
-            {
-                System.setProperty(Environment.PROPERTIES_FILE, this.propertyFile);
+            
+            try {
+                final ServerConfig serverConfig = ServerConfigLocator.locate() ;
+                final File dataDir = serverConfig.getServerDataDir() ;
+                final File esbPropertyFile = new File(dataDir, ESB_PROPERTY_FILE) ;
+                
+                final FileOutputStream esbPropertyOS = new FileOutputStream(esbPropertyFile) ;
+                try {
+                    XMLHelper.replaceSystemProperties(XMLHelper.getXMLStreamReader(xmlPropertyIS),
+                        XMLHelper.getXMLStreamWriter(esbPropertyOS)) ;
+                } finally {
+                    esbPropertyOS.close() ;
+                }
+                
+                System.setProperty(Environment.PROPERTIES_FILE, "abs://" + esbPropertyFile.getAbsolutePath());
+            } finally {
+                xmlPropertyIS.close() ;
             }
         }
         // We also setup the transaction strategy here

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java	2007-12-04 11:45:07 UTC (rev 17010)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -24,6 +24,7 @@
 import java.io.File;
 import java.io.InputStream;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -43,6 +44,7 @@
 import org.jboss.deployment.DeploymentInfo;
 import org.jboss.deployment.SubDeployer;
 import org.jboss.deployment.SubDeployerSupport;
+import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.MetaData;
 import org.jboss.metadata.XmlFileLoader;
@@ -315,9 +317,19 @@
             }
          }
 
-         InputStream inputStream = document.openStream();
-         String jbossEsbXml = Configuration.getStringFromStream(inputStream);
-         inputStream.close();
+         final InputStream inputStream = document.openStream();
+         final String jbossEsbXml ;
+         try
+         {
+             final StringWriter sw = new StringWriter() ;
+             XMLHelper.replaceSystemProperties(XMLHelper.getXMLStreamReader(inputStream),
+                 XMLHelper.getXMLStreamWriter(sw)) ;
+             jbossEsbXml = sw.toString();
+         }
+         finally
+         {
+             inputStream.close();
+         }
          
          addActionDependencies(di.shortName, jbossEsbXml, deps) ;
          

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util;
+
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.Properties;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests associated with the XML helper class.
+ * 
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+public class XMLHelperUnitTest extends TestCase
+{
+    public void testReplaceSystemProperties()
+        throws Exception
+    {
+        final Properties props = System.getProperties() ;
+        props.setProperty("test.property.attributeValue1", " testAttributeValue1 ") ;
+        props.setProperty("test.property.attributeValue2", "testAttributeValue2") ;
+        props.setProperty("test.property.attributeValue3", "${test.property.attributeValue1}") ;
+        props.setProperty("test.property.attributeValue4", "<testAttr/>") ;
+        props.setProperty("test.property.textValue1", "testTextValue1") ;
+        props.setProperty("test.property.textValue2", "${test.property.textValue2}") ;
+        props.setProperty("test.property.textValue3", "<testText/>") ;
+        
+        final InputStream is = getClass().getResourceAsStream("replaceSystemProperties_source.xml") ;
+        final XMLStreamReader streamReader = XMLHelper.getXMLStreamReader(is) ;
+        final String encoding = streamReader.getEncoding() ;
+        
+        final StringWriter sw = new StringWriter() ;
+        
+        XMLHelper.replaceSystemProperties(streamReader,
+            XMLHelper.getXMLStreamWriter(sw)) ;
+        final String contents = sw.toString().trim() ;
+        
+        final String expectedContents = StreamUtils.getResourceAsString("replaceSystemProperties_expected.xml", encoding).trim() ;
+
+        assertEquals("System property replacement", expectedContents, contents) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_expected.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_expected.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_expected.xml	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='UTF-8'?><test attr=" testAttributeValue1 ">
+   testTextValue1
+   <inner xmlns="http://www.jboss.org/jbossesb/test/property-namespace" attr=" testAttributeValue2 ">
+      <inner:inner xmlns:inner="http://www.jboss.org/jbossesb/test/property-namespace2" inner:attr="${test.property.attributeValue1}" inner:attr2="&lt;testAttr/>">
+         ${test.property.textValue2}
+         &lt;testText/>
+      </inner:inner>
+   </inner>
+</test>


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_expected.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_source.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_source.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_source.xml	2007-12-04 13:15:19 UTC (rev 17011)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<test attr="${test.property.attributeValue1}">
+   ${test.property.textValue1}
+   <inner xmlns="http://www.jboss.org/jbossesb/test/property-namespace" attr=" ${test.property.attributeValue2} ">
+      <inner:inner xmlns:inner="http://www.jboss.org/jbossesb/test/property-namespace2"
+         inner:attr="${test.property.attributeValue3}"
+         inner:attr2="${test.property.attributeValue4}">
+         ${test.property.textValue2}
+         ${test.property.textValue3}
+      </inner:inner>
+   </inner>
+</test>
\ No newline at end of file


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/replaceSystemProperties_source.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksService.java	2007-12-04 11:45:07 UTC (rev 17010)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksService.java	2007-12-04 13:15:19 UTC (rev 17011)
@@ -20,19 +20,19 @@
 package org.jboss.soa.esb.actions.converters;
 
 import org.jboss.internal.soa.esb.util.PropertiesHelper;
+import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.system.ServiceMBeanSupport;
 import org.jboss.system.server.ServerConfig;
 import org.jboss.system.server.ServerConfigLocator;
 import org.apache.log4j.Logger;
 
-import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.Enumeration;
-import java.util.Hashtable;
 import java.util.Properties;
 
 /**
@@ -51,20 +51,11 @@
     private static final String SMOOKS_PROPERTY_FILE = "smooks.esb.properties";
     private static final String SMOOKS_PROPERTY_FILE_COMMENTS = "Auto generated property file, do not edit" ;
 
-    private Hashtable<String, String> tokenHash;
-    
     /**
      * The smooks default property file.
      */
     private String propertyFile ;
     
-
-    public void initializeTokenHash() {
-    	tokenHash = new Hashtable<String,String>();
-        String bindAddress = System.getProperty("jboss.bind.address");
-        tokenHash.put("${jboss.bind.address}", bindAddress);
-    }
-    
     protected void startService() throws Exception {
         super.startService();
         
@@ -77,49 +68,28 @@
             } else {
                 xmlPropertyIS = new FileInputStream(baseFile) ;
             }
-            
+            final byte[] propertyFileContents ;
             try {
-                final ServerConfig serverConfig = ServerConfigLocator.locate() ;
-                final File dataDir = serverConfig.getServerDataDir() ;
-                final File smooksPropertyFile = new File(dataDir, SMOOKS_PROPERTY_FILE) ;
-                
-                final FileOutputStream smooksPropertyOS = new FileOutputStream(smooksPropertyFile) ;
-                Properties xmlProperties = null;
-                try {
-                	xmlProperties = PropertiesHelper.translateXMLToText(xmlPropertyIS, smooksPropertyOS, SMOOKS_PROPERTY_FILE_COMMENTS) ;
-                    SmooksConfiguration.setDefaultConfiguration(smooksPropertyFile.getAbsolutePath()) ;
-                    
-                } finally {
-                    smooksPropertyOS.close() ;
-                }
-                
-                // Support ${jboss.bind.address} replacement
-                initializeTokenHash(); 
-                for (Enumeration e = xmlProperties.keys(); e.hasMoreElements();) {
-                	String key = (String) e.nextElement();
-                	String value = xmlProperties.getProperty(key);
-                	for (String tokenKey : tokenHash.keySet()) {
-                		String tokenValue = tokenHash.get(tokenKey);
-                		if (value.contains(tokenKey)) {
-                			value = value.replace(tokenKey, tokenValue);
-                			xmlProperties.setProperty(key, value);
-                		}
-                	}	
-                }
-                
-                // Rewrite for token replacement
-                FileOutputStream rewritePropertyOS = new FileOutputStream(smooksPropertyFile) ;
-                try {
-                	rewritePropertyOS = new FileOutputStream(smooksPropertyFile);
-                    final BufferedOutputStream bos = new BufferedOutputStream(rewritePropertyOS) ;
-                    xmlProperties.store(bos, SMOOKS_PROPERTY_FILE_COMMENTS) ;
-                    bos.flush() ;
-                } finally {
-                	rewritePropertyOS.close();
-                }
+                final ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
+                XMLHelper.replaceSystemProperties(XMLHelper.getXMLStreamReader(xmlPropertyIS),
+                    XMLHelper.getXMLStreamWriter(baos)) ;
+                propertyFileContents = baos.toByteArray() ;
             } finally {
                 xmlPropertyIS.close() ;
             }
+            
+            final ServerConfig serverConfig = ServerConfigLocator.locate() ;
+            final File dataDir = serverConfig.getServerDataDir() ;
+            final File smooksPropertyFile = new File(dataDir, SMOOKS_PROPERTY_FILE) ;
+            
+            final ByteArrayInputStream bais = new ByteArrayInputStream(propertyFileContents) ;
+            final FileOutputStream smooksPropertyOS = new FileOutputStream(smooksPropertyFile) ;
+            try {
+                PropertiesHelper.translateXMLToText(bais, smooksPropertyOS, SMOOKS_PROPERTY_FILE_COMMENTS) ;
+            } finally {
+                smooksPropertyOS.close() ;
+            }
+            SmooksConfiguration.setDefaultConfiguration(smooksPropertyFile.getAbsolutePath()) ;
         }
 
         Properties smooksEsbConfig = new SmooksConfiguration();

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/build.xml	2007-12-04 11:45:07 UTC (rev 17010)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/build.xml	2007-12-04 13:15:19 UTC (rev 17011)
@@ -11,6 +11,9 @@
         <!-- JAXB Intros... -->
         <fileset dir="../../lib/ext" includes="jboss-jaxb-intros.jar"/>
 
+        <!-- StAX jars ... -->
+        <fileset dir="../../lib/ext" includes="xbean.jar stax-api-1.0.1.jar xstream-1.1.3.jar"/>
+
         <!-- Adding the Smooks jars... -->
         <fileset dir="../smooks/lib/ext" includes="*.jar"/>
     </path>

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/ognl-2.6.9.jar
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/stax-api-1.0.1.jar
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/wstx-lgpl-3.2.1.jar
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/xbean.jar
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/lib/ext/xstream-1.1.3.jar
===================================================================
(Binary files differ)




More information about the jboss-svn-commits mailing list