KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > ejb > remote > RemoteEJBValidator


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.util.ejb.remote;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8
9 import com.opensymphony.workflow.*;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13
14 import java.lang.reflect.Method JavaDoc;
15
16 import java.rmi.RemoteException JavaDoc;
17
18 import java.util.Map JavaDoc;
19
20 import javax.ejb.EJBHome JavaDoc;
21
22 import javax.naming.InitialContext JavaDoc;
23
24 import javax.rmi.PortableRemoteObject JavaDoc;
25
26
27 /**
28  *
29  *
30  * @author $Author: hani $
31  * @version $Revision: 1.2 $
32  */

33 public class RemoteEJBValidator implements Validator {
34     //~ Static fields/initializers /////////////////////////////////////////////
35

36     private static final Log log = LogFactory.getLog(RemoteEJBValidator.class);
37
38     //~ Methods ////////////////////////////////////////////////////////////////
39

40     public void validate(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws InvalidInputException, WorkflowException {
41         String JavaDoc ejbLocation = (String JavaDoc) args.get(AbstractWorkflow.EJB_LOCATION);
42
43         ValidatorRemote sessionBean = null;
44
45         try {
46             EJBHome JavaDoc home = (EJBHome JavaDoc) PortableRemoteObject.narrow(new InitialContext JavaDoc().lookup(ejbLocation), EJBHome JavaDoc.class);
47             Method JavaDoc create = home.getClass().getMethod("create", new Class JavaDoc[0]);
48             sessionBean = (ValidatorRemote) create.invoke(home, new Object JavaDoc[0]);
49         } catch (Exception JavaDoc e) {
50             String JavaDoc message = "Could not get handle to remote EJB validator: " + ejbLocation;
51             log.error(message, e);
52             throw new WorkflowException(message, e);
53         }
54
55         try {
56             sessionBean.validate(transientVars, args, ps);
57         } catch (RemoteException JavaDoc e) {
58             String JavaDoc message = "Remote exception while executing remote EJB validator: " + ejbLocation;
59             throw new WorkflowException(message, e);
60         }
61     }
62 }
63
Popular Tags