JBoss.org Community Documentation

Chapter 21. Identifying the deployment structure

21.1. Deployment Descriptors
21.2. Java Archives (JARs)
21.3. Nested deployments
21.4. Declaring a custom deployment structure
21.5. Determining the deployment structure programmatically

Before we can begin to process a deployment we must first determine its structure. This means finding out if it contains any deployment descriptors and/or classes, and if so where they are located relative to the deployment's root. Nested deployments must also be detected and their structures determined in the same way. The purpose of this is to help the parsing actions locate the deployment descriptors in a standard way and to assist in the creation of classloaders. Since we wish to use the Virtual File System (VFS) to represent our deployment we must first create a VFSDeployment using the deployment URI or URL:

VirtualFile root = VFS.getRoot(deploymentURL);     
VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
Deployment deployment = deploymentFactory.createVFSDeployment(root);

The deployment framework then determines the structure of the Deployment using classes that implement the StructureDeployer interface:

public interface StructureDeployer extends Ordered
boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException;

As a deployment can contain nested deployments the determineStructure() method is meant to be called recursively. The root parameter represents the root of the top-level deployment, the file parameter represents the root of the current (possibly nested) deployment being analyzed and the parent parameter its parent (or null if it is the top-level). The deployers parameter represents a class containing a list of all the StructureDeployer implementations and is needed in order to process any nested deployments.

As each deployment is found a ContextInfo object is created to store the paths to any deployment descriptors and/or classes. These are then added to the StructureMetaData parameter so that the structure of the entire deployment is recorded. For example if we had a top-level deployment containing 2 nested deployments then we would create 3 ContextInfo objects, one for each deployment, and add these to the StructureMetaData object.