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 */ 017 package org.apache.camel; 018 019 import java.util.HashMap; 020 import java.util.Map; 021 022 /** 023 * Represents the kind of message exchange pattern 024 * 025 * @version $Revision: 41910 $ 026 */ 027 public enum ExchangePattern { 028 InOnly, RobustInOnly, InOut, InOptionalOut, OutOnly, RobustOutOnly, OutIn, OutOptionalIn; 029 030 protected static final Map<String, ExchangePattern> MAP = new HashMap<String, ExchangePattern>(); 031 032 /** 033 * Returns the WSDL URI for this message exchange pattern 034 */ 035 public String getWsdlUri() { 036 switch (this) { 037 case InOnly: 038 return "http://www.w3.org/ns/wsdl/in-only"; 039 case InOptionalOut: 040 return "http://www.w3.org/ns/wsdl/in-optional-out"; 041 case InOut: 042 return "http://www.w3.org/ns/wsdl/in-out"; 043 case OutIn: 044 return "http://www.w3.org/ns/wsdl/out-in"; 045 case OutOnly: 046 return "http://www.w3.org/ns/wsdl/out-only"; 047 case OutOptionalIn: 048 return "http://www.w3.org/ns/wsdl/out-optional_in"; 049 case RobustInOnly: 050 return "http://www.w3.org/ns/wsdl/robust-in-only"; 051 case RobustOutOnly: 052 return "http://www.w3.org/ns/wsdl/robust-out-only"; 053 default: 054 throw new IllegalArgumentException("Unknown message exchange pattern: " + this); 055 } 056 } 057 058 /** 059 * Return true if there can be an IN message 060 */ 061 public boolean isInCapable() { 062 switch (this) { 063 case OutOnly: 064 case RobustOutOnly: 065 return false; 066 default: 067 return true; 068 } 069 } 070 071 /** 072 * Return true if there can be an OUT message 073 */ 074 public boolean isOutCapable() { 075 switch (this) { 076 case InOnly: 077 case RobustInOnly: 078 return false; 079 default: 080 return true; 081 } 082 } 083 084 /** 085 * Return true if there can be a FAULT message 086 */ 087 public boolean isFaultCapable() { 088 switch (this) { 089 case InOnly: 090 case OutOnly: 091 return false; 092 default: 093 return true; 094 } 095 } 096 097 /** 098 * Converts the WSDL URI into a {@link ExchangePattern} instance 099 */ 100 public static ExchangePattern fromWsdlUri(String wsdlUri) { 101 return MAP.get(wsdlUri); 102 } 103 104 static { 105 for (ExchangePattern mep : values()) { 106 String uri = mep.getWsdlUri(); 107 MAP.put(uri, mep); 108 String name = uri.substring(uri.lastIndexOf('/') + 1); 109 MAP.put("http://www.w3.org/2004/08/wsdl/" + name, mep); 110 MAP.put("http://www.w3.org/2006/01/wsdl/" + name, mep); 111 } 112 } 113 }