All Downloads are FREE. Search and download functionalities are using the official Maven repository.

PUSTEFIX-INF.script.webservice.js Maven / Gradle / Ivy

There is a newer version: 0.23.0
Show newest version
//Add inheritance support
Function.prototype.extend=function(base) {
  var derived=this.prototype=new base;
  this.prototype.superclass=base.prototype;
  return derived;
};



//==================================================================
//CORE_ (Pustefix core classes)
//==================================================================


//*********************************
//CORE_Exception(string msg,string src)
//*********************************
function CORE_Exception(msg,src) {
  this.msg=msg;
  this.src=src;
  this.name="CORE_Exception";
  this.desc="General error";
}
//string toString()
CORE_Exception.prototype.toString=function() {
  return this.name+":"+this.desc+"["+this.src+"] "+this.msg;
}

//*********************************
//CORE_IllegalArgsEx
//*********************************
function CORE_IllegalArgsEx(msg,src) {
  CORE_Exception.call(this,msg,src);
  this.name="IllegalArgumentException";
  this.desc="Illegal arguments";
}
CORE_IllegalArgsEx.extend(CORE_Exception);

//*********************************
//CORE_WrongArgNoEx
//*********************************
function CORE_WrongArgNoEx(msg,src) {
  CORE_IllegalArgsEx.call(this,msg,src);
  this.desc="Wrong number of arguments";
}
CORE_WrongArgNoEx.extend(CORE_IllegalArgsEx);



//==================================================================
//XML_ (Pustefix xml classes)
//==================================================================


//CONSTANTS
var XML_NS_XSD="http://www.w3.org/2001/XMLSchema";
var XML_NS_XSI="http://www.w3.org/2001/XMLSchema-instance";
var XML_NS_SOAPENV="http://schemas.xmlsoap.org/soap/envelope/";
var XML_NS_PREFIX_MAP=new Array();
XML_NS_PREFIX_MAP[XML_NS_XSD]="xsd";
XML_NS_PREFIX_MAP[XML_NS_XSI]="xsi";
XML_NS_PREFIX_MAP[XML_NS_SOAPENV]="S";


//*********************************
//XML_Exception(string msg,string src)
//*********************************
function XML_Exception(msg,src) {
  CORE_Exception.call(this,msg,src);
  this.name="XML_Exception";
  this.desc="XML error";
}
XML_Exception.extend(CORE_Exception);

//*********************************
//XML_Utilities
//*********************************
function XML_Utilities() {
  this.scopeChecked=false;
  this.scopeSupport=false;
}

XML_Utilities.prototype.getChildElements=function(node) {
  var nodes=new Array();
  var nl=node.childNodes;
  if(nl!=null) {
    for(var i=0;i-1) localName=localName.substring(ind+1,localName.length);
      if(localName==name) nodes.push(nl[i]);
    }
  }
  return nodes;
}

XML_Utilities.prototype.getChildrenByNameNS=function(node,nsuri,name) {
  if(arguments.length!=3) throw new CORE_WrongArgNoEx("","XML_Utilities.getChildrenByNameNS");
  var nl=node.childNodes;
  if(nl==null || nl.length==0) return null;
  if(!this.scopeChecked) {
    if(typeof node.scopeName!="undefined") this.scopeSupport=true;
    scopeChecked=true;
  }
  var nodes=new Array();
  for(var i=0;i-1) localName=localName.substring(ind+1,localName.length);
    if(this.scopeSupport) {
      if(nl[i].tagUrn==nsuri && localName==name) nodes.push(nl[i]);
    } else {
      if(nl[i].namespaceURI==nsuri && localName==name) nodes.push(nl[i]);
    }
  }
  return nodes;
}

XML_Utilities.prototype.getText=function(node) {
  if(arguments.length!=1) throw new CORE_WrongArgNoEx("","XML_Utilities.getText");
  var nl=node.childNodes;
  if(nl==null) return null;
  var text="";
  for(var i=0;i";
  }
  this.inStart=false;
  this.currentCtx=this.currentCtx.parent;
}

