Example usage for org.dom4j Element elementTextTrim

List of usage examples for org.dom4j Element elementTextTrim

Introduction

In this page you can find the example usage for org.dom4j Element elementTextTrim.

Prototype

String elementTextTrim(QName qname);

Source Link

Usage

From source file:org.jboss.as.ee.deployment.spi.DeploymentMetaData.java

License:Open Source License

private void init(Document document) {
    Element root = document.getRootElement();
    deploymentName = root.elementTextTrim("deployment-name");
    Iterator it = root.elementIterator("deployment-entry");
    while (it.hasNext()) {
        Element element = (Element) it.next();
        String archiveName = element.elementTextTrim("archive-name");
        String descriptorName = element.elementTextTrim("descriptor-name");
        addEntry(archiveName, descriptorName);
    }//from  www .  j av  a2 s . c o  m
}

From source file:org.jboss.mx.metadata.JBossXMBean10.java

License:Open Source License

protected ModelMBeanConstructorInfo[] buildConstructorInfo(List constructors)
        throws NotCompliantMBeanException {

    List infos = new ArrayList();

    for (Iterator it = constructors.iterator(); it.hasNext();) {
        Element constr = (Element) it.next();
        String name = constr.elementTextTrim("name");
        String description = constr.elementTextTrim("description");
        List params = constr.elements("parameter");

        MBeanParameterInfo[] paramInfo = buildParameterInfo(params);

        Descriptor descr = getDescriptor(constr, name, OPERATION_DESCRIPTOR);
        descr.setField(ROLE, ROLE_CONSTRUCTOR);

        ModelMBeanConstructorInfo info = new ModelMBeanConstructorInfo(name, description, paramInfo, descr);

        infos.add(info);/*from www .java  2 s  .com*/
    }

    return (ModelMBeanConstructorInfo[]) infos.toArray(new ModelMBeanConstructorInfo[0]);
}

From source file:org.jboss.mx.metadata.JBossXMBean10.java

License:Open Source License

protected ModelMBeanOperationInfo[] buildOperationInfo(List operations) throws NotCompliantMBeanException {
    List infos = new ArrayList();

    for (Iterator it = operations.iterator(); it.hasNext();) {
        Element oper = (Element) it.next();
        String name = oper.elementTextTrim("name");
        String description = oper.elementTextTrim("description");
        String type = oper.elementTextTrim("return-type");
        String impact = oper.attributeValue("impact");
        List params = oper.elements("parameter");

        MBeanParameterInfo[] paramInfo = buildParameterInfo(params);

        Descriptor descr = getDescriptor(oper, name, OPERATION_DESCRIPTOR);
        descr.setField(ROLE, ROLE_OPERATION);

        // defaults to ACTION_INFO
        int operImpact = MBeanOperationInfo.ACTION_INFO;

        if (impact != null) {
            if (impact.equals(INFO))
                operImpact = MBeanOperationInfo.INFO;
            else if (impact.equals(ACTION))
                operImpact = MBeanOperationInfo.ACTION;
            else if (impact.equals(ACTION_INFO))
                operImpact = MBeanOperationInfo.ACTION_INFO;
        }/*from   w w w.j a va2 s .  co  m*/

        // default return-type is void
        if (type == null)
            type = "void";

        ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(name, description, paramInfo, type,
                operImpact, descr);

        infos.add(info);
    }

    return (ModelMBeanOperationInfo[]) infos.toArray(new ModelMBeanOperationInfo[0]);
}

From source file:org.jboss.mx.metadata.JBossXMBean10.java

License:Open Source License

protected ModelMBeanNotificationInfo[] buildNotificationInfo(List notifications)
        throws NotCompliantMBeanException {

    List infos = new ArrayList();

    for (Iterator it = notifications.iterator(); it.hasNext();) {
        Element notif = (Element) it.next();
        String name = notif.elementTextTrim("name");
        String description = notif.elementTextTrim("description");
        List notifTypes = notif.elements("notification-type");
        Descriptor descr = getDescriptor(notif, name, NOTIFICATION_DESCRIPTOR);

        List types = new ArrayList();

        for (Iterator iterator = notifTypes.iterator(); iterator.hasNext();) {
            Element type = (Element) iterator.next();
            types.add(type.getTextTrim());
        }//from ww w.j  a  va2s .  c  o m

        ModelMBeanNotificationInfo info = new ModelMBeanNotificationInfo(
                (String[]) types.toArray(new String[types.size()]), name, description, descr);

        infos.add(info);
    }

    return (ModelMBeanNotificationInfo[]) infos.toArray(new ModelMBeanNotificationInfo[infos.size()]);
}

