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.BnProjectUtil;
029: import hero.interfaces.Constants;
030: import hero.util.BonitaProjectLocator;
031: import hero.util.BonitaServiceValue;
032: import hero.util.EventConstants;
033: import hero.util.HeroException;
034: import hero.util.HeroHookException;
035: import hero.util.values.BonitaHookValue;
036: import hero.util.values.BonitaNodeValue;
037: import hero.util.values.BonitaProjectValue;
038:
039: import java.util.Collection;
040: import java.util.Iterator;
041:
042: import javax.ejb.CreateException;
043: import javax.ejb.SessionBean;
044: import javax.ejb.SessionContext;
045:
046: /**
047: * Session Bean Template
048: *
049: * @ejb:bean name="DeadlineSession"
050: * display-name="DeadlineSession Bean"
051: * type="Stateless"
052: * transaction-type="Container"
053: * jndi-name="ejb/hero/DeadlineSession"
054: * local-jndi-name="ejb/hero/DeadlineSession_L"
055: *
056: * @ejb:transaction type="Supports"
057: * @ejb.permission unchecked="yes"
058: * @ejb.security-identity run-as="SuperAdmin"
059: * @jonas.bean
060: * ejb-name="DeadlineSession"
061: * jndi-name="ejb/hero/DeadlineSession"
062: *
063: * @jboss.container-configuration name="Standard Stateless SessionBean for Bonita"
064: **/
065:
066: public class DeadlineSessionBean implements SessionBean, EventConstants {
067:
068: // -------------------------------------------------------------------------
069: // Static
070: // -------------------------------------------------------------------------
071:
072: // -------------------------------------------------------------------------
073: // Members
074: // -------------------------------------------------------------------------
075:
076: private SessionContext mContext;
077:
078: // -------------------------------------------------------------------------
079: // Methods
080: // -------------------------------------------------------------------------
081:
082: /**
083: * Get all projects
084: *
085: * @ejb.permission unchecked="yes"
086: * @ejb:interface-method view-type="both"
087: * @ejb:transaction type="Required"
088: *
089: **/
090: public void executeHookDeadline(String type, String projectName,
091: String nodeName) throws HeroException {
092: BnProjectLocal mProject = null;
093: BonitaProjectValue model;
094: BonitaNodeValue node;
095: Collection hooks;
096:
097: try {
098: BnProjectLocalHome pHome = BnProjectUtil.getLocalHome();
099: mProject = pHome.findByName(projectName);
100: } catch (Exception ple) {
101: ple.printStackTrace();
102: }
103:
104: try {
105: BonitaNodeValue nodeLocal;
106: if (mProject.getType().equals(Constants.Pj.INSTANCE)) {
107: model = BonitaProjectLocator.getInstance()
108: .getModelValue(
109: this .getModel(mProject.getName()),
110: this .getModel(mProject.getVersion()));
111: node = BonitaServiceValue.getNodeFromCache(model,
112: nodeName);
113:
114: if (nodeName.matches(".*_instance.*"))
115: nodeName = nodeName.substring(0, nodeName
116: .indexOf("_instance"));
117: nodeLocal = BonitaServiceValue.getNodeFromCache(model,
118: nodeName);
119: } else {
120: nodeLocal = BonitaServiceValue.getNode(mProject,
121: nodeName);
122: }
123:
124: hooks = nodeLocal.getHooks();
125: for (Iterator i = hooks.iterator(); i.hasNext();) {
126: BonitaHookValue hk = (BonitaHookValue) i.next();
127: if (hk.getEvent().equalsIgnoreCase(
128: hero.interfaces.Constants.Nd.ONDEADLINE)) {
129: hero.hook.Hook h = hero.hook.Hook.make(
130: hk.getName(),
131: hero.interfaces.Constants.Nd.ONDEADLINE, hk
132: .getType());
133: h.execute(this ,
134: hero.interfaces.Constants.Nd.ONDEADLINE,
135: mProject.getBnNode(nodeLocal.getName()));
136: }
137: }
138: } catch (Exception hh) {
139: mContext.setRollbackOnly();
140: throw new HeroHookException("Cannot execute hook "
141: + hh.getMessage());
142: }
143: }
144:
145: // Get the name of the project model of this instance
146: private String getModel(String instanceName) {
147: int i = instanceName.indexOf("_instance");
148: if (i != -1)
149: return (instanceName.substring(0, i));
150: else
151: return (instanceName); // for cooperative processes
152: }
153:
154: /**
155: * Create the All Projects Session Bean
156: *
157: * @throws CreateException
158: *
159: * @ejb.permission unchecked="yes"
160: * @ejb:create-method view-type="both"
161: **/
162:
163: public void ejbCreate() throws CreateException {
164: }
165:
166: public void setSessionContext(final javax.ejb.SessionContext context) {
167: mContext = context;
168: }
169:
170: public void ejbRemove() {
171: }
172:
173: public void ejbActivate() {
174: }
175:
176: public void ejbPassivate() {
177: }
178:
179: }
|