001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import javax.xml.bind.annotation.XmlEnum; 023import javax.xml.bind.annotation.XmlType; 024 025/** 026 * Represents the kind of message exchange pattern 027 * 028 * @version 029 */ 030@XmlType 031@XmlEnum 032public enum ExchangePattern { 033 InOnly, RobustInOnly, InOut, InOptionalOut, OutOnly, RobustOutOnly, OutIn, OutOptionalIn; 034 035 protected static final Map<String, ExchangePattern> MAP = new HashMap<String, ExchangePattern>(); 036 037 /** 038 * Returns the WSDL URI for this message exchange pattern 039 */ 040 public String getWsdlUri() { 041 switch (this) { 042 case InOnly: 043 return "http://www.w3.org/ns/wsdl/in-only"; 044 case InOptionalOut: 045 return "http://www.w3.org/ns/wsdl/in-opt-out"; 046 case InOut: 047 return "http://www.w3.org/ns/wsdl/in-out"; 048 case OutIn: 049 return "http://www.w3.org/ns/wsdl/out-in"; 050 case OutOnly: 051 return "http://www.w3.org/ns/wsdl/out-only"; 052 case OutOptionalIn: 053 return "http://www.w3.org/ns/wsdl/out-opt-in"; 054 case RobustInOnly: 055 return "http://www.w3.org/ns/wsdl/robust-in-only"; 056 case RobustOutOnly: 057 return "http://www.w3.org/ns/wsdl/robust-out-only"; 058 default: 059 throw new IllegalArgumentException("Unknown message exchange pattern: " + this); 060 } 061 } 062 063 /** 064 * Return true if there can be an IN message 065 */ 066 public boolean isInCapable() { 067 switch (this) { 068 case OutOnly: 069 case RobustOutOnly: 070 return false; 071 default: 072 return true; 073 } 074 } 075 076 /** 077 * Return true if there can be an OUT message 078 */ 079 public boolean isOutCapable() { 080 switch (this) { 081 case InOnly: 082 case RobustInOnly: 083 return false; 084 default: 085 return true; 086 } 087 } 088 089 /** 090 * Return true if there can be a FAULT message 091 */ 092 public boolean isFaultCapable() { 093 switch (this) { 094 case InOnly: 095 case OutOnly: 096 return false; 097 default: 098 return true; 099 } 100 } 101 102 /** 103 * Converts the WSDL URI into a {@link ExchangePattern} instance 104 */ 105 public static ExchangePattern fromWsdlUri(String wsdlUri) { 106 return MAP.get(wsdlUri); 107 } 108 109 public static ExchangePattern asEnum(String value) { 110 try { 111 return valueOf(value); 112 } catch (Exception e) { 113 throw new IllegalArgumentException("Unknown message exchange pattern: " + value, e); 114 } 115 } 116 117 static { 118 for (ExchangePattern mep : values()) { 119 String uri = mep.getWsdlUri(); 120 MAP.put(uri, mep); 121 String name = uri.substring(uri.lastIndexOf('/') + 1); 122 MAP.put("http://www.w3.org/2004/08/wsdl/" + name, mep); 123 MAP.put("http://www.w3.org/2006/01/wsdl/" + name, mep); 124 } 125 } 126}