-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCatalogSearchSample.java
138 lines (128 loc) · 4.9 KB
/
CatalogSearchSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* %Z%%W% %I%
*
* =========================================================================
* Licensed Materials - Property of IBM
* "Restricted Materials of IBM"
* (C) Copyright IBM Corp. 2006. All Rights Reserved
*
* DISCLAIMER:
* The following [enclosed] code is sample code created by IBM
* Corporation. This sample code is not part of any standard IBM product
* and is provided to you solely for the purpose of assisting you in the
* development of your applications. The code is provided 'AS IS',
* without warranty of any kind. IBM shall not be liable for any damages
* arising out of your use of the sample code, even if they have been
* advised of the possibility of such damages.
* =========================================================================
*/
package com.ibm.jzos.sample;
import java.io.PrintWriter;
import com.ibm.jzos.CatalogSearch;
import com.ibm.jzos.CatalogSearchField;
import com.ibm.jzos.Format1DSCB;
import com.ibm.jzos.RcException;
import com.ibm.jzos.ZFile;
import com.ibm.jzos.ZUtil;
/**
* Sample program that uses CatalogSearch, LOCATE and OBTAIN to display information about
* datasets matching a filter key. The filter key is given as an argument to main().
* <p>
* The sample program first uses {@link CatalogSearch} to get a list of datasets matching the supplied
* filter key. Then, for each dataset, {@link ZFile#locateDSN(String)} is used to get the first entry
* of the list of MVS volumes that contain the dataset. Finally {@link ZFile#obtainDSN(String, String)}
* is used to obtain the format 1 DSCB information for the dataset.
* <p>
* If the complete lookup cannot be completed for a dataset (e.g. the volume not being mounted) a message
* is written and the dataset is skipped.
* <p/>
* @since 2.1.0
*/
public class CatalogSearchSample {
private static int INVALID_FILTER_KEY = 122;
private static int CATALOG_ERROR = 100;
public static void main(String[] args) throws Exception {
PrintWriter writer = new PrintWriter(System.out);
if (args.length < 1) {
writer.println("USAGE: CatalogSearchSample <filter_key> [entry_types]");
writer.flush();
System.exit(1);
}
String filterKey = args[0].toUpperCase();
writer.println("Performing Catalog Search with filter key: " + filterKey);
CatalogSearch catSearch = new CatalogSearch(filterKey, 64000);
if (args.length == 2) {
catSearch.setEntryTypes(args[1]);
}
int datasetCount = 0;
try {
catSearch.addFieldName("ENTNAME");
catSearch.addFieldName("VOLSER");
catSearch.search();
while (catSearch.hasNext()) {
CatalogSearch.Entry entry = (CatalogSearch.Entry)catSearch.next();
if (entry.isDatasetEntry()) {
datasetCount++;
CatalogSearchField field = entry.getField("ENTNAME");
String dsn = field.getFString().trim();
String qdsn = "'" + dsn + "'"; //Specify that the dsn is fully qualified.
field = entry.getField("VOLSER");
String volser = field.getFString().trim();
if (volser == null || volser.length() == 0) {
writer.println(qdsn + " has no VOLSER");
continue;
}
//If the VOLSER is a system symbol, attempt to resolve it.
String resolvedName = volser;
if (volser.indexOf('&') != -1) {
try {
resolvedName = ZUtil.substituteSystemSymbols(volser, true);
} catch (RcException rce) {
writer.println("Could not resolve symbolic VOLSER '" + volser + "'. Skipping...");
continue;
}
writer.println("...Resolved '"+volser+"' as '"+ resolvedName);
}
//Use OBTAIN to get the dataset's format 1 DSCB
try {
Format1DSCB dscb = ZFile.obtainDSN(qdsn, resolvedName);
writer.println(qdsn + " on " + resolvedName +
" LRECL=" + dscb.getDS1LRECL() +
" BLKSIZE=" + dscb.getDS1BLKL());
} catch (RcException rce) {
String reason = "";
if (rce.getRc() == 4) {
reason = " Volume not mounted";
} else if (rce.getRc() == 8) {
reason = " Volume does not contain a format 1 DSCB for dataset";
}
writer.println(qdsn + " on " + resolvedName + reason);
}
}
}
} catch(RcException rce) {
if (rce.getRc() == 4 && catSearch.getRc() == INVALID_FILTER_KEY) {
//Invalid filter key case
writer.println("Invalid filter key provided: " + filterKey);
writer.flush();
} else if (rce.getRc() == 4 && catSearch.getRc() == CATALOG_ERROR) {
//See if some information can be obtained from the entries.
try {
while (catSearch.hasNext()) {
CatalogSearch.Entry entry = (CatalogSearch.Entry)catSearch.next();
if (entry.hasError()) {
writer.println("Entry Exception: ENTRY_RC=" + entry.getRc() + ", ENTRY_Reason=" + entry.getReason());
writer.flush();
}
}
} catch (RcException rce2) {
throw rce2;
}
} else {
throw rce;
}
}
writer.println(datasetCount + " datasets matched filter key " + filterKey + ".");
writer.flush();
}
}