summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/CMSUIFramework.java
blob: 6949e73f6a4d5a15e360df3214338e91bfe5a2d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.admin.certsrv;

import java.util.*;
import com.netscape.management.client.*;
import com.netscape.management.client.util.*;
import com.netscape.management.client.console.*;
import com.netscape.certsrv.common.*;
import com.netscape.admin.certsrv.connection.*;
import java.util.*;

/**
 * Netscape Certificate Server 4.0 UI Framework
 *
 * This class is responsible for the loading of UI components associated with
 * the certificate server.
 *
 * @author Jack Pan-Chen
 * @version $Revision$, $Date$
 * @date	 	03/30/97
 */
public class CMSUIFramework {

    /*==========================================================
     * variables
     *==========================================================*/
    private ConsoleInfo mConsoleInfo;       // global information
    private CMSServerInfo mServerInfo;		// server-specific information
    private CMSPageFeeder mPageFeeder;      // KP PageFeeder
    private Framework mFramework;           // KP Framework
    private ISubSystemLocator mSubSystemLocator = null;     // subsystem locator
    private UILoaderRegistry mUILoaders;

	/*==========================================================
     * constructors
     *==========================================================*/
    public CMSUIFramework(ConsoleInfo info, CMSServerInfo serverInfo) 
        throws EAdminException
    {
        mConsoleInfo = info;
        mServerInfo = serverInfo;
        mPageFeeder = new CMSPageFeeder(info, serverInfo);
        setSubSystemLocator( new HTTPSSubSystemLocator(serverInfo.getAdmin()));
        init();
        //framework must be created as the last components
        //we are not able to change the components of the
        //pages after creating the framework.
        mFramework = new Framework(mPageFeeder);
        mPageFeeder.expendPages();
    }

    /*==========================================================
	 * public methods
     *==========================================================*/
    public void setSubSystemLocator(ISubSystemLocator locator) {
        mSubSystemLocator = locator;
    }
    
    public IPage getPage(String type, String name) throws EAdminException {
        return mPageFeeder.getPage(type, name);
    }
    
    public Framework getFramework() {
        return mFramework;    
    }
    
    public boolean isNTEnv() throws EAdminException {
        Debug.println("CMSUIFramework - isNTEnv()");
        NameValuePairs response;
        AdminConnection conn = mServerInfo.getAdmin();
        response = conn.search(DestDef.DEST_SERVER_ADMIN,
          ScopeDef.SC_PLATFORM, new NameValuePairs());
        if (response == null) 
            throw new EAdminException("PROTOCOL_ERROR",false);
        if (response.getValue(Constants.PR_NT).equals(Constants.TRUE))
            return true;
        return false;
    }

    /*==========================================================
	 * private methods
     *==========================================================*/
    private void init() throws EAdminException {
        //initialize the kernel UI
        CMSKernelUILoader kernelUI = new CMSKernelUILoader(this);
        kernelUI.register();
        
        //load subsystem information. if no locator specified use default
        if (mSubSystemLocator == null)
            mSubSystemLocator = new DefaultSubSystemLocator();
        SubSystemInfo[] subsystems = mSubSystemLocator.getInstalledSubSystem();
        
        //delegate UI loading to each subsystem loader
        UILoaderRegistry registry = new UILoaderRegistry(this);
        Vector subsystemList = new Vector();
        for (int i=0; i< subsystems.length; i++) {
            try {
                subsystemList.addElement(subsystems[i].mType);
                ISubSystemUILoader loader = registry.getUILoader(subsystems[i].mType);
                loader.register();
            } catch (Exception e) {
                Debug.println("Error loading subsystem UI - "+e.toString());  
            }
        }
       
       //set subsystem setting
       mServerInfo.setInstalledSubsystems(subsystemList);
    }
    
}

//=====================================================================

/**
 * Registry for the Subsystem UI loader.
 * Only single instance of the UI loader should be created.
 */
