[jboss-svn-commits] JBL Code SVN: r6657 - in labs/jbossesb/trunk/product/core/rosetta: src/org/jboss/soa/esb/addressing src/org/jboss/soa/esb/addressing/helpers tests/src/org/jboss/soa/esb/addressing tests/src/org/jboss/soa/esb/addressing/helpers tests/src/org/jboss/soa/esb/addressing/helpers/tests

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Oct 6 12:43:02 EDT 2006


Author: mark.little at jboss.com
Date: 2006-10-06 12:42:55 -0400 (Fri, 06 Oct 2006)
New Revision: 6657

Added:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java
Log:
Added EPR helper/wrapper classes.

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,164 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * 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
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using email style EPRs. Simply create and use instances of
+ * this type.
+ * 
+ * @author marklittle
+ *
+ */
+public class EmailEpr extends EPR
+{
+	public static final String DEFAULT_PORT = "25";
+	public static final String DEFAULT_USERNAME = "";
+	public static final String DEFAULT_PASSWORD = "";
+	
+	public static final String SMTP_PROTOCOL = "smtp";
+	public static final String POP_PROTOCOL = "pop";
+	
+	public static final String USERNAME_TAG = "username";
+	public static final String PASSWORD_TAG = "password";
+	
+	private static final String PROTOCOL_SEPARATOR = "://";
+	private static final String PORT_SEPARATOR = ":";
+	
+	/**
+	 * Create a new email EPR. The port number will be assumed to be 25,
+	 * and there are no values for username and password.
+	 * 
+	 * @param protocol the protocol to use.
+	 * @param host the host name.
+	 */
+	
+	public EmailEpr (String protocol, String host)
+	{
+		this(protocol, host, DEFAULT_PORT, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+	}
+	
+	/**
+	 * Create a new email EPR.
+	 * 
+	 * @param protocol the protocol to use.
+	 * @param host the host name.
+	 * @param port the port to use.
+	 * @param username the username for sending/receiving.
+	 * @param password the password for sending/receiving.
+	 */
+	
+	public EmailEpr (String protocol, String host, String port, String username, String password)
+	{
+		// how many of these do we really need? modify accordingly.
+		
+		if ((protocol == null) || (host == null) || (port == null))
+			throw new IllegalArgumentException();
+		
+		if ((protocol.equals(SMTP_PROTOCOL) || (protocol.equals(POP_PROTOCOL))))
+		{
+			PortReference addr = new PortReference(protocol+PROTOCOL_SEPARATOR+host+PORT_SEPARATOR+port);
+			
+			if (username != null)
+				addr.addExtension(USERNAME_TAG, username);
+			
+			if (password != null)
+				addr.addExtension(PASSWORD_TAG, password);
+			
+			setAddr(addr);
+		}
+		else
+			throw new IllegalArgumentException("Invalid email protocol!");
+	}
+	
+	/**
+	 * @return the email protocol used.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getProtocol () throws URISyntaxException
+	{
+		URI addr = new URI(getAddr().getAddress());
+		
+		return addr.getScheme();
+	}
+	
+	/**
+	 * @return the email host used.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getHost () throws URISyntaxException
+	{
+		URI addr = new URI(getAddr().getAddress());
+		
+		return addr.getHost();
+	}
+	
+	/**
+	 * @return the email port used, or -1 if not specified.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+
+	public final int getPort () throws URISyntaxException
+	{
+		URI addr = new URI(getAddr().getAddress());
+		
+		return addr.getPort();
+	}
+	
+	/*
+	 * There are deliberately no setters for the values once the EPR is created.
+	 */
+	
+	/**
+	 * @return the password for this EPR, or <code>null</code> if none is set.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getPassword () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(PASSWORD_TAG);
+	}
+	
+	/**
+	 * @return the username for this EPR, or <code>null</code> if none is set.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getUserName () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(USERNAME_TAG);
+	}
+
+} 
\ No newline at end of file

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,144 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * 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
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using FTP style EPRs. Simply create instances of this
+ * class instead of the base EPR. Since URLs can use FTP, we try to leverage
+ * that as much as possible.
+ * 
+ * @author marklittle
+ *
+ */
+public class FTPEpr extends EPR
+{
+	public static final String USERNAME_TAG = "username";
+	public static final String PASSWORD_TAG = "password";
+	
+	public FTPEpr (URL url) throws URISyntaxException
+	{
+		super(new URI(url.toString()));
+	}
+	
+	public FTPEpr (String url) throws URISyntaxException
+	{
+		super(new URI(url));
+	}
+
+	/**
+	 * Set the URL for this endpoint.
+	 * 
+	 * @param url the address.
+	 */
+	
+	public final void setURL (URL url)
+	{
+		super.setAddr(new PortReference(url.toString()));
+	}
+	
+	/**
+	 * Get the URL address.
+	 * 
+	 * @return the address.
+	 * @throws URISyntaxException thrown if the address is invalid.
+	 */
+	
+	public final URL getURL () throws MalformedURLException, URISyntaxException
+	{
+		return new URL(super.getAddr().getAddress());
+	}
+
+	/**
+	 * Set the username for this FTP EPR.
+	 * 
+	 * @param username the user's name.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final void setUserName (String username) throws URISyntaxException
+	{
+		if (username == null)
+			throw new IllegalArgumentException();
+		
+		if (userSet)
+			throw new IllegalStateException("Username already set.");
+		
+		getAddr().addExtension(USERNAME_TAG, username);
+		userSet = true;
+	}
+	
+	/**
+	 * @return the user's name associated with this EPR.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final String getUserName () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(USERNAME_TAG);
+	}
+	
+	/**
+	 * Set the password for this FTP EPR.
+	 * 
+	 * @param password the user's name.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final void setPassword (String password) throws URISyntaxException
+	{
+		if (password == null)
+			throw new IllegalArgumentException();
+		
+		if (passwordSet)
+			throw new IllegalStateException("Cannot change password");
+		
+		getAddr().addExtension(PASSWORD_TAG, password);
+		passwordSet = true;
+	}
+	
+	/**
+	 * @return the password associated with this EPR.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final String getPassword () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(PASSWORD_TAG);
+	}
+
+	private boolean passwordSet = false;
+	private boolean userSet = false;
+	
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,80 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * 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
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using HTTP style EPRs. Simply create instances of this
+ * class instead of the base EPR.
+ * 
+ * @author marklittle
+ *
+ */
+public class HTTPEpr extends EPR
+{
+
+	public HTTPEpr (URL url) throws URISyntaxException
+	{
+		super(new URI(url.toString()));
+	}
+	
+	public HTTPEpr (String url) throws URISyntaxException
+	{
+		super(new URI(url));
+	}
+	
+	/**
+	 * Set the URL for this endpoint.
+	 * 
+	 * @param url the address.
+	 */
+	
+	public final void setURL (URL url)
+	{
+		super.setAddr(new PortReference(url.toString()));
+	}
+	
+	/**
+	 * Get the URL address.
+	 * 
+	 * @return the address.
+	 * @throws URISyntaxException thrown if the address is invalid.
+	 */
+	
+	public final URL getURL () throws MalformedURLException, URISyntaxException
+	{
+		return new URL(super.getAddr().getAddress());
+	}
+
+} 
\ No newline at end of file

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,203 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * 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
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using database style EPRs. Simply create instances of this
+ * class instead of the base EPR.
+ * 
+ * @author marklittle
+ *
+ */
+
+public class JDBCEpr extends EPR
+{
+	public static final String JDBC_PROTOCOL = "jdbc";
+	
+	public static final String USERNAME_TAG = "username";
+	public static final String PASSWORD_TAG = "password";
+	public static final String SQL_TAG = "sql";
+	public static final String DRIVER_TAG = "driver";
+	
+	public JDBCEpr (String url, String sql) throws URISyntaxException
+	{
+		super(new URI(url));
+		
+		setSQL(sql);
+	}
+
+	/**
+	 * Set the URL for this endpoint.
+	 * 
+	 * @param url the address.
+	 */
+	
+	public final void setURL (String url)
+	{
+		super.setAddr(new PortReference(url));
+	}
+	
+	/**
+	 * Get the URL address.
+	 * 
+	 * @return the address.
+	 * @throws URISyntaxException thrown if the address is invalid.
+	 */
+	
+	public final String getURL () throws URISyntaxException
+	{
+		return getAddr().getAddress();
+	}
+
+	/**
+	 * Set the username for this FTP EPR.
+	 * 
+	 * @param username the user's name.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final void setUserName (String username) throws URISyntaxException
+	{
+		if (username == null)
+			throw new IllegalArgumentException();
+		
+		if (userSet)
+			throw new IllegalStateException("Username already set.");
+		
+		getAddr().addExtension(USERNAME_TAG, username);
+		userSet = true;
+	}
+	
+	/**
+	 * @return the user's name associated with this EPR.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final String getUserName () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(USERNAME_TAG);
+	}
+	
+	/**
+	 * Set the password for this FTP EPR.
+	 * 
+	 * @param password the user's name.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final void setPassword (String password) throws URISyntaxException
+	{
+		if (password == null)
+			throw new IllegalArgumentException();
+		
+		if (passwordSet)
+			throw new IllegalStateException("Password already set.");
+		
+		getAddr().addExtension(PASSWORD_TAG, password);
+		passwordSet = true;
+	}
+	
+	/**
+	 * @return the password associated with this EPR.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final String getPassword () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(PASSWORD_TAG);
+	}
+	
+	/**
+	 * Set the SQL command that is used by this EPR.
+	 * 
+	 * @param sql the statement.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final void setSQL (String sql) throws URISyntaxException
+	{
+		if (sql == null)
+			throw new IllegalArgumentException();
+		
+		if (sqlSet)
+			throw new IllegalStateException("SQL already set.");
+		
+		getAddr().addExtension(SQL_TAG, sql);
+		sqlSet = true;
+	}
+	
+	/**
+	 * @return the SQL statement for this EPR.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final String getSQL () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(SQL_TAG);
+	}
+	
+	/**
+	 * Set the driver that is used by this EPR.
+	 * 
+	 * @param driver the driver.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final void setDriver (String driver) throws URISyntaxException
+	{
+		if (driver == null)
+			throw new IllegalArgumentException();
+		
+		if (driverSet)
+			throw new IllegalStateException("Driver already set.");
+		
+		getAddr().addExtension(DRIVER_TAG, driver);
+		driverSet = true;
+	}
+	
+	/**
+	 * @return the driver used by this EPR.
+	 * @throws URISyntaxException thrown if this EPR is malformed.
+	 */
+	
+	public final String getDriver () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(DRIVER_TAG);
+	}
+	
+	private boolean userSet = false;
+	private boolean passwordSet = false;
+	private boolean sqlSet = false;
+	private boolean driverSet = false;
+	
+} 
\ No newline at end of file

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,158 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * 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
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using JMS style EPRs. Simply create and use instances of
+ * this type.
+ * 
+ * @author marklittle
+ *
+ */
+
+public class JMSEpr extends EPR
+{
+	public static final String JMS_PROTOCOL = "jms";
+	public static final String PROTOCOL_SEPARATOR = "://";
+	
+	public static final String ONE_ONE_PROTOCOL = "1.1";
+	public static final String ONE_ZERO_TWO_PROTOCOL = "1.0.2b";
+	
+	public static final String SPECIFICATION_VERSION_TAG = "specification-version";
+	public static final String DESTINATION_TYPE_TAG = "destination-type";
+	public static final String DESTINATION_NAME_TAG = "destination-name";
+	public static final String CONNECTION_FACTORY_TAG = "connection-factory";
+	
+	public static final String QUEUE_TYPE = "queue";
+	public static final String TOPIC_TYPE = "topic";
+	
+	/**
+	 * Create a new JMS EPR. The protocol version is assumed to be 1.1.
+	 * 
+	 * @param destinationType the type of destination (queue/topic).
+	 * @param destinationName name of the queue/topic.
+	 * @param connection reference to the connection factory.
+	 */
+	
+	public JMSEpr (String destinationType, String destinationName, String connection)
+	{
+		this(ONE_ONE_PROTOCOL, destinationType, destinationName, connection);
+	}
+	
+	/**
+	 * Create a new JMS EPR.
+	 * 
+	 * @param protocol the protocol version.
+	 * @param destinationType the type of destination (queue/topic).
+	 * @param destinationName name of the queue/topic.
+	 * @param connection reference to the connection factory.
+	 */
+	
+	public JMSEpr (String protocol, String destinationType, String destinationName, String connection)
+	{
+		// how many of these do we really need? modify accordingly.
+		
+		if ((protocol == null) || (destinationType == null) || (destinationName == null) || (connection == null))
+			throw new IllegalArgumentException();
+		
+		if (protocol.equals(ONE_ONE_PROTOCOL) || (protocol.equals(ONE_ZERO_TWO_PROTOCOL)))
+		{
+			if (destinationType.equals(QUEUE_TYPE) || destinationType.equals(TOPIC_TYPE))
+			{	
+				PortReference addr = new PortReference(JMS_PROTOCOL+PROTOCOL_SEPARATOR+destinationType);
+				
+				addr.addExtension(SPECIFICATION_VERSION_TAG, protocol);
+
+				if (destinationName != null)
+					addr.addExtension(DESTINATION_NAME_TAG, destinationName);
+				
+				if (connection != null)
+					addr.addExtension(CONNECTION_FACTORY_TAG, connection);
+				
+				setAddr(addr);
+			}
+			else
+				throw new IllegalArgumentException("Invalid destination type!");
+		}
+		else
+			throw new IllegalArgumentException("Invalid specification version!");
+	}
+	
+	/*
+	 * There are deliberately no setters for the values once the EPR is created.
+	 */
+	
+	/**
+	 * @return the destination type used.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getDestinationType () throws URISyntaxException
+	{
+		URI uri = new URI(getAddr().getAddress());
+		
+		return uri.getHost(); // ;-)
+	}
+	
+	/**
+	 * @return the specification version used.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getVersion () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(SPECIFICATION_VERSION_TAG);
+	}
+	
+	/**
+	 * @return the destination name  used.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+
+	public final String getDestinationName () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(DESTINATION_NAME_TAG);
+	}
+	
+	/**
+	 * @return the connection factory for this EPR, or <code>null</code> if none is set.
+	 * @throws URISyntaxException thrown if the address is malformed.
+	 */
+	
+	public final String getConnectionFactory () throws URISyntaxException
+	{
+		return getAddr().getExtensionValue(CONNECTION_FACTORY_TAG);
+	}
+
+} 
\ No newline at end of file

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,68 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import org.jboss.soa.esb.addressing.helpers.EmailEpr;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the EPR class.
+ * 
+ * @author Mark Little
+ */
+
+public class EmailUnitTest extends TestCase
+{
+
+	public void testConstructor ()
+	{
+		try
+		{
+			EmailEpr em = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "myhost", "25", "foo", "bar");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
+	public void testSetGet ()
+	{
+		try
+		{
+			EmailEpr em = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "myhost", "25", "foo", "bar");
+			
+			assertEquals(em.getHost(), "myhost");
+			assertEquals(em.getProtocol(), EmailEpr.SMTP_PROTOCOL);
+			assertEquals(em.getPort(), 25);
+			assertEquals(em.getUserName(), "foo");
+			assertEquals(em.getPassword(), "bar");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,74 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.helpers.FTPEpr;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the EPR class.
+ * 
+ * @author Mark Little
+ */
+
+public class FTPUnitTest extends TestCase
+{
+
+	public void testConstructor ()
+	{
+		try
+		{
+			FTPEpr ftp = new FTPEpr("ftp://foo.com");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
+	public void testSetGet ()
+	{
+		try
+		{
+			FTPEpr ftp = new FTPEpr("ftp://foo.com");
+			
+			assertEquals(ftp.getURL().toString(), "ftp://foo.com");
+			assertEquals(ftp.getURL().getHost(), "foo.com");
+			assertEquals(ftp.getURL().getProtocol(), "ftp");
+			
+			ftp.setPassword("foobar");
+			assertEquals(ftp.getPassword(), "foobar");
+			
+			ftp.setUserName("barfoo");
+			assertEquals(ftp.getUserName(), "barfoo");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,74 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.helpers.HTTPEpr;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the EPR class.
+ * 
+ * @author Mark Little
+ */
+
+public class HTTPUnitTest extends TestCase
+{
+
+	public void testConstructor ()
+	{
+		try
+		{
+			String url1 = "http://www.local.bar:8080";
+			HTTPEpr epr = new HTTPEpr(url1);
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
+	public void testSetGet ()
+	{
+		try
+		{
+			String url1 = "http://www.local.bar:8080";
+			HTTPEpr epr = new HTTPEpr(url1);
+			
+			assertEquals(epr.getURL().toString(), url1);
+			
+			String url2 = "http://foo.com";
+			epr.setURL(new URL(url2));
+			
+			assertEquals(epr.getURL().toString(), url2);
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,93 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.helpers.JDBCEpr;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the EPR class.
+ * 
+ * @author Mark Little
+ */
+
+public class JDBCUnitTest extends TestCase
+{
+
+	public void testConstructor ()
+	{
+		try
+		{
+			JDBCEpr em = new JDBCEpr("jdbc:arjuna:oracle:thin", "CREATE TABLE foo");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
+	public void testSetGet ()
+	{
+		try
+		{
+			JDBCEpr em = new JDBCEpr("jdbc:arjuna:oracle:thin", "CREATE TABLE foo");
+			
+			assertEquals(em.getURL(), "jdbc:arjuna:oracle:thin");
+			assertEquals(em.getSQL(), "CREATE TABLE foo");
+			
+			em.setURL("jdbc:arjuna:oracle:thin");
+			assertEquals(em.getURL(), "jdbc:arjuna:oracle:thin");
+			
+			em.setUserName("me");
+			assertEquals(em.getUserName(), "me");
+			
+			em.setPassword("foobar");
+			assertEquals(em.getPassword(), "foobar");
+			
+			try
+			{
+				em.setSQL("INVALID");
+				
+				fail();
+			}
+			catch (IllegalStateException ex)
+			{
+			}
+			catch (Exception ex)
+			{
+				fail(ex.toString());
+			}
+			
+			em.setDriver("cloudscape");
+			assertEquals(em.getDriver(), "cloudscape");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java	2006-10-06 16:14:11 UTC (rev 6656)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java	2006-10-06 16:42:55 UTC (rev 6657)
@@ -0,0 +1,67 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the EPR class.
+ * 
+ * @author Mark Little
+ */
+
+public class JMSUnitTest extends TestCase
+{
+
+	public void testConstructor ()
+	{
+		try
+		{
+			JMSEpr jms = new JMSEpr(JMSEpr.ONE_ONE_PROTOCOL, JMSEpr.QUEUE_TYPE, "bar", "foobar");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
+	public void testSetGet ()
+	{
+		try
+		{
+			JMSEpr jms = new JMSEpr(JMSEpr.ONE_ONE_PROTOCOL, JMSEpr.QUEUE_TYPE, "bar", "foobar");
+			
+			assertEquals(jms.getVersion(), JMSEpr.ONE_ONE_PROTOCOL);
+			assertEquals(jms.getConnectionFactory(), "foobar");
+			assertEquals(jms.getDestinationType(), JMSEpr.QUEUE_TYPE);
+			assertEquals(jms.getDestinationName(), "bar");
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+
+}




More information about the jboss-svn-commits mailing list