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@XmlType 029@XmlEnum 030public enum ExchangePattern { 031 InOnly, InOut, InOptionalOut; 032 033 protected static final Map<String, ExchangePattern> MAP = new HashMap<>(); 034 035 /** 036 * Returns the WSDL URI for this message exchange pattern 037 */ 038 public String getWsdlUri() { 039 switch (this) { 040 case InOnly: 041 return "http://www.w3.org/ns/wsdl/in-only"; 042 case InOptionalOut: 043 return "http://www.w3.org/ns/wsdl/in-opt-out"; 044 case InOut: 045 return "http://www.w3.org/ns/wsdl/in-out"; 046 default: 047 throw new IllegalArgumentException("Unknown message exchange pattern: " + this); 048 } 049 } 050 051 /** 052 * Return true if there can be an IN message 053 */ 054 public boolean isInCapable() { 055 return true; 056 } 057 058 /** 059 * Return true if there can be an OUT message 060 */ 061 public boolean isOutCapable() { 062 switch (this) { 063 case InOnly: 064 return false; 065 default: 066 return true; 067 } 068 } 069 070 /** 071 * Return true if there can be a FAULT message 072 */ 073 public boolean isFaultCapable() { 074 switch (this) { 075 case InOnly: 076 return false; 077 default: 078 return true; 079 } 080 } 081 082 /** 083 * Converts the WSDL URI into a {@link ExchangePattern} instance 084 */ 085 public static ExchangePattern fromWsdlUri(String wsdlUri) { 086 return MAP.get(wsdlUri); 087 } 088 089 public static ExchangePattern asEnum(String value) { 090 try { 091 return valueOf(value); 092 } catch (Exception e) { 093 throw new IllegalArgumentException("Unknown message exchange pattern: " + value, e); 094 } 095 } 096 097 static { 098 for (ExchangePattern mep : values()) { 099 String uri = mep.getWsdlUri(); 100 MAP.put(uri, mep); 101 String name = uri.substring(uri.lastIndexOf('/') + 1); 102 MAP.put("http://www.w3.org/2004/08/wsdl/" + name, mep); 103 MAP.put("http://www.w3.org/2006/01/wsdl/" + name, mep); 104 } 105 } 106}