-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
SequenceNumberGeneratorModelHandler.java
85 lines (70 loc) · 3.03 KB
/
SequenceNumberGeneratorModelHandler.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
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2022, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.model.processor;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.SequenceNumberGeneratorModel;
import ch.qos.logback.core.spi.BasicSequenceNumberGenerator;
import ch.qos.logback.core.spi.SequenceNumberGenerator;
import ch.qos.logback.core.util.OptionHelper;
public class SequenceNumberGeneratorModelHandler extends ModelHandlerBase {
SequenceNumberGenerator sequenceNumberGenerator;
private boolean inError;
public SequenceNumberGeneratorModelHandler(Context context) {
super(context);
}
static public ModelHandlerBase makeInstance(Context context, ModelInterpretationContext ic) {
return new SequenceNumberGeneratorModelHandler(context);
}
@Override
protected Class<SequenceNumberGeneratorModel> getSupportedModelClass() {
return SequenceNumberGeneratorModel.class;
}
@Override
public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
SequenceNumberGeneratorModel sequenceNumberGeneratorModel = (SequenceNumberGeneratorModel) model;
String className = sequenceNumberGeneratorModel.getClassName();
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addWarn("Missing className. This should have been caught earlier.");
inError = true;
return;
} else {
className = mic.getImport(className);
}
try {
addInfo("About to instantiate SequenceNumberGenerator of type [" + className + "]");
sequenceNumberGenerator = (SequenceNumberGenerator) OptionHelper.instantiateByClassName(className,
SequenceNumberGenerator.class, context);
sequenceNumberGenerator.setContext(context);
mic.pushObject(sequenceNumberGenerator);
} catch (Exception e) {
inError = true;
addError("Could not create a SequenceNumberGenerator of type [" + className + "].", e);
throw new ModelHandlerException(e);
}
}
public void postHandle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
if (inError) {
return;
}
Object o = mic.peekObject();
if (o != sequenceNumberGenerator) {
addWarn("The object at the of the stack is not the hook pushed earlier.");
} else {
mic.popObject();
addInfo("Registering "+o+" with context.");
context.setSequenceNumberGenerator(sequenceNumberGenerator);
}
}
}