Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source.
* Copyright 2008-2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This 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; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.deployers.common;
import org.jboss.jca.common.api.metadata.Defaults;
import org.jboss.jca.common.api.metadata.common.CommonAdminObject;
import org.jboss.jca.common.api.metadata.common.CommonConnDef;
import org.jboss.jca.common.api.metadata.common.CommonPool;
import org.jboss.jca.common.api.metadata.common.CommonSecurity;
import org.jboss.jca.common.api.metadata.common.CommonTimeOut;
import org.jboss.jca.common.api.metadata.common.CommonValidation;
import org.jboss.jca.common.api.metadata.common.CommonXaPool;
import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.common.FlushStrategy;
import org.jboss.jca.common.api.metadata.common.Recovery;
import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
import org.jboss.jca.common.api.metadata.ironjacamar.IronJacamar;
import org.jboss.jca.common.api.metadata.ra.AdminObject;
import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
import org.jboss.jca.common.api.metadata.ra.ConnectionDefinition;
import org.jboss.jca.common.api.metadata.ra.Connector;
import org.jboss.jca.common.api.metadata.ra.Connector.Version;
import org.jboss.jca.common.api.metadata.ra.MessageListener;
import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
import org.jboss.jca.common.api.metadata.ra.XsdString;
import org.jboss.jca.common.api.metadata.ra.ra10.ResourceAdapter10;
import org.jboss.jca.common.api.metadata.ra.ra16.Activationspec16;
import org.jboss.jca.common.api.metadata.ra.ra16.Connector16;
import org.jboss.jca.common.metadata.ra.common.ConfigPropertyImpl;
import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager;
import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
import org.jboss.jca.core.connectionmanager.ConnectionManager;
import org.jboss.jca.core.connectionmanager.ConnectionManagerFactory;
import org.jboss.jca.core.connectionmanager.pool.api.Pool;
import org.jboss.jca.core.connectionmanager.pool.api.PoolFactory;
import org.jboss.jca.core.connectionmanager.pool.api.PoolStrategy;
import org.jboss.jca.core.connectionmanager.pool.api.PrefillPool;
import org.jboss.jca.core.recovery.DefaultRecoveryPlugin;
import org.jboss.jca.core.spi.recovery.RecoveryPlugin;
import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery;
import org.jboss.jca.core.util.Injection;
import org.jboss.jca.deployers.DeployersBundle;
import org.jboss.jca.deployers.DeployersLogger;
import org.jboss.jca.validator.Failure;
import org.jboss.jca.validator.FailureHelper;
import org.jboss.jca.validator.Key;
import org.jboss.jca.validator.Severity;
import org.jboss.jca.validator.Validate;
import org.jboss.jca.validator.ValidateClass;
import org.jboss.jca.validator.ValidateObject;
import org.jboss.jca.validator.Validator;
import org.jboss.jca.validator.ValidatorException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.resource.ResourceException;
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.BootstrapContext;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterAssociation;
import javax.resource.spi.TransactionSupport;
import javax.resource.spi.TransactionSupport.TransactionSupportLevel;
import javax.resource.spi.security.PasswordCredential;
import javax.resource.spi.work.WorkContext;
import javax.security.auth.Subject;
import javax.transaction.TransactionManager;
import org.jboss.logging.Messages;
import org.jboss.security.SubjectFactory;
/**
* An abstract resource adapter deployer which contains common functionality
* for all resource adapter archive based deployers.
* @author Jesper Pedersen
*/
public abstract class AbstractResourceAdapterDeployer
{
/** The bundle */
private static DeployersBundle bundle = Messages.getBundle(DeployersBundle.class);
/** the logger **/
protected final DeployersLogger log;
/** trace boolean check */
protected final boolean trace;
/** boolean to set if validation is needed at class level or it should be considered already valid
* (IOW object put in repository at previous steps have been already validated at class level**/
protected final boolean validateClasses;
/** The configuration */
private Configuration configuration = null;
/**
* Create a new AbstractResourceAdapterDeployer.
*
* @param validateClasses validateClasses validateClasses boolean to express if this instance will
* apply validation on classes structure
*/
public AbstractResourceAdapterDeployer(boolean validateClasses)
{
super();
this.log = getLogger();
this.trace = log.isTraceEnabled();
this.validateClasses = validateClasses;
}
/**
* Set the configuration
* @param value value value The value
*/
public void setConfiguration(Configuration value)
{
configuration = value;
}
/**
* Get the configuration
* @return The value
*/
public Configuration getConfiguration()
{
return configuration;
}
/**
* validate archive
*
* @param url url url of the archive
* @param archiveValidation archiveValidation archiveValidation classes and/or to validate.
* @param failures failures failures original list of failures
* @return The list of failures gotten with all new failures added. Null in case of no failures
* or if validation is not run according to {@link #getArchiveValidation()} Setting. It returns null also if
* the concrete implementation of this class set validateClasses instance variable to flase and the list of
* archiveValidation contains one or more instance of {@link ValidateClass} type
*/
public Set validateArchive(URL url, List archiveValidation, Set failures)
{
// Archive validation
if (!getConfiguration().getArchiveValidation())
{
return null;
}
for (Validate validate : archiveValidation)
{
if (!(validate instanceof ValidateObject) && !this.validateClasses)
return null;
}
Validator validator = new Validator();
List partialFailures = validator.validate(archiveValidation);
if (partialFailures != null)
{
if (failures == null)
{
failures = new HashSet();
}
failures.addAll(partialFailures);
}
return failures;
}
/**
* print Failures into Log files.
*
* @param urlFileName urlFileName urlFileName filename Of deployed rar
* @param validator validator validator validator instance used to run validation rules
* @param failures failures failures the list of Failures to be printed
* @param reportDirectory reportDirectory reportDirectory where to put various logs
* @param fhInput fhInput fhInput optional parameter. Normally used only for test or in case of
* FailureHelper already present in context
* @return the error Text
*
*/
public String printFailuresLog(String urlFileName, Validator validator, Collection failures,
File reportDirectory, FailureHelper... fhInput)
{
String errorText = "";
FailureHelper fh = null;
if (fhInput.length == 0)
fh = new FailureHelper(failures);
else
fh = fhInput[0];
if (failures != null && failures.size() > 0)
{
if (reportDirectory == null)
{
reportDirectory = getReportDirectory();
}
if (reportDirectory != null && reportDirectory.exists())
{
int lastSlashIndex = urlFileName.lastIndexOf("/");
int lastSepaIndex = urlFileName.lastIndexOf(File.separator);
int lastIndex = lastSlashIndex > lastSepaIndex ? lastSlashIndex : lastSepaIndex;
if (lastIndex != -1)
urlFileName = urlFileName.substring(lastIndex + 1);
urlFileName += ".log";
File report = new File(reportDirectory, urlFileName);
FileWriter fw = null;
BufferedWriter bw = null;
try
{
fw = new FileWriter(report);
bw = new BufferedWriter(fw, 8192);
bw.write(fh.asText(validator.getResourceBundle()));
bw.flush();
errorText = "Validation failures - see: " + report.getAbsolutePath();
}
catch (IOException ioe)
{
log.validationReportFailure(ioe.getMessage(), ioe);
}
finally
{
if (bw != null)
{
try
{
bw.close();
}
catch (IOException ignore)
{
// Ignore
}
}
if (fw != null)
{
try
{
fw.close();
}
catch (IOException ignore)
{
// Ignore
}
}
}
}
else
{
errorText = fh.asText(validator.getResourceBundle());
}
}
return errorText;
}
/**
* Cehck for failures at a certain level
* @param failures failures failures The failures
* @param severity severity severity The level
* @return True if a failure is found with the specified severity; otherwise false
*/
protected boolean hasFailuresLevel(Collection failures, int severity)
{
if (failures != null)
{
for (Failure failure : failures)
{
if (failure.getSeverity() == severity)
{
return true;
}
}
}
return false;
}
/**
* Start the resource adapter
* @param resourceAdapter resourceAdapter resourceAdapter The resource adapter
* @param bootstrapIdentifier bootstrapIdentifier bootstrapIdentifier The bootstrap context identifier;
* may be null
* @throws DeployException DeployException Thrown if the resource adapter cant be started
*/
@SuppressWarnings("unchecked")
protected void startContext(ResourceAdapter resourceAdapter, String bootstrapIdentifier) throws DeployException
{
try
{
Class clz = resourceAdapter.getClass();
Method start = clz.getMethod("start", new Class[]{BootstrapContext.class});
CloneableBootstrapContext cbc = null;
if (bootstrapIdentifier != null && getConfiguration().getBootstrapContexts() != null)
{
CloneableBootstrapContext bc = getConfiguration().getBootstrapContexts().get(bootstrapIdentifier);
if (bc != null)
cbc = bc.clone();
}
if (cbc == null)
cbc = getConfiguration().getDefaultBootstrapContext().clone();
cbc.setResourceAdapter(resourceAdapter);
start.invoke(resourceAdapter, new Object[]{cbc});
}
catch (InvocationTargetException ite)
{
throw new DeployException(bundle.unableToStartResourceAdapter(resourceAdapter.getClass().getName()),
ite.getTargetException());
}
catch (Throwable t)
{
throw new DeployException(bundle.unableToStartResourceAdapter(resourceAdapter.getClass().getName()), t);
}
}
/**
* Associate resource adapter with ojects if they implement ResourceAdapterAssociation
* @param resourceAdapter resourceAdapter resourceAdapter The resource adapter
* @param object object object The of possible association object
* @throws DeployException DeployException Thrown if the resource adapter cant be started
*/
@SuppressWarnings("unchecked")
protected void associateResourceAdapter(ResourceAdapter resourceAdapter, Object object) throws DeployException
{
if (resourceAdapter != null && object != null)
{
if (object instanceof ResourceAdapterAssociation)
{
try
{
Class clz = object.getClass();
Method setResourceAdapter = clz.getMethod("setResourceAdapter", new Class[]{ResourceAdapter.class});
setResourceAdapter.invoke(object, new Object[]{resourceAdapter});
}
catch (Throwable t)
{
throw new DeployException(bundle.unableToAssociate(object.getClass().getName()), t);
}
}
}
}
/**
* Return a list of ManagedConnectionFactory classes
* @param ra The metadata
* @return The classes
*/
private Set findManagedConnectionFactories(org.jboss.jca.common.api.metadata.ra.ResourceAdapter ra)
{
Set result = new HashSet(1);
if (ra != null)
{
if (ra instanceof ResourceAdapter10)
{
result.add(((ResourceAdapter10)ra).getManagedConnectionFactoryClass().getValue());
}
else
{
ResourceAdapter1516 ra1516 = (ResourceAdapter1516)ra;
if (ra1516.getOutboundResourceadapter() != null)
{
for (org.jboss.jca.common.api.metadata.ra.ConnectionDefinition cd :
ra1516.getOutboundResourceadapter().getConnectionDefinitions())
{
result.add(cd.getManagedConnectionFactoryClass().getValue());
}
}
}
}
return result;
}
/**
* Return a list of AdminObject classes
* @param ra The metadata
* @return The classes
*/
private Set resolveAdminObjects(org.jboss.jca.common.api.metadata.ra.ResourceAdapter ra)
{
Set result = new HashSet(1);
if (ra != null)
{
if (ra instanceof ResourceAdapter1516)
{
ResourceAdapter1516 ra1516 = (ResourceAdapter1516)ra;
if (ra1516.getAdminObjects() != null)
{
for (org.jboss.jca.common.api.metadata.ra.AdminObject ao : ra1516.getAdminObjects())
{
result.add(ao.getAdminobjectClass().getValue());
}
}
}
}
return result;
}
/**
* Find the metadata for a managed connection factory
* @param clz The fully quilified class name for the managed connection factory
* @param mcfs The managed connection facotries
* @param defs The connection definitions
* @param cl The class loader
* @return The metadata; null if none could be found
* @exception DeployException Thrown in case of configuration error
*/
protected Set findConnectionDefinitions(String clz, Set mcfs, List defs,
ClassLoader cl)
throws DeployException
{
Set result = null;
if (mcfs != null && defs != null)
{
// If there is only one we will return that
if (mcfs.size() == 1 && defs.size() == 1)
{
CommonConnDef cd = defs.get(0);
if (cd.getClassName() != null && !clz.equals(cd.getClassName()))
{
log.connectionDefinitionMismatch(cd.getClassName());
throw new DeployException(clz + " not a valid connection definition");
}
boolean add = true;
if (cd.getClassName() != null)
{
if (!verifyManagedConnectionFactory(cd.getClassName(), cl))
{
log.connectionDefinitionInvalid(cd.getClassName());
add = false;
}
}
if (add)
{
result = new HashSet(1);
result.add(cd);
return result;
}
}
// If there are multiple definitions the MCF class name is mandatory
if (clz == null)
throw new IllegalArgumentException(bundle.undefinedManagedConnectionFactory());
for (CommonConnDef cd : defs)
{
if (cd.getClassName() == null)
{
log.connectionDefinitionNull();
}
else
{
if (clz.equals(cd.getClassName()))
{
if (result == null)
result = new HashSet();
result.add(cd);
}
else
{
if (!verifyManagedConnectionFactory(cd.getClassName(), cl))
log.connectionDefinitionInvalid(cd.getClassName());
}
}
}
}
return result;
}
/**
* Verify the MCF definition
* @param clz The class name
* @param cl The class loader
* @return True if MCF, otherwise false
*/
private boolean verifyManagedConnectionFactory(String clz, ClassLoader cl)
{
if (clz != null)
{
try
{
Class> c = Class.forName(clz, true, cl);
if (ManagedConnectionFactory.class.isAssignableFrom(c))
return true;
}
catch (Throwable t)
{
// Nothing we can do
}
}
return false;
}
/**
* Verify a class definition
* @param clz The class name
* @param cl The class loader
* @return True if found, otherwise false
*/
private boolean verifyClass(String clz, ClassLoader cl)
{
if (clz != null)
{
try
{
Class> c = Class.forName(clz, true, cl);
return true;
}
catch (Throwable t)
{
// Nothing we can do
}
}
return false;
}
/**
* Verify that a class implements a certain interface
* @param interfaceClz The interface class name
* @param implClz The implementation class name
* @param cl The class loader
* @return True if correct, otherwise false
*/
private boolean verifyInstance(String interfaceClz, String implClz, ClassLoader cl)
{
if (interfaceClz != null && implClz != null)
{
try
{
Class> interfaceDef = Class.forName(interfaceClz, true, cl);
Class> implDef = Class.forName(implClz, true, cl);
return interfaceDef.isAssignableFrom(implDef);
}
catch (Throwable t)
{
// Nothing we can do
}
}
return false;
}
/**
* Find the metadata for an admin object
* @param clz The fully quilified class name for the admin object
* @param aos The admin object classes
* @param defs The admin object definitions
* @return The metadata; null if none could be found
* @exception DeployException Thrown in case of configuration error
*/
protected Set findAdminObjects(String clz, Set aos, List defs)
throws DeployException
{
Set result = null;
if (aos != null && defs != null)
{
// If there is only one we will return that
if (aos.size() == 1 && defs.size() == 1)
{
org.jboss.jca.common.api.metadata.common.CommonAdminObject cao = defs.get(0);
if (cao.getClassName() != null && !clz.equals(cao.getClassName()))
{
log.adminObjectMismatch(cao.getClassName());
throw new DeployException(clz + " not a valid admin object");
}
result = new HashSet(1);
result.add(cao);
return result;
}
// If there are multiple definitions the admin object class name is mandatory
if (clz == null)
throw new IllegalArgumentException(bundle.undefinedAdminObject());
for (org.jboss.jca.common.api.metadata.common.CommonAdminObject cao : defs)
{
if (cao.getClassName() == null)
{
log.adminObjectNull();
}
else
{
if (clz.equals(cao.getClassName()))
{
if (result == null)
result = new HashSet();
result.add(cao);
}
}
}
}
return result;
}
/**
* Create an instance of the pool configuration based on the input
* @param pp pp pp The pool parameters
* @param tp tp tp The timeout parameters
* @param vp vp vp The validation parameters
* @return The configuration
*/
protected PoolConfiguration createPoolConfiguration(CommonPool pp, CommonTimeOut tp, CommonValidation vp)
{
PoolConfiguration pc = new PoolConfiguration();
if (pp != null)
{
if (pp.getMinPoolSize() != null)
pc.setMinSize(pp.getMinPoolSize().intValue());
if (pp.getMaxPoolSize() != null)
pc.setMaxSize(pp.getMaxPoolSize().intValue());
if (pp.isPrefill() != null)
pc.setPrefill(pp.isPrefill());
if (pp.isUseStrictMin() != null)
pc.setStrictMin(pp.isUseStrictMin());
}
if (tp != null)
{
if (tp.getBlockingTimeoutMillis() != null)
pc.setBlockingTimeout(tp.getBlockingTimeoutMillis().longValue());
if (tp.getIdleTimeoutMinutes() != null)
pc.setIdleTimeoutMinutes(tp.getIdleTimeoutMinutes().intValue());
}
if (vp != null)
{
if (vp.isBackgroundValidation() != null)
pc.setBackgroundValidation(vp.isBackgroundValidation().booleanValue());
if (vp.getBackgroundValidationMillis() != null)
pc.setBackgroundValidationMillis(vp.getBackgroundValidationMillis().intValue());
if (vp.isUseFastFail() != null)
pc.setUseFastFail(vp.isUseFastFail());
}
return pc;
}
/**
* Start
*/
public void start()
{
if (!checkConfigurationIsValid())
throw new IllegalStateException("Configuration not valid or not defined");
}
/**
* init the acrtivation spec
*
* @param cl cl
* @param cmd cmd
* @param resourceAdapter resourceAdapter
* @param archiveValidationObjects archiveValidationObjects
* @param beanValidationObjects beanValidationObjects
* @param failures falures to be updated during implemented operations
* @param url url
* @param activateDeployment activateDeployment
* @return failures updated after implemented operations
* @throws DeployException DeployException in case of error
*/
protected Set initActivationSpec(ClassLoader cl, Connector cmd, ResourceAdapter resourceAdapter,
List archiveValidationObjects, List