KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > PropertyProfileResourceType


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.properties;
21
22 import com.sslexplorer.core.CoreEvent;
23 import com.sslexplorer.core.CoreEventConstants;
24 import com.sslexplorer.core.CoreServlet;
25 import com.sslexplorer.policyframework.DefaultResourceType;
26 import com.sslexplorer.policyframework.Resource;
27 import com.sslexplorer.policyframework.ResourceChangeEvent;
28 import com.sslexplorer.security.SessionInfo;
29
30
31 /**
32  * Implementation of a {@link com.sslexplorer.policyframework.ResourceType}
33  * for <i>Profile Profile</i> and <i>Personal Profile</i> resources.
34  *
35  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
36  */

37 public class PropertyProfileResourceType extends DefaultResourceType {
38
39     /**
40      * Constructor
41      *
42      * @param id id
43      * @param permissionClass permission class
44      */

45     public PropertyProfileResourceType(int id, String JavaDoc permissionClass) {
46         super(id, "policyframework", permissionClass);
47     }
48
49     /* (non-Javadoc)
50      * @see com.sslexplorer.navigation.FavoriteResourceType#getResourceById(int)
51      */

52     public Resource getResourceById(int resourceId) throws Exception JavaDoc {
53         return ProfilesFactory.getInstance().getPropertyProfile(resourceId);
54     }
55
56     /* (non-Javadoc)
57      * @see com.sslexplorer.policyframework.DefaultResourceType#getResourceByName(java.lang.String, com.sslexplorer.security.SessionInfo)
58      */

59     public Resource getResourceByName(String JavaDoc resourceName, SessionInfo session) throws Exception JavaDoc {
60         return ProfilesFactory.getInstance().getPropertyProfile(null, resourceName, session.getUser().getRealm().getResourceId());
61     }
62
63
64     /* (non-Javadoc)
65      * @see com.sslexplorer.boot.policyframework.ResourceType#removeResource(int, com.sslexplorer.security.SessionInfo)
66      */

67     public Resource removeResource(int resourceId, SessionInfo session) throws Exception JavaDoc {
68         try {
69             PropertyProfile resource =
70                 ProfilesFactory.getInstance().deletePropertyProfile(resourceId);
71             CoreServlet.getServlet().fireCoreEvent(
72                 new ResourceChangeEvent(this, CoreEventConstants.DELETE_PROPERTY_PROFILE, resource, session,
73                     CoreEvent.STATE_SUCCESSFUL));
74             return resource;
75         } catch (Exception JavaDoc e) {
76             CoreServlet.getServlet().fireCoreEvent(
77                 new ResourceChangeEvent(this, CoreEventConstants.DELETE_PROPERTY_PROFILE, null, session,
78                     CoreEvent.STATE_UNSUCCESSFUL));
79             throw e;
80         }
81     }
82
83     /* (non-Javadoc)
84      * @see com.sslexplorer.boot.policyframework.ResourceType#updateResource(com.sslexplorer.boot.policyframework.Resource, com.sslexplorer.security.SessionInfo)
85      */

86     public void updateResource(Resource resource, SessionInfo session) throws Exception JavaDoc {
87         try {
88             PropertyProfile profile = (PropertyProfile)resource;
89             ProfilesFactory.getInstance().updatePropertyProfile(
90                     profile.getResourceId(),
91                     profile.getResourceName(),
92                     profile.getResourceDescription());
93             CoreServlet.getServlet().fireCoreEvent(
94                 new ResourceChangeEvent(this, CoreEventConstants.UPDATE_PROPERTY_PROFILE, resource, session,
95                     CoreEvent.STATE_SUCCESSFUL));
96         } catch (Exception JavaDoc e) {
97             CoreServlet.getServlet().fireCoreEvent(
98                 new ResourceChangeEvent(this, CoreEventConstants.UPDATE_PROPERTY_PROFILE, session, e));
99             throw e;
100         }
101     }
102 }
103
Popular Tags