public abstract class ApiImplementor extends Object
Constructor and Description |
---|
ApiImplementor() |
Modifier and Type | Method and Description |
---|---|
void |
addApiAction(ApiAction action) |
void |
addApiOptions(AbstractParam param)
Adds the given options to the API implementor.
|
void |
addApiOthers(ApiOther other) |
void |
addApiPersistentConnection(ApiPersistentConnection pconn) |
void |
addApiShortcut(String shortcut) |
void |
addApiView(ApiView view) |
void |
addCustomHeaders(String name,
API.RequestType type,
HttpMessage msg)
Override to add custom headers for specific API operations
|
ApiAction |
getApiAction(String name) |
List<ApiAction> |
getApiActions() |
ApiOther |
getApiOther(String name) |
List<ApiOther> |
getApiOthers() |
ApiPersistentConnection |
getApiPersistentConnection(String name) |
List<ApiPersistentConnection> |
getApiPersistentConnections() |
protected List<String> |
getApiShortcuts() |
ApiView |
getApiView(String name) |
List<ApiView> |
getApiViews() |
String |
getDescriptionKey()
Gets the resource key of the description.
|
protected String |
getI18nPrefix()
Gets the prefix for default resource keys for the description of the API implementor and its
elements.
|
protected boolean |
getParam(net.sf.json.JSONObject params,
String name,
boolean defaultValue) |
protected int |
getParam(net.sf.json.JSONObject params,
String name,
int defaultValue) |
protected long |
getParam(net.sf.json.JSONObject params,
String name,
long defaultValue) |
protected String |
getParam(net.sf.json.JSONObject params,
String name,
String defaultValue) |
abstract String |
getPrefix() |
ApiResponse |
handleApiAction(String name,
net.sf.json.JSONObject params)
Override if implementing one or more actions
|
ApiResponse |
handleApiOptionAction(String name,
net.sf.json.JSONObject params) |
ApiResponse |
handleApiOptionView(String name,
net.sf.json.JSONObject params) |
HttpMessage |
handleApiOther(HttpMessage msg,
String name,
net.sf.json.JSONObject params)
Override if implementing one or more 'other' operations - these are operations that _dont_
return structured data
|
void |
handleApiPersistentConnection(HttpMessage msg,
HttpInputStream httpIn,
HttpOutputStream httpOut,
String name,
net.sf.json.JSONObject params)
Override if implementing one or more 'persistent connection' operations.
|
ApiResponse |
handleApiView(String name,
net.sf.json.JSONObject params)
Override if implementing one or more views
|
String |
handleCallBack(HttpMessage msg)
Override if handling callbacks
|
HttpMessage |
handleShortcut(HttpMessage msg) |
protected void |
validateParamExists(net.sf.json.JSONObject parameters,
String name)
Validates that a parameter with the given
name exists (and it has a value) in the
given parameters . |
public void addApiView(ApiView view)
public void addApiOthers(ApiOther other)
public void addApiAction(ApiAction action)
public void addApiShortcut(String shortcut)
public void addApiPersistentConnection(ApiPersistentConnection pconn)
public void addApiOptions(AbstractParam param)
param
- the options for the APIZapApiIgnore
public ApiResponse handleApiOptionView(String name, net.sf.json.JSONObject params) throws ApiException
ApiException
public ApiResponse handleApiOptionAction(String name, net.sf.json.JSONObject params) throws ApiException
ApiException
public ApiResponse handleApiView(String name, net.sf.json.JSONObject params) throws ApiException
name
- the name of the requested viewparams
- the API request parametersApiException
- if an error occurred while handling the API view endpointpublic ApiResponse handleApiAction(String name, net.sf.json.JSONObject params) throws ApiException
name
- the name of the requested actionparams
- the API request parametersApiException
- if an error occurred while handling the API action endpointpublic HttpMessage handleApiOther(HttpMessage msg, String name, net.sf.json.JSONObject params) throws ApiException
msg
- the HTTP message containing the API requestname
- the name of the requested other endpointparams
- the API request parametersApiException
- if an error occurred while handling the API other endpointpublic void handleApiPersistentConnection(HttpMessage msg, HttpInputStream httpIn, HttpOutputStream httpOut, String name, net.sf.json.JSONObject params) throws ApiException
msg
- the HTTP message containing the API requesthttpIn
- the input streamhttpOut
- the output streamname
- the name of the requested pconn endpointparams
- the API request parametersApiException
- if an error occurred while handling the API pconn endpointpublic String handleCallBack(HttpMessage msg) throws ApiException
msg
- the HTTP message containing the API request and responseApiException
- if an error occurred while handling the API callbackpublic HttpMessage handleShortcut(HttpMessage msg) throws ApiException
ApiException
public abstract String getPrefix()
protected String getI18nPrefix()
Defaults to getPrefix()
.
public String getDescriptionKey()
Defaults to getI18nPrefix() + ".api.desc"
.
I18N.getString(String)
public ApiPersistentConnection getApiPersistentConnection(String name)
public List<ApiPersistentConnection> getApiPersistentConnections()
protected int getParam(net.sf.json.JSONObject params, String name, int defaultValue)
protected long getParam(net.sf.json.JSONObject params, String name, long defaultValue)
protected boolean getParam(net.sf.json.JSONObject params, String name, boolean defaultValue)
protected void validateParamExists(net.sf.json.JSONObject parameters, String name) throws ApiException
name
exists (and it has a value) in the
given parameters
.parameters
- the parametersname
- the name of the parameter that must existApiException
- if the parameter with the given name does not exist or it has no value.public void addCustomHeaders(String name, API.RequestType type, HttpMessage msg)
name
- the name of the operationtype
- the type of the operationmsg
- the HTTP response message to the API request