Package org.jboss.shrinkwrap.api

Examples of org.jboss.shrinkwrap.api.Node


            e.setClassLoader(tempClassLoader);
            appModule.getEjbModules().add(e);
        }

        final EjbJar ejbJar;
        final Node ejbJarXml = archive.get(prefix.concat(EJB_JAR_XML));
        if (ejbJarXml != null) {
            try {
                ejbJar = ReadDescriptors.readEjbJar(ejbJarXml.getAsset().openStream());
            } catch (OpenEJBException e) {
                throw new OpenEJBRuntimeException(e);
            }
        } else {
            ejbJar = new EjbJar();
        }

        if (ejbJar.getModuleName() == null) {
            final String name = archive.getName();
            if (name.endsWith("ar") && name.length() > 4) {
                ejbJar.setModuleName(name.substring(0, name.length() - ".jar".length()));
            } else {
                ejbJar.setModuleName(name);
            }
        }

        final EjbModule ejbModule = new EjbModule(ejbJar);
        ejbModule.setClassLoader(tempClassLoader);

        Node beansXml = archive.get(prefix.concat(BEANS_XML));
        if (beansXml == null && WEB_INF.equals(prefix)) {
            beansXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(BEANS_XML));
        }
        if (beansXml != null) {
            ejbModule.getAltDDs().put(BEANS_XML, new AssetSource(beansXml.getAsset()));
        }

        final org.apache.xbean.finder.archive.Archive finderArchive = finderArchive(beansXml, archive, tempClassLoader, additionalPaths);

        ejbModule.setFinder(new FinderFactory.ModuleLimitedFinder(new AnnotationFinder(finderArchive)));
        if (appModule.isWebapp()) { // war
            appModule.getWebModules().iterator().next().setFinder(ejbModule.getFinder());
        }
        appModule.getEjbModules().add(ejbModule);

        {
            Node persistenceXml = archive.get(prefix.concat(PERSISTENCE_XML));
            if (persistenceXml == null && WEB_INF.equals(prefix)) {
                persistenceXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(PERSISTENCE_XML));
            }
            if (persistenceXml != null) {
                final Asset asset = persistenceXml.getAsset();
                if (UrlAsset.class.isInstance(asset)) {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(URL.class, "url", asset)));
                } else if (FileAsset.class.isInstance(asset)) {
                    try {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(File.class, "file", asset).toURI().toURL()));
                    } catch (MalformedURLException e) {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
                    }
                } else if (ClassLoaderAsset.class.isInstance(asset)) {
                    final URL url = get(ClassLoader.class, "classLoader", asset).getResource(get(String.class, "resourceName", asset));
                    if (url != null) {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(url));
                    } else {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
                    }
                } else {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
                }
            }
        }

        {
            final Node openejbJarXml = archive.get(prefix.concat(OPENEJB_JAR_XML));
            if (openejbJarXml != null) {
                ejbModule.getAltDDs().put(OPENEJB_JAR_XML, new AssetSource(openejbJarXml.getAsset()));
            }
        }

        {
            final Node validationXml = archive.get(prefix.concat(VALIDATION_XML));
            if (validationXml != null) {
                ejbModule.getAltDDs().put(VALIDATION_XML, new AssetSource(validationXml.getAsset()));
            }
        }

        {
            final Node resourcesXml = archive.get(prefix.concat(RESOURCES_XML));
            if (resourcesXml != null) {
                ejbModule.getAltDDs().put(RESOURCES_XML, new AssetSource(resourcesXml.getAsset()));
            }
        }

        {
            final Node envEntriesProperties = archive.get(prefix.concat(ENV_ENTRIES_PROPERTIES));
            if (envEntriesProperties != null) {
                InputStream is = null;
                final Properties properties = new Properties();
                try {
                    is = envEntriesProperties.getAsset().openStream();
                    properties.load(is);
                    ejbModule.getAltDDs().put(ENV_ENTRIES_PROPERTIES, properties);

                    // do it for test class too
                    appModule.getEjbModules().iterator().next().getAltDDs().put(ENV_ENTRIES_PROPERTIES, properties);
View Full Code Here


    }

    @Override
    protected Enumeration<URL> findResources(final String name) throws IOException {
        ArchivePath path = ArchivePaths.create(prefix + name);
        Node node = archive.get(path);
        if (node == null) {
            path = ArchivePaths.create(name);
            node = archive.get(path);

View Full Code Here

    }

    @Override
    protected URL findResource(final String name) {
        ArchivePath path = ArchivePaths.create(prefix + name);
        Node node = archive.get(path);
        if (node == null) {
            path = ArchivePaths.create(name);
            node = archive.get(path);
        }
View Full Code Here

            if (!prefixes.containsKey(arName)) {
                throw new IOException(u.toExternalForm() + " not found");
            }

            String path = prefixes.get(arName) + path(arName, u);
            Node node = archives.get(arName).get(path);
            if (node == null) {
                path = path(arName, u);
                node = archives.get(arName).get(path);
            }
            if (node == null) {
                throw new IOException(u.toExternalForm() + " not found");
            }

            final Asset asset = node.getAsset();
            if (UrlAsset.class.isInstance(asset)) {
                return URL.class.cast(Reflections.get(asset, "url")).openConnection();
            } else if (FileAsset.class.isInstance(asset)) {
                return File.class.cast(Reflections.get(asset, "file")).toURI().toURL().openConnection();
            } else if (ClassLoaderAsset.class.isInstance(asset)) {
View Full Code Here

        }

        final org.apache.xbean.finder.archive.Archive finderArchive = finderArchive(archive, appModule.getClassLoader(), additionalPaths);

        final EjbJar ejbJar;
        final Node ejbJarXml = archive.get(prefix.concat(EJB_JAR_XML));
        if (ejbJarXml != null) {
            try {
                ejbJar = ReadDescriptors.readEjbJar(ejbJarXml.getAsset().openStream());
            } catch (OpenEJBException e) {
                throw new OpenEJBRuntimeException(e);
            }
        } else {
            ejbJar = new EjbJar();
        }

        final EjbModule ejbModule = new EjbModule(ejbJar);
        ejbModule.setFinder(new AnnotationFinder(finderArchive));
        appModule.getEjbModules().add(ejbModule);

        {
            final Node beansXml = archive.get(prefix.concat(BEANS_XML));
            if (beansXml != null) {
                ejbModule.getAltDDs().put(BEANS_XML, new AssetSource(beansXml.getAsset()));
            }
        }

        {
            Node persistenceXml = archive.get(prefix.concat(PERSISTENCE_XML));
            if (persistenceXml == null && prefix.startsWith("WEB-INF")) { // particular case
                persistenceXml = archive.get(prefix.concat("classes/META-INF/").concat(PERSISTENCE_XML));
            }
            if (persistenceXml != null) {
                final Asset asset = persistenceXml.getAsset();
                if (UrlAsset.class.isInstance(asset)) {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(URL.class, "url", asset)));
                } else if (FileAsset.class.isInstance(asset)) {
                    try {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(File.class, "file", asset).toURI().toURL()));
                    } catch (MalformedURLException e) {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
                    }
                } else if (ClassLoaderAsset.class.isInstance(asset)) {
                    final URL url = get(ClassLoader.class, "classLoader", asset).getResource(get(String.class, "resourceName", asset));
                    if (url != null) {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(url));
                    } else {
                        appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
                    }
                } else {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
                }
            }
        }

        {
            final Node openejbJarXml = archive.get(prefix.concat(OPENEJB_JAR_XML));
            if (openejbJarXml != null) {
                ejbModule.getAltDDs().put(OPENEJB_JAR_XML, new AssetSource(openejbJarXml.getAsset()));
            }
        }

        {
            final Node validationXml = archive.get(prefix.concat(VALIDATION_XML));
            if (validationXml != null) {
                ejbModule.getAltDDs().put(VALIDATION_XML, new AssetSource(validationXml.getAsset()));
            }
        }

        {
            final Node envEntriesProperties = archive.get(prefix.concat(ENV_ENTRIES_PROPERTIES));
            if (envEntriesProperties != null) {
                InputStream is = null;
                final Properties properties = new Properties();
                try {
                    is = envEntriesProperties.getAsset().openStream();
                    properties.load(is);
                    ejbModule.getAltDDs().put(ENV_ENTRIES_PROPERTIES, properties);

                    // do it for test class too
                    appModule.getEjbModules().iterator().next().getAltDDs().put(ENV_ENTRIES_PROPERTIES, properties);
View Full Code Here

    private Manifest getBundleManifest(Archive<?> archive)
    {
        try
        {
            Node node = archive.get("META-INF/MANIFEST.MF");
            if (node == null)
                return null;

            Manifest manifest = new Manifest(node.getAsset().openStream());
            return manifest;
        }
        catch (Exception ex)
        {
            return null;
View Full Code Here

  private void assertJar(URL url) throws IOException {
    URLConnection conn = url.openConnection();
    conn.connect();
    InputStream in = conn.getInputStream();
    JavaArchive archive = ShrinkWrap.create(ZipImporter.class).importFrom(in).as(JavaArchive.class);
    Node node = archive.get("/" + ReadFileSystemTestCase.class.getName().replace('.', '/') + ".class");
    assertNotNull(node);
  }
View Full Code Here

        }
    }

    private URL getBeanXmlUrl(Archive archive, String beansXmlPath)
    {
        final Node beansXml = archive.get(beansXmlPath);

        if (beansXml == null)
        {
            return null;
        }

        try
        {
            String urlLocation = "archive://" + archive.getName() + "/" + beansXmlPath;

            return  new URL(null, urlLocation, new URLStreamHandler()
                        {
                            @Override
                            protected URLConnection openConnection(URL u) throws IOException
                            {
                                return new URLConnection(u)
                                {
                                    @Override
                                    public void connect() throws IOException
                                    {}

                                    @Override
                                    public InputStream getInputStream() throws IOException
                                    {
                                        return beansXml.getAsset().openStream();
                                    }
                                };
                            };
                        });
        }
View Full Code Here

   }

   @Override
   protected URL findResource(final String name)
   {
      final Node a = archive.get(name);
      if (a == null)
      {
         return null;
      }
      try
      {
         return new URL(null, ARCHIVE_PROTOCOL + name, new URLStreamHandler()
         {
            @Override
            protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
            {
               return new URLConnection(u)
               {
                  @Override
                  public void connect() throws IOException
                  {
                  }

                  @Override
                  public InputStream getInputStream()
                        throws IOException
                  {
                     return a.getAsset().openStream();
                  }
               };
            }

            ;
View Full Code Here

    contributor.initializeContribution( context );
    contributor.contributeService( context, service );
    contributor.finalizeContribution( context );

    Node node = webArchive.get( "TODO" );
    assertThat( node, notNullValue() );
  }
View Full Code Here

TOP

Related Classes of org.jboss.shrinkwrap.api.Node

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.