SlengCompiler.java
5.32 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.sleng.CacheEnum
* com.scene7.is.sleng.Engine
* com.scene7.is.sleng.FXGServer
* com.scene7.is.sleng.ImageAccessException
* com.scene7.is.sleng.ImageServer
* com.scene7.is.sleng.LayerFactory
* com.scene7.is.sleng.LayerFactoryTypeEnum
* com.scene7.is.sleng.Sleng
* com.scene7.is.sleng.SlengCodeGenerator
* com.scene7.is.sleng.SlengCodeInterpreter
* com.scene7.is.sleng.SlengOptimizerFilter
* com.scene7.is.sleng.SlengPreprocessingFilter
* com.scene7.is.util.text.ParameterException
* org.jetbrains.annotations.NotNull
*/
package com.scene7.is.ps.provider;
import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.RequestProcessor;
import com.scene7.is.sleng.CacheEnum;
import com.scene7.is.sleng.Engine;
import com.scene7.is.sleng.FXGServer;
import com.scene7.is.sleng.ImageAccessException;
import com.scene7.is.sleng.ImageServer;
import com.scene7.is.sleng.LayerFactory;
import com.scene7.is.sleng.LayerFactoryTypeEnum;
import com.scene7.is.sleng.Sleng;
import com.scene7.is.sleng.SlengCodeGenerator;
import com.scene7.is.sleng.SlengCodeInterpreter;
import com.scene7.is.sleng.SlengOptimizerFilter;
import com.scene7.is.sleng.SlengPreprocessingFilter;
import com.scene7.is.util.text.ParameterException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
public class SlengCompiler {
@NotNull
private final ImageServer imageServer;
private static final Logger LOGGER = Logger.getLogger(SlengCompiler.class.getName());
private static final String ERROR_MESSAGE = "error during sleng optimization, reverting to unoptimized code";
private final boolean doPostprocess;
private final boolean doComments;
private final boolean doHotSpots;
public SlengCompiler(@NotNull ImageServer imageServer, boolean doPostprocess, boolean doComments, boolean doHotSpots) {
this.imageServer = imageServer;
this.doPostprocess = doPostprocess;
this.doComments = doComments;
this.doHotSpots = doHotSpots;
}
public byte[] compileRequest(@NotNull Request request) throws ParameterException, IZoomException {
try {
RequestProcessor proc = new RequestProcessor(request, this.doComments, this.doHotSpots);
proc.preprocess();
proc.processLayers();
if (this.doPostprocess) {
proc.postprocess();
}
return proc.getCode();
}
catch (ImageAccessException e) {
throw new IZoomException(IZoomException.IMAGE_NOT_FOUND, e.getMessage(), (Throwable)e);
}
}
public byte[] compileOptimizedRequest(@NotNull FXGServer fxgServer, @NotNull Request request) throws ParameterException, IZoomException {
byte[] unoptimizedCode = this.compileRequest(request);
return this.optimizeSleng(fxgServer, unoptimizedCode);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@NotNull
public byte[] optimizeSleng(@NotNull FXGServer fxgServer, @NotNull byte[] slengCode) {
Engine engine = new Engine(this.imageServer.getLayerFactory(LayerFactoryTypeEnum.LAYER, true), fxgServer, CacheEnum.ON);
try {
SlengPreprocessingFilter slengPreprocessingFilter = new SlengPreprocessingFilter(engine, new SlengCodeGenerator(this.doComments, this.doHotSpots));
SlengCodeInterpreter interpreterForward = new SlengCodeInterpreter((Sleng)slengPreprocessingFilter);
interpreterForward.run((InputStream)new ByteArrayInputStream(slengCode));
byte[] preprocessedSleng = slengPreprocessingFilter.getCode();
byte[] reversedSleng = SlengOptimizerFilter.reverseSleng((byte[])preprocessedSleng, (boolean)this.doComments, (boolean)this.doHotSpots);
SlengOptimizerFilter slengOptimizerFilter = new SlengOptimizerFilter(new SlengCodeGenerator(this.doComments, this.doHotSpots), this.imageServer, 1.0, 1.0);
SlengCodeInterpreter interpreter = new SlengCodeInterpreter((Sleng)slengOptimizerFilter);
interpreter.run((InputStream)new ByteArrayInputStream(reversedSleng));
byte[] arrby = SlengOptimizerFilter.reverseSleng((byte[])slengOptimizerFilter.getCode(), (boolean)this.doComments, (boolean)this.doHotSpots);
return arrby;
}
catch (IOException e) {
LOGGER.log(Level.WARNING, "error during sleng optimization, reverting to unoptimized code", e);
byte[] interpreterForward = slengCode;
return interpreterForward;
}
catch (ImageAccessException e) {
LOGGER.log(Level.WARNING, "error during sleng optimization, reverting to unoptimized code", (Throwable)e);
byte[] interpreterForward = slengCode;
return interpreterForward;
}
catch (UnsupportedOperationException e) {
LOGGER.log(Level.WARNING, "error during sleng optimization, reverting to unoptimized code - " + e.getMessage());
byte[] interpreterForward = slengCode;
return interpreterForward;
}
finally {
engine.dispose();
}
}
}