protected Element generateQueryElement(OSQuery query) {
Element qElement = new Element("Query", OS_NS);
if (query.getRole() != null) {
Attribute roleAttribute = new Attribute("role", query.getRole());
qElement.setAttribute(roleAttribute);
}
else{
throw new RequiredAttributeMissingException("If declaring a Query element, the field 'role' must be be specified");
}
if(query.getOsd() != null){
Attribute osd = new Attribute("osd", query.getOsd());
qElement.setAttribute(osd);
}
if(query.getSearchTerms() != null){
Attribute searchTerms = new Attribute("searchTerms", query.getSearchTerms());
qElement.setAttribute(searchTerms);
}
if(query.getStartPage() > -1){
int startPage = (query.getStartPage() != 0)?query.getStartPage():1;
Attribute sp = new Attribute("startPage", Integer.toString(startPage));
qElement.setAttribute(sp);
}
if(query.getTitle() != null){
qElement.setAttribute(new Attribute("title", query.getTitle()));
}
if(query.getTotalResults() > -1){
qElement.setAttribute(new Attribute("totalResults", Integer.toString(query.getTotalResults())));
}
return qElement;
}