001: package hero.session;
002:
003: /*
004: * 02/01/2002 - 15:24:07
005: *
006: * AllProjectsSessionEJB.java -
007: * Copyright (C) 2002 Ecoo Team
008: * valdes@loria.fr
009: *
010: *
011: * This program is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public License
013: * as published by the Free Software Foundation; either version 2
014: * of the License, or (at your option) any later version.
015: *
016: * This program is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: * GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License
022: * along with this program; if not, write to the Free Software
023: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
024: */
025:
026: import hero.interfaces.BnProjectLocal;
027: import hero.interfaces.BnProjectLocalHome;
028: import hero.interfaces.Constants;
029: import hero.util.EventConstants;
030: import hero.util.HeroException;
031: import hero.util.StrutsProjectValue;
032:
033: import java.util.ArrayList;
034: import java.util.Collection;
035: import java.util.Iterator;
036:
037: import javax.ejb.CreateException;
038: import javax.ejb.FinderException;
039: import javax.ejb.SessionBean;
040: import javax.ejb.SessionContext;
041:
042: /**
043: * Session Bean Template
044: *
045: * @ejb:bean name="AllProjectsSession"
046: * display-name="AllProjectsSession Bean"
047: * type="Stateless"
048: * transaction-type="Container"
049: * jndi-name="ejb/hero/AllProjectsSession"
050: * local-jndi-name="ejb/hero/AllProjectsSession_L"
051: *
052: * @ejb:ejb-ref ejb-name="BnProject"
053: * ref-name="myhero/BnProject"
054: * @ejb:transaction type="Supports"
055: * @ejb.permission unchecked="yes"
056: * @ejb.security-identity run-as="SuperAdmin"
057: * @jonas.bean
058: * ejb-name="AllProjectsSession"
059: * jndi-name="ejb/hero/AllProjectsSession"
060: *
061: * @jboss.container-configuration name="Standard Stateless SessionBean for Bonita"
062: **/
063:
064: public class AllProjectsSessionBean implements SessionBean,
065: EventConstants {
066:
067: // -------------------------------------------------------------------------
068: // Static
069: // -------------------------------------------------------------------------
070:
071: // -------------------------------------------------------------------------
072: // Members
073: // -------------------------------------------------------------------------
074:
075: private SessionContext mContext;
076:
077: // -------------------------------------------------------------------------
078: // Methods
079: // -------------------------------------------------------------------------
080:
081: /**
082: * Get all projects
083: *
084: * @ejb.permission unchecked="yes"
085: * @ejb:interface-method view-type="both"
086: * @ejb:transaction type="Supports"
087: *
088: **/
089: public Collection getProjects() throws HeroException {
090: BnProjectLocalHome pHome;
091: ArrayList projects = new ArrayList();
092:
093: try {
094: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
095: } catch (javax.naming.NamingException be) {
096: throw new HeroException(be.getMessage());
097: }
098: try {
099: Collection allProjects = pHome.findAll();
100: Iterator i = allProjects.iterator();
101: while (i.hasNext()) {
102: BnProjectLocal pvalue = (BnProjectLocal) i.next();
103: StrutsProjectValue spv = new StrutsProjectValue();
104: spv.setName(pvalue.getName());
105: spv.setCreator(pvalue.getCreator());
106: spv
107: .setState(hero.interfaces.Constants.Pj.projectStateName[pvalue
108: .getState()]);
109: spv.setNact(pvalue.getBnNodes().size());
110: spv.setNusers(pvalue.getBnUsers().size());
111: projects.add(spv);
112: }
113: return ((Collection) projects);
114:
115: } catch (FinderException fe) {
116: throw new HeroException(fe.getMessage());
117: }
118: }
119:
120: /**
121: * Get all projects
122: *
123: * @ejb.permission unchecked="yes"
124: * @ejb:interface-method view-type="both"
125: * @ejb:transaction type="Supports"
126: *
127: **/
128: public Collection getProjects(int offset, int numrows)
129: throws HeroException {
130: BnProjectLocalHome pHome;
131: ArrayList projects = new ArrayList();
132:
133: try {
134: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
135: } catch (javax.naming.NamingException be) {
136: throw new HeroException(be.getMessage());
137: }
138: try {
139: Collection allProjects = pHome.findAll();
140: int cnt = 0;
141: int add = 0;
142: Iterator i = allProjects.iterator();
143: while (i.hasNext()) {
144: BnProjectLocal pvalue = (BnProjectLocal) i.next();
145: if (cnt >= offset) {
146: StrutsProjectValue spv = new StrutsProjectValue();
147: spv.setName(pvalue.getName());
148: spv.setCreator(pvalue.getCreator());
149: spv
150: .setState(hero.interfaces.Constants.Pj.projectStateName[pvalue
151: .getState()]);
152: spv.setNact(pvalue.getBnNodes().size());
153: spv.setNusers(pvalue.getBnUsers().size());
154: projects.add(spv);
155: add++;
156: if (add == numrows)
157: break;
158: }
159: cnt++;
160: }
161: return ((Collection) projects);
162: } catch (FinderException fe) {
163: throw new HeroException(fe.getMessage());
164: }
165: }
166:
167: /**
168: * Get number of total entities
169: *
170: * @ejb:interface-method view-type="both"
171: * @ejb:transaction type="Supports"
172: *
173: **/
174: public int getListCnt(String type) throws HeroException {
175: BnProjectLocalHome pHome;
176: Collection list = null;
177: int cnt = 0;
178:
179: if (type.equals(Constants.Pj.GETPROJECTS)) {
180: try {
181: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
182: } catch (javax.naming.NamingException be) {
183: throw new HeroException(be.getMessage());
184: }
185: try {
186: list = pHome.findAll();
187: Iterator i = list.iterator();
188: while (i.hasNext()) {
189: i.next();
190: cnt++;
191: }
192: } catch (FinderException fe) {
193: throw new HeroException(fe.getMessage());
194: }
195: }
196: return (cnt);
197: }
198:
199: /**
200: * Create the All Projects Session Bean
201: *
202: * @throws CreateException
203: *
204: * @ejb.permission unchecked="yes"
205: * @ejb:create-method view-type="both"
206: **/
207:
208: public void ejbCreate() throws CreateException {
209: }
210:
211: public void setSessionContext(final javax.ejb.SessionContext context) {
212: mContext = context;
213: }
214:
215: public void ejbRemove() {
216: }
217:
218: public void ejbActivate() {
219: }
220:
221: public void ejbPassivate() {
222: }
223:
224: }
|