Package org.jbpm.wire.binding

Source Code of org.jbpm.wire.binding.InvokeBinding

/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.wire.binding;

import java.util.List;

import org.jbpm.wire.descriptor.ArgDescriptor;
import org.jbpm.wire.descriptor.ObjectDescriptor;
import org.jbpm.wire.operation.InvokeOperation;
import org.jbpm.wire.xml.WireParser;
import org.jbpm.xml.Binding;
import org.jbpm.xml.Parse;
import org.jbpm.xml.Parser;
import org.jbpm.xml.XmlUtil;
import org.w3c.dom.Element;

/**
* <p>Defines a {@link InvokeOperation}</p>
*
* <p>A invoke is defined by a <b><code>{@literal <invoke>}</code></b> xml element.</p>
*
* <p>This element has a attribute "method", which specifies the name of the method to invoke.</p>
* <p>This element contains a list of child elements that defines {@link ArgDescriptor}s. (see {@link WireParser} )
* This list of ArgDescriptors will be used to create the arguments of the invoked method.</p>
*
* <h3>Example</h3>
*
* Consider the following class:
* <pre> public class Foo {
*   String bar = "";
*   public void appendToBar(String text) {
*     bar += text;
*   }
* }</pre>
*
* The following Xml declaration will create an object 'o' of class 'Foo' (see {@link ObjectDescriptor}), and
* invoke the method <code>o.appendToBar</code> with the value <code>hello</code> as a parameter.
*
* <pre> &lt;objects&gt;
*   &lt;object name='o' class='Foo'&gt;
*     &lt;invoke method='appendToBar'&gt;
*       &lt;arg&gt;
*        &lt;string value='hello' /&gt;
*       &lt;/arg&gt;
*     &lt;/invoke&gt;
*   &lt;/object&gt;
* &lt;/objects&gt;</pre>
*
* The resulting value of <code>o.bar</code> will be <code>hello</code>.
*
* @author Tom Baeyens
* @author Guillaume Porcher (documentation)
*
* @see WireParser
* @see ObjectBinding
*/

public class InvokeBinding implements Binding {
  public Object parse(Element element, Parse parse, Parser parser) {
    InvokeOperation invokeOperation = new InvokeOperation();
    if (element.hasAttribute("method")) {
      invokeOperation.setMethodName(element.getAttribute("method"));
    } else {
      parse.addProblem("invoke must have method : "+XmlUtil.toString(element));
    }
    List<Element> argElements = XmlUtil.elements(element, "arg");
    WireParser wireParser = (WireParser) parser;
    List<ArgDescriptor> argDescriptors = wireParser.parseArgs(argElements, parse);
    invokeOperation.setArgDescriptors(argDescriptors);
    return invokeOperation;
  }
}
TOP

Related Classes of org.jbpm.wire.binding.InvokeBinding

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.