use of org.apache.openejb.config.sys.AbstractService in project tomee by apache.
the class ConfigurationFactory method toConfigDeclaration.
public static Object toConfigDeclaration(final String id, final URI uri) throws OpenEJBException {
final String serviceType;
try {
serviceType = uri.getHost();
final Object object;
try {
object = JaxbOpenejb.create(serviceType);
} catch (final Exception e) {
throw new OpenEJBException("Invalid URI '" + uri + "'. " + e.getMessage());
}
final Map<String, String> map;
try {
map = URISupport.parseParamters(uri);
} catch (final URISyntaxException e) {
throw new OpenEJBException("Unable to parse URI parameters '" + uri + "'. URISyntaxException: " + e.getMessage());
}
if (object instanceof AbstractService) {
final AbstractService service = (AbstractService) object;
service.setId(id);
service.setType(map.remove("type"));
service.setProvider(map.remove("provider"));
service.setClassName(map.remove("class-name"));
service.setConstructor(map.remove("constructor"));
service.setFactoryName(map.remove("factory-name"));
service.setPropertiesProvider(map.remove("properties-provider"));
service.setTemplate(map.remove("template"));
final String cp = map.remove("classpath");
if (null != cp) {
service.setClasspath(cp);
}
service.setClasspathAPI(map.remove("classpath-api"));
if (object instanceof Resource) {
final Resource resource = Resource.class.cast(object);
final String aliases = map.remove("aliases");
if (aliases != null) {
resource.getAliases().addAll(Arrays.asList(aliases.split(",")));
}
final String depOn = map.remove("depends-on");
if (depOn != null) {
resource.getDependsOn().addAll(Arrays.asList(depOn.split(",")));
}
resource.setPostConstruct(map.remove("post-construct"));
resource.setPreDestroy(map.remove("pre-destroy"));
}
service.getProperties().putAll(map);
} else if (object instanceof Deployments) {
final Deployments deployments = (Deployments) object;
deployments.setDir(map.remove("dir"));
deployments.setFile(map.remove("jar"));
final String cp = map.remove("classpath");
if (cp != null) {
final String[] paths = cp.split(File.pathSeparator);
final List<URL> urls = new ArrayList<>();
for (final String path : paths) {
final Set<String> values = ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.value(path));
for (final String v : values) {
urls.add(new File(v).toURI().normalize().toURL());
}
}
deployments.setClasspath(new URLClassLoaderFirst(urls.toArray(new URL[urls.size()]), ParentClassLoaderFinder.Helper.get()));
}
} else if (SystemProperty.class.isInstance(object)) {
final SystemProperty sp = SystemProperty.class.cast(object);
sp.setName(map.remove("name"));
sp.setValue(map.remove("value"));
}
return object;
} catch (final Exception e) {
throw new OpenEJBException("Error declaring service '" + id + "'. Unable to create Service definition from URI '" + uri.toString() + "'", e);
}
}
Aggregations