//package MobyServices.mips.plant.moby;
import MobyServices.mips.plant.genericparser.GenericMobyOutputwriter;
import MobyServices.mips.plant.genericparser.GetDBname;
import MobyServices.mips.plant.genericparser.GetInputDataForQuery;
import MobyServices.mips.plant.helper.MobyServiceHandler;
import MobyServices.mips.plant.client.RetrieveElementClient;
import sun.jdbc.rowset.CachedRowSet;
import mips.genre.exceptions.GenreException;
import mips.genre.general.DBAccess;
import java.sql.SQLException;
import java.util.Vector;
import org.dom4j.Document;
import org.dom4j.Element;
/**
* -- Retrieves all details of an element using element name-- .
*
* -- Description of Class goes here --
*
* (c) MIPS / gsf * GENome Research
Environment (GENRE)
* Apr 30, 2004; 2:09:33 PM
* @author Vijayalakshmi Janakiraman
* adapted to new parser by Octave Noubibou
*/
public class RetrieveElementWS extends GetInputDataForQuery{
private RetrieveElementClient client;
private GetDBname getDbname;
public RetrieveElementWS(){
try {
client = new RetrieveElementClient();
getDbname=new GetDBname();
} catch (GenreException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
public String getElement(String inputXML){
String mobyobjectresult = null;
String result = null;
Vector inner;
Vector simpletype;
GenericMobyOutputwriter gow = new GenericMobyOutputwriter();
// create the document to hold the results
Document mobyDoc = gow.generateSOAPpayloadDocument("mips.gsf.de");
gow.addServiceNotes(mobyDoc, " Service Provider: mips.gsf.de"); //add some Notes
/*now, parse alldata you need for a single query and group them in a
vector see also allparsedData method in the super class
*/
Vector alldata = allParsedData(inputXML);
for (int i = 0; i < alldata.size(); i++) { //each i is a mobyData node=data for a single query
inner = getInnerVector(alldata, i);
// System.out.println("inner===="+ inner);
Element mobyDataTag = gow.addMobyDataTagToMobyContentTag(mobyDoc,"");
Element collection = null;
if (inner.size() > 1) { //is it a collection? add the collection tag
collection = gow.addCollectionTagToMobyDataTag(mobyDataTag,
"myCollection");
}
String queryId = null;
for (int j = 0; j < inner.size(); j++) {//each j is a simple type Node
simpletype = getInnerVector(inner, j);
//System.out.println("simpletype==="+ inner);
setDataForSingleQuery(simpletype); //initialize the namespace and id
queryId = getqueryId();
String locusCode = getId();
//System.out.println("id==="+ locusCode);
String namespace = getNamespace();
String dbname=getDbname.dbName(namespace);
try{
int id=client.getElementIDForElementName(locusCode, dbname);
System.out.println("id======"+id);
if(id != -1){
// use the "plant middleware" to get the result
result = client.getElement(id, dbname);
}else{
mobyDataTag.attribute("moby:queryID").setValue(queryId);
System.out.println("======getElement======= bad ID "+locusCode+" ?");
return mobyDoc.asXML();
}
}catch (GenreException e) {
mobyDataTag.attribute("moby:queryID").setValue(queryId);
//e.printStackTrace();
return mobyDoc.asXML();
}
if (inner.size() > 1) {//it is a collection, so add all simple
// tag in the Collection tag
Element simpleTag = gow
.addSimpleTagToParentElement(collection);
gow.addContentToElement(simpleTag, "text-xml", result,
namespace, locusCode, null);
} else { //otherwise add the simple tag directlly to the mobyData tag
Element simpleTag = gow
.addSimpleTagToParentElement(mobyDataTag);
gow.addContentToElement(simpleTag, "text-xml", result,
namespace, locusCode, null);
}
}
//gow.setqueryid(mobyDataTag, queryId);
mobyDataTag.attribute("moby:queryID").setValue(queryId);
}
mobyobjectresult = mobyDoc.asXML();// transform the Dom4j document to string
return mobyobjectresult;
}
String con="chr4_pseudomolecule_MAtDB";
private String con1="mth1-7g13";
String ele="At1g01740";
public String getInputXML(){
return " "+
"" +
"" +
""+
""+
""+
""+
""+
"";
}
public static void main(String[] args) throws GenreException {
RetrieveElementWS s = new RetrieveElementWS();
String str = s.getElement(s.getInputXML());
System.out.println("str-->"+str);
}
}