//writeAttribute(String name,String value)
//writeAttribute(XML_QName name,String value)
XML_Writer.prototype.writeAttribute=function(name,value) {
  var attrName=null;
  var prefix=null;
  var nsuri=null;
  var newNS=false;
  if(name instanceof XML_QName) {
    attrName=name.localpart;
    nsuri=name.namespaceUri;
    if(nsuri!=null) {
      prefix=this.currentCtx.getPrefix(nsuri);
      if(prefix==null) {
        prefix=this.getPrefix(nsuri);
        newNS=true;
      }
    }
  } else {
    attrName=name;
  }
  if(prefix!=null) attrName=prefix+":"+attrName;
  if(newNS) this.writeNamespaceDeclaration(nsuri,prefix);
  this.xml+=" "+attrName+"=\""+value+"\"";
}

//writeChars(String chars)
XML_Writer.prototype.writeChars=function(chars) {
  if(this.inStart) {
    this.xml+=">";
    this.inStart=false;
  }
  chars=chars.replace(/&/g,"&");
  chars=chars.replace(/0?"-":"+";
    offset=Math.abs(offset);
    var tzh=Math.floor(offset / 60);
    var tzm=offset % 60;
    var tz=tzp+this.fillNulls(tzh,2)+":"+this.fillNulls(tzm,2);
    var date=value.getFullYear()+"-"+this.fillNulls(value.getMonth()+1,2)+"-"+
    this.fillNulls(value.getDate(),2)+"T"+this.fillNulls(value.getHours(),2)+":"+
    this.fillNulls(value.getMinutes(),2)+":"+this.fillNulls(value.getSeconds(),2)+"."+
    this.fillNulls(value.getMilliseconds(),3)+tz;
    this.superclass.serialize(date,name,typeInfo,writer,ctx);
  }
}
SOAP_DateTimeSerializer.prototype.deserialize=function(typeInfo,element) {
  return this.parseDate(this.superclass.deserialize.call(this,typeInfo,element));
}

//*********************************
//SOAP_ArraySerializer
//*********************************
function SOAP_ArraySerializer(xmlType) {
  SOAP_SimpleSerializer.call(this,xmlType);
}
SOAP_ArraySerializer.extend(SOAP_SimpleSerializer);
SOAP_ArraySerializer.prototype.serializeSub=function(value,name,typeInfo,dim,writer,ctx) {
  if(dim>0 && (value instanceof Array || (typeof value=="object" && typeof value.slice!="undefined")) ) {
    //var nsuri=typeInfo.arrayType.xmlType.namespaceUri;
    //var prefix=writer.currentCtx.getPrefix(nsuri);
    //if(prefix==null) {
    //  prefix=writer.getPrefix(nsuri);
    //  writer.writeNamespaceDeclaration(nsuri);
    //}
    for(var i=0;i1) {
    var array=new Array();
    for(var i=0;i0) {
      var deserializer=SOAP_TypeMapping.getSerializerByInfo(propInfo);
      var val=null;
      if(propInfo instanceof SOAP_ArrayInfo) {
        val=deserializer.deserialize(propInfo,items);
      } else {
        val=deserializer.deserialize(propInfo,items[0]);
      }
      obj[propName]=val;
    } else {
      if(propInfo instanceof SOAP_ArrayInfo) obj[propName]=[];
      else obj[propName]=null;
    }
  }
  return obj;
}

//*********************************
//SOAP_ElementSerializer(XML_QName type)
//*********************************
function SOAP_ElementSerializer(type) {
  SOAP_SimpleSerializer.call(this,type);
}
SOAP_ElementSerializer.extend(SOAP_SimpleSerializer);
SOAP_ElementSerializer.prototype.serialize=function(value,name,typeInfo,writer,ctx) {
  writer.startElement(name);
  this.serializeSub(value,writer);
  writer.endElement(name);
}
SOAP_ElementSerializer.prototype.serializeSub=function(element,writer) {
  writer.startElement(element.nodeName);
  for(var j=0;j0) {
    if(arguments[0] instanceof XML_QName) {
      this.setOperationName(arguments[0]);
      ind++;
    }
  }
  if(this.params.length!=arguments.length-ind) throw new CORE_IllegalArgsEx("Wrong number of arguments","SOAP_Call.invoke");
  for(var i=0;i0) {
        nl=XML_Utilities.getChildrenByName(nl[0],"exception");
        if(nl!=null && nl.length>0) {
          ex.name=nl[0].getAttribute("class");
        }
      }
      ex.message=fault.faultString;
      if(this.userCallback) this.userCallback(null,reqID,ex);
      else if(this.userObject) this.userObject[this.opName].call(this.userObject,null,reqID,ex);
      else throw ex;
    } else {
      var rpc=new SOAP_RPCSerializer( this.opName, null, this.targetNamespace, this.retTypeInfo);
      var res = rpc.deserialize(soapMsg.getSoapPart().getEnvelope().getBody().element);
      if(this.userCallback) this.userCallback(res,reqID,null);
      else if(this.userObject) this.userObject[this.opName].call(this.userObject,res,reqID,null);
      else return res;
    }
  } catch(ex) {
    if(this.userCallback) this.userCallback(null,reqID,ex);
    else if(this.userObject) this.userObject[this.opName].call(this.userObject,null,reqID,ex);
    else throw ex;
  }
};


