001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: *
024: --------------------------------------------------------------------------
025: * $Id: MailSample.java,v 1.1 2006/05/29 14:44:54 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.hook;
029:
030: import hero.interfaces.*;
031: import hero.interfaces.BnNodeLocal;
032: import hero.util.HeroHookException;
033: import hero.util.BonitaServiceLocator;
034:
035: import javax.naming.InitialContext;
036: import javax.mail.Session;
037: import javax.mail.Address;
038: import javax.mail.Transport;
039: import javax.mail.internet.InternetAddress;
040: import javax.mail.internet.MimeMessage;
041: import javax.rmi.PortableRemoteObject;
042:
043: import java.util.*;
044:
045: public class MailSample implements hero.hook.NodeHookI {
046:
047: public String getMetadata() {
048: return Constants.Nd.BEFORETERMINATE;
049: }
050:
051: public void create(Object b, BnNodeLocal n)
052: throws HeroHookException {
053: }
054:
055: public void beforeStart(Object b, BnNodeLocal n)
056: throws HeroHookException {
057: }
058:
059: public void afterTerminate(Object b, BnNodeLocal n)
060: throws HeroHookException {
061: }
062:
063: public void onCancel(Object b, BnNodeLocal n)
064: throws HeroHookException {
065: }
066:
067: public void anticipate(Object b, BnNodeLocal n)
068: throws HeroHookException {
069: }
070:
071: public void onDeadline(Object b, BnNodeLocal n)
072: throws HeroHookException {
073: }
074:
075: public void afterStart(Object b, BnNodeLocal n)
076: throws HeroHookException {
077: }
078:
079: public void onReady(Object b, BnNodeLocal n)
080: throws HeroHookException {
081: }
082:
083: public void beforeTerminate(Object b, BnNodeLocal n)
084: throws HeroHookException {
085: try {
086: String nodeName = n.getName();
087:
088: BnProjectLocal project = n.getBnProject();
089: String prjName = project.getName();
090:
091: ProjectSessionHome prjhome = (ProjectSessionHome) ProjectSessionUtil
092: .getHome();
093: ProjectSession prjSession = prjhome.create();
094: prjSession.initProject(prjName);
095:
096: // In this sample we assume that the "Email_address" property was defined at activity level
097: // during the model definition. Otherwise this hook will throw an Exception at
098: // execution time
099: BnNodePropertyValue val = prjSession.getNodeProperty(
100: nodeName, "Email_address");
101: String mailString = val.getTheValue();
102:
103: BonitaServiceLocator serviceLocator = BonitaServiceLocator
104: .getInstance();
105: Session session = (Session) serviceLocator
106: .getMailSession(BonitaServiceLocator.Services.MAIL_SERVICE);
107:
108: MimeMessage m = new MimeMessage(session);
109: m.setFrom();
110: Address[] to = new InternetAddress[] { new InternetAddress(
111: mailString) };
112: m.setRecipients(javax.mail.Message.RecipientType.TO, to);
113: m.setSubject("Request accepted...");
114: m.setSentDate(new java.util.Date());
115: String content = "";
116: m.setContent(content, "text/plain");
117:
118: // Envoi du mail
119: Transport.send(m);
120: System.out.println("send mail OK");
121: } catch (Exception e) {
122: System.out.println("mail service error: " + e);
123: e.printStackTrace();
124: }
125: }
126:
127: }
|