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

org.ow2.bonita.parsing.binding.DataFieldBinding 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.facade.def.dataType.DataTypeDefinition;
import org.ow2.bonita.facade.def.majorElement.DataFieldDefinition;
import org.ow2.bonita.facade.def.majorElement.impl.DataFieldDefinitionImpl;
import org.ow2.bonita.facade.uuid.DataFieldDefinitionUUID;
import org.ow2.bonita.facade.uuid.PackageDefinitionUUID;
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 DataFieldBinding extends MajorElementBinding {

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

  private static String[] javaKeywords = new String[]{"abstract", "continue", "for", "new", "switch",
    "assert", "default", "goto", "package", "synchronized", "boolean", "do", "if", "private", "this", "break",
    "double", "implements", "protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum",
    "instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final", "interface",
    "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while"};

  public DataFieldBinding() {
    super("DataField");
  }

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

    final String id = getId(datafieldElement);
    final String name = getName(datafieldElement);
    for (final String javaKeyword : javaKeywords) {
      if (javaKeyword.equals(id)) {
        parse.addProblem("A datafield is declared with id : " + id + ", it is forbidden as it is a java Keyword");
      }
      if (javaKeyword.equals(name)) {
        parse.addProblem("A datafield is declared with name : " + name + ", it is forbidden as it is a java Keyword");
      }
    }
    final DataFieldDefinitionUUID recordUUID =
      ServiceEnvTool.getUUIDGenerator().getDataFieldDefinitionUUID(
          getObject(PackageDefinitionUUID.class, parse),
          getObject(ProcessDefinitionUUID.class, parse),
          id);
    parse.pushObject(recordUUID);

    final boolean activityDataField = containsExtendedAttribute(datafieldElement, "PropertyActivity");
    if (activityDataField && !datafieldElement.getParentNode().getParentNode().getLocalName().equals("WorkflowProcess")) {
      parse.addProblem("A datafield with processDefinitionUUID = " + id
          + " defined at package level is expected to be an 'activity datafield' as it declares "
          + "the corresponding extended attribute: it is forbiden. "
          + "'Activity datafields' can only be defined at process level.");
    }
    DataTypeDefinition dataType = null;
    final Element dataTypeElement = XmlUtil.element(datafieldElement, "DataType");
    if (dataTypeElement != null) {
      dataType = (DataTypeDefinition) parser.parseElement(dataTypeElement, parse, "dataTypes");
    }
    final String initialValue = getChildTextContent(datafieldElement, "InitialValue");
    final String length = getChildTextContent(datafieldElement, "Length");
    if (length != null) {
      parse.addProblem("Length element not yet supported on element DataField, processDefinitionUUID = " + id);
    }
    final String description = getChildTextContent(datafieldElement, "Description");

    boolean array = false;
    final String isArray = XmlUtil.attribute(datafieldElement, "IsArray");
    if (isArray != null) {
      array = Boolean.valueOf(isArray);
      if (array) {
        parse.addProblem("isArray=true not yet supported on element DataField.");
      }
    }

    final DataFieldDefinition dataFieldDefinition = new DataFieldDefinitionImpl(recordUUID, id,
        getObject(PackageDefinitionUUID.class, parse), getObject(ProcessDefinitionUUID.class, parse),
        dataType, description, initialValue, length, name, array, activityDataField);

    parse.popObject();
    return dataFieldDefinition;
  }

}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy