Search in sources :

Example 1 with AbstractService

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);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) URLClassLoaderFirst(org.apache.openejb.util.classloader.URLClassLoaderFirst) Set(java.util.Set) HashSet(java.util.HashSet) Resource(org.apache.openejb.config.sys.Resource) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) Deployments(org.apache.openejb.config.sys.Deployments) URISyntaxException(java.net.URISyntaxException) AbstractService(org.apache.openejb.config.sys.AbstractService) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 AbstractService (org.apache.openejb.config.sys.AbstractService)1 AdditionalDeployments (org.apache.openejb.config.sys.AdditionalDeployments)1 Deployments (org.apache.openejb.config.sys.Deployments)1 Resource (org.apache.openejb.config.sys.Resource)1 URLClassLoaderFirst (org.apache.openejb.util.classloader.URLClassLoaderFirst)1