00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 package org.jaebi.test.server.service;
00012
00013 import java.io.File;
00014
00015 import org.jaebi.server.service.BackEndHandler;
00016 import org.jaebi.server.service.BackEndHandlerImpl;
00017 import org.jaebi.server.service.XRequestCommand;
00018 import org.jaebi.server.service.XRequestCommandFactory;
00019 import org.jaebi.server.service.exception.BackEndHandlerInitException;
00020 import org.jaebi.server.service.exception.CommandCreationException;
00021 import org.jaebi.server.service.exception.CommandExecException;
00022 import org.jaebi.server.service.exception.XRequestCommandFactoryInitException;
00023 import org.jaebi.server.service.xml.JAXBMarshallerWrapper;
00024 import org.jaebi.server.service.xml.JAXBMarshallerWrapperImpl;
00025 import org.jaebi.server.service.xml.exception.JAXBMarshallerWrapperInitException;
00026 import org.jaebi.server.service.xml.exception.JAXBMarshallerWrapperMarshallException;
00027 import org.jaebi.server.service.xml.exception.JAXBMarshallerWrapperUnmarshallException;
00028 import org.jaebi.server.service.xml.xrequest.Xrequest;
00029 import org.jaebi.server.service.xml.xresponse.Xresponse;
00030
00035 public class MainTestServicePackage {
00036
00040 public static void main(String[] args) {
00041 BackEndHandler beh = null;
00042 JAXBMarshallerWrapper marshWrap;
00043
00044 Xrequest newReq = null;
00045 Xresponse newRes = null;
00046
00047 File sourceFile = new File("/Users/detro/workspace-nb/L2-Project-JAEBI/xrequest-example.xml");
00048 XRequestCommandFactory commFact;
00049 XRequestCommand newCommand = null;
00050
00051 String result = null;
00052
00053
00054 try {
00055 beh = new BackEndHandlerImpl();
00056 } catch ( BackEndHandlerInitException behie ) {
00057 System.out.println("Errore: " + behie);
00058 behie.printStackTrace();
00059 }
00060
00061 try {
00062 marshWrap = new JAXBMarshallerWrapperImpl("org.jaebi.server.service.xml.xrequest");
00063 newReq = (Xrequest)marshWrap.unmarshall(sourceFile);
00064 } catch ( JAXBMarshallerWrapperInitException inite) {
00065 inite.printStackTrace();
00066 } catch ( JAXBMarshallerWrapperUnmarshallException unmarshe) {
00067 unmarshe.printStackTrace();
00068 }
00069
00070 try {
00071 commFact = new XRequestCommandFactory(beh);
00072 newCommand = commFact.createCommand(newReq);
00073 } catch ( XRequestCommandFactoryInitException inite) {
00074 inite.printStackTrace();
00075 } catch ( CommandCreationException cce) {
00076 cce.printStackTrace();
00077 }
00078
00079 System.out.println("Command Creato: \n" + newCommand );
00080
00081 try {
00082 newRes = (Xresponse)newCommand.execute();
00083 } catch ( CommandExecException cee ) {
00084 cee.printStackTrace();
00085 }
00086
00087 try {
00088 JAXBMarshallerWrapper marshWrapResp = new JAXBMarshallerWrapperImpl("org.jaebi.server.service.xml.xresponse");
00089 marshWrapResp.setFormattedMarshalling(true);
00090 result = marshWrapResp.marshall(newRes);
00091 } catch ( JAXBMarshallerWrapperInitException inite) {
00092 inite.printStackTrace();
00093 } catch ( JAXBMarshallerWrapperMarshallException marshe) {
00094 marshe.printStackTrace();
00095 }
00096
00097 System.out.println("Risultato Command: \n" + result);
00098 }
00099
00100 }