001 /** 002 * 003 * Copyright 2005 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 **/ 018 package org.codehaus.activesoap.wsif; 019 020 import org.apache.wsif.WSIFException; 021 import org.apache.wsif.WSIFMessage; 022 import org.apache.wsif.WSIFOperation; 023 import org.apache.wsif.WSIFPort; 024 import org.apache.wsif.providers.WSIFDynamicTypeMap; 025 import org.codehaus.activesoap.RestClient; 026 import org.codehaus.activesoap.handler.stax.AnyElementMarshaler; 027 028 import javax.wsdl.BindingOperation; 029 import javax.wsdl.Definition; 030 import javax.wsdl.Port; 031 import javax.wsdl.Service; 032 import java.util.Iterator; 033 import java.util.List; 034 035 /** 036 * Represents a port in <a href="http://ws.apache.org/wsif/">WSIF</a> 037 * 038 * @version $Revision: 1.1 $ 039 */ 040 public class ASPort implements WSIFPort { 041 private Definition definition; 042 private Service service; 043 private Port port; 044 private WSIFDynamicTypeMap wsifDynamicTypeMap; 045 private RestClient client; 046 private AnyElementMarshaler marshaler; 047 private WSIFMessage context; 048 049 050 public ASPort(Definition definition, Service service, Port port, WSIFDynamicTypeMap wsifDynamicTypeMap, RestClient client, AnyElementMarshaler marshaler) { 051 this.definition = definition; 052 this.service = service; 053 this.port = port; 054 this.wsifDynamicTypeMap = wsifDynamicTypeMap; 055 this.client = client; 056 this.marshaler = marshaler; 057 } 058 059 public void close() throws WSIFException { 060 try { 061 client.close(); 062 } 063 catch (Exception e) { 064 throw new WSIFException("Failed to close down the client: " + e, e); 065 } 066 } 067 068 public WSIFOperation createOperation(String operationName) throws WSIFException { 069 List list = port.getBinding().getBindingOperations(); 070 for (Iterator iter = list.iterator(); iter.hasNext();) { 071 BindingOperation operation = (BindingOperation) iter.next(); 072 if (operationName.equals(operation.getName())) { 073 return createOperation(operation); 074 } 075 } 076 throw new WSIFException("No such operation: " + operationName); 077 } 078 079 public WSIFOperation createOperation(String operationName, String inputName, String outputName) throws WSIFException { 080 BindingOperation operation = port.getBinding().getBindingOperation(operationName, inputName, outputName); 081 return createOperation(operation); 082 } 083 084 public WSIFMessage getContext() throws WSIFException { 085 return context; 086 } 087 088 public void setContext(WSIFMessage context) { 089 this.context = context; 090 } 091 092 public boolean supportsAsync() { 093 return false; /** TODO */ 094 } 095 096 public boolean supportsSync() { 097 return true; 098 } 099 100 // Properties 101 //------------------------------------------------------------------------- 102 public Definition getDefinition() { 103 return definition; 104 } 105 106 public Service getService() { 107 return service; 108 } 109 110 public Port getPort() { 111 return port; 112 } 113 114 public WSIFDynamicTypeMap getWsifDynamicTypeMap() { 115 return wsifDynamicTypeMap; 116 } 117 118 public RestClient getClient() { 119 return client; 120 } 121 122 public AnyElementMarshaler getMarshaler() { 123 return marshaler; 124 } 125 126 // Implementation methods 127 //------------------------------------------------------------------------- 128 protected ASOperation createOperation(BindingOperation operation) { 129 return new ASOperation(this, operation.getOperation(), client, marshaler); 130 } 131 132 }