class UILoaderRegistry {
    private final String PREFIX = "UILOADERREGISTRY_";
    private Hashtable mContent = new Hashtable();
    private ResourceBundle mResource;       // resource boundle
    
    public UILoaderRegistry(CMSUIFramework uiFramework) {
        mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName());
        mContent.put(Constants.PR_CA_INSTANCE,new CMSCAUILoader(uiFramework));
        mContent.put(Constants.PR_KRA_INSTANCE,new CMSEAUILoader(uiFramework));
        mContent.put(Constants.PR_RA_INSTANCE,new CMSRAUILoader(uiFramework));
        mContent.put(Constants.PR_OCSP_INSTANCE,new CMSOCSPUILoader(uiFramework));
        //mContent.put("ccm",new CMSCCMUILoader(uiFramework));
    }
    
    public ISubSystemUILoader getUILoader(String type) throws EAdminException {
        if (!mContent.containsKey(type)) {
            Debug.println("Error Loading Subsystem UI Loader");
            return null;
        }
        return (ISubSystemUILoader) mContent.get(type);
    }
}

//============================================================================

/**
 * Info container for the sub system
 */
class SubSystemInfo {
    String mType;    
    String mNickName;
}

/**
 * Interface for the sub system UI loader
 */
interface ISubSystemLocator {
    public SubSystemInfo[] getInstalledSubSystem() throws EAdminException;
}

//XXX DUMMY that just returned with all components
//XXX installed on the srever side
class DefaultSubSystemLocator implements ISubSystemLocator {
    
    public SubSystemInfo[] getInstalledSubSystem() throws EAdminException {
        SubSystemInfo[] subsystems = new SubSystemInfo[4];
        for (int i=0; i< subsystems.length; i++)
            subsystems[i] = new SubSystemInfo();
        subsystems[0].mType=Constants.PR_CA_INSTANCE;
        subsystems[1].mType=Constants.PR_RA_INSTANCE;
        subsystems[2].mType=Constants.PR_KRA_INSTANCE;
        subsystems[3].mType=Constants.PR_OCSP_INSTANCE;
        //subsystems[3].mType="ccm";
        if (true)
            return subsystems;
        //this should never be called    
        throw new EAdminException("DefaultSubSystemLocator - error loading",true);
    }
}

/**
 * This is the one actually used to communicate with the
 * server side and retreive the subsystem actually loaded
 */
class HTTPSSubSystemLocator implements ISubSystemLocator {
    private AdminConnection mConnection;
    
    public HTTPSSubSystemLocator(AdminConnection conn) {
        mConnection = conn;
    }
    
    public SubSystemInfo[] getInstalledSubSystem() throws EAdminException {
        NameValuePairs input = getSubSystem();
        Debug.println("getInstalledSubSystem() - "+input.toString());
        SubSystemInfo[] subsystems = new SubSystemInfo[input.size()];
        int i =0;
        for (Enumeration e = input.getNames(); e.hasMoreElements() ;) {
            String entry = ((String)e.nextElement()).trim();
            String value = input.getValue(entry);
            subsystems[i] = new SubSystemInfo();
            subsystems[i].mType = value;
            subsystems[i].mNickName = entry;
            i++;
        }
        return subsystems;
    }
    
    private NameValuePairs getSubSystem() throws EAdminException {
        Debug.println("CMSUIFramework - getSubSystem() - started");
        NameValuePairs response;
        response = mConnection.search(DestDef.DEST_SERVER_ADMIN,
                               ScopeDef.SC_SUBSYSTEM,
                               new NameValuePairs());
        if (response == null) {
            throw new EAdminException("PROTOCOL_ERROR",false);        
        }
        Debug.println("CMSUIFramework - getSubSystem() - completed");
        return response;
    }
   
}

/*
//XXX TBD Read the SubSystem installation information
//XXX from the SIE entry.
class SIESubSystemLocator implements ISubSystemLocator {
    public SubSystemInfo[] getInstalledSubSystem() {
    }
}
*/