KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > ApplicationShortcutResourceType


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.applications;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import com.sslexplorer.core.CoreEvent;
25 import com.sslexplorer.core.CoreServlet;
26 import com.sslexplorer.extensions.ExtensionDescriptor;
27 import com.sslexplorer.extensions.store.ExtensionStore;
28 import com.sslexplorer.navigation.FavoriteResourceType;
29 import com.sslexplorer.navigation.WrappedFavoriteItem;
30 import com.sslexplorer.policyframework.DefaultResourceType;
31 import com.sslexplorer.policyframework.PolicyConstants;
32 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
33 import com.sslexplorer.policyframework.Resource;
34 import com.sslexplorer.security.LogonControllerFactory;
35 import com.sslexplorer.security.SessionInfo;
36
37 /**
38  * Implementation of a {@link com.sslexplorer.policyframework.ResourceType} for
39  * <i>Application Shortcut</i> resources.
40  *
41  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
42  */

43 public class ApplicationShortcutResourceType extends DefaultResourceType implements FavoriteResourceType {
44
45     /**
46      * Constructor
47      */

48     public ApplicationShortcutResourceType() {
49         super(ApplicationsPlugin.APPLICATION_SHORTCUT_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.DELEGATION_CLASS);
50     }
51
52     public WrappedFavoriteItem createWrappedFavoriteItem(int resourceId, HttpServletRequest JavaDoc request, String JavaDoc type) throws Exception JavaDoc {
53         SessionInfo sessionInfo = LogonControllerFactory.getInstance().getSessionInfo(request);
54         ApplicationShortcut as = ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resourceId);
55         if (as == null) {
56             return null;
57         }
58         ExtensionDescriptor des = ExtensionStore.getInstance().getExtensionDescriptor(as.getApplication());
59         if (des == null) {
60             throw new Exception JavaDoc("No application extension with ID of " + as.getApplication() + ", skipping favorite.");
61         } else {
62             SessionInfo inf = LogonControllerFactory.getInstance().getSessionInfo(request);
63             ApplicationShortcutItem it = new ApplicationShortcutItem(des, as, PolicyDatabaseFactory.getInstance()
64                             .getPoliciesAttachedToResource(as, sessionInfo.getUser().getRealm()), inf.getNavigationContext(), as
65                             .sessionPasswordRequired(inf));
66             if (as.getApplication() != null) {
67                 return new WrappedFavoriteItem(it, type);
68             } else {
69                 throw new Exception JavaDoc("No application.");
70             }
71         }
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see com.sslexplorer.navigation.FavoriteResourceType#getResourceById(int)
78      */

79     public Resource getResourceById(int resourceId) throws Exception JavaDoc {
80         return ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resourceId);
81     }
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see com.sslexplorer.policyframework.DefaultResourceType#getResourceByName(java.lang.String,
87      * com.sslexplorer.security.SessionInfo)
88      */

89     public Resource getResourceByName(String JavaDoc resourceName, SessionInfo session) throws Exception JavaDoc {
90         return ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resourceName, session.getUser().getRealm().getRealmID());
91     }
92
93     /*
94      * (non-Javadoc)
95      *
96      * @see com.sslexplorer.boot.policyframework.ResourceType#removeResource(int,
97      * com.sslexplorer.security.SessionInfo)
98      */

99     public Resource removeResource(int resourceId, SessionInfo session) throws Exception JavaDoc {
100         try {
101             ApplicationShortcut resource = ApplicationShortcutDatabaseFactory.getInstance().deleteShortcut(resourceId);
102             CoreServlet.getServlet().fireCoreEvent(
103                             new ApplicationShortcutDeleteEvent(this, ApplicationShortcutEventConstants.REMOVE_APPLICATION_SHORTCUT, resource,
104                                             session, CoreEvent.STATE_SUCCESSFUL));
105             return resource;
106         } catch (Exception JavaDoc e) {
107             CoreServlet.getServlet().fireCoreEvent(
108                             new ApplicationShortcutDeleteEvent(this, ApplicationShortcutEventConstants.REMOVE_APPLICATION_SHORTCUT, session, e));
109             throw e;
110         }
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see com.sslexplorer.boot.policyframework.ResourceType#updateResource(com.sslexplorer.boot.policyframework.Resource,
117      * com.sslexplorer.security.SessionInfo)
118      */

119     public void updateResource(Resource resource, SessionInfo session) throws Exception JavaDoc {
120         try {
121             ApplicationShortcutDatabaseFactory.getInstance().updateApplicationShortcut(resource.getResourceId(),
122                             resource.getResourceName(), resource.getResourceDescription(),
123                             ((ApplicationShortcut) resource).getParameters());
124             CoreServlet.getServlet().fireCoreEvent(
125                             new ApplicationShortcutChangeEvent(this, ApplicationShortcutEventConstants.UPDATE_APPLICATION_SHORTCUT,
126                                             (ApplicationShortcut) resource, session, CoreEvent.STATE_SUCCESSFUL));
127         } catch (Exception JavaDoc e) {
128             CoreServlet.getServlet().fireCoreEvent(
129                             new ApplicationShortcutChangeEvent(this, ApplicationShortcutEventConstants.UPDATE_APPLICATION_SHORTCUT, session, e));
130             throw e;
131         }
132     }
133
134 }
135
Popular Tags