1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.sun.jini.logging;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23 import java.io.IOException;
24 import java.io.ObjectInputStream;
25 import java.io.ObjectOutputStream;
26 import java.io.ObjectStreamClass;
27 import java.io.ObjectStreamException;
28 import java.io.OutputStream;
29 import java.io.Serializable;
30 import java.util.logging.Level;
31 import org.apache.river.api.io.AtomicSerial;
32 import org.apache.river.api.io.AtomicSerial.GetArg;
33
34
35
36
37
38
39 @Deprecated
40 public class Levels {
41
42
43
44
45
46
47
48
49
50
51
52 public static final Level FAILED = createLevel("FAILED", 600, null);
53
54
55
56
57
58
59
60
61
62
63
64
65 public static final Level HANDLED = createLevel("HANDLED", 550, null);
66
67
68
69
70 private Levels() {
71 throw new AssertionError("This class cannot be instantiated");
72 }
73
74
75
76
77
78 @AtomicSerial
79 private static final class LevelData implements Serializable {
80 private static final long serialVersionUID = -8176160795706313070L;
81 private final String name;
82 private final int value;
83 private final String resourceBundleName;
84 private final String localizedLevelName;
85
86 LevelData(String name, int value, String resourceBundleName) {
87 this.name = name;
88 this.value = value;
89 this.resourceBundleName = resourceBundleName;
90 this.localizedLevelName = resourceBundleName == null ? name : null;
91 }
92
93 private LevelData(String name,
94 int value,
95 String resourceBundleName,
96 String localizedLevelName)
97 {
98 this.name = name;
99 this.value = value;
100 this.resourceBundleName = resourceBundleName;
101 this.localizedLevelName = localizedLevelName;
102 }
103
104 public LevelData(GetArg arg) throws IOException{
105 this(arg.get("name", null, String.class),
106 arg.get("value", 0),
107 arg.get("resourceBundleName", null, String.class),
108 arg.get("localizedLevelName", null, String.class)
109 );
110 }
111 }
112
113
114
115
116
117
118
119 private static final class ClassReplacingObjectOutputStream extends ObjectOutputStream {
120 private final ObjectStreamClass from;
121 private final ObjectStreamClass to;
122 ClassReplacingObjectOutputStream(OutputStream out, Class from, Class to) throws IOException {
123 super(out);
124 this.from = ObjectStreamClass.lookup(from);
125 this.to = ObjectStreamClass.lookup(to);
126 }
127
128 protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
129 if (from.equals(desc)) {
130 desc = to;
131 }
132 super.writeClassDescriptor(desc);
133 }
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 private static Level createLevel(String name, int value, String resourceBundleName) {
152 Level result = null;
153 try {
154 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
155 ObjectOutputStream out = new ClassReplacingObjectOutputStream(bytes, LevelData.class, Level.class);
156 out.writeObject(new LevelData(name, value, resourceBundleName));
157 out.close();
158 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
159 result = (Level) in.readObject();
160 in.close();
161
162
163 } catch (ClassNotFoundException ex) {
164
165 } catch (IOException e) {
166
167 } finally {
168 if (result == null){
169 final Level withoutName = Level.parse(Integer.valueOf(value).toString());
170 result = new Level(name, value, resourceBundleName) {
171 Object writeReplace() throws ObjectStreamException {
172 return withoutName;
173 }
174 };
175 }
176 return result;
177 }
178 }
179 }