1 10 11 package org.mule.providers.dq; 12 13 import java.util.Map ; 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 33 34 public class DQConnector extends AbstractServiceEnabledConnector 35 { 36 public static final String LIB_PROPERTY = "lib"; 37 public static final String RECORD_DESCRIPTOR_PROPERTY = "recordDescriptor"; 38 private static final long DEFAULT_POLLING = 1000; 39 40 43 public static final String PROPERTY_POLLING_FREQUENCY = "pollingFrequency"; 44 45 private Long pollingFrequency = new Long (DEFAULT_POLLING); 46 private String hostname; 47 private String username; 48 private String password; 49 private String recordFormat = null; 50 private RecordFormat format; 51 52 private AS400 as400System = null; 53 54 58 public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception 59 { 60 Map props = endpoint.getProperties(); 61 if (props != null) 62 { 63 String tempPolling = (String )props.get(PROPERTY_POLLING_FREQUENCY); 65 if (tempPolling != null) 66 { 67 pollingFrequency = new Long (tempPolling); 68 } 69 } 70 71 if (pollingFrequency.longValue() <= 0) 72 { 73 pollingFrequency = new Long (DEFAULT_POLLING); 74 } 75 76 logger.debug("set polling frequency to: " + pollingFrequency); 77 78 String lib = (String )endpoint.getEndpointURI().getParams().get(LIB_PROPERTY); 80 logger.debug("provider endpoint: " + endpoint.getName() + " - lib: " + lib); 81 String 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 []{ 91 pollingFrequency, dq, as400System}); 92 93 } 94 95 98 public final String getPassword() 99 { 100 return password; 101 } 102 103 106 public void setPassword(String pPassword) 107 { 108 password = pPassword; 109 } 110 111 114 public Long getPollingFrequency() 115 { 116 return pollingFrequency; 117 } 118 119 122 public void setPollingFrequency(final Long pPollingFrequency) 123 { 124 pollingFrequency = pPollingFrequency; 125 } 126 127 130 public AS400 getSystem() 131 { 132 return as400System; 133 } 134 135 138 public void setSystem(final AS400 pSystem) 139 { 140 as400System = pSystem; 141 } 142 143 146 public String getHostname() 147 { 148 return hostname; 149 } 150 151 154 public void setHostname(final String pSystemName) 155 { 156 hostname = pSystemName; 157 } 158 159 162 public String getUsername() 163 { 164 return username; 165 } 166 167 170 public void setUsername(String username) 171 { 172 this.username = username; 173 } 174 175 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 e) 189 { 190 throw new InitialisationException(new Message(Messages.FAILED_LOAD_X, "Record Format: " 191 + recordFormat), e, this); 192 } 193 194 } 195 } 196 197 200 public final String getProtocol() 201 { 202 return "dq"; 203 } 204 205 208 209 protected void doStop() throws UMOException 210 { 211 as400System.disconnectAllServices(); 212 } 213 214 public String getRecordFormat() 215 { 216 return recordFormat; 217 } 218 219 public void setRecordFormat(String 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 |