KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > bpel > ws > consumption > partner > DocumentTranslator_Impl


1 package org.jboss.test.bpel.ws.consumption.partner;
2
3 import java.rmi.Remote JavaDoc;
4 import java.rmi.RemoteException JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.Locale JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import org.jboss.test.bpel.ws.consumption.partner.spi.Dictionary;
13 import org.jboss.test.bpel.ws.consumption.partner.spi.DictionaryFactory;
14 import org.jboss.test.bpel.ws.consumption.partner.types.TDictionaryNotAvailable;
15 import org.jboss.test.bpel.ws.consumption.partner.types.TDocument;
16 import org.jboss.test.bpel.ws.consumption.partner.types.TQuotationRequest;
17 import org.jboss.test.bpel.ws.consumption.partner.types.TQuoteStatus;
18 import org.jboss.test.bpel.ws.consumption.partner.types.TStatusRequest;
19 import org.jboss.test.bpel.ws.consumption.partner.types.TStatusResponse;
20 import org.jboss.test.bpel.ws.consumption.partner.types.TTextNotTranslatable;
21 import org.jboss.test.bpel.ws.consumption.partner.types.TTranslationRequest;
22
23 /**
24  * @author Alejandro Guizar
25  * @version $Revision: 43322 $ $Date: 2006-04-03 12:19:24 -0400 (Mon, 03 Apr 2006) $
26  */

27 public class DocumentTranslator_Impl implements DocumentTranslator, Remote JavaDoc {
28   
29   private static Map JavaDoc quotationRequests = new HashMap JavaDoc();
30   
31   private static final Log log = LogFactory.getLog(DocumentTranslator_Impl.class);
32
33   public TDocument translate(TTranslationRequest translationRequest)
34   throws TDictionaryNotAvailable, TTextNotTranslatable, RemoteException JavaDoc {
35     TDocument document = translationRequest.getDocument();
36     Locale JavaDoc sourceLocale = new Locale JavaDoc(document.getHead().getLanguage());
37     Locale JavaDoc targetLocale = new Locale JavaDoc(translationRequest.getTargetLanguage());
38     DictionaryFactory dictionaryFactory = DictionaryFactory.getInstance(sourceLocale, targetLocale);
39     Dictionary dictionary = dictionaryFactory.createDictionary(sourceLocale, targetLocale);
40     return dictionary.translate(document);
41   }
42
43   public void quoteTranslation(TQuotationRequest quotationRequest) throws RemoteException JavaDoc {
44     String JavaDoc clientName = quotationRequest.getClientName();
45     log.debug("received quotation request: clientName=" + clientName);
46     quotationRequests.put(clientName, quotationRequest);
47   }
48   
49   public TStatusResponse getQuotationStatus(TStatusRequest statusRequest)
50   throws RemoteException JavaDoc {
51     TStatusResponse statusResponse = new TStatusResponse();
52     TQuoteStatus quoteStatus = quotationRequests.containsKey(statusRequest.getClientName()) ?
53         TQuoteStatus.received : TQuoteStatus.none;
54     statusResponse.setStatus(quoteStatus);
55       return statusResponse;
56   }
57 }
58
Popular Tags