[jboss-svn-commits] JBL Code SVN: r7578 - in labs/jbossesb/workspace/b_georges/product/core: listeners/tests/src/org/jboss/soa/esb/actions rosetta/src/org/jboss/internal/soa/esb rosetta/src/org/jboss/internal/soa/esb/addressing rosetta/src/org/jboss/soa/esb rosetta/src/org/jboss/soa/esb/addressing

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 13 17:21:07 EST 2006


Author: b_georges
Date: 2006-11-13 17:21:00 -0500 (Mon, 13 Nov 2006)
New Revision: 7578

Removed:
   labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java
   labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl
   labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java
   labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java
   labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java
   labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/
   labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/
   labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/
Log:
sync with latest rel


Deleted: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java	2006-11-13 22:14:59 UTC (rev 7577)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java	2006-11-13 22:21:00 UTC (rev 7578)
@@ -1,110 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.soa.esb.actions;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.actions.converters.SmooksTransformer;
-import org.jboss.soa.esb.helpers.KeyValuePair;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-
-/**
- * SmooksTransformer unit tests.
- * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
- * @since Version 4.0
- */
-public class SmooksTransformerUnitTest extends TestCase {
-
-    @Override
-    protected void setUp() throws Exception {
-        SmooksTransformer.reset();
-    }
-
-    public void test_bad_config() {
-        List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
-
-        // Should get exceptions where required configs are missing...
-        assertConfigException(properties, "Action configuration 'message-type' not specified");
-        properties.add(new KeyValuePair("message-type", "111"));
-        assertConfigException(properties, "Action configuration 'message-from' not specified");
-        properties.add(new KeyValuePair("message-from", "AAA"));
-        assertConfigException(properties, "Action configuration 'message-to' not specified");
-        properties.add(new KeyValuePair("message-to", "BBB"));
-
-        // Should get an exception where the smooks-cdr.lst file is missing....
-        properties.add(new KeyValuePair("smooks-cdr.list-classpath-prefix", "/some/bad/cp/location/"));
-        assertConfigException(properties, "Failed to locate Smooks configuration list file [smooks-cdr.lst].  The folder containing this file must be located at");
-    }
-
-    public void test_trans() throws ActionProcessingException, ConfigurationException {
-        String stringMessage;
-        String transRes;
-        
-        // Very basic test!  Just illustrates profile based resource selection.
-        // Read the smooks-test.cdrl config file in this package!! 
-
-        // Initialise the acme order message...
-        stringMessage = "<a><ddd>value</ddd></a>";
-        
-        // Transform the order message going to "AcmePartner1"...
-        transRes = transform(stringMessage, "Acme-Order-XML", "Acme", "AcmePartner1");
-        assertEquals("<x><b>value</b></x>", transRes);
-        
-        // Transform the order message going to "AcmePartner2"...
-        transRes = transform(stringMessage, "Acme-Order-XML", "Acme", "AcmePartner2");
-        assertEquals("<x><c>value</c></x>", transRes);
-    }
-    
-    private String transform(String stringMessage, String type, String from, String to) throws ActionProcessingException, ConfigurationException {
-        List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
-
-        // Set the message properties in order to trigger the appropriate transformations
-        // on the message...
-        properties.add(new KeyValuePair("message-type", type));
-        properties.add(new KeyValuePair("message-from", from));
-        properties.add(new KeyValuePair("message-to", to));
-
-        // The smooks-cdr.lst and device-profile.xml files are located in the root of the 
-        // test src folder...
-        SmooksTransformer transformer = new SmooksTransformer("trans", properties);
-        
-        Message oMsg = MessageFactory.getInstance().getMessage();
-        ActionUtils.setTaskObject(oMsg,stringMessage);
-        oMsg = transformer.process(oMsg);
-        return (String) ActionUtils.getTaskObject(oMsg);
-    }
-
-    private void assertConfigException(List<KeyValuePair> properties, String expectedException) {
-        try {
-            new SmooksTransformer("trans", properties);
-            fail("Expected ConfigurationException: [" + expectedException + "...]");
-        } catch(ConfigurationException e) {
-            assertTrue("Expected exception message to start with [" + expectedException + "]. Was [" + e.getMessage() + "]", e.getMessage().startsWith(expectedException));
-        }
-    }
-}

