001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.security.ejb.project;
023:
024: import java.rmi.RemoteException;
025: import javax.ejb.CreateException;
026: import javax.ejb.SessionBean;
027: import javax.ejb.SessionContext;
028: import javax.naming.Name;
029: import javax.naming.NamingException;
030: import javax.naming.directory.Attributes;
031: import javax.naming.directory.BasicAttributes;
032: import javax.naming.directory.DirContext;
033:
034: import org.jboss.test.security.ejb.project.support.HeirMemoryMap;
035: import org.jboss.test.security.interfaces.IProjRepository;
036: import org.apache.log4j.Logger;
037:
038: /** The ProjRepository session bean implementation. This is a trivial
039: implementation that always creates the same set of project data.
040:
041: @see javax.naming.Name
042: @see javax.naming.directory.Attributes
043:
044: @author Scott.Stark@jboss.org
045: @version $Revision: 57211 $
046: */
047: public class ProjRepositoryBean implements SessionBean, IProjRepository {
048: static Logger log = Logger.getLogger(ProjRepositoryBean.class);
049:
050: private SessionContext context;
051: private HeirMemoryMap projRepository;
052:
053: // --- Begin IProjRepository interface methods
054: public void createFolder(Name folderPath) throws NamingException,
055: RemoteException {
056: log.debug("createFolder, " + folderPath);
057: }
058:
059: public void deleteFolder(Name folderPath, boolean recursive)
060: throws NamingException, RemoteException {
061: log.debug("deleteFolder, " + folderPath);
062: }
063:
064: public void createItem(Name itemPath, Attributes attributes)
065: throws NamingException, RemoteException {
066: log.debug("createItem, " + itemPath);
067: }
068:
069: public void updateItem(Name itemPath, Attributes attributes)
070: throws NamingException, RemoteException {
071: log.debug("updateItem, " + itemPath);
072: }
073:
074: public void deleteItem(Name itemPath) throws NamingException,
075: RemoteException {
076: try {
077: projRepository.unbind(itemPath);
078: } catch (Exception e) {
079: log.debug("failed", e);
080: }
081: }
082:
083: public Attributes getItem(Name itemPath) throws NamingException,
084: RemoteException {
085: log.debug("ProjRepositoryBean.getItem() itemPath=" + itemPath);
086: Attributes attributes = projRepository.getAttributes(itemPath);
087: return attributes;
088: }
089:
090: // --- End IProjRepository interface methods
091:
092: // --- Begin ProjRepositoryHome methods
093: public void ejbCreate(Name projectName) throws CreateException {
094: log.debug("ProjRepositoryBean.ejbCreate() projectName="
095: + projectName);
096: // Add the same data structure to every project
097: projRepository = new HeirMemoryMap();
098: try {
099: BasicAttributes attributes = new BasicAttributes();
100: attributes.put("name", projectName);
101: attributes.put("owner", "scott");
102: DirContext projectCtx = projRepository.createSubcontext(
103: projectName, attributes);
104: attributes = new BasicAttributes();
105: attributes.put("name", "Drawings");
106: attributes.put("isFolder", "false");
107: attributes.put("contentType", "text/html");
108: attributes.put("size", "1024");
109: projectCtx.bind("readme.html", null, attributes);
110: attributes.put("owner", "scott");
111: // Documents subctx
112: attributes = new BasicAttributes();
113: attributes.put("name", "Documents");
114: attributes.put("isFolder", "true");
115: attributes.put("owner", "scott");
116: DirContext dctx = projectCtx.createSubcontext("Documents",
117: attributes);
118: attributes = new BasicAttributes();
119: attributes.put("name", "index.html");
120: attributes.put("isFolder", "false");
121: attributes.put("contentType", "text/html");
122: attributes.put("size", "1234");
123: dctx.bind("index.html", null, attributes);
124: attributes.put("owner", "scott");
125: // Documents/Private subctx
126: attributes = new BasicAttributes();
127: attributes.put("name", "Private");
128: attributes.put("isFolder", "true");
129: attributes.put("owner", "scott");
130: dctx = projectCtx.createSubcontext("Documents/Private",
131: attributes);
132: attributes = new BasicAttributes();
133: attributes.put("name", "passwords");
134: attributes.put("isFolder", "false");
135: attributes.put("contentType", "text/plain");
136: attributes.put("size", "8173");
137: attributes.put("owner", "scott");
138: dctx.bind("passwords", null, attributes);
139: // Documents/Public subctx
140: attributes = new BasicAttributes();
141: attributes.put("name", "Public");
142: attributes.put("isFolder", "true");
143: attributes.put("owner", "scott");
144: dctx = projectCtx.createSubcontext("Documents/Public",
145: attributes);
146: attributes = new BasicAttributes();
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();
155: attributes.put("name", "starksm");
156: attributes.put("isFolder", "true");
157: attributes.put("owner", "starksm");
158: dctx = projectCtx.createSubcontext(
159: "Documents/Public/starksm", attributes);
160: attributes = new BasicAttributes();
161: attributes.put("name", ".bashrc");
162: attributes.put("isFolder", "false");
163: attributes.put("contentType", "text/plain");
164: attributes.put("size", "1167");
165: attributes.put("owner", "starksm");
166: dctx.bind(".bashrc", null, attributes);
167: // Drawing subctx
168: attributes = new BasicAttributes();
169: attributes.put("name", "Drawings");
170: attributes.put("isFolder", "true");
171: attributes.put("owner", "scott");
172: dctx = projectCtx.createSubcontext("Drawings", attributes);
173: attributes = new BasicAttributes();
174: attributes.put("name", "view1.jpg");
175: attributes.put("isFolder", "false");
176: attributes.put("contentType", "image/jpeg");
177: attributes.put("owner", "scott");
178: dctx.bind("view1.jpg", null, attributes);
179: } catch (NamingException e) {
180: throw new CreateException(e.toString(true));
181: }
182: }
183:
184: // --- End ProjRepositoryHome methods
185:
186: // --- Begin SessionBean interface methods
187: public void setSessionContext(SessionContext context) {
188: this .context = context;
189: }
190:
191: public void ejbRemove() {
192: }
193:
194: public void ejbActivate() {
195: }
196:
197: public void ejbPassivate() {
198: }
199: // --- End SessionBean interface methods
200: }
|