1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.plugin.jagacy;
20
21 import net.sf.jameleon.SessionTag;
22 import net.sf.jameleon.function.ContextHelper;
23 import net.sf.jameleon.util.Configurator;
24
25 import com.jagacy.Session3270;
26 import com.jagacy.util.JagacyException;
27
28 /***
29 * A Session tag for the Jagacy 3270 plug-in.
30 *
31 * An example of its use might:
32 *
33 * <pre><source>
34 * <testcase xmlns="jelly:jameleon">
35 * <jagacy-session host="locis.loc.gov" beginSession="true">
36 * <jagacy-is-text-present
37 * functionId="Check that page has 'the' in it."
38 * text="the"/>
39 * </jagacy-session>
40 * </testcase>
41 * </source></pre>
42 * @jameleon.function name="jagacy-session"
43 */
44 public class JagacySessionTag extends SessionTag {
45
46 protected final static String SESSION_NAME = "jagacy-plugin";
47 protected final static String HOST_PROP_NAME = "jagacy.host";
48 protected final static String HOST_CONTEXT_NAME = "jagacyHost";
49 protected String host;
50 protected Boolean visible;
51
52 /***
53 * The 3270 session handle
54 */
55 protected Session3270 session;
56
57 public void setUpSession() {
58 System.setProperty(SESSION_NAME+".window", getVisible()+"");
59 try{
60 if (isStringNotNull(getHost())) {
61 System.setProperty(HOST_PROP_NAME, getHost());
62 }
63 session = new Session3270(SESSION_NAME);
64 }catch (JagacyException je){
65 throw new RuntimeException("Could not set up Session3270", je);
66 }
67 }
68
69 public void startApplication() {
70 if (isStringNotNull(getHost())) {
71 try{
72 session.open();
73 }catch(JagacyException je){
74 throw new RuntimeException("Could not connect to host '"+host+"'",je );
75 }
76 }else{
77 throw new RuntimeException("'host' is a required attribute when beginSession is true!");
78 }
79 }
80
81 public String getHost(){
82 if (host == null || host.trim().length() == 0) {
83 host = ContextHelper.getVariableAsString(context, HOST_CONTEXT_NAME);
84 }
85 return host;
86 }
87
88 public Session3270 getSession3270(){
89 return session;
90 }
91
92 /***
93 * @jameleon.attribute
94 */
95 public void setHost(String host){
96 this.host = host;
97 }
98
99
100 public Boolean getVisible(){
101 String val = Configurator.getInstance().getValue("jagacy-plugin.visible");
102 if (isStringNotNull(val)) {
103 visible = new Boolean(val);
104 }else{
105 visible = new Boolean(false);
106 }
107 return visible;
108 }
109
110 /***
111 * @jameleon.attribute
112 */
113 public void setVisible(boolean visible){
114 this.visible = new Boolean(visible);
115 }
116
117
118 protected void tearDownSession(){
119 if (session != null) {
120 try {
121 session.close();
122 } catch (JagacyException e) {
123 System.err.println("Trouble closing Session3270 connection");
124 e.printStackTrace();
125 }
126 }
127 }
128
129 protected boolean isStringNotNull(String str){
130 boolean isNotNull = false;
131 if (str != null && str.trim().length() > 0 ) {
132 isNotNull = true;
133 }
134 return isNotNull;
135 }
136
137 }