1 2 24 25 package com.sun.enterprise.connectors.util; 26 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.deployment.archivist.*; 29 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 30 import com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive; 31 import com.sun.enterprise.config.serverbeans.ElementProperty; 32 import com.sun.enterprise.connectors.*; 33 import com.sun.logging.LogDomains; 34 35 import java.util.logging.*; 36 import java.util.*; 37 import java.io.FileInputStream ; 38 import java.io.IOException ; 39 40 import org.xml.sax.SAXParseException ; 41 42 43 50 51 public class ConnectorDDTransformUtils { 52 53 static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 54 55 62 63 public static ConnectorDescriptorInfo getConnectorDescriptorInfo( 64 ConnectionDefDescriptor connectionDefDescriptor) 65 { 66 67 ConnectorDescriptorInfo connectorDescInfo = 68 new ConnectorDescriptorInfo(); 69 connectorDescInfo.setConnectionDefinitionName( 70 connectionDefDescriptor.getConnectionFactoryIntf()); 71 connectorDescInfo.setManagedConnectionFactoryClass( 72 connectionDefDescriptor.getManagedConnectionFactoryImpl()); 73 connectorDescInfo.setConnectionFactoryClass( 74 connectionDefDescriptor.getConnectionFactoryImpl()); 75 connectorDescInfo.setConnectionFactoryInterface( 76 connectionDefDescriptor.getConnectionFactoryIntf()); 77 connectorDescInfo.setConnectionInterface( 78 connectionDefDescriptor.getConnectionIntf()); 79 connectorDescInfo.setConnectionClass( 80 connectionDefDescriptor.getConnectionImpl()); 81 connectorDescInfo.setMCFConfigProperties( 82 connectionDefDescriptor.getConfigProperties()); 83 return connectorDescInfo; 84 } 85 86 98 99 public static Set mergeProps(ElementProperty[] props, Set defaultMCFProps){ 100 HashSet mergedSet = new HashSet(); 101 102 if(defaultMCFProps != null) { 103 Object [] defaultProps = defaultMCFProps.toArray(); 104 105 for (int i = 0; i < defaultProps.length; i++) { 106 mergedSet.add(defaultProps[i]); 107 } 108 } 109 110 for (int i =0; props!= null && i< props.length; i++) { 111 EnvironmentProperty ep = new EnvironmentProperty( 112 props[i].getName(),props[i].getValue(),null); 113 if (defaultMCFProps.contains(ep)) { 114 Iterator iter = defaultMCFProps.iterator(); 116 while(iter.hasNext()){ 117 EnvironmentProperty envProp = 118 (EnvironmentProperty)iter.next(); 119 121 if (envProp.equals(ep)) { 126 if (envProp.getType() != null) { 127 ep.setType(envProp.getType()); 128 } 129 } 130 } 131 132 _logger.log(Level.FINER, 133 "After merging props with defaultMCFProps: envPropName: " 134 + ep.getName() + " envPropValue : " + ep.getValue()); 135 mergedSet.remove(ep); 136 } 137 mergedSet.add(ep); 138 } 139 140 return mergedSet; 141 } 142 143 154 155 public static ConnectorDescriptor getConnectorDescriptor(String moduleDir) 156 throws ConnectorRuntimeException 157 { 158 159 try { 160 161 FileArchive fileArchive = new FileArchive(); 162 fileArchive.open(moduleDir); ConnectorArchivist connectorArchivist = new ConnectorArchivist(); 164 ConnectorDescriptor connectorDescriptor = 165 (ConnectorDescriptor) connectorArchivist.open(fileArchive); 166 return connectorDescriptor; 167 } catch(IOException ex) { 168 ConnectorRuntimeException cre = new ConnectorRuntimeException( 169 "Failed to read the connector deployment descriptors"); 170 cre.initCause(ex); 171 _logger.log(Level.SEVERE, 172 "rardeployment.connector_descriptor_read_error",moduleDir); 173 _logger.log(Level.SEVERE,"",cre); 174 throw cre; 175 } catch(SAXParseException ex) { 176 ConnectorRuntimeException cre = new ConnectorRuntimeException( 177 "Failed to parse the connector deployment descriptors"); 178 cre.initCause(ex); 179 _logger.log(Level.SEVERE, 180 "rardeployment.connector_descriptor_parse_error",moduleDir); 181 _logger.log(Level.SEVERE,"",cre); 182 throw cre; 183 } 184 } 185 186 195 196 197 public static ConnectionDefDescriptor[] getConnectionDefs( 198 ConnectorDescriptor connectorDesc) 199 { 200 ConnectionDefDescriptor[] connectionDefDescs = null; 201 OutboundResourceAdapter ora = 202 connectorDesc.getOutboundResourceAdapter(); 203 if (ora != null) { 204 Set connectionDefs = ora.getConnectionDefs(); 205 int size = connectionDefs.size(); 206 if(size == 0) { 207 return null; 208 } 209 Iterator iter = connectionDefs.iterator(); 210 connectionDefDescs = new ConnectionDefDescriptor[size]; 211 for (int i=0; i<size; ++i) { 212 connectionDefDescs[i] = 213 (ConnectionDefDescriptor)iter.next(); 214 } 215 } 216 return connectionDefDescs; 217 } 218 219 225 226 public MessageListener[] getMessageListeners(ConnectorDescriptor desc) { 227 228 InboundResourceAdapter inboundRA = null; 229 Set messageListenerSet = null; 230 if(desc != null && 231 (inboundRA = desc.getInboundResourceAdapter()) != null) { 232 messageListenerSet = inboundRA.getMessageListeners(); 233 } 234 235 if(messageListenerSet == null) { 236 return null; 237 } 238 int size = messageListenerSet.size(); 239 MessageListener[] messageListeners = 240 new MessageListener[size]; 241 Iterator iter = messageListenerSet.iterator(); 242 for(int i=0;i<size;++i){ 243 messageListeners[i] = (MessageListener)iter.next(); 244 } 245 return messageListeners; 246 } 247 248 public static String getResourceAdapterClassName 249 (String rarLocation) { 250 try { 253 FileInputStream fis = new FileInputStream (rarLocation); 254 MemoryMappedArchive mma = new MemoryMappedArchive(fis); 255 ConnectorArchivist ca = new ConnectorArchivist(); 256 ConnectorDescriptor cd = (ConnectorDescriptor)ca.open(mma); 257 return cd.getResourceAdapterClass(); 258 } catch (IOException e) { 259 _logger.info(e.getMessage()); 260 _logger.log(Level.FINE, "Error while trying to read connector" + 261 "descriptor to get resource-adapter properties", e); 262 } catch (SAXParseException e) { 263 _logger.info(e.getMessage()); 264 _logger.log(Level.FINE, "Error while trying to read connector" + 265 "descriptor to get resource-adapter properties", e); 266 } 267 return null; 268 } 269 } 270 271 | Popular Tags |