service-model
Version:
An object oriented web service framework inspired by Windows Communication Foundation.
84 lines (83 loc) • 2.98 kB
JavaScript
/**
* Represents an endpoint for a service in the dispatcher. Exposes configuration options for the endpoint.
*
* <uml>
* hide members
* hide circle
* DispatchService *-- DispatchEndpoint : endpoints
* DispatchEndpoint *-- DispatchOperation : operations
* DispatchEndpoint *- MessageFilter : filter
* OperationSelector -* DispatchEndpoint : operationSelector
* DispatchEndpoint *-- MessageInspector : messageInspectors
* DispatchEndpoint *-- ErrorHandler : errorHandlers
* DispatchEndpoint *-- FaultFormatter : faultFormatter
* </uml>
*/
var DispatchEndpoint = (function () {
function DispatchEndpoint(service, address, contractName) {
this.service = service;
/**
* Indicates the priority of the endpoint if more than one endpoint can process the message. A higher value
* indicates a higher priority. If all endpoints have the same priority then the first matching endpoint is used.
*/
this.filterPriority = 0;
/**
* A list of operations available for the endpoint.
*/
this.operations = [];
/**
* A list of message inspectors for this endpoint.
*/
this.messageInspectors = [];
/**
* A list of error handlers for this endpoint.
*/
this.errorHandlers = [];
if (!service) {
throw new Error("Missing required parameter 'service'.");
}
if (!address) {
throw new Error("Missing required parameter 'address'.");
}
if (!contractName) {
throw new Error("Missing required parameter 'contractName'.");
}
this.address = address;
this.contractName = contractName;
}
/**
* Validates that the endpoint is correctly configured.
*/
DispatchEndpoint.prototype.validate = function () {
if (!this.filter) {
this._throwConfigError("Undefined 'filter'.");
}
if (!this.operationSelector) {
this._throwConfigError("Undefined 'operationSelector'.");
}
if (!this.faultFormatter) {
this._throwConfigError("Undefined 'faultFormatter'.");
}
};
/**
* Throws a configuration error.
* @param message A message to display
* @hidden
*/
DispatchEndpoint.prototype._throwConfigError = function (message) {
throw new Error("Endpoint at address '" + this.address + "' incorrectly configured: " + message);
};
/**
* Returns the [[DispatchOperation]] that will be invoked for the [[Message]].
* @param message The message.
*/
DispatchEndpoint.prototype.chooseOperation = function (message) {
var operation = this.operationSelector.selectOperation(message);
if (!operation) {
operation = this.unhandledOperation;
}
return operation;
};
return DispatchEndpoint;
})();
exports.DispatchEndpoint = DispatchEndpoint;