use of com.sun.enterprise.connectors.deployment.util.ConnectorArchivist in project Payara by payara.
the class ConnectorDDTransformUtils method getConnectorDescriptor.
/**
* Get the ConnectorDescriptor object which represents the ra.xml and
* sun-ra.xml from an exploded rar module.
*
* @param moduleDir Directory where rar is exploded.
* @return ConnectorDescriptor object which
* represents the ra.xml and sun-ra.xml
* @throws ConnectorRuntimeException if ra.xml could not be located or
* invalid. For 1.0 type rar if sun-ra.xml is not present or
* invalid this exception is thrown. For 1.5 type rar sun-ra.xml
* should not be present.
*/
public static ConnectorDescriptor getConnectorDescriptor(String moduleDir, String rarModuleName) throws ConnectorRuntimeException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
File module = new File(moduleDir);
FileArchive fileArchive = new FileArchive();
// directory where rar is exploded
fileArchive.open(module.toURI());
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
ClassLoader loader;
if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
loader = ConnectorRuntime.getRuntime().getSystemRARClassLoader(rarModuleName);
Thread.currentThread().setContextClassLoader(loader);
} else {
loader = runtime.createConnectorClassLoader(moduleDir, null, rarModuleName);
}
ConnectorArchivist connectorArchivist = runtime.getConnectorArchvist();
// TODO V3 what happens to embedded .rar ? as its parent classloader should be application CL
// setting the classloader so that annotation processor can make use of it.
connectorArchivist.setClassLoader(loader);
// fileArchive.entries("META-INF/ra.xml");
// TODO V3 need to check whether ra.xml is present, if so, check the version. process annotations
// only if its 1.6 or above ?
connectorArchivist.setAnnotationProcessingRequested(true);
return connectorArchivist.open(fileArchive);
} catch (IOException ex) {
ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to read the connector deployment descriptors");
cre.initCause(ex);
_logger.log(Level.SEVERE, "rardeployment.connector_descriptor_read_error", moduleDir);
_logger.log(Level.SEVERE, "", cre);
throw cre;
} catch (SAXParseException ex) {
ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to parse the connector deployment descriptors");
cre.initCause(ex);
_logger.log(Level.SEVERE, "rardeployment.connector_descriptor_parse_error", moduleDir);
_logger.log(Level.SEVERE, "", cre);
throw cre;
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of com.sun.enterprise.connectors.deployment.util.ConnectorArchivist in project Payara by payara.
the class ConnectorDDTransformUtils method getResourceAdapterClassName.
public static String getResourceAdapterClassName(String rarLocation) {
// class through the connector descriptor
try {
FileInputStream fis = new FileInputStream(rarLocation);
MemoryMappedArchive mma = new MemoryMappedArchive(fis);
ConnectorArchivist ca = new ConnectorArchivist();
ConnectorDescriptor cd = (ConnectorDescriptor) ca.open(mma);
return cd.getResourceAdapterClass();
} catch (IOException e) {
_logger.info(e.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Error while trying to read connector" + "descriptor to get resource-adapter properties", e);
}
} catch (SAXParseException e) {
_logger.info(e.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Error while trying to read connector" + "descriptor to get resource-adapter properties", e);
}
}
return null;
}
Aggregations