Package org.jboss.gravia.resource

Examples of org.jboss.gravia.resource.ResourceBuilder


    @Test
    public void testMultipleContentCapabilities() throws Exception {

        Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class);

        ResourceBuilder builderF = new DefaultResourceBuilder();
        ResourceIdentity identityF = ResourceIdentity.create(RESOURCE_F, Version.emptyVersion);
        builderF.addIdentityCapability(identityF);
        builderF.addContentCapability(deployer.getDeployment(CONTENT_F1), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, RuntimeType.TOMCAT.name()));
        builderF.addContentCapability(deployer.getDeployment(CONTENT_F2), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, RuntimeType.WILDFLY.name()));
        builderF.addContentCapability(deployer.getDeployment(CONTENT_F3), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, RuntimeType.KARAF.name()));

        ResourceBuilder builderG = new DefaultResourceBuilder();
        ResourceIdentity identityG = ResourceIdentity.create(RESOURCE_G, Version.emptyVersion);
        builderG.addIdentityCapability(identityG);
        builderG.addContentCapability(deployer.getDeployment(CONTENT_G1), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, RuntimeType.TOMCAT.name()));
        builderG.addContentCapability(deployer.getDeployment(CONTENT_G2), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, RuntimeType.WILDFLY.name()));
        builderG.addContentCapability(deployer.getDeployment(CONTENT_G3), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, RuntimeType.KARAF.name()));

        List<ResourceHandle> handles = new ArrayList<>();
        handles.add(provisioner.installSharedResource(builderF.getResource()));
        handles.add(provisioner.installResource(builderG.getResource()));
        try {
            // Verify that the modules got installed
            Runtime runtime = RuntimeLocator.getRequiredRuntime();
            for (ResourceHandle handle : handles) {
                ResourceIdentity identity = handle.getResource().getIdentity();
View Full Code Here


        Resource result;

        // Copy the resource to this storage, if the content URL does not match
        if (urlspec.startsWith(getBaseURL().toExternalForm()) == false) {
            ResourceBuilder builder = createResourceBuilder();
            for (Capability cap : res.getCapabilities(null)) {
                if (!ContentNamespace.CONTENT_NAMESPACE.equals(cap.getNamespace())) {
                    builder.addCapability(cap.getNamespace(), cap.getAttributes(), cap.getDirectives());
                }
            }
            for (Capability cap : ccaps) {
                ContentCapability ccap = cap.adapt(ContentCapability.class);
                Map<String, Object> contentAtts = new HashMap<String, Object>();
                String mimeType = (String) ccap.getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE);
                if (mimeType != null) {
                    contentAtts.put(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, mimeType);
                }
                InputStream input = getResourceContent(ccap);
                try {
                    addResourceContent(input, contentAtts);
                    builder.addCapability(ContentNamespace.CONTENT_NAMESPACE, contentAtts, cap.getDirectives());
                } catch (RepositoryStorageException ex) {
                    throw new RepositoryStorageException("Cannot add resource to storeage: " + mimeType, ex);
                }
            }
            for (Requirement req : res.getRequirements(null)) {
                String namespace = req.getNamespace();
                builder.addRequirement(namespace, req.getAttributes(), req.getDirectives());
            }
            result = builder.getResource();
        } else {
            result = res;
        }

        result = super.addResource(result);
View Full Code Here

            // ignore
        }
    }

    private Resource readResourceElement(XMLStreamReader reader) throws XMLStreamException {
        ResourceBuilder builder = createResourceBuilder();
        while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
            Element element = Element.forName(reader.getLocalName());
            switch (element) {
                case CAPABILITY:
                    readCapabilityElement(reader, builder);
                    break;
                case REQUIREMENT:
                    readRequirementElement(reader, builder);
                    break;
                default:
                    continue;
            }
        }
        return builder.getResource();
    }