Deleted: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl	2006-11-13 22:14:59 UTC (rev 7577)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl	2006-11-13 22:21:00 UTC (rev 7578)
@@ -1,28 +0,0 @@
-<?xml version='1.0'?>
-<!DOCTYPE smooks-resource-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://milyn.org/dtd/smooksres-list-1.0.dtd'>
-
-<smooks-resource-list>
-
-	<!-- 
-		"Acme-Order-XML" messages going from "Acme" to "AcmePartner1" 
-	-->
-	<smooks-resource useragent="type:Acme-Order-XML AND from:Acme AND to:AcmePartner1" selector="ddd" path="org.milyn.cdres.trans.RenameElementTU">
-		<param name="replacementElement">b</param>
-	</smooks-resource>
-
-	<!-- 
-		"Acme-Order-XML" messages going from "Acme" to "AcmePartner2" 
-	-->
-	<smooks-resource useragent="type:Acme-Order-XML AND from:Acme AND to:AcmePartner2" selector="ddd" path="org.milyn.cdres.trans.RenameElementTU">
-		<param name="replacementElement">c</param>
-	</smooks-resource>
-
-	<!-- 
-		"Acme-Order-XML" messages going from "Acme" to anywhere
-	-->
-	<smooks-resource useragent="type:Acme-Order-XML AND from:Acme" selector="a" path="org.milyn.cdres.trans.RenameElementTU">
-		<param name="replacementElement">x</param>
-	</smooks-resource>
-
-</smooks-resource-list>
-

Deleted: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java	2006-11-13 22:14:59 UTC (rev 7577)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java	2006-11-13 22:21:00 UTC (rev 7578)
@@ -1,215 +0,0 @@
-package org.jboss.internal.soa.esb.addressing;
-
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * 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 Lesser General Public License, v. 2.1.
- * 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 Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 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 mark.little at jboss.com
- */
-
-import java.net.URI;
-import java.security.InvalidParameterException;
-
-import org.jboss.soa.esb.addressing.Call;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.XMLUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class CallHelper
-{
-
-	public static Element toXML (Call call, Document doc, Element header)
-	{
-		if (call == null)
-			throw new InvalidParameterException();
-		
-		try
-		{
-			if (call.getTo() != null)
-			{
-				Element toElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG);
-				PortReferenceHelper.toXML(header, doc, toElement, call.getTo().getAddr(), true);
-				header.appendChild(toElement);
-			}
-			
-			if (call.getFrom() != null)
-			{
-				Element fromElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG);
-				PortReferenceHelper.toXML(header, doc, fromElement, call.getFrom().getAddr(), false);
-				header.appendChild(fromElement);
-			}
-			
-			if (call.getReplyTo() != null)
-			{
-				Element replyToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG);
-				PortReferenceHelper.toXML(header, doc, replyToElement, call.getReplyTo().getAddr(), false);
-				header.appendChild(replyToElement);
-			}
-			
-			if (call.getRelatesTo() != null)
-			{
-				Element relatesToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.RELATES_TO_TAG);
-				relatesToElement.setNodeValue(call.getRelatesTo().toString());
-				header.appendChild(relatesToElement);
-			}
-			
-			if (call.getFaultTo() != null)
-			{
-				Element faultToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG);
-				PortReferenceHelper.toXML(header, doc, faultToElement, call.getFaultTo().getAddr(), false);
-				header.appendChild(faultToElement);
-			}
-			
-			if (call.getAction() != null)
-			{
-				Element actionElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG);
-				actionElement.setNodeValue(call.getAction().toString());
-				header.appendChild(actionElement);
-			}
-			
-			if (call.getMessageID() != null)
-			{
-				Element messageIDElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG);
-				messageIDElement.setNodeValue(call.getMessageID().toString());
-				header.appendChild(messageIDElement);
-			}
-				
-			return header;
-		}
-		catch (Exception ex)
-		{
-			// TODO improve error handling.
-			
-			ex.printStackTrace();
-			
-			throw new InvalidParameterException(ex.toString());
-		}
-	}
-	
-	public static Call fromXML (Element header)
-	{
-		Call call = null;
-		
-		try
-		{
-			call = new Call();
-			
-			NodeList nl = header.getChildNodes();
-			
-			for (int i = 0; i < nl.getLength(); i++)
-			{
-				Node n = nl.item(i);
-				
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG))
-				{
-					try
-					{
-						call.setTo(new EPR(PortReferenceHelper.fromXML((Element) n, true)));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-				
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG))
-				{
-					try
-					{
-						call.setFrom(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-				
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG))
-				{
-					try
-					{
-						call.setReplyTo(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.RELATES_TO_TAG))
-				{
-					try
-					{
-						call.setRelatesTo(new URI(n.getNodeValue()));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG))
-				{
-					try
-					{
-						call.setFaultTo(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG))
-				{			
-					try
-					{
-						call.setAction(new URI(n.getNodeValue()));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-				
-				if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG))
-				{
-					try
-					{
-						call.setMessageID(new URI(n.getNodeValue()));
-					}
-					catch (Exception ex)
-					{
-						
-					}
-				}
-			}
-		}
-		catch (Exception ex)
-		{
-			// TODO error checking!!
-			
-			ex.printStackTrace();
-		}
-		
-		return call;
-	}
-	
-} 
\ No newline at end of file

