String version = reader.getAttributeValue(null, "version");
String scdlLocation = reader.getAttributeValue(null, "scdlLocation");
String jarLocation = reader.getAttributeValue(null, "jarLocation");
LoaderUtil.skipToEndElement(reader);
CompositeImplementation impl = new CompositeImplementation();
impl.setName(name);
if (scdlLocation != null) {
try {
impl.setScdlLocation(new URL(deploymentContext.getScdlLocation(), scdlLocation));
} catch (MalformedURLException e) {
InvalidValueException ive = new InvalidValueException(scdlLocation, e);
ive.setIdentifier(name);
throw ive;
}
impl.setClassLoader(deploymentContext.getClassLoader());
} else if (jarLocation != null) {
URL jarUrl;
try {
jarUrl = new URL(deploymentContext.getScdlLocation(), jarLocation);
} catch (MalformedURLException e) {
InvalidValueException ive = new InvalidValueException(jarLocation, e);
ive.setIdentifier(name);
throw ive;
}
try {
impl.setScdlLocation(new URL("jar:" + jarUrl.toExternalForm() + "!/META-INF/sca/default.scdl"));
} catch (MalformedURLException e) {
throw new AssertionError("Could not convert URL to a jar: url");
}
impl.setClassLoader(new CompositeClassLoader(new URL[]{jarUrl}, deploymentContext.getClassLoader()));
} else if (artifactRepository != null && group != null && version != null) {
Artifact artifact = new Artifact();
artifact.setGroup(group);
artifact.setName(name);
artifact.setVersion(version);
artifact.setType("jar");
artifactRepository.resolve(artifact);
if (artifact.getUrl() == null) {
MissingResourceException mre = new MissingResourceException(artifact.toString());
mre.setIdentifier(name);
throw mre;
}
try {
impl.setScdlLocation(new URL("jar:" + artifact.getUrl() + "!/META-INF/sca/default.scdl"));
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
Set<URL> artifactURLs = artifact.getUrls();
URL[] urls = new URL[artifactURLs.size()];
int i = 0;
for (URL artifactURL : artifactURLs) {
urls[i++] = artifactURL;
}
impl.setClassLoader(new CompositeClassLoader(urls, deploymentContext.getClassLoader()));
}
return impl;
}