KickJava   Java API By Example, From Geeks To Geeks.

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


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 : Edifact.java 154 ${date} rbarraza
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.engine.edifact;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28
29 import javax.jbi.JBIException;
30 import javax.jbi.component.Component;
31 import javax.jbi.component.ComponentContext;
32 import javax.jbi.component.ComponentLifeCycle;
33 import javax.jbi.component.ServiceUnitManager;
34 import javax.jbi.messaging.DeliveryChannel;
35 import javax.jbi.messaging.MessageExchange;
36 import javax.jbi.servicedesc.ServiceEndpoint;
37 import javax.management.ObjectName JavaDoc;
38 import javax.xml.namespace.QName JavaDoc;
39
40 import org.ebmwebsourcing.b2bgw.edifact.dictionary.Dictionary;
41 import org.objectweb.petals.component.common.listener.MessageExchangeListener;
42 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager;
43 import org.objectweb.petals.component.common.util.ComponentLogger;
44 import org.objectweb.petals.component.common.util.XMLHelper;
45
46 import org.w3c.dom.Document JavaDoc;
47 import org.w3c.dom.DocumentFragment JavaDoc;
48 import org.w3c.dom.Node JavaDoc;
49
50 /**
51  *
52  * @version $Rev: 250 $Date: {date}
53  * @since Petals 1.0
54  * @author alouis, Rocio BARRAZA - eBMWebsourcing
55  *
56  */

57 public class Edifact implements Component, ComponentLifeCycle {
58
59     protected DeliveryChannel channel;
60
61     protected PetalsServiceUnitManager suManager;
62
63     protected Map JavaDoc<QName JavaDoc, QName JavaDoc> mapEndpointXslt;
64
65     private ComponentContext context;
66
67     private MessageExchangeListener listener;
68
69     private Logger JavaDoc logger;
70
71     public ObjectName JavaDoc getExtensionMBeanName() {
72         return null;
73     }
74
75     public ComponentLifeCycle getLifeCycle() {
76         return this;
77     }
78
79     /**
80      * If arg0.service = EdifactService, return the wsdl description
81      */

82     public Document JavaDoc getServiceDescription(ServiceEndpoint arg0) {
83         return suManager.getServiceDescription(arg0);
84     }
85
86     public ServiceUnitManager getServiceUnitManager() {
87         return suManager;
88     }
89
90     public void init(ComponentContext ctx) throws JBIException {
91         this.context = ctx;
92         Logger JavaDoc log = context.getLogger("", null);
93         logger = new ComponentLogger(log, log.getName(), log
94             .getResourceBundleName(), context.getComponentName());
95         logger.log(Level.INFO, "init()");
96
97         this.channel = ctx.getDeliveryChannel();
98         this.mapEndpointXslt = new HashMap JavaDoc<QName JavaDoc, QName JavaDoc>();
99     }
100
101     public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0,
102         MessageExchange arg1) {
103
104         logger.log(Level.FINE, "accept the exchange");
105         return true;
106     }
107
108     public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0,
109         MessageExchange arg1) {
110         return false;
111     }
112
113     /**
114      * If requested service is EdifactService, return the endpoint
115      */

116     public ServiceEndpoint resolveEndpointReference(DocumentFragment JavaDoc arg0) {
117         ServiceEndpoint result = null;
118
119         if (arg0 != null) {
120             String JavaDoc prefix = arg0.getPrefix();
121             if (prefix == null) {
122                 prefix = new String JavaDoc();
123             } else {
124                 prefix += ":";
125             }
126             Node JavaDoc service = XMLHelper.findChild(arg0, prefix + "service", true);
127
128             if (service != null) {
129                 String JavaDoc serviceRequested = XMLHelper.getAttributeValue(service,
130                     "name");
131                 if (serviceRequested != null) {
132                     result = suManager.findEndpointForService(QName
133                         .valueOf(serviceRequested));
134                 }
135             }
136         }
137         return result;
138     }
139
140     public void shutDown() throws JBIException {
141         logger.log(Level.INFO, "shutDown()");
142         listener = null;
143
144     }
145
146     public void start() throws JBIException {
147         logger.log(Level.INFO, "start()");
148
149         EdifactProcessor processor = new EdifactProcessor(channel, logger,
150             this.context, this.mapEndpointXslt);
151
152         listener = new MessageExchangeListener(channel, processor,
153             MessageExchangeListener.IgnoredStatus.DONE_AND_ERROR_IGNORED, 0,
154             context.getComponentName());
155         listener.listen();
156         EdifactSUHandler SUHandler = new EdifactSUHandler(context,
157             this.mapEndpointXslt, logger);
158         EdifactMappingHandler mappingHandler = new EdifactMappingHandler(
159             context, logger);
160         this.suManager = new PetalsServiceUnitManager(context, logger);
161
162         suManager.addNewHandler(SUHandler);
163         suManager.addNewHandler(mappingHandler);
164
165         Dictionary.getInstance();
166     }
167
168     public void stop() throws JBIException {
169         logger.log(Level.INFO, "stop");
170         this.listener.terminate();
171
172     }
173
174 }
175
Popular Tags