
org.ow2.bonita.facade.impl.CommandAPIImpl 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.facade.impl;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ow2.bonita.pvm.env.Environment;
import org.ow2.bonita.facade.internal.InternalCommandAPI;
import org.ow2.bonita.facade.uuid.PackageDefinitionUUID;
import org.ow2.bonita.runtime.ClassDataLoader;
import org.ow2.bonita.util.Command;
public class CommandAPIImpl implements InternalCommandAPI {
private static final Logger LOG = Logger.getLogger(CommandAPIImpl.class.getName());
protected CommandAPIImpl() {
}
public T execute(final Command command) throws Exception {
return executeCommand(command, null);
}
public T execute(final Command command, final PackageDefinitionUUID packageUUID)
throws Exception {
return executeCommand(command, packageUUID);
}
private T executeCommand(final Command command, final PackageDefinitionUUID packageUUID) throws Exception {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Executing command: " + command + ". PackageUUID: " + packageUUID);
}
ClassLoader classLoader = null;
if (packageUUID != null) {
//the command was deployed at package level
classLoader = ClassDataLoader.getPackageClassLoader(packageUUID);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Executing a command. packageUUID is not null, packageClassLoader found: " + classLoader);
}
}
if (classLoader == null) {
classLoader = ClassDataLoader.getCommonClassLoader();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Executing a command. commonClassLoader found: " + classLoader);
}
}
if (classLoader == null) {
classLoader = contextClassLoader;
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Executing a command. commonClassLoader not found, taking the contextClassLoader: "
+ classLoader);
}
}
try {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Executing a command. Setting current classloader to: " + classLoader);
}
Thread.currentThread().setContextClassLoader(classLoader);
return command.execute(Environment.getCurrent());
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy