Автор: Пользователь скрыл имя, 18 Декабря 2012 в 17:28, курсовая работа
Целью данного курсового проекта является создание сервиса кулинарной книги с возможностью поиска блюд по ингредиентам. Для достижения данной цели необходимо решить следующие задачи:
1) изучить и проанализировать особенности процесса создания кулинарной книги;
2) описать модели, определить основные требования к разрабатываемой системе;
3) разработать сервис кулинарной книги с возможностью поиска блюд по ингредиентам.
@WebMethod(operationName = "findAllCategory")
public ServerResponse findAllCategory() {
long start = System.currentTimeMillis();
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
List<Category> list = loc.findAllCategory();
for (Category giv : list) {
Element userEl = doc.createElement("cat");
userEl.setAttribute("id", giv.getId().toString());
userEl.setAttribute("name", giv.getName());
rootEl.appendChild(userEl);
}
long end = System.currentTimeMillis();
Long res = end - start;
Element el = doc.createElement("res");
el.setAttribute("name", res.toString());
rootEl.appendChild(el);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("cat.xsl"
return xmlMes;
}
@WebMethod(operationName = "addCategory")
public ServerResponse addCategory() {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("editCat.
return xmlMes;
}
@WebMethod(operationName = "editCategory")
public ServerResponse editCategory(int id) {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
Category g = loc.findCategory(id);
Element userEl = doc.createElement("cat");
userEl.setAttribute("id", g.getId().toString());
userEl.setAttribute("name", g.getName());
rootEl.appendChild(userEl);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("editCat.
return xmlMes;
}
@WebMethod(operationName = "saveCategory")
@Oneway
public void saveCategory(ServerResponse msg) {
Element el = msg.xml.part;
Element user = ((Element) el.getElementsByTagName("cat")
String id = user.getAttribute("id");
String name = user.getAttribute("name");
Category g = new Category();
g.setName(name);
if (!"0".equals(id)) {
g.setId(Integer.valueOf(id));
loc.editCategory(g);
} else {
loc.createCategory(g);
}
}
@WebMethod(operationName = "deleteCategory")
@Oneway
public void deleteCategory(int id) {
loc.removeCategory(loc.
}
@WebMethod(operationName = "findAllIngredient")
public ServerResponse findAllIngredient() {
long start = System.currentTimeMillis();
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
List<Ingredient> list = loc.findAllIngredient();
for (Ingredient giv : list) {
Element userEl = doc.createElement("ingr");
userEl.setAttribute("id", giv.getId().toString());
userEl.setAttribute("name", giv.getName());
rootEl.appendChild(userEl);
}
long end = System.currentTimeMillis();
Long res = end - start;
Element el = doc.createElement("res");
el.setAttribute("name", res.toString());
rootEl.appendChild(el);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("ingr.
return xmlMes;
}
@WebMethod(operationName = "addIngredient")
public ServerResponse addIngredient() {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("
return xmlMes;
}
@WebMethod(operationName = "find")
public ServerResponse find() {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("find.
return xmlMes;
}
@WebMethod(operationName = "findResult")
public ServerResponse findResult(String str) {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
String []mas=new String [100];
mas=str.split(" ");
Set list=new TreeSet();
// List<Ingredient> list=new ArrayList();
for(int i=0;i<mas.length;i++){
Ingredient ingr=loc.findIngrByName(mas[i]
System.out.println("mas="+mas[
List <BludoIngredient> bi=new ArrayList();
if(ingr!=null){
bi=loc.findBludoIngredient(
}
for(int j=0;j<bi.size();j++){
Bludo b=loc.findBludo(bi.get(j).
try{
list.add(b);
}catch(Exception e){
}
System.out.println("b="+b.
}
}
List<Bludo> nlist=new ArrayList(list);
for (Bludo giv : nlist) {
Element userEl = doc.createElement("bl");
userEl.setAttribute("id", giv.getId().toString());
userEl.setAttribute("name", giv.getName());
userEl.setAttribute("recept", giv.getRecept());
rootEl.appendChild(userEl);
}
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("
return xmlMes;
}
@WebMethod(operationName = "editIngredient")
public ServerResponse editIngredient(int id) {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
Ingredient g = loc.findIngredient(id);
Element userEl = doc.createElement("ingr");
userEl.setAttribute("id", g.getId().toString());
userEl.setAttribute("name", g.getName());
rootEl.appendChild(userEl);
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("
return xmlMes;
}
@WebMethod(operationName = "saveIngredient")
@Oneway
public void saveIngredient(ServerResponse msg) {
Element el = msg.xml.part;
Element user = ((Element) el.getElementsByTagName("ingr"
String id = user.getAttribute("id");
String name = user.getAttribute("name");
Ingredient g = new Ingredient();
g.setName(name);
if (!"0".equals(id)) {
g.setId(Integer.valueOf(id));
loc.editIngredient(g);
} else {
loc.createIngredient(g);
}
}
@WebMethod(operationName = "deleteIngredient")
@Oneway
public void deleteIngredient(int id) {
loc.removeIngredient(loc.
}
///////////////
@WebMethod(operationName = "saveBludoIngredient")
@Oneway
public void saveBludoIngredient(ServerResp
Element el = msg.xml.part;
Element user = ((Element) el.getElementsByTagName("ingr"
String id = user.getAttribute("id");
String name = user.getAttribute("bl");
String ingr = user.getAttribute("ingr");
BludoIngredient g = new BludoIngredient();
Bludo b=new Bludo();
b.setId(Integer.valueOf(name))
Ingredient in=new Ingredient();
in.setId(Integer.valueOf(ingr)
g.setBludoId(b);
g.setIngredientId(in);
loc.createBludoIngredient(g);
}
@WebMethod(operationName = "deleteBludoIngredient")
@Oneway
public void deleteBludoIngredient(int id) {
loc.removeBludoIngredient(loc.
}
@WebMethod(operationName = "addBludoIngredient")
public ServerResponse addBludoIngredient() {
Document doc = new DocumentImpl();
Element rootEl = doc.createElement("message");
doc.appendChild(rootEl);
List<Ingredient> list = loc.findAllIngredient();
for (Ingredient giv : list) {
Element el = doc.createElement("ingr");
el.setAttribute("id", giv.getId().toString());
el.setAttribute("name", giv.getName());
rootEl.appendChild(el);
}
ServerResponse xmlMes = new ServerResponse();
XmlXsl partMesXML = new XmlXsl();
partMesXML.part = doc.getDocumentElement();
xmlMes.setXml(partMesXML);
xmlMes.setXsl(getXSL("
return xmlMes;
}
}