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

org.camunda.bpm.container.impl.metadata.DeploymentMetadataParse Maven / Gradle / Ivy

There is a newer version: 7.23.0-alpha2
Show newest version
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.camunda.bpm.container.impl.metadata;

import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.CONFIGURATION;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.DATASOURCE;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.DEFAULT;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.*;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.JOB_ACQUISITION;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.NAME;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.PROPERTIES;
import static org.camunda.bpm.container.impl.metadata.DeploymentMetadataConstants.PROPERTY;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.camunda.bpm.container.impl.metadata.spi.ProcessEnginePluginXml;
import org.camunda.bpm.container.impl.metadata.spi.ProcessEngineXml;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.impl.util.xml.Element;
import org.camunda.bpm.engine.impl.util.xml.Parse;
import org.camunda.bpm.engine.impl.util.xml.Parser;

/**
 * 

{@link Parse} implementation for Deployment Metadata.

* *

This class is NOT Threadsafe

* * @author Daniel Meyer * */ public abstract class DeploymentMetadataParse extends Parse { private final static Logger LOGGER = Logger.getLogger(DeploymentMetadataParse.class.getName()); public DeploymentMetadataParse(Parser parser) { super(parser); } public Parse execute() { super.execute(); try { parseRootElement(); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Unknown exception", e); throw new ProcessEngineException("Error while parsing deployment descriptor: " + e.getMessage(), e); } finally { if (hasWarnings()) { logWarnings(); } if (hasErrors()) { throwExceptionForErrors(); } } return this; } /** * to be overridden by subclasses. */ protected abstract void parseRootElement(); /** * parse a <process-engine .../> element and add it to the list of parsed elements */ protected void parseProcessEngine(Element element, List parsedProcessEngines) { ProcessEngineXmlImpl processEngine = new ProcessEngineXmlImpl(); // set name processEngine.setName(element.attribute(NAME)); // set default String defaultValue = element.attribute(DEFAULT); if(defaultValue == null || defaultValue.isEmpty()) { processEngine.setDefault(false); } else { processEngine.setDefault(Boolean.parseBoolean(defaultValue)); } Map properties = new HashMap(); List plugins = new ArrayList(); for (Element childElement : element.elements()) { if(CONFIGURATION.equals(childElement.getTagName())) { processEngine.setConfigurationClass(childElement.getText()); } else if(DATASOURCE.equals(childElement.getTagName())) { processEngine.setDatasource(childElement.getText()); } else if(JOB_ACQUISITION.equals(childElement.getTagName())) { processEngine.setJobAcquisitionName(childElement.getText()); } else if(PROPERTIES.equals(childElement.getTagName())) { parseProperties(childElement, properties); } else if(PLUGINS.equals(childElement.getTagName())) { parseProcessEnginePlugins(childElement, plugins); } } // set collected properties processEngine.setProperties(properties); // set plugins processEngine.setPlugins(plugins); // add the process engine to the list of parsed engines. parsedProcessEngines.add(processEngine); } /** * Transform a <plugins ... /> structure. */ protected void parseProcessEnginePlugins(Element element, List plugins) { for (Element chidElement : element.elements()) { if(PLUGIN.equals(chidElement.getTagName())) { parseProcessEnginePlugin(chidElement, plugins); } } } /** * Transform a <plugin ... /> structure. */ protected void parseProcessEnginePlugin(Element element, List plugins) { ProcessEnginePluginXmlImpl plugin = new ProcessEnginePluginXmlImpl(); Map properties = new HashMap(); for (Element childElement : element.elements()) { if(PLUGIN_CLASS.equals(childElement.getTagName())) { plugin.setPluginClass(childElement.getText()); } else if(PROPERTIES.equals(childElement.getTagName())) { parseProperties(childElement, properties); } } plugin.setProperties(properties); plugins.add(plugin); } /** * Transform a *
   * <properties>
   *   <property name="name">value</property>
   * </properties>
   * 
* structure into a properties {@link Map} * */ protected void parseProperties(Element element, Map properties) { for (Element childElement : element.elements()) { if(PROPERTY.equals(childElement.getTagName())) { properties.put(childElement.attribute(NAME), childElement.getText()); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy