Example usage for javax.xml.namespace QName valueOf

List of usage examples for javax.xml.namespace QName valueOf

Introduction

In this page you can find the example usage for javax.xml.namespace QName valueOf.

Prototype

public static QName valueOf(String qNameAsString) 

Source Link

Document

<p><code>QName</code> derived from parsing the formatted <code>String</code>.</p> <p>If the <code>String</code> is <code>null</code> or does not conform to #toString() QName.toString() formatting, an <code>IllegalArgumentException</code> is thrown.</p> <p><em>The <code>String</code> <strong>MUST</strong> be in the form returned by #toString() QName.toString() .</em></p> <p>The commonly accepted way of representing a <code>QName</code> as a <code>String</code> was <a href="http://jclark.com/xml/xmlns.htm">defined</a> by James Clark.

Usage

From source file:org.wso2.carbon.humantask.core.api.client.TransformerUtils.java

/**
 * @param matchingTask ://  www  .j  a  va  2s . co  m
 * @return :
 */
public static TTaskSimpleQueryResultRow transformToSimpleQueryRow(TaskDAO matchingTask) {
    TTaskSimpleQueryResultRow row = new TTaskSimpleQueryResultRow();

    row.setName(QName.valueOf(matchingTask.getDefinitionName()));
    row.setTaskType(matchingTask.getType().toString());
    try {
        row.setId(new URI(matchingTask.getId().toString()));
    } catch (URI.MalformedURIException e) {
        throw new HumanTaskRuntimeException("The task id :[" + matchingTask.getId() + "] is invalid", e);
    }
    Calendar createdTime = Calendar.getInstance();
    createdTime.setTime(matchingTask.getCreatedOn());
    row.setCreatedTime(createdTime);

    //set the task priority.
    TPriority priority = new TPriority();
    priority.setTPriority(BigInteger.valueOf(matchingTask.getPriority()));
    row.setPriority(priority);

    //set the task status
    TStatus taskStatus = new TStatus();
    taskStatus.setTStatus(matchingTask.getStatus().toString());
    row.setStatus(taskStatus);
    row.setPresentationSubject(
            (transformPresentationSubject(CommonTaskUtil.getDefaultPresentationSubject(matchingTask))));
    row.setPresentationName(transformPresentationName(CommonTaskUtil.getDefaultPresentationName(matchingTask)));

    return row;
}

From source file:org.wso2.carbon.humantask.core.api.client.TransformerUtils.java

/**
 * Transform a TaskDAO object to a TTaskAbstract object.
 *
 * @param task           : The TaskDAO object to be transformed.
 * @param callerUserName : The user name of the caller.
 * @return : The transformed TTaskAbstract object.
 *///from www  . ja  v a2  s . com
