KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > edifact > EdifactMappingHandler


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 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 : EdifactMappingHandler.java 154 ${date} rbarraza
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.engine.edifact;
23
24 import java.io.File JavaDoc;
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27
28 import javax.jbi.component.ComponentContext;
29 import javax.jbi.management.DeploymentException;
30
31 import org.ebmwebsourcing.b2bgw.edifact.dictionary.Dictionary;
32 import org.objectweb.petals.component.common.serviceunitmanager.handler.PetalsServiceUnitHandler;
33 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager;
34 import org.objectweb.petals.component.common.util.ManagementMessageUtil;
35
36 /**
37  *
38  * @version $Rev: 250 $Date: {date}
39  * @since Petals 1.0
40  * @author Rocio BARRAZA - eBMWebsourcing
41  *
42  */

43 public class EdifactMappingHandler extends PetalsServiceUnitHandler {
44
45     public EdifactMappingHandler(ComponentContext context, Logger JavaDoc logger) {
46         this.context = context;
47         this.logger = logger;
48         SERVICE_UNIT_TYPE = "EdiMappingServiceUnit";
49     }
50
51     private EdifactMappingHandler() {
52         SERVICE_UNIT_TYPE = "EdiMappingServiceUnit";
53     }
54
55     public void init(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath)
56         throws DeploymentException {
57         logger.fine("init serviceUnitName " + serviceUnitName);
58         this.serviceUnitInstallationRootPath.put(serviceUnitName,
59                 serviceUnitRootPath);
60     }
61
62     public void setContext(ComponentContext context) {
63         this.context = context;
64     }
65
66     public void setLogger(Logger JavaDoc logger) {
67         this.logger = logger;
68     }
69
70     public void shutDown(String JavaDoc serviceUnitName,
71             PetalsServiceUnitManager epHandler) throws DeploymentException {
72     }
73
74     public void start(String JavaDoc serviceUnitName, PetalsServiceUnitManager epHandler)
75         throws DeploymentException {
76         String JavaDoc serviceUnitRootPath = serviceUnitInstallationRootPath
77                 .get(serviceUnitName);
78
79         File JavaDoc[] files = new File JavaDoc(serviceUnitRootPath).listFiles();
80
81         for (File JavaDoc file : files) {
82             if (file.getName().endsWith(".xml")) {
83                 try {
84                     Dictionary.getInstance().reloadMapping(
85                             file.getAbsolutePath());
86                 } catch (Exception JavaDoc e) {
87                     String JavaDoc msg = "Error loading mapping in Edifact Dictionary";
88                     logger.log(Level.SEVERE, msg);
89                     throw new DeploymentException(msg, e);
90                 }
91
92             }
93         }
94     }
95
96     public void stop(String JavaDoc serviceUnitName, PetalsServiceUnitManager epHandler)
97         throws DeploymentException {
98         /*
99          * When service unit is stopped, so properties of directory are deleted
100          */

101         try {
102             serviceUnitInstallationRootPath.remove(serviceUnitName);
103             deactivateEndpointsFromJBIDescription(serviceUnitName, epHandler);
104         } catch (Exception JavaDoc e) {
105             throw new DeploymentException(FAILED_DEACTIVATE_ENDPOINT, e);
106         }
107     }
108
109     public String JavaDoc undeploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath)
110         throws DeploymentException {
111         return ManagementMessageUtil.getComponentTaskResult(context
112                 .getComponentName(), "undeploy",
113                 ManagementMessageUtil.TASK_RESULT_SUCCESS);
114     }
115
116     @Override JavaDoc
117     public String JavaDoc deploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitType,
118             String JavaDoc serviceUnitRootPath) throws DeploymentException {
119         if (SERVICE_UNIT_TYPE.equals(serviceUnitType)) {
120             logger.fine(" DEPLOY serviceUnitName " + serviceUnitName
121                     + " serviceUnitRootPath " + serviceUnitRootPath);
122             return ManagementMessageUtil.getComponentTaskResult(context
123                     .getComponentName(), "deploy",
124                     ManagementMessageUtil.TASK_RESULT_SUCCESS);
125         } else {
126             return null;
127         }
128     }
129
130 }
131
Popular Tags