-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPeopleCodeContainerFromFile.java
151 lines (138 loc) · 4.08 KB
/
PeopleCodeContainerFromFile.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
139
140
141
142
143
144
145
146
147
148
149
150
151
package decodepcode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;
public class PeopleCodeContainerFromFile extends PeopleCodeContainer implements PeopleToolsObject
{
File binFile;
String key;
Logger logger = Logger.getLogger(this.getClass().getName());
Map<Integer, String>references = new HashMap<Integer, String>();
String[] keys;
int objType;
public PeopleCodeContainerFromFile( File _binFile) throws IOException
{
this( _binFile, null);
}
public PeopleCodeContainerFromFile( File _binFile, PeopleToolsObject obj) throws IOException
{
binFile = _binFile;
InputStream io = new FileInputStream(binFile);
logger.fine("Reading byte code from " + binFile);
bytes = new byte[(int) binFile.length()];
io.read( bytes);
io.close();
String binFileName = binFile.getName();
if (binFileName.endsWith(".bin"))
{
key = binFileName.substring(0, binFileName.length() - 4);
String txtFileName = key + ".txt";
File txtFile = new File( binFile.getParent(), txtFileName);
if (txtFile.exists())
{
logger.fine("Trying to read PeopleCode from " + txtFile);
readPeopleCodeTextFromFile(txtFile);
}
File refFile = new File( binFile.getParent(), key + ".references");
if (refFile.exists())
{
logger.fine("Trying to read References from " + refFile);
Properties p = new Properties();
p.load(new FileInputStream(refFile));
for ( Object r: p.keySet())
{
references.put( new Integer((String) r), (String) p.get(r));
}
}
File stampFile = new File( binFile.getParent(), key + ".last_update");
if (stampFile.exists())
{
logger.fine("Trying to read last-update info from " + stampFile);
BufferedReader br = new BufferedReader(new FileReader(stampFile));
String line = br.readLine();
try {
setLastChangedDtTm(ProjectReader.df2.parse(line));
} catch ( ParseException e) {}
setLastChangedBy(br.readLine());
br.close();
}
if (obj == null)
{
try
{
parseFileName();
}
catch (IllegalArgumentException ia)
{
logger.severe("Not setting pcode type and keys: cannot parse file name");
logger.severe(ia.getMessage());
}
}
else
{
objType = obj.getPeopleCodeType();
keys = obj.getKeys();
key = JDBCPeopleCodeContainer.objectTypeStr(objType);
for (String k: keys)
if (k != null && k.length() > 0)
key += "-" + k;
}
}
else
key = binFileName;
}
void parseFileName()
{
// e.g. App_Package_PeopleCode-PT_ANALYTICMODELDEFN-RuleExpressions-Assignment-OnExecute
String[] parts = key.split("-");
if (parts.length < 2)
throw new IllegalArgumentException("Name convention for PeopleCode file '" + key + "' not used");
objType = JDBCPeopleCodeContainer.objectTypeFromString(parts[0]);
if (objType < 0)
throw new IllegalArgumentException("Don't recognize PeopleCode type '" + parts[0] + "'");
keys = new String[parts.length - 1];
for (int i = 1; i < parts.length; i++)
keys[i-1] = parts[i];
}
@Override
public String getCompositeKey() {
return key;
}
@Override
String getReference(int nameNum) {
return references.get(nameNum);
}
public static void main( String[] a)
{
try {
new PeopleCodeParser().reverseEngineer(
new PeopleCodeContainerFromFile(new File("C:\\projects\\sandbox\\PeopleCode\\TEST", "BO_SEARCH_Runtime_Apps_ServiceOrder_BusinessContact_Contact_OnExecute.bin"))
);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
void writeReferencesInDirectory(File f) throws IOException {
throw new IllegalArgumentException("Class " + getClass().getName() + " can not write its contents back to the file system");
}
@Override
public String[] getKeys() {
return keys;
}
@Override
public int getPeopleCodeType() {
return objType;
}
public int[] getKeyTypes() {
return CreateProjectDefProcessor.getObjTypesFromPCType(objType, keys);
}
}