View Full Code Here

            return null;

        Resource resource = ThreadResourceAssociation.getResource();
        Dictionary<String, String> headers = bundle.getHeaders();
        if (resource == null) {
            ResourceBuilder builder = new DictionaryResourceBuilder().load(headers);
            if (builder.isValid() == false) {
                String symbolicName = bundle.getSymbolicName();
                String version = bundle.getVersion().toString();
                builder.addIdentityCapability(symbolicName, version);
            }
            resource = builder.getResource();
        }

        try {
            module = installModule(classLoader, resource, headers);
        } catch (ModuleException ex) {
View Full Code Here

        ClassLoader classLoader = ApplicationActivator.class.getClassLoader();
        Manifest manifest = getWebappManifest(servletContext);
        if (manifest == null)
            return null;

        ResourceBuilder resbuilder = new ManifestResourceBuilder().load(manifest);
        if (resbuilder.isValid() == false)
            return null;

        AttachableSupport context = new AttachableSupport();
        context.putAttachment(TomcatRuntime.SERVLET_CONTEXT_KEY, servletContext);

        Module module;
        try {
            Resource resource = resbuilder.getResource();
            ManifestHeadersProvider headersProvider = new ManifestHeadersProvider(manifest);
            module = runtime.installModule(classLoader, resource, headersProvider.getHeaders(), context);
            servletContext.setAttribute(Module.class.getName(), module);
        } catch (RuntimeException rte) {
            throw rte;
View Full Code Here

            return null;

        Resource resource = ThreadResourceAssociation.getResource();
        Dictionary<String, String> headers = bundle.getHeaders();
        if (resource == null) {
            ResourceBuilder builder = new DictionaryResourceBuilder().load(headers);
            if (builder.isValid() == false) {
                String symbolicName = bundle.getSymbolicName();
                String version = bundle.getVersion().toString();
                builder.addIdentityCapability(symbolicName, version);
            }
            resource = builder.getResource();
        }

        try {
            module = installModule(classLoader, resource, headers);
        } catch (ModuleException ex) {
View Full Code Here

            return null;

        Resource resource = ThreadResourceAssociation.getResource();
        Dictionary<String, String> headers = bundle.getHeaders();
        if (resource == null) {
            ResourceBuilder builder = new DictionaryResourceBuilder().load(headers);
            if (builder.isValid() == false) {
                String symbolicName = bundle.getSymbolicName();
                String version = bundle.getVersion().toString();
                builder.addIdentityCapability(symbolicName, version);
            }
            resource = builder.getResource();
        }

        try {
            module = installModule(classLoader, resource, headers);
        } catch (ModuleException ex) {
View Full Code Here

            tempFile = tempPath.toFile();
        } catch (Exception ex) {
            throw new ProvisionException(ex);
        }

        ResourceBuilder builder;
        if (headers != null) {
            builder = new DictionaryResourceBuilder().load(headers);
        } else {
            Manifest manifest;
            JarFile jarFile = null;
            try {
                jarFile = new JarFile(tempFile);
                manifest = jarFile.getManifest();
            } catch (IOException ex) {
                throw new ProvisionException(ex);
            } finally {
                IOUtils.safeClose(jarFile);
            }
            builder = new ManifestResourceBuilder().load(manifest);
            headers = getManifestHeaders(manifest);
        }

        // Build the {@link Resource}
        builder.addContentCapability(contentURL);
        Resource resource = builder.getResource();

        // Install the {@link Resource}
        ResourceHandle handle;
        try {
            Context context = new DefaultInstallerContext(resource);
View Full Code Here

            return null;

        Resource resource = ThreadResourceAssociation.getResource();
        Dictionary<String, String> headers = bundle.getHeaders();
        if (resource == null) {
            ResourceBuilder builder = new DictionaryResourceBuilder().load(headers);
            if (builder.isValid() == false) {
                String symbolicName = bundle.getSymbolicName();
                String version = bundle.getVersion().toString();
                builder.addIdentityCapability(symbolicName, version);
            }
            resource = builder.getResource();
        }

        try {
            module = installModule(classLoader, resource, headers);
        } catch (ModuleException ex) {
View Full Code Here

        if (resource == null && headers == null)
            throw new IllegalArgumentException("Cannot create module identity");

        // Build the resource
        if (resource == null) {
            ResourceBuilder builder = new DictionaryResourceBuilder().load(headers);
            resource = builder.getResource();
        }
        this.resource = resource;

        // Build the headers
        ResourceIdentity resourceIdentity = resource.getIdentity();
View Full Code Here

TOP

Related Classes of org.jboss.gravia.resource.ResourceBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.