KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > ejb > project > ProjRepositoryBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.ejb.project;
23
24 import java.rmi.RemoteException JavaDoc;
25 import javax.ejb.CreateException JavaDoc;
26 import javax.ejb.SessionBean JavaDoc;
27 import javax.ejb.SessionContext JavaDoc;
28 import javax.naming.Name JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.naming.directory.Attributes JavaDoc;
31 import javax.naming.directory.BasicAttributes JavaDoc;
32 import javax.naming.directory.DirContext JavaDoc;
33
34 import org.jboss.test.security.ejb.project.support.HeirMemoryMap;
35 import org.jboss.test.security.interfaces.IProjRepository;
36 import org.jboss.logging.Logger;
37
38 /** The ProjRepository session bean implementation. This is a trivial
39 implementation that always creates the same set of project data.
40
41 @see javax.naming.Name
42 @see javax.naming.directory.Attributes
43
44 @author Scott.Stark@jboss.org
45 @version $Revision: 58115 $
46 */

47 public class ProjRepositoryBean implements SessionBean JavaDoc, IProjRepository
48 {
49    static Logger log = Logger.getLogger(ProjRepositoryBean.class);
50    
51     private SessionContext JavaDoc context;
52     private HeirMemoryMap projRepository;
53
54 // --- Begin IProjRepository interface methods
55
public void createFolder(Name JavaDoc folderPath) throws NamingException JavaDoc, RemoteException JavaDoc
56     {
57        log.debug("createFolder, "+folderPath);
58     }
59
60     public void deleteFolder(Name JavaDoc folderPath,boolean recursive) throws NamingException JavaDoc, RemoteException JavaDoc
61     {
62        log.debug("deleteFolder, "+folderPath);
63     }
64
65     public void createItem(Name JavaDoc itemPath,Attributes JavaDoc attributes) throws NamingException JavaDoc, RemoteException JavaDoc
66     {
67        log.debug("createItem, "+itemPath);
68     }
69
70     public void updateItem(Name JavaDoc itemPath,Attributes JavaDoc attributes) throws NamingException JavaDoc, RemoteException JavaDoc
71     {
72        log.debug("updateItem, "+itemPath);
73     }
74
75     public void deleteItem(Name JavaDoc itemPath) throws NamingException JavaDoc, RemoteException JavaDoc
76     {
77         try
78         {
79             projRepository.unbind(itemPath);
80         }
81         catch(Exception JavaDoc e)
82         {
83             log.debug("failed", e);
84         }
85     }
86
87     public Attributes JavaDoc getItem(Name JavaDoc itemPath) throws NamingException JavaDoc, RemoteException JavaDoc
88     {
89         log.debug("ProjRepositoryBean.getItem() itemPath="+itemPath);
90         Attributes JavaDoc attributes = projRepository.getAttributes(itemPath);
91         return attributes;
92     }
93 // --- End IProjRepository interface methods
94

95 // --- Begin ProjRepositoryHome methods
96
public void ejbCreate(Name JavaDoc projectName) throws CreateException JavaDoc
97     {
98         log.debug("ProjRepositoryBean.ejbCreate() projectName="+projectName);
99         // Add the same data structure to every project
100
projRepository = new HeirMemoryMap();
101         try
102         {
103             BasicAttributes JavaDoc attributes = new BasicAttributes JavaDoc();
104             attributes.put("name", projectName);
105             attributes.put("owner", "scott");
106             DirContext JavaDoc projectCtx = projRepository.createSubcontext(projectName, attributes);
107             attributes = new BasicAttributes JavaDoc();
108             attributes.put("name", "Drawings");
109             attributes.put("isFolder", "false");
110             attributes.put("contentType", "text/html");
111             attributes.put("size", "1024");
112             projectCtx.bind("readme.html", null, attributes);
113             attributes.put("owner", "scott");
114             // Documents subctx
115
attributes = new BasicAttributes JavaDoc();
116             attributes.put("name", "Documents");
117             attributes.put("isFolder", "true");
118             attributes.put("owner", "scott");
119             DirContext JavaDoc dctx = projectCtx.createSubcontext("Documents", attributes);
120             attributes = new BasicAttributes JavaDoc();
121             attributes.put("name", "index.html");
122             attributes.put("isFolder", "false");
123             attributes.put("contentType", "text/html");
124             attributes.put("size", "1234");
125             dctx.bind("index.html", null, attributes);
126             attributes.put("owner", "scott");
127             // Documents/Private subctx
128
attributes = new BasicAttributes JavaDoc();
129             attributes.put("name", "Private");
130             attributes.put("isFolder", "true");
131             attributes.put("owner", "scott");
132             dctx = projectCtx.createSubcontext("Documents/Private", attributes);
133             attributes = new BasicAttributes JavaDoc();
134             attributes.put("name", "passwords");
135             attributes.put("isFolder", "false");
136             attributes.put("contentType", "text/plain");
137             attributes.put("size", "8173");
138             attributes.put("owner", "scott");
139             dctx.bind("passwords", null, attributes);
140             // Documents/Public subctx
141
attributes = new BasicAttributes JavaDoc();
142             attributes.put("name", "Public");
143             attributes.put("isFolder", "true");
144             attributes.put("owner", "scott");
145             dctx = projectCtx.createSubcontext("Documents/Public", attributes);
146             attributes = new BasicAttributes JavaDoc();
147             attributes.put("name", "readme.txt");
148             attributes.put("isFolder", "false");
149             attributes.put("contentType", "text/plain");
150             attributes.put("size", "13584");
151             attributes.put("owner", "scott");
152             dctx.bind("readme.txt", null, attributes);
153             // Documents/Public/starksm subctx
154
attributes = new BasicAttributes JavaDoc();
155             attributes.put("name", "starksm");
156             attributes.put("isFolder", "true");
157             attributes.put("owner", "starksm");
158             dctx = projectCtx.createSubcontext("Documents/Public/starksm", attributes);
159             attributes = new BasicAttributes JavaDoc();
160             attributes.put("name", ".bashrc");
161             attributes.put("isFolder", "false");
162             attributes.put("contentType", "text/plain");
163             attributes.put("size", "1167");
164             attributes.put("owner", "starksm");
165             dctx.bind(".bashrc", null, attributes);
166             // Drawing subctx
167
attributes = new BasicAttributes JavaDoc();
168             attributes.put("name", "Drawings");
169             attributes.put("isFolder", "true");
170             attributes.put("owner", "scott");
171             dctx = projectCtx.createSubcontext("Drawings", attributes);
172             attributes = new BasicAttributes JavaDoc();
173             attributes.put("name", "view1.jpg");
174             attributes.put("isFolder", "false");
175             attributes.put("contentType", "image/jpeg");
176             attributes.put("owner", "scott");
177             dctx.bind("view1.jpg", null, attributes);
178         }
179         catch(NamingException JavaDoc e)
180         {
181             throw new CreateException JavaDoc(e.toString(true));
182         }
183     }
184
185 // --- End ProjRepositoryHome methods
186

187 // --- Begin SessionBean interface methods
188
public void setSessionContext(SessionContext JavaDoc context)
189     {
190         this.context = context;
191     }
192     
193     public void ejbRemove()
194     {
195     }
196
197     public void ejbActivate()
198     {
199     }
200     
201     public void ejbPassivate()
202     {
203     }
204 // --- End SessionBean interface methods
205
}
206
Popular Tags