2222import ch .qos .logback .core .joran .util .ConfigurationWatchListUtil ;
2323import ch .qos .logback .core .model .IncludeModel ;
2424import ch .qos .logback .core .model .Model ;
25+ import ch .qos .logback .core .spi .ContextAwarePropertyContainer ;
2526import ch .qos .logback .core .spi .ErrorCodes ;
2627import ch .qos .logback .core .util .Loader ;
2728import ch .qos .logback .core .util .OptionHelper ;
@@ -60,18 +61,35 @@ protected Class<IncludeModel> getSupportedModelClass() {
6061 @ Override
6162 public void handle (ModelInterpretationContext mic , Model model ) throws ModelHandlerException {
6263 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 {
6381
6482 this .optional = OptionHelper .toBoolean (includeModel .getOptional (), false );
6583
6684 if (!checkAttributes (includeModel )) {
6785 inError = true ;
68- return ;
86+ return null ;
6987 }
7088
71- InputStream in = getInputStream (mic , includeModel );
72- if (in == null ) {
89+ InputStream in = getInputStream (capc , includeModel );
90+ if (in == null ) {
7391 inError = true ;
74- return ;
92+ return null ;
7593 }
7694
7795 SaxEventRecorder recorder = null ;
@@ -82,41 +100,40 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
82100 List <SaxEvent > saxEvents = recorder .getSaxEventList ();
83101 if (saxEvents .isEmpty ()) {
84102 addWarn ("Empty sax event list" );
85- return ;
103+ return null ;
86104 }
87105
88- Supplier <? extends GenericXMLConfigurator > jcSupplier = mic .getConfiguratorSupplier ();
106+ Supplier <? extends GenericXMLConfigurator > jcSupplier = capc .getConfiguratorSupplier ();
89107 if (jcSupplier == null ) {
90108 addError ("null configurator supplier. Abandoning inclusion of [" + attributeInUse + "]" );
91109 inError = true ;
92- return ;
110+ return null ;
93111 }
94112
95113 GenericXMLConfigurator genericXMLConfigurator = jcSupplier .get ();
96114 genericXMLConfigurator .getRuleStore ().addPathPathMapping (INCLUDED_TAG , CONFIGURATION_TAG );
97115
98116 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 ;
106118 } catch (JoranException e ) {
107119 inError = true ;
108120 addError ("Error processing XML data in [" + attributeInUse + "]" , e );
121+ return null ;
109122 }
110123 }
111124
125+ private void processModelFromIncludedFile (IncludeModel includeModel , Model modelFromIncludedFile ) {
126+ includeModel .getSubModels ().addAll (modelFromIncludedFile .getSubModels ());
127+ }
128+
112129 public SaxEventRecorder populateSaxEventRecorder (final InputStream inputStream ) throws JoranException {
113130 SaxEventRecorder recorder = new SaxEventRecorder (context );
114131 recorder .recordEvents (inputStream );
115132 return recorder ;
116133 }
117134
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 );
120137 if (inputURL == null )
121138 return null ;
122139 ConfigurationWatchListUtil .addToWatchList (context , inputURL );
0 commit comments