KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > sample > Sample


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.sample;
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.navigation.FavoriteResourceType;
27 import com.sslexplorer.navigation.WrappedFavoriteItem;
28 import com.sslexplorer.policyframework.DefaultResourceType;
29 import com.sslexplorer.policyframework.PolicyConstants;
30 import com.sslexplorer.policyframework.Resource;
31 import com.sslexplorer.policyframework.ResourceChangeEvent;
32 import com.sslexplorer.policyframework.ResourceType;
33 import com.sslexplorer.security.SessionInfo;
34
35 /**
36  * <p>
37  * A sample resource.
38  *
39  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
40  *
41  */

42 public interface Sample extends Resource {
43
44     public final static int SAMPLE_RESOURCE_TYPE_ID = 999999;
45
46     public final static ResourceType SAMPLE_RESOURCE_TYPE = new SampleResourceType();
47
48     static class SampleResourceType extends DefaultResourceType implements FavoriteResourceType {
49
50         public SampleResourceType() {
51             super(SAMPLE_RESOURCE_TYPE_ID, "sample", PolicyConstants.DELEGATION_CLASS);
52         }
53
54         public WrappedFavoriteItem createWrappedFavoriteItem(int resourceId, HttpServletRequest JavaDoc request, String JavaDoc type)
55                         throws Exception JavaDoc {
56             Resource r = getResourceById(resourceId);
57             if (r == null) {
58                 return null;
59             }
60             return new WrappedFavoriteItem(new SampleItem((Sample) r, CoreServlet.getServlet().getPolicyDatabase()
61                 .getPoliciesAttachedToResource(r)), type);
62         }
63
64         public Resource getResourceById(int resourceId) throws Exception JavaDoc {
65             return SamplePlugin.getDatabase().getSample(resourceId);
66         }
67
68         public Resource getResourceByName(String JavaDoc resourceName) throws Exception JavaDoc {
69             return SamplePlugin.getDatabase().getSample(resourceName);
70         }
71
72         public Resource removeResource(int resourceId, SessionInfo session) throws Exception JavaDoc {
73             try {
74                 Sample resource = SamplePlugin.getDatabase().removeSample(resourceId);
75                 // #ifdef XTRA
76
CoreServlet.getServlet().fireCoreEvent(
77                     new ResourceChangeEvent(this, SamplePlugin.EVT_SAMPLE_DELETED, resource, session, CoreEvent.STATE_SUCCESSFUL));
78                 // #endif
79
return resource;
80             } catch (Exception JavaDoc e) {
81                 // #ifdef XTRA
82
CoreServlet.getServlet().fireCoreEvent(
83                     new ResourceChangeEvent(this, SamplePlugin.EVT_SAMPLE_DELETED, null, session, CoreEvent.STATE_UNSUCCESSFUL));
84                 // #endif
85
throw e;
86             }
87
88         }
89
90         public void updateResource(Resource resource, SessionInfo session) throws Exception JavaDoc {
91             try {
92                 SamplePlugin.getDatabase().updateSample((Sample) resource);
93                 // #ifdef XTRA
94
CoreServlet.getServlet().fireCoreEvent(
95                     new ResourceChangeEvent(this, SamplePlugin.EVT_SAMPLE_UPDATED, resource, session, CoreEvent.STATE_SUCCESSFUL));
96                 // #endif
97
} catch (Exception JavaDoc e) {
98                 // #ifdef XTRA
99
CoreServlet.getServlet().fireCoreEvent(
100                     new ResourceChangeEvent(this, SamplePlugin.EVT_SAMPLE_UPDATED, null, session, CoreEvent.STATE_UNSUCCESSFUL));
101                 // #endif
102
throw e;
103             }
104         }
105
106     }
107 }
Popular Tags