From source file:org.jboss.mx.metadata.JBossXMBean10.java

License:Open Source License

protected ModelMBeanAttributeInfo[] buildAttributeInfo(List attributes) throws NotCompliantMBeanException {

    List infos = new ArrayList();

    for (Iterator it = attributes.iterator(); it.hasNext();) {
        Element attr = (Element) it.next();
        String name = attr.elementTextTrim("name");
        String description = attr.elementTextTrim("description");
        String type = attr.elementTextTrim("type");
        String access = attr.attributeValue("access");
        String getMethod = attr.attributeValue("getMethod");
        String setMethod = attr.attributeValue("setMethod");
        Descriptor descr = getDescriptor(attr, name, ATTRIBUTE_DESCRIPTOR);
        //Convert types here from string to specified type
        String unconvertedValue = (String) descr.getFieldValue(CACHED_VALUE);
        if (unconvertedValue != null && !"java.lang.String".equals(type)) {
            descr.setField(CACHED_VALUE, convertValue(unconvertedValue, type));
        } else {// ww  w.j  a  v a 2 s.co m
            // if <value value="xxx"/> is absent
            // try new syntax for VALUE initialization
            // e.g <value><nested-element/></value>
            Object value = getAttributeValue(attr, type, CACHED_VALUE);
            if (value != null)
                descr.setField(CACHED_VALUE, value);
        }
        String unconvertedDefault = (String) descr.getFieldValue(DEFAULT);
        if (unconvertedDefault != null && !"java.lang.String".equals(type)) {
            descr.setField(DEFAULT, convertValue(unconvertedDefault, type));
        } else {
            // if <defaul value="xxx"/> is absent
            // try new syntax for DEFAULT initialization
            // e.g <default><nested-element/></default>
            Object value = getAttributeValue(attr, type, DEFAULT);
            if (value != null)
                descr.setField(DEFAULT, value);
        }
        if (getMethod != null) {
            descr.setField(GET_METHOD, getMethod);
        } // end of if ()

        if (setMethod != null) {
            descr.setField(SET_METHOD, setMethod);
        } // end of if ()

        // defaults read-write
        boolean isReadable = true;
        boolean isWritable = true;

        if (access.equalsIgnoreCase("read-only"))
            isWritable = false;

        else if (access.equalsIgnoreCase("write-only"))
            isReadable = false;

        ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(name, type, description, isReadable,
                isWritable, false, descr);

        infos.add(info);
    }

    return (ModelMBeanAttributeInfo[]) infos.toArray(new ModelMBeanAttributeInfo[0]);
}

From source file:org.jboss.mx.metadata.JBossXMBean10.java

License:Open Source License

protected MBeanParameterInfo[] buildParameterInfo(List parameters) {
    Iterator it = parameters.iterator();
    List infos = new ArrayList();

    while (it.hasNext()) {
        Element param = (Element) it.next();
        String name = param.elementTextTrim("name");
        String type = param.elementTextTrim("type");
        String descr = param.elementTextTrim("description");

        MBeanParameterInfo info = new MBeanParameterInfo(name, type, descr);

        infos.add(info);//w w w . java  2 s  .  co  m
    }

    return (MBeanParameterInfo[]) infos.toArray(new MBeanParameterInfo[0]);
}

From source file:org.jbpm.jpdl.internal.convert.Jpdl3Converter.java

License:Open Source License

/**
 * Call this method to convert the jpdl3 process.
 * The return value will be a converted jpdl4 XML model.
 *//* w  w  w.  j av a 2  s  .com*/
