KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > cmdui > HandlerContext


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 package org.jmanage.cmdui;
17
18 import org.jmanage.core.services.ServiceContext;
19 import org.jmanage.core.services.ServiceContextImpl;
20 import org.jmanage.core.auth.User;
21
22 /**
23  *
24  * date: Feb 4, 2005
25  * @author Rakesh Kalra
26  */

27 public class HandlerContext {
28
29     private final Command command;
30     private final ServiceContextImpl serviceContext;
31
32     HandlerContext(Command command){
33         this(command, true);
34     }
35
36     HandlerContext(Command command, boolean isAuthRequired){
37         this.command = command;
38         this.serviceContext = getServiceContext(command, isAuthRequired);
39     }
40
41     public Command getCommand(){
42         return command;
43     }
44
45     public ServiceContext getServiceContext(){
46         return serviceContext;
47     }
48
49     public ServiceContext getServiceContext(String JavaDoc appName){
50         assert appName != null;
51         ServiceContextImpl serviceContext = getServiceContext(command, true);
52         serviceContext.setApplicationName(appName);
53         return serviceContext;
54     }
55
56     public ServiceContext getServiceContext(String JavaDoc appName, String JavaDoc mbeanName) {
57         assert mbeanName != null;
58         ServiceContextImpl serviceContext =
59                 (ServiceContextImpl)getServiceContext(appName);
60         serviceContext.setMBeanName(mbeanName);
61         return serviceContext;
62     }
63
64     private static ServiceContextImpl getServiceContext(Command command,
65                                                         boolean isAuthRequired){
66         ServiceContextImpl context = new ServiceContextImpl();
67         if(isAuthRequired){
68             assert command.getUsername() != null;
69             assert command.getPassword() != null;
70             User user = new User(command.getUsername(),
71                     null, null, null, 0);
72             user.setPlaintextPassword(command.getPassword());
73             context.setUser(user);
74         }
75         return context;
76     }
77 }
78
Popular Tags