001: package org.enhydra.shark.ejb;
002:
003: import javax.ejb.EJBException;
004: import javax.naming.Context;
005: import javax.rmi.PortableRemoteObject;
006:
007: import org.enhydra.shark.Shark;
008: import org.enhydra.shark.api.client.wfmodel.WfAssignmentEventAudit;
009: import org.enhydra.shark.api.client.wfmodel.WfCreateProcessEventAudit;
010: import org.enhydra.shark.api.client.wfmodel.WfDataEventAudit;
011: import org.enhydra.shark.api.client.wfmodel.WfEventAudit;
012: import org.enhydra.shark.api.client.wfmodel.WfStateEventAudit;
013: import org.enhydra.shark.api.client.wfservice.WfPackageEventAudit;
014: import org.enhydra.shark.utilities.MiscUtilities;
015:
016: /**
017: * @author
018: *
019: * The various utilities needed by engine.
020: */
021: public class SharkEJBUtilities {
022:
023: static String username = "admin";
024: static String password = "enhydra";
025: static String hostName = "shark";
026:
027: /**
028: * Constant value that represents Shark.conf file parameter
029: */
030: public static final String ENVIRONMENT_TYPE = "EnvironmentType";
031:
032: /**
033: *
034: */
035: public static final String TOMCAT_USER_TRANS_JNDI_NAME = "java:comp/env/UserTransaction";
036:
037: /**
038: * Environment type takes value from Shark.conf property 'environmentType'
039: * and can be: 'standard', 'geronimo', 'tomcat'
040: */
041: // public static String environmentType = null;
042: /**
043: * When 'environmentType' is 'tomcat' this argument has value 'true'. The
044: * type of environment is information which need to be used in all method
045: * call in EJB-Web Services or Tomcat-Web Services call. The comparsion with
046: * boolean is fast and this is the reason for existence of this argument.
047: */
048: // public static boolean isTomcatEnvironment = false;
049: /**
050: * This static variable is used to cache environment type represented as integer.
051: * -1 means that environment is not defined, 0 means that enviroment is any other than
052: * tomcat and 1 means that environment is tomcat.
053: */
054: public static int envType = -1;
055:
056: /**
057: * Returns environment type represented as integer. Value 0 means that enviroment is
058: * any other than tomcat and 1 means that environment is tomcat.
059: * @return 0 for enviroment other than tomcat and 1 for tomcat environment.
060: * @throws Exception
061: */
062: public static int getEnvType() throws Exception {
063: if (SharkEJBUtilities.envType == -1) {
064: String environmentType = (String) MiscUtilities
065: .convertNameValueArrayToProperties(
066: Shark.getInstance().getProperties())
067: .getProperty(SharkEJBUtilities.ENVIRONMENT_TYPE);
068: if (environmentType != null
069: && environmentType.equalsIgnoreCase("tomcat")) {
070: SharkEJBUtilities.envType = 1;
071: } else {
072: SharkEJBUtilities.envType = 0;
073: }
074: }
075: return SharkEJBUtilities.envType;
076: }
077:
078: static WfEventAudit makeSSEventAudit(
079: org.enhydra.shark.api.client.wfmodel.WfEventAudit wfshark) {
080: try {
081: if (wfshark instanceof org.enhydra.shark.api.client.wfmodel.WfCreateProcessEventAudit) {
082: WfCreateProcessEventAuditSS wf = null;
083: try {
084: Context initialContext = EJBJNDIContext
085: .getInstance().getInitialContext();
086: wf = ((org.enhydra.shark.ejb.WfCreateProcessEventAuditSSHome) PortableRemoteObject
087: .narrow(
088: initialContext
089: .lookup("org/enhydra/shark/ejb/WfCreateProcessEventAuditSS"),
090: org.enhydra.shark.ejb.WfCreateProcessEventAuditSSHome.class))
091: .create((WfCreateProcessEventAudit) wfshark);
092: return (WfCreateProcessEventAuditSS) wf
093: .getPassedEJBObject();
094: } catch (Exception ex) {
095: throw new EJBException(ex);
096: }
097: } else if (wfshark instanceof org.enhydra.shark.api.client.wfmodel.WfAssignmentEventAudit) {
098: WfAssignmentEventAuditSS wf = null;
099: try {
100: Context initialContext = EJBJNDIContext
101: .getInstance().getInitialContext();
102: wf = ((org.enhydra.shark.ejb.WfAssignmentEventAuditSSHome) PortableRemoteObject
103: .narrow(
104: initialContext
105: .lookup("org/enhydra/shark/ejb/WfAssignmentEventAuditSS"),
106: org.enhydra.shark.ejb.WfAssignmentEventAuditSSHome.class))
107: .create((WfAssignmentEventAudit) wfshark);
108: return (WfAssignmentEventAuditSS) wf
109: .getPassedEJBObject();
110: } catch (Exception ex) {
111: throw new EJBException(ex);
112: }
113: } else if (wfshark instanceof org.enhydra.shark.api.client.wfmodel.WfDataEventAudit) {
114: WfDataEventAuditSS wf = null;
115: try {
116: Context initialContext = EJBJNDIContext
117: .getInstance().getInitialContext();
118: wf = ((org.enhydra.shark.ejb.WfDataEventAuditSSHome) PortableRemoteObject
119: .narrow(
120: initialContext
121: .lookup("org/enhydra/shark/ejb/WfDataEventAuditSS"),
122: org.enhydra.shark.ejb.WfDataEventAuditSSHome.class))
123: .create((WfDataEventAudit) wfshark);
124: return (WfDataEventAuditSS) wf.getPassedEJBObject();
125: } catch (Exception ex) {
126: throw new EJBException(ex);
127: }
128: } else if (wfshark instanceof org.enhydra.shark.api.client.wfmodel.WfStateEventAudit) {
129: WfStateEventAuditSS wf = null;
130: try {
131: Context initialContext = EJBJNDIContext
132: .getInstance().getInitialContext();
133: wf = ((org.enhydra.shark.ejb.WfStateEventAuditSSHome) PortableRemoteObject
134: .narrow(
135: initialContext
136: .lookup("org/enhydra/shark/ejb/WfStateEventAuditSS"),
137: org.enhydra.shark.ejb.WfStateEventAuditSSHome.class))
138: .create((WfStateEventAudit) wfshark);
139: return (WfStateEventAuditSS) wf
140: .getPassedEJBObject();
141: } catch (Exception ex) {
142: throw new EJBException(ex);
143: }
144: } else if (wfshark instanceof org.enhydra.shark.api.client.wfservice.WfPackageEventAudit) {
145: WfPackageEventAuditSS wf = null;
146: try {
147: Context initialContext = EJBJNDIContext
148: .getInstance().getInitialContext();
149: wf = ((org.enhydra.shark.ejb.WfPackageEventAuditSSHome) PortableRemoteObject
150: .narrow(
151: initialContext
152: .lookup("org/enhydra/shark/ejb/WfPackageEventAuditSS"),
153: org.enhydra.shark.ejb.WfPackageEventAuditSSHome.class))
154: .create((WfPackageEventAudit) wfshark);
155: return (WfPackageEventAuditSS) wf
156: .getPassedEJBObject();
157: } catch (Exception ex) {
158: throw new EJBException(ex);
159: }
160: } else {
161: return null;
162: }
163: } catch (Exception ex) {
164: return null;
165: }
166: }
167:
168: static WfEventAudit[] makeSSEventAudits(
169: org.enhydra.shark.api.client.wfmodel.WfEventAudit[] objs) {
170: int size = 0;
171: if (objs != null)
172: size = objs.length;
173: WfEventAudit[] cobjs = new WfEventAudit[size];
174: for (int i = 0; i < cobjs.length; i++) {
175: cobjs[i] = makeSSEventAudit(objs[i]);
176: }
177: return cobjs;
178: }
179:
180: }
|