Package org.jboss.gravia.resource

Examples of org.jboss.gravia.resource.ResourceBuilder


            }
        }

        Resource result = null;
        if (contentURL != null) {
            ResourceBuilder builder = new DefaultResourceBuilder();
            builder.addIdentityCapability(mavenid);
            Capability ccap = builder.addCapability(ContentNamespace.CONTENT_NAMESPACE, null, null);
            ccap.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, contentURL);
            LOGGER.debug("Found maven resource: {}", result = builder.getResource());
        }

        return result;
    }
View Full Code Here


    private Resource addContentResource(Resource res, List<Capability> ccaps, boolean writeXML) throws RepositoryStorageException {

        // Copy the resource to this storage, if the content URL does not match
        URL urlatt = (URL) ccaps.get(0).getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
        if (urlatt == null || urlatt.toExternalForm().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());
            }
            res = builder.getResource();
        }

        Resource result = super.addResource(res);
        if (writeXML == true) {
            writeRepositoryXML();
View Full Code Here

        String attkey = ContentNamespace.CAPABILITY_MAVEN_IDENTITY_ATTRIBUTE;
        MavenCoordinates attval = (MavenCoordinates) icap.getAttributes().get(attkey);
        if (attval != null && !attval.equals(mavenid))
            throw new IllegalArgumentException("Resource already contains a " + attkey + " attribute: " + attval);

        ResourceBuilder builder = new DefaultResourceBuilder();
        for (Capability aux : res.getCapabilities(null)) {
            Capability cap = builder.addCapability(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
            if (IdentityNamespace.IDENTITY_NAMESPACE.equals(cap.getNamespace())) {
                cap.getAttributes().put(attkey, mavenid);
            }
        }
        for (Requirement aux : res.getRequirements(null)) {
            builder.addRequirement(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
        }
        Resource rescopy = builder.getResource();
        return getRequiredRepositoryStorage().addResource(rescopy);
    }
View Full Code Here

    private Resource addContentResource(Resource res, List<Capability> ccaps, boolean writeXML) throws RepositoryStorageException {

        // Copy the resource to this storage, if the content URL does not match
        URL urlatt = (URL) ccaps.get(0).getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
        if (urlatt == null || urlatt.toExternalForm().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());
            }
            res = builder.getResource();
        }

        Resource result = super.addResource(res);
        if (writeXML == true) {
            writeRepositoryXML();
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

        String attkey = IdentityNamespace.CAPABILITY_MAVEN_IDENTITY_ATTRIBUTE;
        String attval = (String) icap.getAttributes().get(attkey);
        if (attval != null && !attval.equals(mavenid.toExternalForm()))
            throw new IllegalArgumentException("Resource already contains a " + attkey + " attribute: " + attval);

        ResourceBuilder builder = new DefaultResourceBuilder();
        for (Capability aux : res.getCapabilities(null)) {
            Capability cap = builder.addCapability(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
            if (IdentityNamespace.IDENTITY_NAMESPACE.equals(cap.getNamespace())) {
                cap.getAttributes().put(attkey, mavenid.toExternalForm());
            }
        }
        for (Requirement aux : res.getRequirements(null)) {
            builder.addRequirement(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
        }
        Resource rescopy = builder.getResource();
        return getRequiredRepositoryStorage().addResource(rescopy);
    }
View Full Code Here

        String attkey = IdentityNamespace.CAPABILITY_MAVEN_IDENTITY_ATTRIBUTE;
        String attval = (String) icap.getAttributes().get(attkey);
        if (attval != null && !attval.equals(mavenid.toExternalForm()))
            throw new IllegalArgumentException("Resource already contains a " + attkey + " attribute: " + attval);

        ResourceBuilder builder = new DefaultResourceBuilder();
        for (Capability aux : res.getCapabilities(null)) {
            Capability cap = builder.addCapability(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
            if (IdentityNamespace.IDENTITY_NAMESPACE.equals(cap.getNamespace())) {
                cap.getAttributes().put(attkey, mavenid.toExternalForm());
            }
        }
        for (Requirement aux : res.getRequirements(null)) {
            builder.addRequirement(aux.getNamespace(), aux.getAttributes(), aux.getDirectives());
        }
        Resource rescopy = builder.getResource();
        return getRequiredRepositoryStorage().addResource(rescopy);
    }
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

    @Override
    public ResourceBuilder getContentResourceBuilder(ResourceIdentity identity, InputStream inputStream) {
        IllegalArgumentAssertion.assertNotNull(identity, "identity");
        IllegalArgumentAssertion.assertNotNull(inputStream, "inputStream");

        ResourceBuilder builder = new DefaultResourceBuilder();
        builder.addIdentityCapability(identity);
        builder.addContentCapability(inputStream);

        return builder;
    }
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.