public static TTaskAbstract transformTask(final TaskDAO task, final String callerUserName) {
    TTaskAbstract taskAbstract = new TTaskAbstract();

    //Set the task Id
    try {
        taskAbstract.setId(new URI(task.getId().toString()));
    } catch (URI.MalformedURIException e) {
        log.warn("Invalid task Id found");
    }

    taskAbstract.setName(QName.valueOf(task.getDefinitionName()));
    taskAbstract.setRenderingMethodExists(true);

    //Set the created time
    Calendar calCreatedOn = Calendar.getInstance();
    calCreatedOn.setTime(task.getCreatedOn());
    taskAbstract.setCreatedTime(calCreatedOn);

    if (task.getUpdatedOn() != null) {
        Calendar updatedTime = Calendar.getInstance();
        updatedTime.setTime(task.getUpdatedOn());
        taskAbstract.setUpdatedTime(updatedTime);
    }

    //Set the activation time if exists.
    if (task.getActivationTime() != null) {
        Calendar calActivationTime = Calendar.getInstance();
        calActivationTime.setTime(task.getActivationTime());
        taskAbstract.setActivationTime(calActivationTime);
    }

    //Set the expiration time if exists.
    if (task.getExpirationTime() != null) {
        Calendar expirationTime = Calendar.getInstance();
        expirationTime.setTime(task.getExpirationTime());
        taskAbstract.setExpirationTime(expirationTime);
    }

    if (task.getStartByTime() != null) {
        taskAbstract.setStartByTimeExists(true);
    } else {
        taskAbstract.setStartByTimeExists(false);
    }

    if (task.getCompleteByTime() != null) {
        taskAbstract.setCompleteByTimeExists(true);
    } else {
        taskAbstract.setCompleteByTimeExists(false);
    }

    taskAbstract.setTaskType(task.getType().toString());
    taskAbstract.setHasSubTasks(CommonTaskUtil.hasSubTasks(task));
    taskAbstract.setHasComments(CommonTaskUtil.hasComments(task));
    taskAbstract.setHasAttachments(CommonTaskUtil.hasAttachments(task));
    taskAbstract.setHasFault(CommonTaskUtil.hasFault(task));
    taskAbstract.setHasOutput(CommonTaskUtil.hasOutput(task));
    taskAbstract.setEscalated(task.isEscalated());
    taskAbstract.setIsSkipable(task.isSkipable());
    taskAbstract.setStatus(transformStatus(task.getStatus()));
    taskAbstract.setPriority(transformPriority(task.getPriority()));
    taskAbstract.setPreviousStatus(transformStatus(task.getStatusBeforeSuspension()));
    taskAbstract.setHasPotentialOwners(CommonTaskUtil.hasPotentialOwners(task));

    if (CommonTaskUtil.getUserEntityForRole(task,
            GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER) != null) {
        taskAbstract.setActualOwner(createTUser(CommonTaskUtil.getUserEntityForRole(task,
                GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER)));
    }
    taskAbstract.setPotentialOwners(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task,
            GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS)));
    taskAbstract.setBusinessAdministrators(transformOrganizationalEntityList(CommonTaskUtil
            .getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS)));
    taskAbstract.setNotificationRecipients(transformOrganizationalEntityList(CommonTaskUtil
            .getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS)));
    taskAbstract.setTaskStakeholders(transformOrganizationalEntityList(
            CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS)));
    taskAbstract.setTaskInitiator(createTUser(CommonTaskUtil.getUserEntityForRole(task,
            GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR)));

    HumanTaskBaseConfiguration baseConfiguration = CommonTaskUtil.getTaskConfiguration(task);
    if (baseConfiguration == null) {
        throw new HumanTaskRuntimeException(
                "There's not matching task configuration for " + "task" + task.getName());
    }
    // Set the versioned package name
    taskAbstract.setPackageName(baseConfiguration.getPackageName() + "-" + baseConfiguration.getVersion());

    taskAbstract.setTenantId(task.getTenantId());
    // If this is a task set the response operation and the port type.
    if (TaskType.TASK.equals(task.getType())) {
        TaskConfiguration taskConfig = (TaskConfiguration) baseConfiguration;
        taskAbstract.setResponseOperationName(taskConfig.getResponseOperation());
        taskAbstract.setResponseServiceName(taskConfig.getResponsePortType().toString());
    }

    taskAbstract
            .setPresentationName(transformPresentationName(CommonTaskUtil.getDefaultPresentationName(task)));
    taskAbstract.setPresentationSubject(
            transformPresentationSubject(CommonTaskUtil.getDefaultPresentationSubject(task)));
    taskAbstract.setPresentationDescription(
            transformPresentationDescription(CommonTaskUtil.getDefaultPresentationDescription(task)));

    //Setting attachment specific information
    taskAbstract.setHasAttachments(!task.getAttachments().isEmpty());
    taskAbstract.setNumberOfAttachments(task.getAttachments().size());

    return taskAbstract;
}

From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java

