* @see DataService
*/
@SuppressWarnings("unchecked")
public static DataService createDataService(OMElement dbsElement,
String dsLocation) throws DataServiceFault {
DataService dataService = null;
try {
/* get service name */
String serviceName = dbsElement.getAttributeValue(new QName(DBSFields.NAME));
String serviceNamespace = dbsElement.getAttributeValue(new QName(DBSFields.SERVICE_NAMESPACE));
if (DBUtils.isEmptyString(serviceNamespace)) {
serviceNamespace = DBConstants.WSO2_DS_NAMESPACE;
}
String defaultNamespace = dbsElement.getAttributeValue(new QName(DBSFields.BASE_URI));
if (DBUtils.isEmptyString(defaultNamespace)) {
defaultNamespace = serviceNamespace;
}
String serviceGroup = dbsElement.getAttributeValue(new QName(DBSFields.SERVICE_GROUP));
if (DBUtils.isEmptyString(serviceGroup)) {
serviceGroup = serviceName;
}
/* get the description */
OMElement descEl = dbsElement.getFirstChildWithName(new QName(DBSFields.DESCRIPTION));
String description = null;
if (descEl != null) {
description = descEl.getText();
}
String serviceStatus = dbsElement.getAttributeValue(
new QName(DBSFields.SERVICE_STATUS));
boolean batchRequestsEnabled = false;
boolean boxcarringEnabled = false;
String batchRequestsEnabledStr = dbsElement.getAttributeValue(
new QName(DBSFields.ENABLE_BATCH_REQUESTS));
if (batchRequestsEnabledStr != null) {
batchRequestsEnabled = Boolean.parseBoolean(batchRequestsEnabledStr);
}
String boxcarringEnabledStr = dbsElement.getAttributeValue(
new QName(DBSFields.ENABLE_BOXCARRING));
if (boxcarringEnabledStr != null) {
boxcarringEnabled = Boolean.parseBoolean(boxcarringEnabledStr);
}
String emptyParamFixStr = dbsElement.getAttributeValue(
new QName(DBSFields.EMPTY_PARAM_FIX));
boolean emptyParamFix = false;
if (emptyParamFixStr != null) {
emptyParamFix = Boolean.parseBoolean(emptyParamFixStr);
}
boolean disableStreaming = false;
String disableStreamingStr = dbsElement.getAttributeValue(
new QName(DBSFields.DISABLE_STREAMING));
if (disableStreamingStr != null) {
disableStreaming = Boolean.parseBoolean(disableStreamingStr);
}
/* transaction management */
boolean enableDTP = false;
String enableDTPStr = dbsElement.getAttributeValue(new QName(DBSFields.ENABLE_DTP));
if (enableDTPStr != null) {
enableDTP = Boolean.parseBoolean(enableDTPStr);
}
/* txManagerName property */
String userTxJNDIName = dbsElement.getAttributeValue(
new QName(DBSFields.TRANSACTION_MANAGER_JNDI_NAME));
dataService = new DataService(serviceName, description,
defaultNamespace, dsLocation, serviceStatus,
batchRequestsEnabled, boxcarringEnabled, enableDTP,
userTxJNDIName, emptyParamFix);
/* set service group */
dataService.setServiceGroup(serviceGroup);
/* set service namespace */
dataService.setServiceNamespace(serviceNamespace);
/* set disable streaming */
dataService.setDisableStreaming(disableStreaming);
/* add the password manager */
Iterator<OMElement> passwordMngrItr = dbsElement.getChildrenWithName(
new QName(SecurityConstants.PASSWORD_MANAGER_SIMPLE));
if (passwordMngrItr.hasNext()) {
SecretResolver secretResolver = SecretResolverFactory.create(dbsElement, false);
dataService.setSecretResolver(secretResolver);
}
/* add the configs */
for (Iterator<OMElement> itr = dbsElement.getChildrenWithName(
new QName(DBSFields.CONFIG)); itr.hasNext();) {
dataService.addConfig(ConfigFactory.createConfig(dataService, itr.next()));
}
/* add event triggers */
for (Iterator<OMElement> itr = dbsElement.getChildrenWithName(
new QName(DBSFields.EVENT_TRIGGER)); itr.hasNext();) {
dataService.addEventTrigger(
EventTriggerFactory.createEventTrigger(dataService, itr.next()));
}
/* add the queries */
for (Iterator<OMElement> itr = dbsElement
.getChildrenWithName(new QName(DBSFields.QUERY)); itr.hasNext();) {
dataService.addQuery(QueryFactory.createQuery(dataService, itr.next()));
}
/* add the operations */
for (Iterator<OMElement> itr = dbsElement
.getChildrenWithName(new QName(DBSFields.OPERATION)); itr.hasNext();) {
dataService.addOperation(OperationFactory.createOperation(dataService,
itr.next()));
}
/* add the resources */
for (Iterator<OMElement> itr = dbsElement.getChildrenWithName(
new QName(DBSFields.RESOURCE)); itr.hasNext();) {
dataService.addResource(ResourceFactory.createResource(dataService,
itr.next()));
}
/* init the data service object */
dataService.init();
for (String opName : dataService.getOperationNames()) {
Result result = dataService.getOperation(opName).getCallQueryGroup()
.getDefaultCallQuery().getQuery().getResult();
if (result != null && result.getResultType() == DBConstants.ResultTypes.RDF ) {
throw new DataServiceFault("Cannot create operation "
+ dataService.getOperation(opName) + "for the result output type RDF");
}
}
/* add necessary equivalent batch operation for the above defined operation */
if (dataService.isBatchRequestsEnabled()) {
List<Operation> tmpOpList = new ArrayList<Operation>();
Operation operation;
for (String opName : dataService.getOperationNames()) {
if (isBoxcarringOps(opName)) {
/* skip boxcarring operations */
continue;
}
operation = dataService.getOperation(opName);
if (isBatchCompatible(operation)) {
/* this is a batch operation and the parent operation is also given */
Operation batchOp = new Operation(
operation.getDataService(),
operation.getName() + DBConstants.BATCH_OPERATON_NAME_SUFFIX,
"batch operation for '" + operation.getName() + "'",
operation.getCallQueryGroup(), true,
operation, operation.isDisableStreamingRequest(),
operation.isDisableStreamingEffective());
batchOp.setReturnRequestStatus(operation.isReturnRequestStatus());
tmpOpList.add(batchOp);
}
}
/* the operations are added outside the loop that iterates the operation list,
* if we add it inside the loop while iterating, we will get a concurrent modification exception */
for (Operation tmpOp : tmpOpList) {
dataService.addOperation(tmpOp);
}
}
/* register data service for event service notification */
DataServicesDSComponent.registerEventBrokerServiceListener(dataService);