KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > deployment > undeploy > AllConnectionsRemovalTask


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: AllConnectionsRemovalTask.java 154 10 oct. 06 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.deployment.undeploy;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.xml.namespace.QName JavaDoc;
28
29 import org.objectweb.petals.jbi.component.lifecycle.ServiceAssemblyLifeCycle;
30 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants;
31 import org.objectweb.petals.jbi.management.service.EndpointService;
32 import org.objectweb.petals.processor.Task;
33 import org.objectweb.petals.tools.jbicommon.descriptor.Connection;
34 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceAssembly;
35
36 /**
37  * This task remove all connections from the registry.
38  *
39  * @author ofabre - EBM Websourcing
40  *
41  */

42 public class AllConnectionsRemovalTask implements Task {
43
44     protected EndpointService endpointService;
45
46     public AllConnectionsRemovalTask(EndpointService endpointService) {
47         super();
48         this.endpointService = endpointService;
49     }
50
51     public void execute(HashMap JavaDoc context) throws Exception JavaDoc {
52
53         ServiceAssemblyLifeCycle lifeCycle = (ServiceAssemblyLifeCycle) context
54                 .get(DeploymentContextConstants.SA_LIFECYCLE);
55
56         removeConnections(lifeCycle);
57
58     }
59
60     /**
61      * Remove all connections registered during the SA deployment process
62      *
63      * @param saLifeCycle
64      * the service assembly life cycle
65      * @throws Exception
66      * if problem occurs during the deletion of a specific
67      * connection
68      */

69     protected void removeConnections(ServiceAssemblyLifeCycle saLifeCycle)
70         throws Exception JavaDoc {
71         ServiceAssembly saDesc = saLifeCycle.getServiceAssembly();
72         List JavaDoc<Connection> connections = saDesc.getConnections();
73         if (connections != null) {
74             for (Connection connection : connections) {
75                 QName JavaDoc consInterface = connection.getConsumerInterfaceName();
76                 QName JavaDoc consService = connection.getConsumerServiceName();
77                 String JavaDoc consEndpoint = connection.getConsumerEndpointName();
78                 QName JavaDoc provService = connection.getProviderServiceName();
79                 String JavaDoc provEndpoint = connection.getProviderEndpointName();
80
81                 if (provEndpoint != null && provService != null) {
82                     if (consInterface != null) {
83                         endpointService.deleteConnection(consInterface,
84                                 provService, provEndpoint);
85                     } else if (consService != null && consEndpoint != null) {
86                         endpointService.deleteConnection(consService,
87                                 consEndpoint, provService, provEndpoint);
88                     }
89                 }
90             }
91         }
92     }
93
94     public void undo(HashMap JavaDoc context) throws Exception JavaDoc {
95         // Nothing to do
96

97     }
98
99 }
100
Popular Tags