com.sforce.ws.codegen.templates.connection.st Maven / Gradle / Ivy
connection(gen) ::= <<
package $gen.packageName$;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
import com.sforce.ws.bind.XMLizable;
import com.sforce.ws.bind.TypeMapper;
import java.util.HashMap;
import javax.xml.namespace.QName;
/**
* This is a generated class for the SObject Enterprise API.
* Do not edit this file, as your changes will be lost.
*/
public class $gen.className$ {
private TypeMapper __typeMapper = new TypeMapper($gen.packagePrefix$, null, false);
private ConnectorConfig __config;
private HashMap __extraHeaders = new HashMap();
public ConnectorConfig getConfig() {
return __config;
}
$gen.headersMetadata: { header |
private $header.type$ __$header.name$;
public void set$header.name$($header.args$) {
__$header.name$ = new $header.type$();
$header.elements: { ael |
__$header.name$.$ael.setMethod$($ael.name$);
}$ \}
public void clear$header.name$() {
__$header.name$ = null;
\}
public $header.type$ get$header.name$() {
return __$header.name$;
\}
public void __set$header.name$($header.type$ __header) {
__$header.name$ = __header ;
\}
}$
public $gen.className$(ConnectorConfig config) throws ConnectionException {
this.__config = config;
this.__typeMapper.setConfig(config);
$ if (gen.hasLoginCall)$
config.$gen.verifyEndpoint$();
if (!config.isManualLogin()) {
if (config.getSessionId()==null) {
config.setServiceEndpoint(config.getAuthEndpoint());
$gen.loginResult$ result = login(config.getUsername(), config.getPassword());
config.setSessionId(result.getSessionId());
config.setServiceEndpoint(result.getServerUrl());
} else {
if (config.getServiceEndpoint() == null) {
throw new com.sforce.ws.ConnectionException("Please set ServiceEndpoint");
}
}
}
$endif$
$if (gen.hasSessionHeader)$
__SessionHeader = new SessionHeader_element();
__SessionHeader.setSessionId(config.getSessionId());
$endif$
}
private com.sforce.ws.transport.SoapConnection newConnection() {
com.sforce.ws.transport.SoapConnection __c = new com.sforce.ws.transport.SoapConnection(
__config.getServiceEndpoint(), $gen.sObjectNamespace$, __typeMapper, __config);
__c.setConnection(this);
__c.setKnownHeaders(knownHeaders);
return __c;
}
$gen.operations: { op |
public $op.returnType$ $op.operationName$($op.argsWithClasses$)
throws com.sforce.ws.ConnectionException {
com.sforce.ws.transport.SoapConnection __connection = newConnection();
$op.requestType$ __request = new $op.requestType$();
$op.elements: { ael |
__request.$ael.setMethod$($ael.name$);
}$
$op.headers: { header |
if (__$header.name$ != null) __connection.addHeader($header.element$, __$header.name$);
}$
addHeaders(__connection);
$if(op.hasReturnType)$$op.responseType$ __response = ($op.responseType$) $endif$__connection.send($op.soapAction$,
$op.requestName$, __request, $op.responseName$,
$op.responseType$.class);
$if(op.hasReturnType)$$op.resultCall$$endif$
\}}$
private void addHeaders(com.sforce.ws.transport.SoapConnection __connection) {
for(java.util.Map.Entry entry : __extraHeaders.entrySet()) {
__connection.addHeader(entry.getKey(), entry.getValue());
}
}
public void addExtraHeader(QName __headerName, XMLizable __value) {
__extraHeaders.put(__headerName, __value);
}
public void removeExtraHeader(QName __headerName) {
__extraHeaders.remove(__headerName);
}
public XMLizable getExtraHeader(QName __headerName) {
return __extraHeaders.get(__headerName);
}
public void clearExtraHeaders() {
__extraHeaders = new HashMap();
}
$gen.qNames$
private static HashMap knownHeaders = new HashMap();
static {
$gen.knownHeaders$ }
}
>>