From Ogce
package org.ogce.fileagentservice.client;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.ogce.fileagentservice.*;
import org.ogce.fileagentservice.db.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ArrayList;
public class QueryUserSpace{
public static void main(String[] args) throws AxisFault {
int option = 0;
String serviceLoc = "http://gridfarm002.ucs.indiana.edu:8080/axis2/services/FileAgentService";
String username= null;
String host=null;
String port=null;
String commCertDN=null;
String protocol=null;
LinkedList loUS = new LinkedList();
for (int j = 0; j < args.length; j++){
String argVal = args[j];
if (argVal.compareToIgnoreCase("--help")==0||
argVal.compareToIgnoreCase("-help")==0){
QueryUserSpace.usage();
return;
}else if(argVal.startsWith("-")){
if (argVal.compareToIgnoreCase("-f")==0)
option =1;
else if (argVal.compareToIgnoreCase("-l")==0)
option = 2;
else if (argVal.compareToIgnoreCase("-h")==0)
option = 3;
else if (argVal.compareToIgnoreCase("-p")==0)
option = 4;
else if (argVal.compareToIgnoreCase("-dn")==0)
option = 5;
else if (argVal.compareToIgnoreCase("-pr")==0)
option = 6;
else if (argVal.compareToIgnoreCase("-us")==0)
option = 7;
else return;
}else if (option > 0){
if (option ==1)
serviceLoc = argVal;
else if (option ==2)
username = argVal;
else if (option ==3)
host = argVal;
else if (option ==4)
port = argVal;
else if (option ==5)
commCertDN = argVal;
else if (option ==6)
protocol = argVal;
else if (option == 7)
loUS.add(argVal);
}
}
FASBean fb = new FASBean();
if (username != null){
fb.setUsername(username);
}
if (host != null){
fb.setHost(host);
}
if (port != null){
fb.setPort(port);
}
if (commCertDN != null){
fb.setCommCertDN(commCertDN);
}
if (protocol != null){
fb.setProtocol(protocol);
}
if (loUS.size()>0){
String [] loUSArray = new String[loUS.size()];
for (int k = 0; k < loUS.size(); k++){
loUSArray[k] = (String)loUS.get(k);
}
fb.setLogicalUserSpace(loUSArray);
}
System.out.println(fb.toString());
LinkedList resultBeans = QueryUserSpace.queryUserSpaceInfo(serviceLoc,fb);
System.out.println("\n\n\n############ Query Result ##############");
for (int i = 0; i<resultBeans.size(); i++){
System.out.println("QUERY RESULTS [" +i+"]");
System.out.println(resultBeans.get(i).toString());
}
}
public static LinkedList queryUserSpaceInfo(String serviceLoc, FASBean queryBean){
try{
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(serviceLoc);
options.setTo(targetEPR);
QName query = new QName("http://fileagentservice.ogce.org", "queryDataSpaceInfo");
Object[] queryArgs = new Object[] {queryBean};
org.apache.axiom.om.OMElement ome = serviceClient.invokeBlocking(query, queryArgs);
java.util.Iterator ri = ome.getChildren();
LinkedList fasBeans = new LinkedList();
//System.out.println(ome.toString());
while (ri.hasNext()){
fasBeans.add(QueryUserSpace.convertToFASBean((org.apache.axiom.om.OMElement)ri.next()));
}
return fasBeans;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
public static FASBean convertToFASBean(org.apache.axiom.om.OMElement omElement){
String username = "";
String host = "";
String port = "";
String commCertDN = "";
String protocol = "";
String timestamp = "";
QName qn_username = new QName("http://db.fileagentservice.ogce.org/xsd","username");
QName qn_host = new QName("http://db.fileagentservice.ogce.org/xsd","host");
QName qn_port = new QName("http://db.fileagentservice.ogce.org/xsd","port");
QName qn_commCertDN = new QName("http://db.fileagentservice.ogce.org/xsd","commCertDN");
QName qn_protocol = new QName("http://db.fileagentservice.ogce.org/xsd","protocol");
QName qn_timestamp = new QName("http://db.fileagentservice.ogce.org/xsd","timestamp");
QName qn_logicalUserSpace = new QName("http://db.fileagentservice.ogce.org/xsd","logicalUserSpace");
Iterator cn_username = omElement.getChildrenWithName(qn_username);
Iterator cn_host = omElement.getChildrenWithName(qn_host);
Iterator cn_port = omElement.getChildrenWithName(qn_port);
Iterator cn_commCertDN = omElement.getChildrenWithName(qn_commCertDN);
Iterator cn_protocol = omElement.getChildrenWithName(qn_protocol);
Iterator cn_timestamp = omElement.getChildrenWithName(qn_timestamp);
Iterator cn_logicalUserSpace = omElement.getChildrenWithName(qn_logicalUserSpace);
FASBean fb = new FASBean();
if (cn_username.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_username.next();
username = oe.getText();
fb.setUsername(username);
}
if (cn_host.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_host.next();
host = oe.getText();
fb.setHost(host);
}
if (cn_port.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_port.next();
port = oe.getText();
fb.setPort(port);
}
if (cn_commCertDN.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_commCertDN.next();
commCertDN = oe.getText();
fb.setCommCertDN(commCertDN);
}
if (cn_protocol.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_protocol.next();
protocol = oe.getText();
fb.setProtocol(protocol);
}
if (cn_timestamp.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_timestamp.next();
timestamp = oe.getText();
fb.setTimestamp(timestamp);
}
ArrayList<String> userSpace = new ArrayList();
while (cn_logicalUserSpace.hasNext()){
org.apache.axiom.om.OMElement oe = (org.apache.axiom.om.OMElement)cn_logicalUserSpace.next();
userSpace.add(oe.getText());
}
if (userSpace.size()>0){
String [] userSpaceArray = (String [])userSpace.toArray(new String [userSpace.size()]);
fb.setLogicalUserSpace(userSpaceArray);
}
return fb;
}
private static void usage(){
System.out.println("Usage: QueryUserSpace -f <FAS service location> "+
"-l <username> -h <host> -p <port> "+
"-dn <Distingushed Name of the community certificate> "+
"-pr <protocol> -us <user space>");
return;
}
}