All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.parsing.binding.ParticipantBinding Maven / Gradle / Ivy

/**
 * Copyright (C) 2006  Bull S. A. S.
 * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
 * This library 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
 * version 2.1 of the License.
 * This library 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
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA  02110-1301, USA.
 **/
package org.ow2.bonita.parsing.binding;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.ow2.bonita.pvm.internal.util.XmlUtil;
import org.ow2.bonita.pvm.internal.xml.Parse;
import org.ow2.bonita.pvm.internal.xml.Parser;
import org.ow2.bonita.definition.InstanceInitiator;
import org.ow2.bonita.facade.def.element.ExternalReferenceDefinition;
import org.ow2.bonita.facade.def.element.RoleMapperDefinition;
import org.ow2.bonita.facade.def.element.impl.RoleMapperDefinitionImpl;
import org.ow2.bonita.facade.def.majorElement.ParticipantDefinition;
import org.ow2.bonita.facade.def.majorElement.ParticipantDefinition.ParticipantType;
import org.ow2.bonita.facade.def.majorElement.impl.ParticipantDefinitionImpl;
import org.ow2.bonita.facade.uuid.PackageDefinitionUUID;
import org.ow2.bonita.facade.uuid.ParticipantDefinitionUUID;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.services.util.ServiceEnvTool;
import org.w3c.dom.Element;

/**
 * @author Marc Blachon, Guillaume Porcher, Charles Souillard, Miguel Valdes, Pierre Vigneras
 */
public class ParticipantBinding extends MajorElementBinding {

  private static final Logger LOG = Logger.getLogger(PackageBinding.class.getName());

  public ParticipantBinding() {
    super("Participant");
  }

  public Object parse(final Element participantElement, final Parse parse, final Parser parser) {
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("parsing element = " + participantElement);
    }


    final String id = getId(participantElement);
    final String name = getName(participantElement);

    final ParticipantDefinitionUUID recordUUID = ServiceEnvTool.getUUIDGenerator().getParticipantDefinitionUUID(
        getObject(PackageDefinitionUUID.class, parse),
        getObject(ProcessDefinitionUUID.class, parse),
        id);
    parse.pushObject(recordUUID);

    final RoleMapperDefinition roleMapper = getRoleMapper(participantElement, parse);

    final String description = getChildTextContent(participantElement, "Description");

    ParticipantType participantType = null;
    final Element participantTypeElement = XmlUtil.element(participantElement, "ParticipantType");
    if (participantElement != null) {
      participantType = getEnumValue(ParticipantType.class, XmlUtil.attribute(participantTypeElement, "Type"), null);
    }
    if (participantType == null) {
      parse.addProblem("Participant: " + id
          + " does not define the mandatory Type attribute on ParticipantType element.");
    } else if (ParticipantType.RESOURCE_SET.equals(participantType)) {
      parse.addProblem("Participant type: " + participantType + " is currently not supported by Bonita");
    }

    final ExternalReferenceDefinition externalReference = getExternalereference(participantElement);
    if (externalReference != null) {
      parse.addProblem("Externalreference not supported on Participant element.");
    }

    final ParticipantDefinition participant = new ParticipantDefinitionImpl(recordUUID, id,
        getObject(PackageDefinitionUUID.class, parse), getObject(ProcessDefinitionUUID.class, parse),
        description, roleMapper, externalReference, participantType, name);

    parse.popObject();
    return participant;
  }

  protected RoleMapperDefinition getRoleMapper(final Element participantElement, final Parse parse) {
    final Element mapperElement = getExtendedAttribute(participantElement, "Mapper");
    if (mapperElement != null) {
      final String value = XmlUtil.attribute(mapperElement, "Value");
      String className = null;
      if ("Custom".equals(value)) {
        final Element mapperClassNameElement = getExtendedAttribute(participantElement, "MapperClassName");
        className = XmlUtil.attribute(mapperClassNameElement, "Value");
      } else if ("Properties".equals(value)) {
        parse.addWarning("Mapper type 'Properties' is a Bonita v3 XPDL extension. Please use 'Instance Initiator' instead");
        className = InstanceInitiator.class.getName();
      } else if ("Instance Initiator".equals(value)) {
        className = InstanceInitiator.class.getName();
      } else {
        parse.addProblem("Unsupported value on extendedAttribute Mapper: " + value);
      }
      return new RoleMapperDefinitionImpl(className, null);
    }
    return null;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy