package org.jboss.axis.description;
import org.jboss.axis.enums.Style;
import org.jboss.axis.enums.Use;
import org.jboss.logging.Logger;
import javax.xml.namespace.QName;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
public class OperationDesc
{
public static final int MSG_METHOD_BODYARRAY = 1;
public static final int MSG_METHOD_SOAPENVELOPE = 2;
public static final int MSG_METHOD_ELEMENTARRAY = 3;
public static final int MSG_METHOD_DOCUMENT = 4;
public static final int MSG_METHOD_NONCONFORMING = -4;
private static Logger log = Logger.getLogger(OperationDesc.class.getName());
private ServiceDesc parent;
private ArrayList parameters = new ArrayList();
private String name;
private QName elementQName;
private Method method;
private Style style = null;
private Use use = null;
private int numInParams = 0;
private int numOutParams = 0;
private String soapAction = null;
private ArrayList faults = null;
private ParameterDesc returnDesc = new ParameterDesc();
private int messageOperationStyle = -1;
private boolean oneWay = false;
public OperationDesc()
{
returnDesc.setMode(ParameterDesc.OUT);
returnDesc.setIsReturn(true);
}
public OperationDesc(String name, ParameterDesc[] parameters, QName returnQName)
{
this.name = name;
returnDesc.setQName(returnQName);
returnDesc.setMode(ParameterDesc.OUT);
returnDesc.setIsReturn(true);
for (int i = 0; i < parameters.length; i++)
{
addParameter(parameters[i]);
}
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public QName getReturnQName()
{
return returnDesc.getQName();
}
public void setReturnQName(QName returnQName)
{
returnDesc.setQName(returnQName);
}
public QName getReturnType()
{
return returnDesc.getTypeQName();
}
public void setReturnType(QName returnType)
{
log.debug("@" + Integer.toHexString(hashCode()) + "setReturnType(" + returnType + ")");
returnDesc.setTypeQName(returnType);
}
public Class getReturnClass()
{
return returnDesc.getJavaType();
}
public void setReturnClass(Class returnClass)
{
returnDesc.setJavaType(returnClass);
}
public QName getElementQName()
{
return elementQName;
}
public void setElementQName(QName elementQName)
{
this.elementQName = elementQName;
}
public boolean isOneWay()
{
return oneWay;
}
public void setOneWay(boolean oneWay)
{
this.oneWay = oneWay;
}
public ServiceDesc getParent()
{
return parent;
}
public void setParent(ServiceDesc parent)
{
this.parent = parent;
}
public String getSoapAction()
{
return soapAction;
}
public void setSoapAction(String soapAction)
{
this.soapAction = soapAction;
}
public void setStyle(Style style)
{
this.style = style;
}
public Style getStyle()
{
if (style == null)
{
if (parent != null)
{
return parent.getStyle();
}
return Style.DEFAULT; }
return style;
}
public void setUse(Use use)
{
this.use = use;
}
public Use getUse()
{
if (use == null)
{
if (parent != null)
{
return parent.getUse();
}
return Use.DEFAULT; }
return use;
}
public void addParameter(ParameterDesc param)
{
parameters.add(param);
if ((param.getMode() == ParameterDesc.IN) ||
(param.getMode() == ParameterDesc.INOUT))
{
param.setOrder(numInParams++);
}
if ((param.getMode() == ParameterDesc.OUT) ||
(param.getMode() == ParameterDesc.INOUT))
{
numOutParams++;
}
log.debug("@" + Integer.toHexString(hashCode()) + " added parameter >" + param + "@" + Integer.toHexString(param.hashCode()) + "<total parameters:" + getNumParams());
}
public void addParameter(QName paramName,
QName xmlType,
Class javaType,
byte parameterMode,
boolean inHeader,
boolean outHeader)
{
ParameterDesc param =
new ParameterDesc(paramName, parameterMode, xmlType,
javaType, inHeader, outHeader);
addParameter(param);
}
public ParameterDesc getParameter(int i)
{
if (parameters.size() <= i)
return null;
return (ParameterDesc)parameters.get(i);
}
public ArrayList getParameters()
{
return parameters;
}
public void setParameters(ArrayList newParameters)
{
parameters = new ArrayList(); numInParams = 0;
numOutParams = 0;
for (java.util.ListIterator li = newParameters.listIterator();
li.hasNext();)
{
addParameter((ParameterDesc)li.next());
}
}
public int getNumInParams()
{
return numInParams;
}
public int getNumOutParams()
{
return numOutParams;
}
public int getNumParams()
{
return parameters.size();
}
public Method getMethod()
{
return method;
}
public void setMethod(Method method)
{
this.method = method;
}
public boolean isReturnHeader()
{
return returnDesc.isOutHeader();
}
public void setReturnHeader(boolean value)
{
returnDesc.setOutHeader(value);
}
public ParameterDesc getParamByQName(QName qname)
{
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc param = (ParameterDesc)i.next();
if (param.getQName().equals(qname))
return param;
}
return null;
}
public ParameterDesc getInputParamByQName(QName qname)
{
ParameterDesc param = null;
param = getParamByQName(qname);
if ((param == null) || (param.getMode() == ParameterDesc.OUT))
{
param = null;
}
return param;
}
public ParameterDesc getOutputParamByQName(QName qname)
{
ParameterDesc param = null;
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc pnext = (ParameterDesc)i.next();
if (pnext.getQName().equals(qname) &&
pnext.getMode() != ParameterDesc.IN)
{
param = pnext;
break;
}
}
if (param == null)
{
if (null == returnDesc.getQName())
{
param = new ParameterDesc(returnDesc); param.setQName(qname);
}
else if (qname.equals(returnDesc.getQName()))
{
param = returnDesc;
}
}
return param;
}
public ArrayList getAllInParams()
{
ArrayList result = new ArrayList();
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc desc = (ParameterDesc)i.next();
if (desc.getMode() != ParameterDesc.OUT)
{
result.add(desc);
}
}
return result;
}
public ArrayList getAllOutParams()
{
ArrayList result = new ArrayList();
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc desc = (ParameterDesc)i.next();
if (desc.getMode() != ParameterDesc.IN)
{
result.add(desc);
}
}
return result;
}
public ArrayList getInParams()
{
ArrayList result = new ArrayList();
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc desc = (ParameterDesc)i.next();
if (desc.getMode() == ParameterDesc.IN)
{
result.add(desc);
}
}
return result;
}
public ArrayList getOutParams()
{
ArrayList result = new ArrayList();
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc desc = (ParameterDesc)i.next();
if (desc.getMode() == ParameterDesc.OUT)
{
result.add(desc);
}
}
return result;
}
public void addFault(FaultDesc fault)
{
if (faults == null)
faults = new ArrayList();
faults.add(fault);
}
public ArrayList getFaults()
{
return faults;
}
public FaultDesc getFaultByClass(Class cls)
{
if (faults == null || cls == null)
{
return null;
}
while (cls != null)
{
for (Iterator iterator = faults.iterator(); iterator.hasNext();)
{
FaultDesc desc = (FaultDesc)iterator.next();
if (cls.getName().equals(desc.getClassName()))
{
return desc;
}
}
cls = cls.getSuperclass();
if (cls != null && (cls.getName().startsWith("java.") ||
cls.getName().startsWith("javax.")))
{
cls = null;
}
}
return null;
}
public FaultDesc getFaultByQName(QName qname)
{
if (faults != null)
{
for (Iterator iterator = faults.iterator(); iterator.hasNext();)
{
FaultDesc desc = (FaultDesc)iterator.next();
if (qname.equals(desc.getQName()))
{
return desc;
}
}
}
return null;
}
public FaultDesc getFaultByXmlType(QName xmlType)
{
if (faults != null)
{
for (Iterator iterator = faults.iterator(); iterator.hasNext();)
{
FaultDesc desc = (FaultDesc)iterator.next();
if (xmlType.equals(desc.getXmlType()))
{
return desc;
}
}
}
return null;
}
public ParameterDesc getReturnParamDesc()
{
return returnDesc;
}
public String toString()
{
return toString("");
}
public String toString(String indent)
{
String text = getClass().getName() + "\n";
text += indent + "name: " + getName() + "\n";
text += indent + "returnQName: " + getReturnQName() + "\n";
text += indent + "returnType: " + getReturnType() + "\n";
text += indent + "returnClass: " + getReturnClass() + "\n";
text += indent + "elementQName:" + getElementQName() + "\n";
text += indent + "soapAction: " + getSoapAction() + "\n";
text += indent + "style: " + getStyle().getName() + "\n";
text += indent + "use: " + getUse().getName() + "\n";
text += indent + "numInParams: " + getNumInParams() + "\n";
text += indent + "method:" + getMethod() + "\n";
for (int i = 0; i < parameters.size(); i++)
{
text += indent + " ParameterDesc[" + i + "]:\n";
text += indent + ((ParameterDesc)parameters.get(i)).toString(" ") + "\n";
}
if (faults != null)
{
for (int i = 0; i < faults.size(); i++)
{
text += indent + " FaultDesc[" + i + "]:\n";
text += indent + ((FaultDesc)faults.get(i)).toString(" ") + "\n";
}
}
return text;
}
public int getMessageOperationStyle()
{
return messageOperationStyle;
}
public void setMessageOperationStyle(int messageOperationStyle)
{
this.messageOperationStyle = messageOperationStyle;
}
}