Source code: com/yaftp/ftp/mvsjobs/MvsJobParser.java
1 /**
2 *
3 * CopyRights Jean-Yves MENGANT 1999,2000,2001,2002
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package com.yaftp.ftp.mvsjobs;
21
22 import java.io.* ;
23
24 /**
25
26 this class is used to parse a MVS executed standard batch
27 job result.
28
29 it builds an MvsJobRi class out of it.
30
31 the MvsJobRi contains all the resulting JOB semantics
32 number of steps , condition codes , CPU times , elapse times.
33
34 */
35
36 public class MvsJobParser
37 {
38 private final static String _STEP_ = "JOB" ;
39 private final static String _TIME_ = "TIME=" ;
40 private final static String _ALLIEF_ = "IEF*" ;
41 private final static String _IEF403I_ = "IEF403I" ;
42 private final static String _IEF404I_ = "IEF404I" ;
43 private final static String _IEF373I_ = "IEF373I" ;
44 private final static String _IEF374I_ = "IEF374I" ;
45 private final static String _IEF376I_ = "IEF376I" ;
46 private final static String _IEF142I_ = "IEF142I" ;
47 private final static String _BLANK_ = " " ;
48
49 private MvsJobLexer _lexer = null ;
50 private CustomSysoutParserListener _sysoutListener = null ;
51 private MvsJobRi _ri = new MvsJobRi() ;
52
53 private MvsJobStep _curStep = null ;
54
55 public MvsJobParser( BufferedReader in )
56 throws MvsJobsException
57 {
58 _lexer = new MvsJobLexer(in) ;
59 }
60
61 private void parse373I( String token )
62 throws MvsJobsException
63 {
64 _curStep.parseStartInfos(token);
65 }
66
67 private void parse374I( String token )
68 throws MvsJobsException
69 {
70 _curStep.parseStopInfos(token);
71 }
72
73 private String parse403_404I( String token )
74 throws MvsJobsException
75 {
76 int position = token.indexOf(_BLANK_) ;
77 if ( position == -1 )
78 throw new MvsJobsException("IEF403I/404I syntax Error : " + token ) ;
79 _ri.set_jobName( token.substring(0,position) ) ;
80 position = token.indexOf(_TIME_) ;
81 if ( position == -1 )
82 throw new MvsJobsException("IEF403I/404I syntax Error : " + token ) ;
83 return token.substring( position+_TIME_.length() ) ;
84 }
85
86 private void parse404I( String token )
87 throws MvsJobsException
88 {
89 _ri.set_endedTime( parse403_404I(token) ) ;
90 }
91
92 private void parse403I( String token )
93 throws MvsJobsException
94 {
95 _ri.set_startedTime( parse403_404I(token) ) ;
96 }
97
98 private void parse142I( String token )
99 throws MvsJobsException
100 {
101 _curStep = new MvsJobStep() ; // 142I is assumed to start a new Step
102 _curStep.parseCondCodeInfos(token);
103 }
104
105 /** define who is responsible of the non JCL/IEF sysout parsing */
106 public void addCustomSysoutParserListener( CustomSysoutParserListener listener )
107 { _sysoutListener = listener ; }
108
109 /**
110 the main MVS job parser takes place here
111 */
112 public void parse()
113 throws MvsJobsException
114 {
115 String curIef = "" ;
116 while ( ! curIef.equals(_IEF376I_) )
117 {
118 if ( _lexer.scanFor( _ALLIEF_ , false , false ) )
119 {
120 curIef = _lexer.get_curToken() ;
121 if ( curIef.equals(_IEF373I_) )
122 parse373I( _lexer.readEndOfLine() ) ;
123 else if ( curIef.equals(_IEF374I_) )
124 parse374I( _lexer.readEndOfLine() ) ;
125 if ( curIef.equals(_IEF403I_) )
126 parse403I( _lexer.readEndOfLine() ) ;
127 if ( curIef.equals(_IEF404I_) )
128 parse404I( _lexer.readEndOfLine() ) ;
129 if ( curIef.equals(_IEF142I_) )
130 parse142I( _lexer.readEndOfLine() ) ;
131 _lexer.readToken();
132 }
133 }
134 // if some guy wants to parse the reminder of SYSOUT just call it
135 // providing him the parser
136 if ( _sysoutListener != null )
137 _sysoutListener.parseSysout( _lexer );
138 }
139
140 public static void main( String args[] )
141 {
142 System.out.println( "testing MvsJobParser") ;
143 try
144 {
145 BufferedReader in = new BufferedReader( new FileReader(args[0]) ) ;
146 MvsJobParser parser = new MvsJobParser(in) ;
147 long elapse = System.currentTimeMillis() ;
148 parser.parse() ;
149 elapse = System.currentTimeMillis() - elapse ;
150 System.out.println("elapse:"+elapse+ " milliseconds") ;
151 }
152 catch ( FileNotFoundException e )
153 { System.out.println(args[0] + " inexisting file " ) ; }
154
155 catch ( MvsJobsException e )
156 { System.out.println( e.getMessage() ) ; }
157 }
158
159 }