KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > modules > websphere > WebSphereServerConnectionFactory


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.jmanage.core.modules.websphere;
18
19 import org.jmanage.core.management.ServerConnectionFactory;
20 import org.jmanage.core.management.ServerConnection;
21 import org.jmanage.core.management.ConnectionFailedException;
22 import org.jmanage.core.config.ApplicationConfig;
23
24 import java.util.Properties JavaDoc;
25
26 import com.ibm.websphere.management.AdminClient;
27 import com.ibm.websphere.management.AdminClientFactory;
28
29 /**
30  * Date: Jan 23, 2005 5:48:07 PM
31  * @author Shashank Bellary
32  */

33 public class WebSphereServerConnectionFactory implements ServerConnectionFactory{
34     /**
35      * Get connection to the server.
36      *
37      * @param config
38      * @return
39      * @throws ConnectionFailedException
40      */

41     public ServerConnection getServerConnection(ApplicationConfig config)
42             throws ConnectionFailedException {
43         /* Initialize the AdminClient */
44         Properties JavaDoc adminProps = new Properties JavaDoc();
45         adminProps.setProperty(AdminClient.CONNECTOR_TYPE,
46               AdminClient.CONNECTOR_TYPE_SOAP);
47         adminProps.setProperty(AdminClient.CONNECTOR_HOST, config.getHost());
48         adminProps.setProperty(AdminClient.CONNECTOR_PORT,
49               config.getPort().toString());
50         if(config.getUsername() != null && config.getUsername().trim().length() > 0){
51             adminProps.setProperty(AdminClient.USERNAME, config.getUsername());
52             adminProps.setProperty(AdminClient.PASSWORD, config.getPassword());
53         }
54         try{
55             AdminClient adminClient = AdminClientFactory.createAdminClient(adminProps);
56             return new WebSphereServerConnection(adminClient);
57         }catch(Throwable JavaDoc e){
58             throw new ConnectionFailedException(e);
59         }
60     }
61 }
62
Popular Tags