public SetTaskOutputResponse setTaskOutput(URI taskIdentifier, SetOutputValuesType values)
        throws SetTaskOutputFaultException {

    //Retrieve task information
    TaskDAO htTaskDAO;//from   w  ww .  j  a  va2 s  . c  o  m
    try {
        htTaskDAO = getTaskDAO(taskIdentifier);
    } catch (Exception e) {
        log.error("Error occurred while retrieving task data", e);
        throw new SetTaskOutputFaultException(e);
    }

    QName taskName = QName.valueOf(htTaskDAO.getName());

    //Check hash map for output message template
    Element outputMsgTemplate = outputTemplates.get(taskName);

    if (outputMsgTemplate == null) {
        //Output message template not available

        try {
            //generate output message template
            int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
            HumanTaskBaseConfiguration htConf = HumanTaskServiceComponent.getHumanTaskServer()
                    .getTaskStoreManager().getHumanTaskStore(tenantID).getTaskConfiguration(taskName);
            TaskConfiguration taskConf = (TaskConfiguration) htConf;

            //retrieve response binding
            Service callbackService = (Service) taskConf.getResponseWSDL().getServices()
                    .get(taskConf.getCallbackServiceName());
            Port callbackPort = (Port) callbackService.getPorts().get(taskConf.getCallbackPortName());
            String callbackBinding = callbackPort.getBinding().getQName().getLocalPart();

            outputMsgTemplate = createSoapTemplate(taskConf.getResponseWSDL().getDocumentBaseURI(),
                    taskConf.getResponsePortType().getLocalPart(), taskConf.getResponseOperation(),
                    callbackBinding);
        } catch (Exception e) {
            log.error("Error occurred while output message template generation", e);
            throw new SetTaskOutputFaultException("Unable to generate output message", e);
        }

        //add to the template HashMap
        if (outputMsgTemplate != null) {
            outputTemplates.put(taskName, outputMsgTemplate);

        } else {
            log.error("Unable to create output message template");
            throw new SetTaskOutputFaultException("Unable to generate output message");
        }
    }

    //update template with new values
    try {
        //TODO improve this section with caching
        QName renderingType = new QName(htRenderingNS, "output", "wso2");
        String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
        SetOutputvalueType[] valueSet = values.getValue();

        if (outputRenderings != null && valueSet.length > 0) {
            Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
            //update elements in the template to create output xml
            for (int i = 0; i < valueSet.length; i++) {
                Element outElement = getOutputElementById(valueSet[i].getId(), outputRenderingsElement);
                if (outElement != null) {
                    outputMsgTemplate = updateXmlByXpath(outputMsgTemplate,
                            outElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent(),
                            valueSet[i].getString(), outputRenderingsElement.getOwnerDocument());
                }
            }
        } else {
            log.error("Retrieving output renderings failed");
            throw new SetTaskOutputFaultException("Retrieving output renderings failed");
        }

        //TODO what is this NCName?
        taskOps.setOutput(taskIdentifier, new NCName("message"), DOMUtils.domToString(outputMsgTemplate));

    } catch (IllegalArgumentFault illegalArgumentFault) {
        //Error occurred while retrieving HT renderings and set output message
        throw new SetTaskOutputFaultException(illegalArgumentFault);
    } catch (SAXException e) {
        log.error("Error occured while parsing output renderings", e);
        throw new SetTaskOutputFaultException("Response message generation failed");
    } catch (XPathExpressionException e) {
        //Error occured while updating elements in the template to create output xml
        log.error("XPath evaluation failed", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    } catch (Exception e) {
        //Error occurred while updating template with new values
        log.error("Error occurred while updating template with new values", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    }

    SetTaskOutputResponse response = new SetTaskOutputResponse();
    response.setSuccess(true);

    return response;
}

From source file:org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task.java

public void fail(String faultName, Element faultData) {
    if (faultData != null && StringUtils.isNotEmpty(faultName)) {
        MessageDAO faultMessage = new Message();
        faultMessage.setMessageType(MessageDAO.MessageType.FAILURE);
        faultMessage.setData(faultData);
        faultMessage.setName(QName.valueOf(faultName));
        faultMessage.setTask(this);
        this.setFailureMessage(faultMessage);
    }//from ww w . j  av  a2  s . c om
    this.setStatus(TaskStatus.FAILED);
    this.getEntityManager().merge(this);
}

From source file:org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task.java

public void persistFault(String faultName, Element faultData) {
    if (StringUtils.isNotEmpty(faultName) && faultData != null) {
        MessageDAO faultMessage = new Message();
        faultMessage.setMessageType(MessageDAO.MessageType.FAILURE);
        faultMessage.setData(faultData);
        faultMessage.setName(QName.valueOf(faultName));
        faultMessage.setTask(this);
        this.setFailureMessage(faultMessage);
        this.getEntityManager().merge(this);
    }/*from w  w w. j a  v a2s. co  m*/
}

From source file:org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task.java

public void persistOutput(String outputName, Element outputData) {
    if (StringUtils.isNotEmpty(outputName) && outputData != null) {
        MessageDAO output = new Message();
        output.setMessageType(MessageDAO.MessageType.OUTPUT);

        Document doc = DOMUtils.newDocument();
        Element message = doc.createElement("message");
        doc.appendChild(message);/* ww w. j a  v a  2s  .  c o  m*/
        Node importedNode = doc.importNode(outputData, true);
        message.appendChild(importedNode);
        output.setData(message);

        output.setName(QName.valueOf(outputName));
        output.setTask(this);
        this.setOutputMessage(output);
        this.getEntityManager().merge(this);
    }
}

From source file:org.wso2.carbon.humantask.core.engine.util.CommonTaskUtil.java

/**
 * Gets the task configuration object for the given task.
 *
 * @param task :/*from  w  w w . j  av a2  s.  co  m*/
 * @return : The task configuration object.
 */
public static HumanTaskBaseConfiguration getTaskConfiguration(TaskDAO task) {
    HumanTaskStore taskStore = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager()
            .getHumanTaskStore(task.getTenantId());
    return taskStore.getTaskConfiguration(QName.valueOf(task.getName()));
}

From source file:org.wso2.carbon.humantask.core.scheduler.JobProcessorImpl.java

private void executeDeadline(long taskId, String name) throws HumanTaskException {
    //TODO what if two deadlines fired at the same time???
    //TODO do the needful for deadlines. i.e create notifications and re-assign
    log.info("ON DEADLINE: " + " : now: " + new Date());

    TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection()
            .getTask(taskId);/*from  ww  w.  j  a va  2 s  .co  m*/

    // Setting the tenant id and tenant domain
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(task.getTenantId());
    String tenantDomain = null;
    try {
        tenantDomain = HumanTaskServiceComponent.getRealmService().getTenantManager()
                .getDomain(task.getTenantId());
    } catch (UserStoreException e) {
        log.error(" Cannot find the tenant domain " + e.toString());
    }

    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }

    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);

    TaskConfiguration taskConf = (TaskConfiguration) HumanTaskServiceComponent.getHumanTaskServer()
            .getTaskStoreManager().getHumanTaskStore(task.getTenantId())
            .getTaskConfiguration(QName.valueOf(task.getName()));
    TDeadline deadline = taskConf.getDeadline(name);
    EvaluationContext evalCtx = new ExpressionEvaluationContext(task, taskConf);

    List<TEscalation> validEscalations = new ArrayList<TEscalation>();
    boolean reassingnmentAdded = false;
    for (TEscalation escalation : deadline.getEscalationArray()) {
        if (!escalation.isSetCondition()) {
            //We only need the first Re-assignment and we ignore all other re-assignments
            if (escalation.isSetReassignment() && !reassingnmentAdded) {
                reassingnmentAdded = true;
            } else if (escalation.isSetReassignment()) {
                continue;
            }
            validEscalations.add(escalation);
            continue;
        }

        if (evaluateCondition(escalation.getCondition().newCursor().getTextValue(),
                escalation.getCondition().getExpressionLanguage() == null ? taskConf.getExpressionLanguage()
                        : escalation.getCondition().getExpressionLanguage(),
                evalCtx)) {
            if (escalation.isSetReassignment() && !reassingnmentAdded) {
                reassingnmentAdded = true;
            } else if (escalation.isSetReassignment()) {
                continue;
            }
            validEscalations.add(escalation);
        }
    }

    //We may do this in the above for loop as well
    for (TEscalation escalation : validEscalations) {
        if (log.isDebugEnabled()) {
            log.debug("Escalation: " + escalation.getName());
        }
        if (escalation.isSetLocalNotification() || escalation.isSetNotification()) {
            QName qName;
            if (escalation.isSetLocalNotification()) {
                qName = escalation.getLocalNotification().getReference();
            } else {
                qName = new QName(taskConf.getName().getNamespaceURI(), escalation.getNotification().getName());
            }

            HumanTaskBaseConfiguration notificationConfiguration = HumanTaskServiceComponent
                    .getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(task.getTenantId())
                    .getActiveTaskConfiguration(qName);
            if (notificationConfiguration == null) {
                log.error("Fatal Error, notification definition not found for name " + qName.toString());
                return;
            }

            TaskCreationContext taskContext = new TaskCreationContext();
            taskContext.setTaskConfiguration(notificationConfiguration);
            taskContext.setTenantId(task.getTenantId());
            taskContext.setPeopleQueryEvaluator(
                    HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator());

            Map<String, Element> tempBodyParts = new HashMap<String, Element>();
            Map<String, Element> tempHeaderParts = new HashMap<String, Element>();
            QName tempName = null;

            TToParts toParts = escalation.getToParts();
            if (toParts == null) {
                //get the input message of the task
                MessageDAO msg = task.getInputMessage();
                tempName = msg.getName();
                for (Map.Entry<String, Element> partEntry : msg.getBodyParts().entrySet()) {
                    tempBodyParts.put(partEntry.getKey(), partEntry.getValue());
                }
                for (Map.Entry<String, Element> partEntry : msg.getHeaderParts().entrySet()) {
                    tempHeaderParts.put(partEntry.getKey(), partEntry.getValue());
                }

                taskContext.setMessageBodyParts(tempBodyParts);
                taskContext.setMessageHeaderParts(tempHeaderParts);
                taskContext.setMessageName(tempName);
            } else {
                for (TToPart toPart : toParts.getToPartArray()) {
                    if (!notificationConfiguration.isValidPart(toPart.getName())) {
                        //This validation should be done at the deployment time
                        String errMsg = "The part: " + toPart.getName() + " is not available"
                                + " in the corresponding WSDL message";
                        log.error(errMsg);
                        throw new RuntimeException(errMsg);
                    }
                    String expLang = toPart.getExpressionLanguage() == null ? taskConf.getExpressionLanguage()
                            : toPart.getExpressionLanguage();
                    Node nodePart = HumanTaskServerHolder.getInstance().getHtServer().getTaskEngine()
                            .getExpressionLanguageRuntime(expLang)
                            .evaluateAsPart(toPart.newCursor().getTextValue(), toPart.getName(), evalCtx);
                    tempBodyParts.put(toPart.getName(), (Element) nodePart);
                }
            }

            taskContext.setMessageBodyParts(tempBodyParts);
            taskContext.setMessageHeaderParts(tempHeaderParts);
            taskContext.setMessageName(tempName);
            HumanTaskServerHolder.getInstance().getHtServer().getTaskEngine().getDaoConnectionFactory()
                    .getConnection().createTask(taskContext);
        } else { //if re-assignment
            if (escalation.getReassignment().getPotentialOwners().isSetFrom()) {
                escalation.getReassignment().getPotentialOwners().getFrom().getArgumentArray();

                String roleName = null;
                for (TArgument argument : escalation.getReassignment().getPotentialOwners().getFrom()
                        .getArgumentArray()) {
                    if ("role".equals(argument.getName())) {
                        roleName = argument.newCursor().getTextValue().trim();
                    }
                }

                if (roleName == null) {
                    String errMsg = "Value for argument name 'role' is expected.";
                    log.error(errMsg);
                    throw new Scheduler.JobProcessorException(errMsg);
                }

                if (!isExistingRole(roleName, task.getTenantId())) {
                    log.warn("Role name " + roleName + " does not exist for tenant id" + task.getTenantId());
                }

                List<OrganizationalEntityDAO> orgEntities = new ArrayList<OrganizationalEntityDAO>();
                OrganizationalEntityDAO orgEntity = HumanTaskServiceComponent.getHumanTaskServer()
                        .getDaoConnectionFactory().getConnection().createNewOrgEntityObject(roleName,
                                OrganizationalEntityDAO.OrganizationalEntityType.GROUP);
                orgEntities.add(orgEntity);
                task.replaceOrgEntitiesForLogicalPeopleGroup(
                        GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS, orgEntities);
            } else {
                String errMsg = "From element is expected inside the assignment";
                log.error(errMsg);
                throw new Scheduler.JobProcessorException(errMsg);
            }
        }
    }
}