Deleted: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java	2006-11-13 22:14:59 UTC (rev 7577)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java	2006-11-13 22:21:00 UTC (rev 7578)
@@ -1,173 +0,0 @@
-package org.jboss.internal.soa.esb.addressing;
-
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * 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 Lesser General Public License, v. 2.1.
- * 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 Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 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 mark.little at jboss.com
- */
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.net.URISyntaxException;
-import java.security.InvalidParameterException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.jboss.soa.esb.MarshalException;
-import org.jboss.soa.esb.addressing.EPR;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-import com.sun.org.apache.xml.internal.serialize.OutputFormat;
-import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
-
-public class EPRHelper
-{
-    public static final String ELEMENT_NAME = "EPR";
-    
-    public static final Element toXML (EPR epr, Document doc, Element header)
-    {
-	if (epr == null)
-	    throw new InvalidParameterException();
-
-	try
-	{
-        	PortReferenceHelper.toXML(null, doc, header, epr.getAddr(), false);
-        
-        	return header;
-	}
-	catch (URISyntaxException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-	catch (MarshalException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-    }
-
-    public static final String toXMLString (EPR epr)
-    {
-	if (epr == null)
-	    throw new InvalidParameterException();
-	
-	try
-	{
-	    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-	    DocumentBuilder builder = factory.newDocumentBuilder();
-	    Document doc = builder.newDocument();
-	    Element portReferenceElement = doc.createElement(ELEMENT_NAME);
-        
-	    doc.appendChild(portReferenceElement);
-        	
-	    toXML(epr, doc, portReferenceElement);
-	    
-	    StringWriter sWriter = new StringWriter();
-	    OutputFormat format = new OutputFormat();
-	    format.setIndenting(true);
-
-	    XMLSerializer xmlS = new XMLSerializer(sWriter, format);
-
-	    xmlS.asDOMSerializer();
-	    xmlS.serialize(doc);
-
-	    return sWriter.toString();
-	}
-	catch (IOException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-	catch (ParserConfigurationException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-    }
-    
-    public static final EPR fromXML (Element header)
-    {
-	if (header == null)
-	    throw new InvalidParameterException();
-	
-	try
-	{
-	    if (header.getNodeName().equals(ELEMENT_NAME))
-		return new EPR(PortReferenceHelper.fromXML(header, false));
-	    else
-		return null;
-	}
-	catch (MarshalException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-    }
-    
-    public static final EPR fromXMLString (String xml)
-    {
-	if (xml == null)
-	    throw new InvalidParameterException();
-	
-	try
-	{
-        	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        	DocumentBuilder builder = factory.newDocumentBuilder();
-        	Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
-        	Element rootElement = doc.getDocumentElement();
-        	
-        	return new EPR(PortReferenceHelper.fromXML(rootElement, false));
-	}
-	catch (MarshalException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-	catch (SAXException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-	catch (IOException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-	catch (ParserConfigurationException ex)
-	{
-	    ex.printStackTrace();
-	    
-	    return null;
-	}
-    }
-   
-}
\ No newline at end of file

Deleted: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java	2006-11-13 22:14:59 UTC (rev 7577)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java	2006-11-13 22:21:00 UTC (rev 7578)
@@ -1,430 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * 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 Lesser General Public License, v. 2.1.
- * 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 Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 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 mark.little at jboss.com
- */
-
-/*
- * Copyright (c) 2002, 2003, Arjuna Technologies Limited.
- *
- * PortReferenceHelper.java
- */
-
-package org.jboss.internal.soa.esb.addressing;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-
-import org.jboss.soa.esb.MarshalException;
-import org.jboss.soa.esb.addressing.PortReference;
-import org.jboss.soa.esb.addressing.XMLUtil;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-/*
- * This should pack the PortReference into an ERP.
- * 
- * It would be better if PortReference had a packToXML and unpackFromXML.
- * 
- * This needs rewriting after the interoperability workshop!
- */
-
-public class PortReferenceHelper
-{
-	/**
-	 * WS-Addressing is broken in that the To field is a URI, even if the From
-	 * field was an EPR! You have to use the EPR bits separately. So, the
-	 * toField is used to indicate whether we are packing this address as a To
-	 * field (when we need to treat it differently) or as an EPR.
-	 */
-
-	/** ************************************************** */
-	public static void toXML(org.w3c.dom.Element header,
-			org.w3c.dom.Document document,
-			org.w3c.dom.Element portReferenceElement,
-			PortReference portReference, boolean toField)
-			throws MarshalException
-	{
-		try
-		{
-			if (!toField)
-			{
-				Element addressElement = document.createElementNS(
-						XMLUtil.WSA_NAMESPACE_URI, XMLUtil.ADDRESS_TAG);
-				addressElement.setPrefix(XMLUtil.WSA_PREFIX);
-				addressElement.appendChild(document
-						.createTextNode(portReference.getAddress()));
-				portReferenceElement.appendChild(addressElement);
-			}
-			else
-			{
-				portReferenceElement.appendChild(document
-						.createTextNode(portReference.getAddress()));
-			}
-
-			Iterator extensions = portReference.getExtensions();
-			Element referenceProperties = null;
-
-			while (extensions.hasNext())
-			{
-				PortReference.Extension extension = (PortReference.Extension) extensions
-						.next();
-
-				/*
-				 * WS-Addressing is broken in that the To field is a URI, even
-				 * if the From field was an EPR! You have to use the EPR bits
-				 * separately. Doh!
-				 */
-
-				if (!toField)
-				{
-					if (referenceProperties == null)
-					{
-						referenceProperties = document.createElementNS(
-								XMLUtil.WSA_NAMESPACE_URI,
-								XMLUtil.REFERENCE_PROPERTIES_TAG);
-						referenceProperties.setPrefix(XMLUtil.WSA_PREFIX);
-						portReferenceElement.appendChild(referenceProperties);
-					}
-				}
-				else
-					referenceProperties = header;
-
-				extensionToXML(referenceProperties, document, extension);
-			}
-		}
-		catch (Exception exception)
-		{
-			exception.printStackTrace();
-			throw new MarshalException("Marshal failure: " + exception);
-		}
-	}
-
-	/** **************************** */
-	public static PortReference fromXML(
-			org.w3c.dom.Element portReferenceElement, boolean toField)
-			throws MarshalException
-	{
-		PortReference portReference = new PortReference();
-
-		if (toField)
-			portReference.setAddress(portReferenceElement.getTextContent());
-		
-		org.w3c.dom.NodeList elements = portReferenceElement.getChildNodes();
-
-		for (int i = 1; i < elements.getLength(); i++)
-		{
-			final Object extensionObject = elements.item(i);
-
-			if (extensionObject instanceof Element)
-			{
-				int parentNodeType = PortReference.Extension.NEITHER;
-				Element extensionElement = (Element) extensionObject;
-				NodeList children = extensionElement.getChildNodes();
-				String parentName = extensionElement.getNodeName();
-				boolean haveChildren = false;
-
-				if (parentName.equals(XMLUtil.REFERENCE_PROPERTIES_TAG))
-					parentNodeType = PortReference.Extension.REFERENCE_PROPERTIES;
-				else
-				{
-					if (parentName.equals(XMLUtil.REFERENCE_PARAMETERS_TAG))
-						parentNodeType = PortReference.Extension.REFERENCE_PARAMETERS;
-					else
-					{
-						if (!toField
-								&& parentName.equals(XMLUtil.WSA_PREFIX + ":"
-										+ XMLUtil.ADDRESS_TAG))
-						{
-							portReference.setAddress(extensionElement
-									.getTextContent());
-						}
-					}
-				}
-
-				final int numChildren = children.getLength();
-				
-				for (int count = 0; count < numChildren; count++)
-				{
-					final Object childObject = children.item(count);
-
-					if (childObject instanceof Element)
-					{
-						Element childElement = (Element) childObject;
-
-						portReference
-								.addExtension(childrenFromXML(childElement));
-						haveChildren = true;
-					}
-				}
-
-				if (!haveChildren && !parentName.equals(XMLUtil.WSA_PREFIX + ":"+ XMLUtil.ADDRESS_TAG))
-				{
-					PortReference.Extension ext = new PortReference.Extension(
-							extensionElement.getNodeName(), null, null,
-							extensionElement.getNodeValue(), parentNodeType);
-
-					portReference.addExtension(ext);
-
-					final NamedNodeMap attrs = extensionElement.getAttributes();
-					final int numAttrs = attrs.getLength();
-					if (numAttrs > 0)
-					{
-						final HashMap<ArjunaName, String> p = new HashMap<ArjunaName, String>();
-						for (int count = 0; count < numAttrs; count++)
-						{
-							final Attr attr = (Attr) attrs.item(count);
-							if (!"http://www.w3.org/2000/xmlns/".equals(attr
-									.getNamespaceURI()))
-							{
-								final ArjunaName name = generateName(attr);
-								p.put(name, attr.getValue());
-							}
-						}
-
-						ext.addAttributes(p);
-					}
-				}
-			}
-		}
-
-		return portReference;
-	}
-
-	private final static PortReference.Extension childrenFromXML(
-			Element childRoot)
-	{
-		final NodeList children = childRoot.getChildNodes();
-		final int numChildNodes = children.getLength();
-
-		final PortReference.Extension extension;
-		if (numChildNodes > 0)
-		{
-			Object childObject = children.item(0);
-			if (childObject instanceof Element)
-			{
-				extension = new PortReference.Extension(
-						childRoot.getNodeName(), childRoot.getPrefix(),
-						childRoot.getNamespaceURI());
-				
-				for (int count = 1; count < numChildNodes; count++)
-				{
-					extension.addChild(childrenFromXML((Element) childObject));
-					childObject = children.item(count);
-				}
-			}
-			else
-			{
-				extension = new PortReference.Extension(
-						childRoot.getNodeName(), childRoot.getPrefix(),
-						childRoot.getNamespaceURI(), ((Node) childObject)
-								.getNodeValue());
-			}
-		}
-		else
-		{
-			extension = new PortReference.Extension(childRoot.getNodeName(),
-					childRoot.getPrefix(), childRoot.getNamespaceURI(),
-					childRoot.getNodeValue());
-		}
-
-		final NamedNodeMap attrs = childRoot.getAttributes();
-		final int numAttrs = attrs.getLength();
-		if (numAttrs > 0)
-		{
-			final HashMap<ArjunaName, String> p = new HashMap<ArjunaName, String>();
-			for (int count = 0; count < numAttrs; count++)
-			{
-				final Attr attr = (Attr) attrs.item(count);
-				if (!"http://www.w3.org/2000/xmlns/".equals(attr
-						.getNamespaceURI()))
-				{
-					final ArjunaName name = generateName(attr);
-					p.put(name, attr.getValue());
-				}
-			}
-
-			extension.addAttributes(p);
-		}
-		return extension;
-	}
-
-	private final static Element extensionToXML(Element packInto,
-			org.w3c.dom.Document document, PortReference.Extension toPack)
-			throws MarshalException
-	{
-		final String uri = toPack.getURI();
-		final Element element;
-		if (uri == null)
-		{
-			element = document.createElement(toPack.getTag());
-		}
-		else
-		{
-			final String prefix = toPack.getPrefix();
-			element = document.createElementNS(uri, toPack.getTag());
-			element.setPrefix(prefix);
-			element.setAttributeNS(XMLUtil.XMLNS_URI, XMLUtil.XMLNS_PREFIX
-					+ toPack.getPrefix(), uri);
-		}
-		packInto.appendChild(element);
-
-		if (toPack.getValue() != null)
-		{
-			final Text text = document.createTextNode(toPack.getValue());
-			element.appendChild(text);
-		}
-
-		LinkedList extensions = toPack.getChildren();
-
-		if (extensions != null)
-		{
-			for (int i = 0; i < extensions.size(); i++)
-			{
-				PortReference.Extension ext = (PortReference.Extension) extensions
-						.get(i);
-
-				extensionToXML(element, document, ext);
-			}
-		}
-
-		HashMap attrs = toPack.getAttributes();
-
-		if (attrs != null)
-		{
-			Iterator names = attrs.entrySet().iterator();
-
-			while (names.hasNext())
-			{
-				Map.Entry entry = (Map.Entry) names.next();
-				ArjunaName name = (ArjunaName) entry.getKey();
-				final String value = (String) entry.getValue();
-				final String attrURI = name.toString();
-				if (attrURI != null)
-				{
-					element.setAttributeNS(attrURI, name.getQualifiedName(),
-							value);
-				}
-				else
-				{
-					element.setAttribute(name.getQualifiedName(), value);
-				}
-			}
-		}
-
-		return element;
-	}
-
-	/**
-	 * Generate a name based on the attribute.
-	 * 
-	 * @param attr
-	 *            The current attribute.
-	 * @return The name
-	 */
-	private static ArjunaName generateName(final Attr attr)
-	{
-		final String localName = attr.getNodeName();
-		final String uri = attr.getNamespaceURI();
-		final String prefix = attr.getPrefix();
-
-		return new ArjunaName(uri, prefix, localName);
-	}
-
-	private static class ArjunaName
-	{
-		/**
-		 * The uri.
-		 */
-		private final String uri;
-
-		/**
-		 * The prefix.
-		 */
-		private final String prefix;
-
-		/**
-		 * The local name.
-		 */
-		private final String localName;
-
-		/**
-		 * Construct the name.
-		 * 
-		 * @param uri
-		 *            The uri.
-		 * @param prefix
-		 *            The prefix.
-		 * @param localName
-		 *            The local name.
-		 */
-		public ArjunaName(final String uri, final String prefix,
-				final String localName)
-		{
-			this.uri = uri;
-			this.prefix = prefix;
-			this.localName = localName;
-		}
-
-		/**
-		 * Get the uri.
-		 * 
-		 * @return the uri.
-		 */
-		public String getURI()
-		{
-			return uri;
-		}
-
-		/**
-		 * Get the prefix.
-		 * 
-		 * @return the prefix.
-		 */
-		public String getPrefix()
-		{
-			return prefix;
-		}
-
-		/**
-		 * Get the local name.
-		 * 
-		 * @return the local name.
-		 */
-		public String getLocalName()
-		{
-			return localName;
-		}
-
-		/**
-		 * Get the qualified name.
-		 * 
-		 * @return the qualified name.
-		 */
-		public String getQualifiedName()
-		{
-			return (prefix == null ? localName : prefix + ":" + localName);
-		}
-	}
-}




More information about the jboss-svn-commits mailing list