assert moduleFile != null : "moduleFile is null";
assert targetPath != null : "targetPath is null";
assert !targetPath.endsWith("/") : "targetPath must not end with a '/'";
String specDD = null;
ConnectorBase connector = null;
try {
if (specDDUrl == null) {
specDDUrl = JarUtils.createJarURL(moduleFile, "META-INF/ra.xml");
}
// read in the entire specDD as a string, we need this for getDeploymentDescriptor
// on the J2ee management object
specDD = JarUtils.readAll(specDDUrl);
} catch (Exception e) {
if (!moduleFile.getName().endsWith(".rar")) {
//no ra.xml, not a .rar file, not for us.
return null;
}
}
//we found ra.xml, if it won't parse it's an error.
// parse it
if (specDD != null) {
// XmlObject xmlObject;
// try {
// xmlObject = XmlBeansUtil.parse(specDD);
// xmlObject = convertToConnectorSchema(xmlObject);
// } catch (XmlException e) {
// throw new DeploymentException("Could not read or convert ra.xml with xmlbeans: " + specDDUrl.toExternalForm(), e);
// }
// InputStream in = xmlObject.newInputStream();
try {
InputStream in = specDDUrl.openStream();
try {
connector = (ConnectorBase) JaxbJavaee.unmarshal(Connector.class, in);
} catch (JAXBException e) {
in.close();
in = specDDUrl.openStream();
connector = (ConnectorBase) JaxbJavaee.unmarshal(Connector10.class, in);
} finally {
in.close();
}
} catch (SAXException e) {
throw new DeploymentException("Cannot parse the ra.xml file: " + specDDUrl.toExternalForm(), e);
} catch (JAXBException e) {
throw new DeploymentException("Cannot unmarshall the ra.xml file: " + specDDUrl.toExternalForm(), e);
// } catch (IOException e) {
// throw new DeploymentException("Cannot read the ra.xml file: " + specDDUrl.toExternalForm(), e);
} catch (Exception e) {
throw new DeploymentException("Encountered unknown error parsing the ra.xml file: " + specDDUrl.toExternalForm(), e);
}
}
GerConnectorType gerConnector = null;
try {
// load the geronimo connector plan from either the supplied plan or from the earFile
try {
if (plan instanceof XmlObject) {
gerConnector = (GerConnectorType) SchemaConversionUtils.getNestedObjectAsType((XmlObject) plan,
CONNECTOR_QNAME,
GerConnectorType.type);
} else {
GerConnectorDocument gerConnectorDoc;
ArrayList errors = new ArrayList();
if (plan != null) {
gerConnectorDoc = GerConnectorDocument.Factory.parse((File) plan, XmlBeansUtil.createXmlOptions(errors));
} else {
URL path = JarUtils.createJarURL(moduleFile, "META-INF/geronimo-ra.xml");
gerConnectorDoc = GerConnectorDocument.Factory.parse(path, XmlBeansUtil.createXmlOptions(errors));
}
if (errors.size() > 0) {
throw new DeploymentException("Could not parse connector doc: " + errors);
}
if (gerConnectorDoc != null) {
gerConnector = gerConnectorDoc.getConnector();
}
}
} catch (IOException e) {
//do nothing
}
// if we got one extract the validate it otherwise create a default one
if (gerConnector == null) {
throw new DeploymentException("A connector module must be deployed using a Geronimo deployment plan" +
" (either META-INF/geronimo-ra.xml in the RAR file or a standalone deployment plan passed to the deployer).");
}
ConnectorPlanRectifier.rectifyPlan(gerConnector);
XmlCursor cursor = gerConnector.newCursor();
try {
SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
} finally {
cursor.dispose();
}
XmlBeansUtil.validateDD(gerConnector);
} catch (XmlException e) {
throw new DeploymentException("Could not parse module descriptor", e);
}
EnvironmentType environmentType = gerConnector.getEnvironment();
Environment environment = EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment);
if (earEnvironment != null) {
EnvironmentBuilder.mergeEnvironments(earEnvironment, environment);
environment = earEnvironment;
if (!environment.getConfigId().isResolved()) {
throw new IllegalStateException("Connector module ID should be fully resolved (not " + environment.getConfigId() + ")");
}
} else {
idBuilder.resolve(environment, new File(moduleFile.getName()).getName(), "car");
}
AbstractName moduleName;
if (earName == null) {
earName = naming.createRootName(environment.getConfigId(), NameFactory.NULL, NameFactory.J2EE_APPLICATION);
moduleName = naming.createChildName(earName, environment.getConfigId().toString(), NameFactory.RESOURCE_ADAPTER_MODULE);
} else {
moduleName = naming.createChildName(earName, targetPath, NameFactory.RESOURCE_ADAPTER_MODULE);
}
boolean standAlone = earEnvironment == null;
AnnotatedApp annotatedApp = null;
String name = null;
if (connector != null && connector.getModuleName() != null) {
name = connector.getModuleName();
} else if (standAlone) {
name = FileUtils.removeExtension(new File(moduleFile.getName()).getName(), ".rar");
} else {
name = FileUtils.removeExtension(targetPath, ".rar");
}