FileDocCategorySizeDatePackage
JMSURLHelper.javaAPI DocApache Axis 1.46648Sat Apr 22 18:57:28 BST 2006org.apache.axis.transport.jms

JMSURLHelper

public class JMSURLHelper extends Object
JMSURLHelper provides access to properties in the URL. The URL must be of the form: "jms:/?[=&]*"
author
Ray Chun (rchun@sonicsoftware.com)

Fields Summary
private URL
url
private String
destination
private HashMap
properties
private Vector
requiredProperties
private Vector
appProperties
Constructors Summary
public JMSURLHelper(URL url)

        this(url, null);
    
public JMSURLHelper(URL url, String[] requiredProperties)

        this.url = url;
        properties = new HashMap();
        appProperties = new Vector();

        // the path should be something like '/SampleQ1'
        // clip the leading '/' if there is one
        destination = url.getPath();
        if (destination.startsWith("/"))
            destination = destination.substring(1);

        if ((destination == null) || (destination.trim().length() < 1))
            throw new java.net.MalformedURLException("Missing destination in URL");

        // parse the query string and populate the properties table
        String query = url.getQuery();
        StringTokenizer st = new StringTokenizer(query, "&;");
        while (st.hasMoreTokens()) {
            String keyValue = st.nextToken();
            int eqIndex = keyValue.indexOf("=");
            if (eqIndex > 0)
            {
                String key = keyValue.substring(0, eqIndex);
                String value = keyValue.substring(eqIndex+1);
                if (key.startsWith(JMSConstants._MSG_PROP_PREFIX)) {
                    key = key.substring(
                        JMSConstants._MSG_PROP_PREFIX.length());
                    addApplicationProperty(key);
                }
                properties.put(key, value);
            }
        }

        // set required properties
        addRequiredProperties(requiredProperties);
        validateURL();
    
Methods Summary
public voidaddApplicationProperty(java.lang.String property)
Adds the name of a property from the url properties that should be added to the JMS message.

        if (property == null)
            return;

        if (appProperties == null)
            appProperties = new Vector();

        appProperties.addElement(property);
    
public voidaddApplicationProperty(java.lang.String property, java.lang.String value)
Adds the name and value od the application property to the JMS URL.

        if (property == null)
            return;

        if (appProperties == null)
            appProperties = new Vector();
        
        properties.put(property, value);
        appProperties.addElement(property);
    
public voidaddRequiredProperties(java.lang.String[] properties)

        if (properties == null)
            return;

        for (int i = 0; i < properties.length; i++)
        {
            addRequiredProperty(properties[i]);
        }
    
public voidaddRequiredProperty(java.lang.String property)

        if (property == null)
            return;

        if (requiredProperties == null)
            requiredProperties = new Vector();

        requiredProperties.addElement(property);
    
public java.util.VectorgetApplicationProperties()
Returns a collection of properties that are defined within the JMS URL to be added directly to the JMS messages.

return
collection or null depending on presence of elements

        return appProperties;
    
public java.lang.StringgetDestination()

        return destination;
    
public java.lang.StringgetDomain()

        return getPropertyValue(JMSConstants._DOMAIN);
    
public java.util.HashMapgetProperties()

        return properties;
    
public java.lang.StringgetPropertyValue(java.lang.String property)

        return (String)properties.get(property);
    
public java.util.VectorgetRequiredProperties()

        return requiredProperties;
    
public java.lang.StringgetURLString()
Returns a URL formatted String. The properties of the URL may not end up in the same order as the JMS URL that was originally used to create this object.

        StringBuffer text = new StringBuffer("jms:/");
        text.append(getDestination());
        text.append("?");
        Map props = (Map)properties.clone();
        boolean firstEntry = true;
        for(Iterator itr=properties.keySet().iterator(); itr.hasNext();) {
            String key = (String)itr.next();
            if (!firstEntry) {
                text.append("&");
            }
            if (appProperties.contains(key)) {
                text.append(JMSConstants._MSG_PROP_PREFIX);
            }
            text.append(key);
            text.append("=");
            text.append(props.get(key));
            firstEntry = false;
        }
        return text.toString();
    
public java.lang.StringgetVendor()

        return getPropertyValue(JMSConstants._VENDOR);
    
public voidsetDestination(java.lang.String destination)

        this.destination = destination;
    
public java.lang.StringtoString()
Returns a formatted URL String with the assigned properties

        return getURLString();
    
private voidvalidateURL()

        Vector required = getRequiredProperties();
        if (required == null)
            return;

        for (int i = 0; i < required.size(); i++)
        {
            String key = (String)required.elementAt(i);
            if (properties.get(key) == null)
                throw new java.net.MalformedURLException();
        }