Серверная сторона
/*Дописанный код в скелете сервера. Использует сгенерированные классы возвращаемого типа и аргумента Trequest TResponse */
package org. apache. axis2.calc;
public class SSkeleton{
public boolean isOp(String s){
if (s. charAt(0)=='+' ||s. charAt(0)=='-' ||s. charAt(0)=='*' ||s. charAt(0)=='/' ||s. charAt(0)=='^')
return true;
return false;
}
public double res (double x1, double x2, String op){
if (op. charAt(0)=='+') return x1+x2;
else if (op. charAt(0)=='-') return x1-x2;
else if (op. charAt(0)=='*') return x1*x2;
else if (op. charAt(0)=='/') return x1/x2;
else if (op. charAt(0)=='^') return Math. pow(x1, x2);
return x1;
}
public void operands_out(double [] operands, int ub){
System. out. print("operands: ");
for (int i=0;i<=ub;i++){
System. out. print(operands[i]);
System. out. print(" ");
}
System. out. println();
}
public String calc(String expr){
int j=0,i=expr. indexOf(" ", j);
System. out. println("i:"+Integer. toString(i) );
double [] operands=new double[20];
int ub=-1; //ubound – верхняя граница (номер последнего //занесенного операнда) в operands
while (i!=-1){
String s=expr. substring(j, i);
System. out. println("substring: "+s);
if (isOp(s)) {
if (ub<1) return null;
operands[ub-1]=res(operands[ub-1],operands[ub],s); ub--;
// строку рассматриваем слева направо, операнд применяется
// справа налево.
}
else {operands[++ub]=Double. parseDouble(s);}
j=i+1; i=expr. indexOf(" ",j);
System. out. println("i:"+Integer. toString(i) );
operands_out(operands, ub);
}
System. out. println("circle is done");
String s=expr. substring(j, expr. length());
System. out. println("substring: "+s);
if (isOp(s)) {
if (ub<1) return null;
operands[ub-1]=res(operands[ub-1],operands[ub],s);
ub--;
} else {operands[++ub]=Double. parseDouble(s);}
operands_out(operands, ub);
if (ub>0) return null;
return Double. toString(operands[0]);
}
public org. apache. axis2.calc. TResponse wsdlOpN
(
org. apache. axis2.calc. TRequest tRequest
) {
//TODO : fill this with the necessary business logic
//throw new java. lang. UnsupportedOperationException("Please implement " + this. getClass().getName() + "#wsdlOpN");
System. out. println("It seems, somebody wants me");
String expr=tRequest. getParam();
String value=calc(expr);
org. apache. axis2.calc. TResponse tResponse=new org. apache. axis2.calc. TResponse();
if (value==null) tResponse. setValue("expression error");
else tResponse. setValue(value);
return tResponse;
}
}
Клиентская сторона
/* Специально созданный класс клиента, использует внутренние классы сгенерированной заглушки класса Stub*/
package org. apache. axis2.calc;
import org. apache. axis2.calc. SStub. TRequest;
import org. apache. axis2.calc. SStub. TResponse;
public class Client {
public static void main(java. lang. String args[]){
if (args. length==0) {System. out. println("input an expression"); return;};
String expr=args[0]; for (int i=1;i<args. length;i++) expr+=" "+args[i];
System. out. println("Ok. You\'ve inputted the next: "+expr+".");
try{
SStub stub = new SStub("http://localhost:8080/axis2/services/S");
TRequest request = new TRequest();
request. setParam(expr);
TResponse response=stub. wsdlOpN(request);
String answer=response. getValue();
System. out. println("server\'s answer: "+answer);
} catch(Exception e){ e. printStackTrace(); System. out. println("\n\n\n"); }
}
}


