KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > deployment > deploy > SAAndSUInstallRootRetrievalTask


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: SAAndSUInstallRootRetrievalTask.java 154 6 oct. 06 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.deployment.deploy;
23
24 import java.net.URI JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants;
30 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils;
31 import org.objectweb.petals.jbi.management.service.PackageHandler;
32 import org.objectweb.petals.processor.Task;
33 import org.objectweb.petals.repository.RepositoryService;
34 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor;
35 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit;
36
37 /**
38  * This task retrieves the SA install root and all SUs install roots
39  *
40  * @author ofabre - EBM Websourcing
41  *
42  */

43 public class SAAndSUInstallRootRetrievalTask implements Task {
44
45     /**
46      * Platform Component :: Repository Service
47      */

48     protected RepositoryService repositorySrv;
49
50     /**
51      * Package Handler
52      */

53     protected PackageHandler packageHandler;
54
55     public SAAndSUInstallRootRetrievalTask(RepositoryService repositorySrv,
56             PackageHandler packageHandler) {
57         super();
58         this.repositorySrv = repositorySrv;
59         this.packageHandler = packageHandler;
60     }
61
62     @SuppressWarnings JavaDoc("unchecked")
63     public void execute(HashMap JavaDoc context) throws Exception JavaDoc {
64         JBIDescriptor descriptor = (JBIDescriptor) context
65                 .get(DeploymentContextConstants.SA_DESCRIPTOR);
66
67         URI JavaDoc installationRoot = repositorySrv.getServiceAssemblyInstallRoot(
68                 DeploymentUtils.getServiceAssemblyName(descriptor)).toURI();
69         Map JavaDoc<String JavaDoc, URI JavaDoc> suInstallRoots = retrieveSUInstallRoots(
70                 installationRoot, descriptor);
71
72         /*
73          * Fill context
74          */

75         context.put(DeploymentContextConstants.SA_INSTALL_ROOT,
76                 installationRoot);
77         context
78                 .put(DeploymentContextConstants.SU_INSTALL_ROOTS,
79                         suInstallRoots);
80
81     }
82
83     /**
84      * Retrieve all su installation root {@link URI}
85      *
86      * @param descriptor
87      * the service assembly descriptor
88      * @param installationRoot
89      * the sa intallation root {@link URI}
90      * @return the service unit install roots {@link Map}
91      */

92     protected Map JavaDoc<String JavaDoc, URI JavaDoc> retrieveSUInstallRoots(URI JavaDoc installationRoot,
93             JBIDescriptor descriptor) {
94         Map JavaDoc<String JavaDoc, URI JavaDoc> suInstallRoots = new HashMap JavaDoc<String JavaDoc, URI JavaDoc>();
95         List JavaDoc<ServiceUnit> sus = descriptor.getServiceAssembly()
96                 .getServiceUnits();
97         for (ServiceUnit unit : sus) {
98             String JavaDoc suName = unit.getIdentification().getName();
99             suInstallRoots.put(suName, packageHandler.processAndGetPackageURI(
100                     "file://" + installationRoot.getPath() + suName, true));
101         }
102         return suInstallRoots;
103     }
104
105     public void undo(HashMap JavaDoc context) {
106         // Nothing to do
107

108     }
109
110 }
111
Popular Tags