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