22
22
import ch .qos .logback .core .joran .util .ConfigurationWatchListUtil ;
23
23
import ch .qos .logback .core .model .IncludeModel ;
24
24
import ch .qos .logback .core .model .Model ;
25
+ import ch .qos .logback .core .spi .ContextAwarePropertyContainer ;
25
26
import ch .qos .logback .core .spi .ErrorCodes ;
26
27
import ch .qos .logback .core .util .Loader ;
27
28
import ch .qos .logback .core .util .OptionHelper ;
@@ -60,18 +61,35 @@ protected Class<IncludeModel> getSupportedModelClass() {
60
61
@ Override
61
62
public void handle (ModelInterpretationContext mic , Model model ) throws ModelHandlerException {
62
63
IncludeModel includeModel = (IncludeModel ) model ;
64
+ Model modelFromIncludedFile = buildModelFromIncludedFile (mic , includeModel );
65
+ if (modelFromIncludedFile == null ) {
66
+ warnIfRequired ("Failed to build include model from included file" );
67
+ return ;
68
+ }
69
+ processModelFromIncludedFile (includeModel , modelFromIncludedFile );
70
+ }
71
+
72
+ /**
73
+ * This method is called by logback-tyler at TylerConfigurator run-time.
74
+ *
75
+ * @param capc
76
+ * @param includeModel
77
+ * @throws ModelHandlerException
78
+ * @since 1.5.11
79
+ */
80
+ public Model buildModelFromIncludedFile (ContextAwarePropertyContainer capc , IncludeModel includeModel ) throws ModelHandlerException {
63
81
64
82
this .optional = OptionHelper .toBoolean (includeModel .getOptional (), false );
65
83
66
84
if (!checkAttributes (includeModel )) {
67
85
inError = true ;
68
- return ;
86
+ return null ;
69
87
}
70
88
71
- InputStream in = getInputStream (mic , includeModel );
72
- if (in == null ) {
89
+ InputStream in = getInputStream (capc , includeModel );
90
+ if (in == null ) {
73
91
inError = true ;
74
- return ;
92
+ return null ;
75
93
}
76
94
77
95
SaxEventRecorder recorder = null ;
@@ -82,41 +100,40 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
82
100
List <SaxEvent > saxEvents = recorder .getSaxEventList ();
83
101
if (saxEvents .isEmpty ()) {
84
102
addWarn ("Empty sax event list" );
85
- return ;
103
+ return null ;
86
104
}
87
105
88
- Supplier <? extends GenericXMLConfigurator > jcSupplier = mic .getConfiguratorSupplier ();
106
+ Supplier <? extends GenericXMLConfigurator > jcSupplier = capc .getConfiguratorSupplier ();
89
107
if (jcSupplier == null ) {
90
108
addError ("null configurator supplier. Abandoning inclusion of [" + attributeInUse + "]" );
91
109
inError = true ;
92
- return ;
110
+ return null ;
93
111
}
94
112
95
113
GenericXMLConfigurator genericXMLConfigurator = jcSupplier .get ();
96
114
genericXMLConfigurator .getRuleStore ().addPathPathMapping (INCLUDED_TAG , CONFIGURATION_TAG );
97
115
98
116
Model modelFromIncludedFile = genericXMLConfigurator .buildModelFromSaxEventList (recorder .getSaxEventList ());
99
- if (modelFromIncludedFile == null ) {
100
- addError (ErrorCodes .EMPTY_MODEL_STACK );
101
- return ;
102
- }
103
-
104
- includeModel .getSubModels ().addAll (modelFromIncludedFile .getSubModels ());
105
-
117
+ return modelFromIncludedFile ;
106
118
} catch (JoranException e ) {
107
119
inError = true ;
108
120
addError ("Error processing XML data in [" + attributeInUse + "]" , e );
121
+ return null ;
109
122
}
110
123
}
111
124
125
+ private void processModelFromIncludedFile (IncludeModel includeModel , Model modelFromIncludedFile ) {
126
+ includeModel .getSubModels ().addAll (modelFromIncludedFile .getSubModels ());
127
+ }
128
+
112
129
public SaxEventRecorder populateSaxEventRecorder (final InputStream inputStream ) throws JoranException {
113
130
SaxEventRecorder recorder = new SaxEventRecorder (context );
114
131
recorder .recordEvents (inputStream );
115
132
return recorder ;
116
133
}
117
134
118
- private InputStream getInputStream (ModelInterpretationContext mic , IncludeModel includeModel ) {
119
- URL inputURL = getInputURL (mic , includeModel );
135
+ private InputStream getInputStream (ContextAwarePropertyContainer capc , IncludeModel includeModel ) {
136
+ URL inputURL = getInputURL (capc , includeModel );
120
137
if (inputURL == null )
121
138
return null ;
122
139
ConfigurationWatchListUtil .addToWatchList (context , inputURL );
0 commit comments