package org.jboss.axis.wsdl.symbolTable;
import org.jboss.axis.enums.Style;
import org.jboss.axis.enums.Use;
import org.jboss.axis.utils.LinkedHashMap;
import javax.wsdl.Binding;
import javax.wsdl.Operation;
import javax.wsdl.extensions.soap.SOAPFault;
import javax.wsdl.extensions.soap.SOAPHeader;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class BindingEntry extends SymTabEntry
{
public static final int TYPE_SOAP = 0;
public static final int TYPE_HTTP_GET = 1;
public static final int TYPE_HTTP_POST = 2;
public static final int TYPE_UNKNOWN = 3;
public static final int USE_ENCODED = 0;
public static final int USE_LITERAL = 1;
public static final int NO_HEADER = 0;
public static final int IN_HEADER = 1;
public static final int OUT_HEADER = 2;
private Binding binding;
private int bindingType;
private Style bindingStyle;
private boolean hasLiteral;
private Map attributes;
private LinkedHashMap parameters = new LinkedHashMap();
private Map faults = new LinkedHashMap();
private Map mimeTypes;
private Map headerParts;
private ArrayList dimeOps = new ArrayList();
public BindingEntry(Binding binding, int bindingType, Style bindingStyle,
boolean hasLiteral, HashMap attributes, Map mimeTypes,
Map headerParts)
{
super(binding.getQName());
this.binding = binding;
this.bindingType = bindingType;
this.bindingStyle = bindingStyle;
this.hasLiteral = hasLiteral;
if (attributes == null)
{
this.attributes = new LinkedHashMap();
}
else
{
this.attributes = attributes;
}
if (mimeTypes == null)
{
this.mimeTypes = new LinkedHashMap();
}
else
{
this.mimeTypes = mimeTypes;
}
if (headerParts == null)
{
this.headerParts = new LinkedHashMap();
}
else
{
this.headerParts = headerParts;
}
}
public BindingEntry(Binding binding)
{
super(binding.getQName());
this.binding = binding;
this.bindingType = TYPE_UNKNOWN;
this.bindingStyle = Style.DOCUMENT;
this.hasLiteral = false;
this.attributes = new LinkedHashMap();
this.mimeTypes = new LinkedHashMap();
this.headerParts = new LinkedHashMap();
}
public Parameters getParameters(Operation operation)
{
return (Parameters)parameters.get(operation);
}
public Map getParameters()
{
return parameters;
}
public void setParameters(LinkedHashMap parameters)
{
this.parameters = parameters;
}
public MimeInfo getMIMEInfo(String operationName, String parameterName)
{
Map opMap = (Map)mimeTypes.get(operationName);
if (opMap == null)
{
return null;
}
else
{
return (MimeInfo)opMap.get(parameterName);
}
}
public Map getMIMETypes()
{
return mimeTypes;
}
public void setMIMEInfo(String operationName, String parameterName, String type, String dims)
{
Map opMap = (Map)mimeTypes.get(operationName);
if (opMap == null)
{
opMap = new LinkedHashMap();
mimeTypes.put(operationName, opMap);
}
opMap.put(parameterName, new MimeInfo(type, dims));
}
public void setOperationDIME(String operationName)
{
if (dimeOps.indexOf(operationName) == -1)
{
dimeOps.add(operationName);
}
}
public boolean isOperationDIME(String operationName)
{
return (dimeOps.indexOf(operationName) >= 0);
}
public boolean isInHeaderPart(String operationName,
String partName)
{
return (headerPart(operationName, partName) & IN_HEADER) > 0;
}
public boolean isOutHeaderPart(String operationName,
String partName)
{
return (headerPart(operationName, partName) & OUT_HEADER) > 0;
}
private int headerPart(String operationName,
String partName)
{
Map opMap = (Map)headerParts.get(operationName);
if (opMap == null)
{
return NO_HEADER;
}
else
{
HeaderPart headerPart = (HeaderPart)opMap.get(partName);
return headerPart == null ? NO_HEADER : headerPart.getFlags();
}
}
public Map getHeaderParts()
{
return headerParts;
}
public void setHeaderPart(String operationName, String partName, SOAPHeader soapHeader, int headerFlags)
{
Map opMap = (Map)headerParts.get(operationName);
if (opMap == null)
{
opMap = new LinkedHashMap();
headerParts.put(operationName, opMap);
}
QName message = (soapHeader != null ? soapHeader.getMessage() : null);
HeaderPart headerPart = (HeaderPart)opMap.get(partName);
if (headerPart == null)
headerPart = new HeaderPart(partName, message, headerFlags);
else
headerPart = new HeaderPart(partName, message, headerFlags | headerPart.getFlags());
opMap.put(partName, headerPart);
}
public Binding getBinding()
{
return binding;
}
public int getBindingType()
{
return bindingType;
}
protected void setBindingType(int bindingType)
{
if (bindingType >= TYPE_SOAP && bindingType <= TYPE_UNKNOWN)
{
}
this.bindingType = bindingType;
}
public Style getBindingStyle()
{
return bindingStyle;
}
protected void setBindingStyle(Style bindingStyle)
{
this.bindingStyle = bindingStyle;
}
public boolean hasLiteral()
{
return hasLiteral;
}
protected void setHasLiteral(boolean hasLiteral)
{
this.hasLiteral = hasLiteral;
}
public Use getInputBodyType(Operation operation)
{
OperationAttr attr = (OperationAttr)attributes.get(operation);
if (attr == null)
{
return Use.ENCODED; }
else
{
return attr.getInputBodyType();
}
}
protected void setInputBodyType(Operation operation, Use inputBodyType)
{
OperationAttr attr = (OperationAttr)attributes.get(operation);
if (attr == null)
{
attr = new OperationAttr();
attributes.put(operation, attr);
}
attr.setInputBodyType(inputBodyType);
if (inputBodyType == Use.LITERAL)
{
setHasLiteral(true);
}
}
public Use getOutputBodyType(Operation operation)
{
OperationAttr attr = (OperationAttr)attributes.get(operation);
if (attr == null)
{
return Use.ENCODED; }
else
{
return attr.getOutputBodyType();
}
}
protected void setOutputBodyType(Operation operation, Use outputBodyType)
{
OperationAttr attr = (OperationAttr)attributes.get(operation);
if (attr == null)
{
attr = new OperationAttr();
attributes.put(operation, attr);
}
attr.setOutputBodyType(outputBodyType);
if (outputBodyType == Use.LITERAL)
{
setHasLiteral(true);
}
}
protected void setBodyType(Operation operation, Use bodyType, boolean input)
{
if (input)
{
setInputBodyType(operation, bodyType);
}
else
{
setOutputBodyType(operation, bodyType);
}
}
public Use getFaultBodyType(Operation operation, String faultName)
{
OperationAttr attr = (OperationAttr)attributes.get(operation);
if (attr == null)
{
return Use.ENCODED; }
else
{
Map m = attr.getFaultBodyTypeMap();
SOAPFault soapFault = (SOAPFault)m.get(faultName);
if (soapFault == null)
{
return Use.ENCODED;
}
String use = soapFault.getUse();
if ("literal".equals(use))
{
return Use.LITERAL;
}
return Use.ENCODED;
}
}
public Map getFaults()
{
return faults;
}
public void setFaults(Map faults)
{
this.faults = faults;
}
public Set getOperations()
{
return attributes.keySet();
}
protected void setFaultBodyTypeMap(Operation operation, Map faultBodyTypeMap)
{
OperationAttr attr = (OperationAttr)attributes.get(operation);
if (attr == null)
{
attr = new OperationAttr();
attributes.put(operation, attr);
}
attr.setFaultBodyTypeMap(faultBodyTypeMap);
}
protected static class OperationAttr
{
private Use inputBodyType;
private Use outputBodyType;
private Map faultBodyTypeMap;
public OperationAttr(Use inputBodyType, Use outputBodyType, Map faultBodyTypeMap)
{
this.inputBodyType = inputBodyType;
this.outputBodyType = outputBodyType;
this.faultBodyTypeMap = faultBodyTypeMap;
}
public OperationAttr()
{
this.inputBodyType = Use.ENCODED;
this.outputBodyType = Use.ENCODED;
this.faultBodyTypeMap = null;
}
public Use getInputBodyType()
{
return inputBodyType;
}
protected void setInputBodyType(Use inputBodyType)
{
this.inputBodyType = inputBodyType;
}
public Use getOutputBodyType()
{
return outputBodyType;
}
protected void setOutputBodyType(Use outputBodyType)
{
this.outputBodyType = outputBodyType;
}
public Map getFaultBodyTypeMap()
{
return faultBodyTypeMap;
}
protected void setFaultBodyTypeMap(Map faultBodyTypeMap)
{
this.faultBodyTypeMap = faultBodyTypeMap;
}
}
protected static class HeaderPart
{
private String part;
private QName message;
private int flags;
public HeaderPart(String part, QName message, int type)
{
this.part = part;
this.message = message;
this.flags = type;
}
public String getPartName()
{
return part;
}
public QName getMessageQName()
{
return message;
}
public int getFlags()
{
return flags;
}
public String toString()
{
return "[part=" + part + ",message=" + message + ",flags=" + flags + "]";
}
}
}