Añado los fuentes de java
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package com.tarisan.chipcard.tpvvs.webservicetrayicon.messages;
|
||||
|
||||
/**
|
||||
* @author jjrider
|
||||
*/
|
||||
import es.chipcard.util.*;
|
||||
import org.w3c.dom.*;
|
||||
import java.io.*;
|
||||
|
||||
public abstract class Msg {
|
||||
public static int TYPE_OF_MESSAGE_ERROR=-1;
|
||||
public static int TYPE_OF_MESSAGE_CCREQ=1;
|
||||
public static int TYPE_OF_MESSAGE_CCRES=2;
|
||||
public static String DEFAULT_XML_DECLARATION="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
|
||||
|
||||
private Document xmlDoc=null;
|
||||
|
||||
|
||||
public Msg(String sMessage) throws Exception{
|
||||
xmlDoc=SerClsXMLUtils.parsearDocumento(new StringReader(DEFAULT_XML_DECLARATION+"<Msg version=\"1.0\">"+sMessage+"</Msg>"));
|
||||
}
|
||||
|
||||
public Msg(Document doc) throws Exception{
|
||||
if(doc==null)
|
||||
throw new Exception("El XML dado como argumento no puede ser NULL");
|
||||
if(!doc.getDocumentElement().getNodeName().equals("Msg")){
|
||||
throw new Exception("El XML dado como argumento no es un Msg");
|
||||
}
|
||||
xmlDoc=doc;
|
||||
}
|
||||
|
||||
public abstract int getTypeOfMessage();
|
||||
|
||||
protected Document getDocument(){
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
public void setRepeticion(boolean blnValue){
|
||||
xmlDoc.getDocumentElement().setAttribute("repeticion",((blnValue)?"true":"false"));
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return SerClsXMLUtils.dameTextoXml(xmlDoc);
|
||||
}
|
||||
|
||||
public void saveToOutputStream(OutputStream out) throws Exception{
|
||||
SerClsXMLUtils.toOutputStream(getDocument(),out);
|
||||
}
|
||||
|
||||
/******
|
||||
* Crea un objeto Msg a partir de una cadena
|
||||
* @param sResponse
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Msg createMsgFromString(String sResponse) throws Exception{
|
||||
/**if(sResponse!=null){
|
||||
if(!sResponse.trim().startsWith("<?xml")){
|
||||
|
||||
}
|
||||
}**/
|
||||
sResponse=DEFAULT_XML_DECLARATION+sResponse;
|
||||
//System.err.println("XML Respuesta:"+sResponse);
|
||||
Document xmlResponse=SerClsXMLUtils.parsearDocumentoFromString(sResponse);
|
||||
if(SerClsXMLUtils.existeElemento(xmlResponse.getDocumentElement(),"Error")){
|
||||
return new Error(xmlResponse);
|
||||
}else if(SerClsXMLUtils.existeElemento(xmlResponse.getDocumentElement(),"CCRes")){
|
||||
return new AutRes(xmlResponse);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user