KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > dq > DQConnector


1 /*
2  * $Id: DQConnector.java 3982 2006-11-22 14:28:01Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.dq;
12
13 import java.util.Map JavaDoc;
14
15 import org.mule.config.i18n.Message;
16 import org.mule.config.i18n.Messages;
17 import org.mule.providers.AbstractServiceEnabledConnector;
18 import org.mule.umo.UMOComponent;
19 import org.mule.umo.UMOException;
20 import org.mule.umo.endpoint.UMOEndpoint;
21 import org.mule.umo.lifecycle.InitialisationException;
22 import org.mule.umo.provider.UMOMessageReceiver;
23
24 import com.ibm.as400.access.AS400;
25 import com.ibm.as400.access.DataQueue;
26 import com.ibm.as400.access.RecordFormat;
27
28 /**
29  * <code>DQConnector</code> is a delegate provider that encapsulates an AS400
30  * DataQueue provider. The properties hostname, userId and password must be set for
31  * connection. The Message Queue location is the provider endpoint.
32  */

33
34 public class DQConnector extends AbstractServiceEnabledConnector
35 {
36     public static final String JavaDoc LIB_PROPERTY = "lib";
37     public static final String JavaDoc RECORD_DESCRIPTOR_PROPERTY = "recordDescriptor";
38     private static final long DEFAULT_POLLING = 1000;
39
40     /**
41      * Polling frequency property name
42      */

43     public static final String JavaDoc PROPERTY_POLLING_FREQUENCY = "pollingFrequency";
44
45     private Long JavaDoc pollingFrequency = new Long JavaDoc(DEFAULT_POLLING);
46     private String JavaDoc hostname;
47     private String JavaDoc username;
48     private String JavaDoc password;
49     private String JavaDoc recordFormat = null;
50     private RecordFormat format;
51
52     private AS400 as400System = null;
53
54     /**
55      * @see org.mule.providers.AbstractConnector#createReceiver(org.mule.umo.UMOComponent,
56      * org.mule.umo.endpoint.UMOEndpoint)
57      */

58     public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception JavaDoc
59     {
60         Map JavaDoc props = endpoint.getProperties();
61         if (props != null)
62         {
63             // Override properties on the provider for the specific endpoint
64
String JavaDoc tempPolling = (String JavaDoc)props.get(PROPERTY_POLLING_FREQUENCY);
65             if (tempPolling != null)
66             {
67                 pollingFrequency = new Long JavaDoc(tempPolling);
68             }
69         }
70
71         if (pollingFrequency.longValue() <= 0)
72         {
73             pollingFrequency = new Long JavaDoc(DEFAULT_POLLING);
74         }
75
76         logger.debug("set polling frequency to: " + pollingFrequency);
77
78         // TODO Can we include the Lib as part of the URI
79
String JavaDoc lib = (String JavaDoc)endpoint.getEndpointURI().getParams().get(LIB_PROPERTY);
80         logger.debug("provider endpoint: " + endpoint.getName() + " - lib: " + lib);
81         String JavaDoc name = "";
82         if (lib != null)
83         {
84             name = lib + "/";
85         }
86
87         name += endpoint.getEndpointURI().getAddress();
88
89         DataQueue dq = new DataQueue(as400System, name);
90         return serviceDescriptor.createMessageReceiver(this, component, endpoint, new Object JavaDoc[]{
91             pollingFrequency, dq, as400System});
92
93     }
94
95     /**
96      * @return Returns the password.
97      */

98     public final String JavaDoc getPassword()
99     {
100         return password;
101     }
102
103     /**
104      * @param pPassword The password to set.
105      */

106     public void setPassword(String JavaDoc pPassword)
107     {
108         password = pPassword;
109     }
110
111     /**
112      * @return Returns the pollingFrequency.
113      */

114     public Long JavaDoc getPollingFrequency()
115     {
116         return pollingFrequency;
117     }
118
119     /**
120      * @param pPollingFrequency The pollingFrequency to set.
121      */

122     public void setPollingFrequency(final Long JavaDoc pPollingFrequency)
123     {
124         pollingFrequency = pPollingFrequency;
125     }
126
127     /**
128      * @return Returns the system.
129      */

130     public AS400 getSystem()
131     {
132         return as400System;
133     }
134
135     /**
136      * @param pSystem The system to set.
137      */

138     public void setSystem(final AS400 pSystem)
139     {
140         as400System = pSystem;
141     }
142
143     /**
144      * @return Returns the hostname.
145      */

146     public String JavaDoc getHostname()
147     {
148         return hostname;
149     }
150
151     /**
152      * @param pSystemName The hostname to set.
153      */

154     public void setHostname(final String JavaDoc pSystemName)
155     {
156         hostname = pSystemName;
157     }
158
159     /**
160      * @return Returns the userId.
161      */

162     public String JavaDoc getUsername()
163     {
164         return username;
165     }
166
167     /**
168      * @param username The userId to set.
169      */

170     public void setUsername(String JavaDoc username)
171     {
172         this.username = username;
173     }
174
175     /**
176      * @see org.mule.providers.AbstractConnector#doInitialise()
177      */

178     public void doInitialise() throws InitialisationException
179     {
180         super.doInitialise();
181         as400System = new AS400(hostname, username, password);
182         if (recordFormat != null)
183         {
184             try
185             {
186                 format = DQMessageUtils.getRecordFormat(recordFormat, as400System);
187             }
188             catch (Exception JavaDoc e)
189             {
190                 throw new InitialisationException(new Message(Messages.FAILED_LOAD_X, "Record Format: "
191                                 + recordFormat), e, this);
192             }
193
194         }
195     }
196
197     /**
198      * @see org.mule.providers.AbstractConnector#getProtocol()
199      */

200     public final String JavaDoc getProtocol()
201     {
202         return "dq";
203     }
204
205     /**
206      * @see org.mule.providers.AbstractConnector#stopConnector()
207      */

208
209     protected void doStop() throws UMOException
210     {
211         as400System.disconnectAllServices();
212     }
213
214     public String JavaDoc getRecordFormat()
215     {
216         return recordFormat;
217     }
218
219     public void setRecordFormat(String JavaDoc recordFormat)
220     {
221         this.recordFormat = recordFormat;
222     }
223
224     public RecordFormat getFormat()
225     {
226         return format;
227     }
228
229     public void setFormat(RecordFormat format)
230     {
231         this.format = format;
232     }
233
234 }
235
Popular Tags