//*********************************
// SOAP_Message()
// SOAP_Message(Document xml)
//*********************************
function SOAP_Message() {
  if(arguments.length==0) {
    this.soapPart=new SOAP_Part();
  } else if(arguments.length==1) {
    this.soapPart=new SOAP_Part(arguments[0]);
  } else throw new CORE_WrongArgNoEx("","SOAP_Message");
}

//SOAP_Part getSoapPart()
SOAP_Message.prototype.getSoapPart=function() {
  return this.soapPart;
}

//write(XML_Writer writer) {
SOAP_Message.prototype.write=function(writer) {
  this.soapPart.write(writer);
}

//*********************************
// SOAP_Part()
// SOAP_Part(Document xml)
//*********************************
function SOAP_Part() {
  if(arguments.length==0) {
    this.envelope=new SOAP_Envelope();
  } else if(arguments.length==1) {
    var e=XML_Utilities.getChildrenByNameNS(arguments[0],XML_NS_SOAPENV,"Envelope")[0];
    if(e==null) throw new SOAP_Exception("NO SOAP MESSAGE","SOAP_Part");
    this.envelope=new SOAP_Envelope(e);
  } else throw new CORE_WrongArgNoEx("","SOAP_Part");
}

//SOAP_Envelope getEnvelope()
SOAP_Part.prototype.getEnvelope=function() {
  return this.envelope;
}

//write(XML_Writer writer) {
SOAP_Part.prototype.write=function(writer) {
  this.envelope.write(writer);
}


//*********************************
// SOAP_Envelope()
// SOAP_Envelope(Element elem)
//*********************************
function SOAP_Envelope() {
  if(arguments.length==0) {
    this.header=null;
    this.body=new SOAP_Body();
    this.element=null;
  } else if(arguments.length==1) {
    var e=XML_Utilities.getChildrenByNameNS(arguments[0],XML_NS_SOAPENV,"Header")[0];
    if(e!=null) this.header=new SOAP_Header(e);
    else this.header=null;
    e=XML_Utilities.getChildrenByNameNS(arguments[0],XML_NS_SOAPENV,"Body")[0];
    if(e!=null) this.body=new SOAP_Body(e);
    else throw new SOAP_Exception("NO MESSAGE BODY","SOAP_Envelope");
    this.element=arguments[0];
  } else throw new CORE_WrongArgNoEx("","SOAP_Envelope");
}

//write(XML_Writer writer) {
SOAP_Envelope.prototype.write=function(writer) {
  var envName=new XML_QName(XML_NS_SOAPENV,"Envelope");
  writer.startElement(envName);
  writer.writeNamespaceDeclaration(XML_NS_XSI);
  writer.writeNamespaceDeclaration(XML_NS_XSD);
  if(this.header!=null) this.header.write(writer);
  this.body.write(writer);
  writer.endElement(envName);
}