public Document readAndConvert() {

    // create a new definition
    jpdl4Document = DocumentHelper.createDocument();

    // initialize lists
    problems = new ArrayList<Problem>();
    unresolvedTransitionDestinations = new ArrayList<Object[]>();
    unresolvedActionReferences = new ArrayList<Object[]>();

    try {

        // parse the document into a XML dom tree
        jpdl3Document = Jpdl3ConverterParser.parse(inputSource, this);
        jpdl4Document.setXMLEncoding(jpdl3Document.getXMLEncoding());

        // Convert the root element 
        Element jpdl3Root = jpdl3Document.getRootElement();
        Element jpdl4Root = parseProcessDefinitionAttributes(jpdl3Root);

        // convert process description as comment
        String description = jpdl3Root.elementTextTrim("description");
        if (description != null) {
            jpdl4Root.addComment(description);
        }

        // first pass
        convertSwimlanes(jpdl3Root, jpdl4Root);
        convertActions(jpdl3Root, null, null); // Todo: refactor
        convertNodes(jpdl3Root, jpdl4Root);
        convertEvents(jpdl3Root, jpdl4Root);
        convertExceptionHandlers(jpdl3Root, jpdl4Root);
        convertTasks(jpdl3Root, jpdl4Root);

        // second pass processing: process any unresolved elements 
        resolveTransitionDestinations();
        //resolveActionReferences(); // not yet implemented
        verifySwimlaneAssignments();

    } catch (Exception e) {
        log.error("couldn't parse process definition", e);
        addProblem(new Problem(Problem.LEVEL_ERROR, "couldn't parse process definition", e));
    }

    // After conversion: check if there were any conversion problems

    if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR)) {
        throw new ConvertException(problems);
    }

    if (problems != null) {
        for (Problem problem : problems) {
            log.warn("process parse warning: " + problem.getDescription());
        }
    }

    return jpdl4Document;
}

From source file:org.jbpm.jpdl.internal.convert.Jpdl3Converter.java

License:Open Source License

public Element convertTask(Element taskElement, Element jpdlElement) {

    Element task4 = jpdlElement.addElement("task");
    String name = taskElement.attributeValue("name");
    if (name != null) {
        task4.attributeValue("name", name);
    }//www  . ja va 2  s .  c  om

    String description = taskElement.elementTextTrim("description");
    if (description != null) {
        task4.addComment(description);
    }

    String condition = taskElement.elementTextTrim("condition");
    if (condition == null) {
        condition = taskElement.attributeValue("condition");
    }
    if (condition == null) {
        addWarning("Unsupported condition attribute converstion for task : " + taskElement.asXML());
    }

    //The converted the elements in task should be in this sequence 
    //assignment-handler, on, notification, reminder, timer

    // assignment
    String swimlaneName = taskElement.attributeValue("swimlane");
    Element assignmentElement = taskElement.element("assignment");

    // if there is a swimlane attribute specified
    if (swimlaneName != null) {

        Element swimLane = swimlanesCollection.get(swimlaneName);
        if (swimLane == null) {
            addWarning("task references unknown swimlane '" + swimlaneName + "':" + taskElement.asXML());
        } else {
            task4.addAttribute("swimlane", swimlaneName);
        }
    } else if (assignmentElement != null) {
        if ((assignmentElement.attribute("actor-id") != null)
                || (assignmentElement.attribute("pooled-actors") != null)) {

            String actorid = assignmentElement.attributeValue("actor-id");
            String pooledactors = assignmentElement.attributeValue("pooled-actors");

            if (actorid != null) {
                task4.addAttribute("assignee", actorid);
            }
            if (pooledactors != null) {
                task4.addAttribute("candidate-groups", pooledactors);
            }

        } else {
            convertAssignmentDelegation(assignmentElement, task4);
        }
    } else {
        // the user has to manage assignment manually, so we better inform him/her.
        log.info("process xml information: no swimlane or assignment specified for task '" + taskElement.asXML()
                + "'");
    }

    //notification attribute
    String notificationsText = taskElement.attributeValue("notify");
    if (notificationsText != null && ("true".equalsIgnoreCase(notificationsText)
            || "on".equalsIgnoreCase(notificationsText) || "yes".equalsIgnoreCase(notificationsText))) {
        //TODO:Review if there is "continue" attribute to converted
        Element notify = task4.addElement("notification");
        notify.addAttribute("continue", "sync");
    }
    //Reminder elements
    convertTaskReminders(taskElement, task4);

    //event elements  
    convertEvents(taskElement, task4);

    //timer elements
    convertTaskTimers(taskElement, task4);

    convertExceptionHandlers(taskElement, task4);

    String duedateText = taskElement.attributeValue("duedate");

    if (duedateText != null) {
        addWarning("Unsupported duedateDate attribute converstion for task : " + taskElement.asXML());
    }

    String priorityText = taskElement.attributeValue("priority");
    if (priorityText != null) {
        addWarning("Unsupported priorityText attribute converstion for task : " + taskElement.asXML());
    }

    String blockingText = taskElement.attributeValue("blocking");
    if (blockingText != null) {
        addWarning("Unsupported blocking attribute converstion for task : " + taskElement.asXML());
    }

    String signallingText = taskElement.attributeValue("signalling");
    if (signallingText != null) {
        addWarning("Unsupported signallingText attribute converstion for task : " + taskElement.asXML());
    }

    Element taskControllerElement = taskElement.element("controller");
    if (taskControllerElement != null) {
        addWarning("Unsupported controller converstion for task : " + taskElement.asXML());
    }

    return task4;
}

