Search in sources :

Example 1 with BundleResource

use of org.apache.aries.application.resolver.obr.ext.BundleResource in project aries by apache.

the class RepositoryGeneratorImpl method generateRepository.

public static void generateRepository(RepositoryAdmin repositoryAdmin, String repositoryName, Collection<? extends ModelledResource> byValueBundles, OutputStream os) throws ResolverException, IOException {
    logger.debug(LOG_ENTRY, "generateRepository", new Object[] { repositoryAdmin, repositoryName, byValueBundles, os });
    Document doc;
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    } catch (ParserConfigurationException pce) {
        throw new ResolverException(pce);
    }
    Element root = doc.createElement("repository");
    root.setAttribute("name", repositoryName);
    doc.appendChild(root);
    for (ModelledResource mr : byValueBundles) {
        BundleResource bundleResource = new BundleResource(mr, repositoryAdmin);
        if (bundleResourceTransformers.size() > 0) {
            for (BundleResourceTransformer brt : bundleResourceTransformers) {
                bundleResource = brt.transform(bundleResource);
            }
        }
        writeResource(bundleResource, mr.getLocation(), doc, root);
    }
    try {
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        trans.transform(new DOMSource(doc), new StreamResult(os));
    } catch (TransformerException te) {
        logger.debug(LOG_EXIT, "generateRepository", te);
        throw new ResolverException(te);
    }
    logger.debug(LOG_EXIT, "generateRepository");
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) ResolverException(org.apache.aries.application.management.ResolverException) Transformer(javax.xml.transform.Transformer) BundleResourceTransformer(org.apache.aries.application.resolver.obr.ext.BundleResourceTransformer) StreamResult(javax.xml.transform.stream.StreamResult) BundleResourceTransformer(org.apache.aries.application.resolver.obr.ext.BundleResourceTransformer) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) BundleResource(org.apache.aries.application.resolver.obr.ext.BundleResource) TransformerException(javax.xml.transform.TransformerException) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 ResolverException (org.apache.aries.application.management.ResolverException)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1 BundleResource (org.apache.aries.application.resolver.obr.ext.BundleResource)1 BundleResourceTransformer (org.apache.aries.application.resolver.obr.ext.BundleResourceTransformer)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1