protected void buildServiceAssembly()

in platforms/geronimo/deployer-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixConfigBuilder.java [331:379]


    protected void buildServiceAssembly(Descriptor descriptor, DeploymentContext context, JarFile module)
                    throws Exception {
        Environment environment = context.getConfiguration().getEnvironment();
        // Unzip the component
        File targetDir = new File(context.getBaseDir(), "install");
        targetDir.mkdirs();
        unzip(context, module, new URI("install/"));
        // Unzip SUs
        ServiceUnit[] sus = descriptor.getServiceAssembly().getServiceUnits();
        List<ServiceUnitReference> serviceUnitReferences = new LinkedList<ServiceUnitReference>();
        
        for (int i = 0; i < sus.length; i++) {
            String name = sus[i].getIdentification().getName();
            String zip = sus[i].getTarget().getArtifactsZip();
            String comp = sus[i].getTarget().getComponentName();
            URI installUri = new URI("sus/" + comp + "/" + name + "/");
            unzip(context, new JarFile(new File(targetDir, zip)), installUri);
            // Add component config as a dependency
            Artifact sl = new Artifact("servicemix-components", comp, "0.0", "car");
            environment.addDependency(sl, ImportType.ALL);
             // Deploy the SU on the component
             Component jbiServiceUnit = null;
             try {
                 jbiServiceUnit = getAssociatedJbiServiceUnit(comp, sl);
             } catch (GBeanNotFoundException e) {
                 throw new DeploymentException("Can not find the associated service unit for this service assembly. "
                         + "Check if it's deployed and started.", e);
             }
             ServiceUnitManager serviceUnitManager = jbiServiceUnit.getServiceUnitManager();
             File installDir = new File(context.getBaseDir(), installUri.toString());
             String deploy = serviceUnitManager.deploy(name, installDir.getAbsolutePath());  
             serviceUnitReferences.add(new ServiceUnitReference(sl, name, installDir.getAbsolutePath()));
             LOGGER.debug(deploy);
        }
        // Create the JBI deployment managed object
        Properties props = new Properties();
        props.put("jbiType", "JBIServiceAssembly");
        props.put("name", descriptor.getServiceAssembly().getIdentification().getName());
        AbstractName name = new AbstractName(environment.getConfigId(), props);
        GBeanData gbeanData = new GBeanData(name, ServiceAssembly.GBEAN_INFO);
        gbeanData.setAttribute("name", descriptor.getServiceAssembly().getIdentification().getName());
        gbeanData.setAttribute("serviceUnitReferences", serviceUnitReferences);
        gbeanData.setReferencePattern("container", containerName);
        for (int i = 0; i < sus.length; i++) {
            String comp = sus[i].getTarget().getComponentName();
            gbeanData.addDependency(getComponentName(comp));
        }
        context.addGBean(gbeanData);
    }