From source file:org.jbpm.jpdl.internal.convert.Jpdl3Converter.java

License:Open Source License

public void convertNode(Element jpdl3Element, Element jpdl4Element) {

    String name = jpdl3Element.attributeValue("name");
    if (name != null) {
        jpdl4Element.addAttribute("name", name);
        nodeCollection.put(name, jpdl4Element);
    }/* ww  w  .  ja v a  2 s  .c  o m*/

    // get the node description
    String description = jpdl3Element.elementTextTrim("description");
    if (description != null) {
        jpdl4Element.addComment(description);
    }

    String asyncText = jpdl3Element.attributeValue("async");
    if ("true".equalsIgnoreCase(asyncText)) {
        jpdl4Element.addAttribute("continue", "async");
    } else if ("exclusive".equalsIgnoreCase(asyncText)) {
        jpdl4Element.addAttribute("continue", "exclusive");
    } //else if -> uses the default continue="sync"

    // parse common subelements

    convertNodeTimers(jpdl3Element, jpdl4Element);
    convertEvents(jpdl3Element, jpdl4Element);
    convertExceptionHandlers(jpdl3Element, jpdl4Element);

    // save the transitions and parse them at the end
    addUnresolvedTransitionDestination(jpdl3Element, jpdl4Element);
}

From source file:org.jbpm.jpdl.internal.convert.Jpdl3Converter.java

License:Open Source License

public void resolveTransitionDestination(Element transitionElement, Element jpdl4Element) {

    Element transition4 = jpdl4Element.addElement("transition");
    transition4.addAttribute("name", transitionElement.attributeValue("name"));
    if (transitionElement.elementTextTrim("description") != null) {
        transition4.addComment(transitionElement.elementTextTrim("description"));
    }//from  w w  w  . j a v  a2  s .  c  o m
    //Get condition from jpdl3 element
    String condition = transitionElement.attributeValue("condition");
    if (condition == null) {
        Element conditionElement = transitionElement.element("condition");
        if (conditionElement != null) {
            condition = conditionElement.getTextTrim();
            // for backwards compatibility
            if ((condition == null) || (condition.length() == 0)) {
                condition = conditionElement.attributeValue("expression");
            }
        }
    }

    if (condition != null && condition.length() > 0) {
        Element condition4 = transition4.addElement("condition");
        condition4.addAttribute("expr", condition);
    }

    // set destinationNode of the transition
    String toName = transitionElement.attributeValue("to");
    if (toName == null) {
        addWarning("node '" + transitionElement.getPath()
                + "' has a transition without a 'to'-attribute to specify its destinationNode");
    } else {
        Element to = this.findNode(toName);
        if (to == null) {
            addWarning("transition to='" + toName + "' on node '" + transitionElement.getName()
                    + "' cannot be resolved");
        }

        transition4.addAttribute("to", toName);
    }

    // read the actions
    convertActions(transitionElement, transition4, "");

    convertExceptionHandlers(transitionElement, transition4);
}