From source file:org.wso2.carbon.identity.workflow.impl.WorkflowImplServiceImpl.java

/**
 * This method is used to remove the BPS Artifacts upon a deletion of
 * a Workflow.//www .  j  a  va 2  s. com
 *
 * @param workflow - Workflow request to be deleted.
 * @throws WorkflowImplException
 */

@Override
public void removeBPSPackage(Workflow workflow) throws WorkflowImplException {

    List<WorkflowImplServiceListener> workflowListenerList = WorkflowImplServiceDataHolder.getInstance()
            .getWorkflowListenerList();
    for (WorkflowImplServiceListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreRemoveBPSPackage(workflow);
        }
    }
    WorkflowImplService workflowImplService = WorkflowImplServiceDataHolder.getInstance()
            .getWorkflowImplService();
    WorkflowManagementService workflowManagementService = WorkflowImplServiceDataHolder.getInstance()
            .getWorkflowManagementService();

    if (workflowImplService == null || workflowManagementService == null) {
        throw new WorkflowImplException(
                "Error while deleting the BPS artifacts of: " + workflow.getWorkflowName());
    }

    try {
        List<Parameter> workflowParameters = workflowManagementService
                .getWorkflowParameters(workflow.getWorkflowId());
        Parameter bpsParameter = WorkflowManagementUtil.getParameter(workflowParameters,
                WFImplConstant.ParameterName.BPS_PROFILE, WFConstant.ParameterHolder.WORKFLOW_IMPL);
        if (bpsParameter == null) {
            throw new WorkflowImplException(
                    "Error while deleting the BPS artifacts of: " + workflow.getWorkflowName());
        }
        String bpsProfileName = bpsParameter.getParamValue();
        if (StringUtils.isEmpty(bpsProfileName)) {
            throw new WorkflowImplException(
                    "Error while deleting the BPS artifacts of: " + workflow.getWorkflowName());
        }

        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        BPSProfile bpsProfile = workflowImplService.getBPSProfile(bpsProfileName, tenantId);

        if (log.isDebugEnabled()) {
            log.debug("Removing BPS Artifacts of " + bpsProfileName + " " + "for Tenant ID : " + tenantId);
        }

        BPELPackageManagementServiceClient bpsPackageClient;
        ProcessManagementServiceClient bpsProcessClient;

        //Authorizing BPS Package Management & BPS Process Management Stubs.
        String host = bpsProfile.getManagerHostURL();
        if (bpsProfileName.equals(WFImplConstant.DEFAULT_BPS_PROFILE_NAME)) {
            //If emebeded_bps, use mutual ssl authentication
            bpsPackageClient = new BPELPackageManagementServiceClient(host, bpsProfile.getUsername());
            bpsProcessClient = new ProcessManagementServiceClient(host, bpsProfile.getUsername());
        } else {
            //For external BPS profiles, use password authentication
            bpsPackageClient = new BPELPackageManagementServiceClient(host, bpsProfile.getUsername(),
                    bpsProfile.getPassword());
            bpsProcessClient = new ProcessManagementServiceClient(host, bpsProfile.getUsername(),
                    bpsProfile.getPassword());
        }

        DeployedPackagesPaginated deployedPackagesPaginated = bpsPackageClient.listDeployedPackagesPaginated(0,
                workflow.getWorkflowName());
        PackageType[] packageTypes = deployedPackagesPaginated.get_package();
        if (packageTypes == null || packageTypes.length == 0) {
            throw new WorkflowImplException(
                    "Error while deleting the BPS artifacts of: " + workflow.getWorkflowName());
        }
        int numberOfPackages = packageTypes.length;
        for (int i = 0; i < numberOfPackages; i++) {
            PackageType packageType = deployedPackagesPaginated.get_package()[i];
            int numberOfVersions = packageType.getVersions().getVersion().length;
            //Iterating through BPS Packages deployed for the Workflow and retires each associated active processes.
            for (int j = 0; j < numberOfVersions; j++) {
                Version_type0 versionType = packageType.getVersions().getVersion()[j];
                if (versionType.getIsLatest()) {
                    int numberOfProcesses = versionType.getProcesses().getProcess().length;
                    if (numberOfProcesses == 0) {
                        throw new WorkflowImplException(
                                "Error while deleting the BPS artifacts of: " + workflow.getWorkflowName());
                    }
                    for (int k = 0; k < numberOfProcesses; k++) {
                        QName pid = null;
                        try {
                            String processStatus = versionType.getProcesses().getProcess()[k].getStatus()
                                    .getValue();
                            if (StringUtils.equals(processStatus, WFImplConstant.BPS_STATUS_ACTIVE)) {
                                String processID = versionType.getProcesses().getProcess()[k].getPid();
                                pid = QName.valueOf(processID);
                                bpsProcessClient.retireProcess(pid);
                            }
                        } catch (RemoteException | ProcessManagementException e) {
                            //If exception throws at retiring one process, it will continue with
                            // other processes without terminating.
                            log.info("Failed to retire BPS process : " + pid);
                        }
                    }
                }
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("BPS Artifacts Successfully removed for Workflow : " + workflow.getWorkflowName());
        }

    } catch (WorkflowException | PackageManagementException | RemoteException e) {
        throw new WorkflowImplException(
                "Error while deleting the BPS Artifacts of the Workflow " + workflow.getWorkflowName(), e);
    }
    for (WorkflowImplServiceListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostRemoveBPSPackage(workflow);
        }
    }

}

From source file:org.xchain.example.namespaces.guide.HelloWorldCommand.java

/**
 * This method will be called when an {http://www.xchain.org/guide}hello-world element is encountered.
 *
 * @param context the context in which this command is called.
 *///w w  w .j  a  v a 2 s .  c  om
public boolean execute(JXPathContext context) throws Exception {
    // create a QName for the variable that we are going to set.
    QName name = QName.valueOf("{http://www.xchain.org/guide}hello");

    // declare the variable.  Out of the box, JXPath does not cleanly implement variables with
    // QNames and it does not have a concept of scope, so we will need to cast the variables
    // class to a org.xchain.framework.jxpath.ScopedQNameVariables class.
    ((ScopedQNameVariables) context.getVariables()).declareVariable(name, "Hello World", Scope.chain);

    // return false, so that other chains will execute.
    return false;
}