org.camunda.bpm.container.impl.metadata.DeploymentMetadataParse Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; 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.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.camunda.bpm.container.impl.ContainerIntegrationLogger;
import org.camunda.bpm.container.impl.metadata.spi.ProcessEnginePluginXml;
import org.camunda.bpm.container.impl.metadata.spi.ProcessEngineXml;
import org.camunda.bpm.engine.impl.ProcessEngineLogger;
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 ContainerIntegrationLogger LOG = ProcessEngineLogger.CONTAINER_INTEGRATION_LOGGER;
public DeploymentMetadataParse(Parser parser) {
super(parser);
}
public Parse execute() {
super.execute();
try {
parseRootElement();
}
catch (Exception e) {
throw LOG.unknownExceptionWhileParsingDeploymentDescriptor(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}
*
* Supports resolution of Ant-style placeholders against system properties.
*
*/
protected void parseProperties(Element element, Map properties) {
for (Element childElement : element.elements()) {
if(PROPERTY.equals(childElement.getTagName())) {
String resolved = PropertyHelper.resolveProperty(System.getProperties(), childElement.getText());
properties.put(childElement.attribute(NAME), resolved);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy