1 2 24 25 package com.sun.enterprise.connectors; 26 import java.util.*; 27 import javax.naming.*; 28 import com.sun.enterprise.deployment.*; 29 30 34 35 public class ConnectorAdminServiceUtils implements ConnectorConstants{ 36 37 private ConnectorAdminServiceUtils(){ 39 } 40 41 47 48 public static ResourcePrincipal getDefaultResourcePrincipal( String poolName ) 49 throws NamingException { 50 ConnectorConnectionPool connectorConnectionPool = null; 52 try { 53 String jndiNameForPool = getReservePrefixedJNDINameForPool(poolName) ; 54 InitialContext ic = new InitialContext(); 55 connectorConnectionPool = 56 (ConnectorConnectionPool) ic.lookup(jndiNameForPool); 57 } catch (NamingException ne ) { 58 throw ne; 59 } 60 61 ConnectorDescriptorInfo cdi = connectorConnectionPool. 62 getConnectorDescriptorInfo(); 63 64 Set mcfConfigProperties = cdi.getMCFConfigProperties(); 65 Iterator mcfConfPropsIter = mcfConfigProperties.iterator(); 66 String userName = ""; 67 String password = ""; 68 while( mcfConfPropsIter.hasNext() ) { 69 EnvironmentProperty prop = 70 (EnvironmentProperty)mcfConfPropsIter.next(); 71 72 if ( prop.getName().toUpperCase().equals("USERNAME") || 73 prop.getName().toUpperCase().equals("USER") ) { 74 userName = prop.getValue(); 75 } else if ( prop.getName().toUpperCase().equals("PASSWORD") ) { 76 password = prop.getValue(); 77 } 78 } 79 80 return new ResourcePrincipal( userName, password ); 82 83 } 84 85 private static String getReservePrefixedJNDIName (String prefix, String resourceName) { 86 return prefix + resourceName; 87 } 88 89 public static String getReservePrefixedJNDINameForPool (String poolName) { 90 return getReservePrefixedJNDIName(ConnectorConstants.POOLS_JNDINAME_PREFIX, poolName); 91 } 92 93 public static String getReservePrefixedJNDINameForDescriptor(String moduleName) { 94 return getReservePrefixedJNDIName(ConnectorConstants.DD_PREFIX, moduleName); 95 } 96 97 public static String getReservePrefixedJNDINameForResource(String moduleName) { 98 return getReservePrefixedJNDIName(ConnectorConstants.RESOURCE_JNDINAME_PREFIX, moduleName); 99 } 100 101 public static String getOriginalResourceName (String reservePrefixedJNDIName) { 102 String prefix = null; 103 if ( reservePrefixedJNDIName.startsWith(ConnectorConstants.POOLS_JNDINAME_PREFIX) ) { 104 prefix = ConnectorConstants.POOLS_JNDINAME_PREFIX; 105 } else if ( reservePrefixedJNDIName.startsWith(ConnectorConstants.DD_PREFIX) ) { 106 prefix = ConnectorConstants.DD_PREFIX; 107 } else if ( reservePrefixedJNDIName.startsWith( ConnectorConstants.RESOURCE_JNDINAME_PREFIX) ) { 108 prefix = ConnectorConstants.RESOURCE_JNDINAME_PREFIX; 109 } 110 return (( prefix == null ) ? reservePrefixedJNDIName : reservePrefixedJNDIName.substring(prefix.length()) ); 111 } 112 113 public static boolean isEmbeddedConnectorModule(String moduleName){ 114 return (moduleName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) != -1); 115 } 116 117 public static String getApplicationName(String moduleName){ 118 if (isEmbeddedConnectorModule(moduleName)) { 119 int idx = moduleName.indexOf( 120 ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER); 121 return moduleName.substring(0, idx); 122 } else { 123 return null; 124 } 125 } 126 127 public static String getConnectorModuleName(String moduleName) { 128 if (isEmbeddedConnectorModule(moduleName)) { 129 int idx = moduleName.indexOf( 130 ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER); 131 return moduleName.substring(idx+1); 132 } else { 133 return moduleName; 134 } 135 } 136 137 public static boolean isJMSRA(String moduleName) { 138 return moduleName.equalsIgnoreCase(ConnectorConstants.DEFAULT_JMS_ADAPTER); 139 } 140 } 141 | Popular Tags |