Class ScatteredArchive

    • Constructor Detail

      • ScatteredArchive

        public ScatteredArchive​(String name,
                                ScatteredArchive.Type type)
        Construct a new empty scattered archive.
        Parameters:
        name - name of the archive.
        type - type of the archive
        Throws:
        NullPointerException - if name or type is null
      • ScatteredArchive

        public ScatteredArchive​(String name,
                                ScatteredArchive.Type type,
                                File rootDirectory)
                         throws IOException
        Construct a new scattered archive with all the contents from the rootDirectory.

        By default, a scattered archive is not different from any other archive where all the files are located under a top level directory (rootDirectory).

        For example, In case of a WAR type archive, the rootDirectory should look like this:

              rootDirectory/WEB-INF/classes/org/myorg/FooServlet.class
              rootDirectory/WEB-INF/classes/org/myorg/Bar.class
              rootDirectory/WEB-INF/web.xml
              rootDirectory/WEB-INF/lib/myjar.jar
              rootDirectory/index.jsp
              rootDirectory/theme.css
              rootDirectory/helper.js
         
        Some files can then be scattered in different locations and be specified through the appropriate add methods of this class.

        Parameters:
        name - name of the archive.
        type - type of the archive
        rootDirectory - root directory.
        Throws:
        NullPointerException - if name, type or rootDirectory is null.
        IOException - if rootDirectory does not exist.
        IllegalArgumentException - if rootDirectory is not a directory.
    • Method Detail

      • addClassPath

        public void addClassPath​(File classpath)
                          throws IOException
        Add a directory or a JAR file to this scattered archive.

        The classpath that is added is considered as a plain Java CLASSPATH.

        Case 1 : classpath is a directory:

        Let us say there is TEMP/abc directory, which has following contents:

              TEMP/abc/org/myorg/a/A.class
              TEMP/abc/org/myorg/b/B.class
              TEMP/abc/com/xyz/c/C.class
              TEMP/abc/LocalStrings.properties
              TEMP/abc/image/1.png
         
        then addClassPath(new File("TEMP", "abc") will make:

        (a) The following classes available in the deployed scattered archive application:

                  org.myorg.a.A
                  org.myorg.b.B
                  com.xyz.c.C
         
        (b) LocalStrings.properties available in the deployed scattered archive application. So, the deployed application can do ResourceBundle.getBundle("LocalStrings");

        (c) image/1.png available in the deployed scattered archive application. So, the deployed application can load the image file via getClass().getClassLoader().getResource("image/1.png");

        If there is any other type of file under TEMP/abc then it will also be available in the deployed scattered archive application's classloader.

        Case 2: classpath is a JAR file

        Let us say there is TEMP/xyz.jar, then addClassPath(new File("TEMP", "xyz.jar")) will make all the classes and any random files inside TEMP/xyz.jar available in the deployed scattered archive application.

        Parameters:
        classpath - A directory or a JAR file.
        Throws:
        NullPointerException - if classpath is null
        IOException - if the classpath is not found.
      • addMetadata

        public void addMetadata​(File metadata)
                         throws IOException
        Add a new metadata to this scattered archive.

        The addMetadata(metadata) method has the same effect as:

              addMetadata(metadata, null)
         
        Follows the same semantics as addMetadata(File, String) method.
        Throws:
        IOException
      • addMetadata

        public void addMetadata​(File metadata,
                                String name)
                         throws IOException
        Add a new metadata to this scattered archive.

        A metadata is identified by its name (e.g., META-INF/ejb.xml).

        If the specified name is null, then the metadata is considered as a deployment descriptor metadata and the name is computed as:

              "WEB-INF/" + metadata.getName() for WAR type archive.
              "META-INF/" + metadata.getName() for other type of archive.
         
        If the scattered archive already contains the metadata with the same name, then the old value is replaced.
        Parameters:
        metadata - location of the metadata
        name - name of the metadata (e.g., META-INF/ejb.xml or META-INF/sun-ejb-jar.xml)
        Throws:
        NullPointerException - if metadata is null
        IOException - if metadata does not exist.
        IllegalArgumentException - if metadata is a directory.
      • toURI

        public URI toURI()
                  throws IOException
        Get the deployable URI for this scattered archive.

        Note : java.io.tmpdir is used while building the URI.

        Returns:
        Deployable scattered archive URI.
        Throws:
        IOException - if any I/O error happens while building the URI or while reading metadata, classpath elements, rootDirectory.