//SOAP_Header addHeader()
SOAP_Envelope.prototype.addHeader=function() {
  if(this.header!=null) throw new SOAP_Exception("Message already contains header","SOAP_Envelope");
  this.header=new SOAP_Header();
  return this.header;
}

//SOAP_Header getHeader()
SOAP_Envelope.prototype.getHeader=function() {
  return this.header;
}

//SOAP_Body getBody()
SOAP_Envelope.prototype.getBody=function() {
  return this.body;
}

//*********************************
// SOAP_BodyElement(serializer)
//*********************************
function SOAP_BodyElement(serializer) {
  this.serializer=serializer;
}

SOAP_BodyElement.prototype.write=function(writer) {
  this.serializer.serialize(writer);
}

//*********************************
// SOAP_Body()
// SOAP_Body(Element elem)
//*********************************
function SOAP_Body() {
  if(arguments.length==0) {
    this.fault=null;
    this.bodyElems=new Array();
    this.element=null;
  } else if(arguments.length==1) {
    var e=XML_Utilities.getChildrenByNameNS(arguments[0],XML_NS_SOAPENV,"Fault")[0];
    if(e!=null) this.fault=new SOAP_Fault(e);
    this.element=arguments[0];
  } else throw new CORE_WrongArgNoEx("","SOAP_Envelope");
}

//addBodyElement(SOAP_BodyElement bodyElem)
SOAP_Body.prototype.addBodyElement=function(bodyElem) {
  this.bodyElems.push(bodyElem);  
}

//SOAP_Fault getFault()
SOAP_Body.prototype.getFault=function(fault) {
  return this.fault;
}

//setFault(SOAP_Fault fault) 
SOAP_Body.prototype.setFault=function(fault) {
  this.fault=fault;
}

//write(XML_Writer writer) {
SOAP_Body.prototype.write=function(writer) {
  var bodyName=new XML_QName(XML_NS_SOAPENV,"Body");
  writer.startElement(bodyName);
  if(this.fault!=null) {
    return;
  }
  if(this.bodyElems!=null) {
    for(var i=0;i0) this.faultCode=XML_Utilities.getText(nl[0]);
    nl=XML_Utilities.getChildrenByName(arguments[0],"faultstring");
    if(nl!=null && nl.length>0) this.faultString=XML_Utilities.getText(nl[0]);
    this.element=arguments[0];
  } else throw new CORE_WrongArgNoEx("","SOAP_Fault");
}
SOAP_Fault.prototype.toString=function() {
  var str="";
  if(this.faultCode!=null) str+=": "+this.faultCode;
  if(this.faultString!=null) str+=": "+this.faultString;
  return str;
}


//*********************************
// SOAP_TypeInfo(XML_QName xmlType)
//*********************************
function SOAP_TypeInfo(xmlType) {
  this.xmlType=xmlType;
}

//*********************************
// SOAP_ArrayInfo(XML_QName xmlType)
// SOAP_ArrayInfo(XML_QName xmlType,TypeInfo arrayType,Number dimension)
//*********************************
function SOAP_ArrayInfo(xmlType,arrayType,dimension) {
  SOAP_TypeInfo.call(this,xmlType);
  if(arguments.length==3) {
    this.dimension=dimension;
    this.arrayType=arrayType;
  }
}
SOAP_ArrayInfo.extend(SOAP_TypeInfo);
SOAP_ArrayInfo.prototype.populate=function(arrayType,dimension) {
  this.arrayType=arrayType;
  this.dimension=dimension;
}

//*********************************
// SOAP_BeanInfo(XML_QName xmlType)
// SOAP_BeanInfo(XML_QName xmlType,Array props)
//*********************************
function SOAP_BeanInfo(xmlType,props) {
  SOAP_TypeInfo.call(this,xmlType);
  this.props=null;
  this.propNames=null;
  this.propToInfo=null;
  if(arguments.length==2) {
    this.props=props;
    this.init();
  }
}
SOAP_BeanInfo.extend(SOAP_TypeInfo);
SOAP_BeanInfo.prototype.init=function() {
  this.propNames=new Array();
  this.propToInfo=new Array();
  for(var i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy