org.coos.messaging.ExchangePattern Maven / Gradle / Ivy
/**
* COOS - Connected Objects Operating System (www.connectedobjects.org).
*
* Copyright (C) 2009 Telenor ASA and Tellu AS. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This library 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see .
*
* You may also contact one of the following for additional information:
* Telenor ASA, Snaroyveien 30, N-1331 Fornebu, Norway (www.telenor.no)
* Tellu AS, Hagalokkveien 13, N-1383 Asker, Norway (www.tellu.no)
*/
package org.coos.messaging;
import java.util.Hashtable;
/**
* @author Knut Eilif Husa, Tellu AS Represents the kind of message exchange
* pattern
*/
public class ExchangePattern {
public static final String OutOnly = "OutOnly";
public static final String RobustOutOnly = "RobustOutOnly";
public static final String OutIn = "OutIn";
public static final String OutOptionalIn = "OutOptionalIn";
public static final String InOnly = "InOnly";
public static final String RobustInOnly = "RobustInOnly";
public static final String InOut = "InOut";
public static final String InOptionalOut = "InOptionalOut";
protected static final Hashtable map = new Hashtable();
private String exchangePattern;
public ExchangePattern(String exchangePattern) {
this.exchangePattern = exchangePattern;
}
/**
* Returns the WSDL URI for this message exchange pattern
*
* @return the WSDL URI for this message exchange pattern
*/
public static String getWsdlUri(String exchangePattern) {
if (exchangePattern.equals(OutOnly))
return "http://www.w3.org/ns/wsdl/out-only";
if (exchangePattern.equals(OutOptionalIn))
return "http://www.w3.org/ns/wsdl/out-optional-in";
if (exchangePattern.equals(OutIn))
return "http://www.w3.org/ns/wsdl/out-in";
if (exchangePattern.equals(InOut))
return "http://www.w3.org/ns/wsdl/in-out";
if (exchangePattern.equals(InOnly))
return "http://www.w3.org/ns/wsdl/in-only";
if (exchangePattern.equals(InOptionalOut))
return "http://www.w3.org/ns/wsdl/in-optional_out";
if (exchangePattern.equals(RobustOutOnly))
return "http://www.w3.org/ns/wsdl/robust-out-only";
if (exchangePattern.equals(RobustInOnly))
return "http://www.w3.org/ns/wsdl/robust-in-only";
throw new IllegalArgumentException("Unknown message exchange pattern: " + exchangePattern);
}
/**
* Return true if there can be an IN message
*/
public boolean isInCapable() {
if (exchangePattern.equals(InOnly) || exchangePattern.equals(RobustInOnly))
return false;
else
return true;
}
/**
* Return true if there can be an OUT message
*/
public boolean isOutCapable() {
if (exchangePattern.equals(OutOnly) || exchangePattern.equals(RobustOutOnly))
return false;
else
return true;
}
/**
* Return true if there can be a FAULT message
*/
public boolean isFaultCapable() {
if (exchangePattern.equals(OutOnly) || exchangePattern.equals(InOnly))
return false;
else
return true;
}
public boolean equals(Object obj) {
if ((obj instanceof String) && exchangePattern.equals(obj)) {
return true;
}
return super.equals(obj);
}
public String toString() {
return exchangePattern;
}
/**
* Converts the WSDL URI into a {@link ExchangePattern} instance
*/
/*
* public static ExchangePattern fromWsdlUri(String wsdlUri) { return
* (ExchangePattern) map.get(wsdlUri); }
*
* static { for (int i = 1; i < 7; i++) { String uri = getWsdlUri(i); String
* pattern = null; populatePattern(uri, pattern); } }
*
* private static void populatePattern(String uri, String pattern) {
* map.put(uri, pattern); String name = uri.substring(uri.lastIndexOf('/') +
* 1); map.put("http://www.w3.org/2004/08/wsdl/" + name, pattern);
* map.put("http://www.w3.org/2006/01/wsdl/" + name, pattern); }
*/
public boolean isOutBoundInitiated() {
return exchangePattern.equals(OutOnly) || exchangePattern.equals(RobustOutOnly) || exchangePattern.equals(OutIn) ||
exchangePattern.equals(OutOptionalIn);
}
public boolean isInBoundInitiated() {
return exchangePattern.equals(InOnly) || exchangePattern.equals(RobustInOnly) || exchangePattern.equals(InOut) ||
exchangePattern.equals(InOptionalOut);
}
}