KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > ConnectorAdminServiceUtils


1
2 /*
3  * The contents of this file are subject to the terms
4  * of the Common Development and Distribution License
5  * (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the license at
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
10  * glassfish/bootstrap/legal/CDDLv1.0.txt.
11  * See the License for the specific language governing
12  * permissions and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL
15  * Header Notice in each file and include the License file
16  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
17  * If applicable, add the following below the CDDL Header,
18  * with the fields enclosed by brackets [] replaced by
19  * you own identifying information:
20  * "Portions Copyrighted [year] [name of copyright owner]"
21  *
22  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23  */

24
25 package com.sun.enterprise.connectors;
26 import java.util.*;
27 import javax.naming.*;
28 import com.sun.enterprise.deployment.*;
29
30 /**
31  * Util classes common to all connector Services
32  * @author Srikanth P
33  */

34
35 public class ConnectorAdminServiceUtils implements ConnectorConstants{
36     
37     //Private Constructor, to prevent initialising this class
38
private ConnectorAdminServiceUtils(){
39     }
40
41     /*
42      * Returns a ResourcePrincipal object populated with a pool's
43      * default USERNAME and PASSWORD
44      *
45      * @throws NamingException if poolname lookup fails
46      */

47
48     public static ResourcePrincipal getDefaultResourcePrincipal( String JavaDoc poolName )
49         throws NamingException {
50         // All this to get the default user name and principal
51
ConnectorConnectionPool connectorConnectionPool = null;
52         try {
53             String JavaDoc 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 JavaDoc userName = "";
67         String JavaDoc 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         //Now return the ResourcePrincipal
81
return new ResourcePrincipal( userName, password );
82                
83     }
84     
85     private static String JavaDoc getReservePrefixedJNDIName (String JavaDoc prefix, String JavaDoc resourceName) {
86         return prefix + resourceName;
87     }
88     
89     public static String JavaDoc getReservePrefixedJNDINameForPool (String JavaDoc poolName) {
90         return getReservePrefixedJNDIName(ConnectorConstants.POOLS_JNDINAME_PREFIX, poolName);
91     }
92     
93     public static String JavaDoc getReservePrefixedJNDINameForDescriptor(String JavaDoc moduleName) {
94         return getReservePrefixedJNDIName(ConnectorConstants.DD_PREFIX, moduleName);
95     }
96
97     public static String JavaDoc getReservePrefixedJNDINameForResource(String JavaDoc moduleName) {
98         return getReservePrefixedJNDIName(ConnectorConstants.RESOURCE_JNDINAME_PREFIX, moduleName);
99     }
100     
101     public static String JavaDoc getOriginalResourceName (String JavaDoc reservePrefixedJNDIName) {
102         String JavaDoc 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 JavaDoc moduleName){
114         return (moduleName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) != -1);
115     }
116     
117     public static String JavaDoc getApplicationName(String JavaDoc 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 JavaDoc getConnectorModuleName(String JavaDoc 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 JavaDoc moduleName) {
138         return moduleName.equalsIgnoreCase(ConnectorConstants.DEFAULT_JMS_ADAPTER);
139     }
140 }
141
Popular Tags