1
2
3
4
5
6
7 package genie.core;
8
9 import genie.commons.chain.CommandRunner;
10 import genie.commons.chain.OrderedCatalogBase;
11 import genie.commons.jxpath.JXPathContextUtils;
12
13 import java.util.Iterator;
14 import java.util.Properties;
15
16 import org.apache.commons.chain.Command;
17 import org.apache.commons.chain.Context;
18 import org.apache.commons.chain.impl.ContextBase;
19 import org.apache.commons.collections.MapUtils;
20 import org.apache.commons.collections.map.ListOrderedMap;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.jdom.Document;
24 import org.jdom.Element;
25
26 /***
27 *
28 *
29 * @author T. Kia Ntoni
30 *
31 * 5 janv. 2005
32 * Manager @version
33 */
34 public class Manager extends CommandRunner implements IManagerConstants{
35 protected static Log log = LogFactory.getLog(Manager.class);
36 protected Document config;
37 protected Properties properties;
38 protected Manager parent;
39
40 protected String processedTypeLog = "Manager";
41
42 protected String testedTypeLog = "Manager";
43 public static final String DEFAULT_CONFIG_KEY = "genie.core.config";
44 public static final String CONFIG_KEY = "genie.core.config.key";
45 public static final String CONFIG_EXPOSE_KEY = "genie.core.config.expose";
46 public static final String CONFIG_INHERIT_KEY = "genie.core.config.inherit";
47 public static final String CONFIG_SETTING_KEY = "genie.core.config.setting";
48 public static final String DEFAULT_PROPERTIES_KEY = "genie.core.properties";
49 public static final String PROPERTIES_KEY = "genie.core.properties.key";
50 public static final String PROPERTIES_EXPOSE_KEY = "genie.core.properties.expose";
51 public static final String PROPERTIES_INHERIT_KEY = "genie.core.properties.inherit";
52 public static final String PROPERTIES_SETTING_KEY = "genie.core.properties.setting";
53 public static final String DEFAULT_CONTEXT_KEY = "genie.core.context.parent";
54 public static final String CONTEXT_KEY = "genie.core.context.parent.key";
55 public static final String CONTEXT_EXPOSE_KEY = "genie.core.context.expose";
56 public static final String CONTEXT_INHERIT_KEY = "genie.core.context.inherit";
57
58 /***
59 *
60 */
61 public Manager() {
62 super();
63 catalog = new OrderedCatalogBase();
64 contexts = new ListOrderedMap();
65
66 }
67
68 public void addCommand(String name, Command command) {
69 this.catalog.addCommand(name, command);
70 if (command instanceof Manager) {
71 ((Manager) command).setParent(this);
72 }
73 }
74
75 public Command getCommand(String name) {
76 return this.catalog.getCommand(name);
77 }
78
79 public Iterator getCommandNames() {
80 return this.catalog.getNames();
81 }
82
83 public void addContext(String key, Context value) {
84 contexts.put(key, value);
85 }
86
87 public Context getContext(String key) {
88 return contexts.get(key);
89 }
90
91 public Iterator getContextsNames() {
92 return contexts.keySet().iterator();
93 }
94
95 protected boolean isActive(String id) {
96 if (id.equals(Engine.GENIE_CORE_ENGINE_CONTEXT)) {
97 return true;
98 }
99 Element element;
100 if (id.equals(config.getRootElement().getAttributeValue("id"))) {
101 element = config.getRootElement();
102 } else {
103 element = (Element) JXPathContextUtils.selectSingleNode(config.getRootElement(), "//*[@id='"+id+"']");
104 }
105
106 if (element != null) {
107 if (element.getAttributeValue("active") == null) {
108 return true;
109 }
110 if ("true".equalsIgnoreCase(element.getAttributeValue("active"))) {
111 return true;
112 }
113 }
114 debug("isActive(String) - " + testedTypeLog + "[" + id + "] is inactive[IGNORED]");
115 return false;
116 }
117
118 protected boolean isLenient(String id) {
119
120
121
122
123
124
125
126
127 Element element;
128 if (id.equals(config.getRootElement().getAttributeValue("id"))) {
129 element = config.getRootElement();
130 } else {
131 element = (Element) JXPathContextUtils.selectSingleNode(config.getRootElement(), "//*[@id='"+id+"']");
132 }
133
134 if (element != null) {
135 if (element.getAttributeValue("lenient") == null) {
136 return true;
137 }
138 if ("true".equalsIgnoreCase(element.getAttributeValue("lenient"))) {
139 return true;
140 }
141 }
142 debug("isLenient(String) - " + testedTypeLog + "[" + id + "] is not lenient[FAILS ON ERROR]");
143 return false;
144 }
145
146 protected boolean isNullContextEnabled(String id) {
147
148
149
150
151
152
153
154
155 Element element;
156 if (id.equals(config.getRootElement().getAttributeValue("id"))) {
157 element = config.getRootElement();
158 } else {
159 element = (Element) JXPathContextUtils.selectSingleNode(config.getRootElement(), "//*[@id='"+id+"']");
160 }
161
162 if (element != null &&
163 element.getAttributeValue("nullContextEnabled") != null &&
164 "false".equalsIgnoreCase(element.getAttributeValue("nullContextEnabled"))) {
165 debug("isNullContextEnabled(String) - " + testedTypeLog + "[" + id + "] - Processing against null context DISABLED");
166 return false;
167 }
168 debug("isNullContextEnabled(String) - " + testedTypeLog + "[" + id + "] - Processing against null context ENABLED");
169 return true;
170 }
171
172 protected boolean isLoggingEnabled(Context context) {
173 System.out.println("genie.core.logging.enabled from properties : " + properties.getProperty("genie.core.logging.enabled"));
174
175 if (context == null) {
176 return properties.getProperty("genie.core.logging.enabled", "true").equalsIgnoreCase("false") ? false : true;
177 }
178 Object ctxtual = JXPathContextUtils.getValue(context, "//genie.core.logging.enabled");
179 System.out.println("genie.core.logging.enabled from context : " + ctxtual);
180 if (ctxtual == null) {
181 return true;
182 }
183 return ctxtual.toString().equalsIgnoreCase("false") ? false : true;
184 }
185 /***
186 * @return Returns the config.
187 */
188 public Document getConfig() {
189 return config;
190 }
191 /***
192 * @param config The config to set.
193 */
194 public void setConfig(Document configDoc) {
195 this.config = configDoc;
196 }
197
198 protected void logTypesReset(Object current) {
199 if (current instanceof Context) {
200 testedTypeLog = "context";
201 }
202 if (current instanceof Manager) {
203 processedTypeLog = "Manager";
204 testedTypeLog = "Manager";
205 }else {
206 processedTypeLog = "handler";
207 testedTypeLog = "handler";
208 }
209 }
210
211 protected void debug(String message) {
212 if (log.isDebugEnabled()) {
213 log.debug(message);
214 }
215 }
216
217 protected void debug(String message, Throwable throwable) {
218 if (log.isDebugEnabled()) {
219 log.debug(message, throwable);
220 }
221 }
222
223 protected void trace(String message, Throwable throwable) {
224 if (log.isTraceEnabled()) {
225 log.trace(message, throwable);
226 }
227 }
228
229 protected void trace(String message) {
230 if (log.isTraceEnabled()) {
231 log.trace(message);
232 }
233 }
234
235 protected void warn(String message, Throwable throwable) {
236 if (log.isWarnEnabled()) {
237 log.warn(message, throwable);
238 }
239 }
240
241 protected void warn(String message) {
242 if (log.isWarnEnabled()) {
243 log.warn(message);
244 }
245 }
246
247 protected void error(String message, Throwable throwable) {
248 if (log.isErrorEnabled()) {
249 log.error(message, throwable);
250 }
251 }
252
253 protected void error(String message) {
254 if (log.isErrorEnabled()) {
255 log.error(message);
256 }
257 }
258
259 protected void info(String message, Throwable throwable) {
260 if (log.isInfoEnabled()) {
261 log.info(message, throwable);
262 }
263 }
264
265 protected void info(String message) {
266 if (log.isInfoEnabled()) {
267 log.info(message);
268 }
269 }
270
271 protected void fatal(String message, Throwable throwable) {
272 if (log.isFatalEnabled()) {
273 log.fatal(message, throwable);
274 }
275 }
276
277 protected void fatal(String message) {
278 if (log.isFatalEnabled()) {
279 log.fatal(message);
280 }
281 }
282
283 /***
284 * @return Returns the properties.
285 */
286 public Properties getProperties() {
287 return properties;
288 }
289 /***
290 * @param properties The properties to set.
291 */
292 public void setProperties(Properties properties) {
293 this.properties = properties;
294 }
295 /***
296 * return true if "false" found as value under the context key "genie.core.config.expose"
297 * Otherwise, return false.
298 * @param context
299 * @return
300 */
301 public static boolean isExposeConfigDisabled(Context context) {
302 if (context != null && context.containsKey(CONFIG_EXPOSE_KEY)) {
303 boolean returnboolean =
304 MapUtils.getString(context, CONFIG_EXPOSE_KEY, "true").equalsIgnoreCase("false") ? true : false;
305 if (log.isDebugEnabled()) {
306 log.debug("isExposeConfigDisabled(Context) - [" + returnboolean + "]");
307 }
308 return returnboolean;
309 }
310 if (log.isDebugEnabled()) {
311 log.debug("isExposeConfigDisabled(Context) - [true]");
312 }
313 return false;
314 }
315
316 /***
317 * return false if "false" found as value under the context key "genie.core.config.expose".
318 * If the key "genie.core.config.expose" not found in the context,
319 * return false if exists as property key with the same value.
320 * Otherwise, return true
321 * @param context
322 * @return
323 */
324 public boolean isExposeConfigEnabled(Context context) {
325 if (context != null && context.containsKey(CONFIG_EXPOSE_KEY)) {
326 boolean returnboolean = MapUtils.getString(context,
327 CONFIG_EXPOSE_KEY, "true").trim().equalsIgnoreCase("false") ? false : true;
328 debug("isExposeConfigEnabled(Context) - [" + returnboolean + "]");
329 return returnboolean;
330 }
331 if (properties != null && properties.containsKey(CONFIG_EXPOSE_KEY)) {
332 boolean returnboolean = MapUtils.getString(properties,
333 CONFIG_EXPOSE_KEY, "true").trim().equalsIgnoreCase("false") ? false : true;
334 debug("isExposeConfigEnabled(Context) - [" + returnboolean + "]");
335 return returnboolean;
336 }
337 debug("isExposeConfigEnabled(Context) - [false]");
338 return true;
339 }
340
341 public static boolean isInheritConfigDisabled(Context context) {
342 if (context != null && context.containsKey(CONFIG_INHERIT_KEY)) {
343 boolean returnboolean = MapUtils.getString(context,
344 CONFIG_INHERIT_KEY, "true").equals("true") ? false : true;
345 if (log.isDebugEnabled()) {
346 log.debug("isInheritConfigDisabled(Context) - [" + returnboolean + "]");
347 }
348 return returnboolean;
349 }
350 if (log.isDebugEnabled()) {
351 log.debug("isInheritConfigDisabled(Context) - [true]");
352 }
353 return true;
354 }
355
356 public boolean isInheritConfigEnabled(Context context) {
357 if (context != null && context.containsKey(CONFIG_INHERIT_KEY)) {
358 boolean returnboolean = MapUtils.getString(context,
359 CONFIG_INHERIT_KEY, "true").equals("false") ? false : true;
360 debug("isInheritConfigEnabled(Context) - [" + returnboolean + "]");
361 return returnboolean;
362 }
363 if (properties != null && properties.containsKey(CONFIG_INHERIT_KEY)) {
364 boolean returnboolean = MapUtils.getString(properties,
365 CONFIG_INHERIT_KEY, "true").equals("false") ? false : true;
366 debug("isInheritConfigEnabled(Context) - [" + returnboolean + "]");
367 return returnboolean;
368 }
369 debug("isInheritConfigEnabled(Context) - [false]");
370 return false;
371 }
372
373 public static boolean isConfigSettingDisabled(Context context) {
374 if (context != null && context.containsKey(CONFIG_SETTING_KEY)) {
375 boolean returnboolean = MapUtils.getString(context,
376 CONFIG_SETTING_KEY, "true").equals("false") ? true : false;
377 if (log.isDebugEnabled()) {
378 log.debug("isConfigSettingDisabled(Context) - [" + returnboolean + "]");
379 }
380 return returnboolean;
381 }
382
383 if (log.isDebugEnabled()) {
384 log.debug("isConfigSettingDisabled(Context) - [false]");
385 }
386 return false;
387 }
388
389 public boolean isConfigSettingEnabled(Context context) {
390 if (context != null && context.containsKey(CONFIG_SETTING_KEY)) {
391 boolean returnboolean = MapUtils.getString(context,
392 CONFIG_SETTING_KEY, "true").equals("false") ? false : true;
393 debug("isConfigSettingEnabled(Context) - [" + returnboolean + "]");
394 return returnboolean;
395 }
396 if (properties != null && properties.containsKey(CONFIG_SETTING_KEY)) {
397 boolean returnboolean = MapUtils.getString(properties,
398 CONFIG_SETTING_KEY, "true").equals("false") ? false : true;
399 debug("isConfigSettingEnabled(Context) - [" + returnboolean + "]");
400 return returnboolean;
401 }
402 debug("isConfigSettingEnabled(Context) - [true]");
403 return true;
404 }
405
406 public static String getConfigKey(Context context) {
407 String returnString = context != null ? MapUtils.getString(context,
408 CONFIG_KEY, DEFAULT_CONFIG_KEY) : DEFAULT_CONFIG_KEY;
409 if (log.isDebugEnabled()) {
410 log.debug("getConfigKey(Context) - [" + returnString + "]");
411 }
412 return returnString;
413 }
414
415 public static boolean isExposePropertiesDisabled(Context context) {
416 if (context != null && context.containsKey(PROPERTIES_EXPOSE_KEY)) {
417 boolean returnboolean = MapUtils.getString(context,
418 PROPERTIES_EXPOSE_KEY, "true").equals("true") ? false
419 : true;
420 if (log.isDebugEnabled()) {
421 log.debug("isExposePropertiesDisabled(Context) - [" + returnboolean + "]");
422 }
423 return returnboolean;
424 }
425
426 if (log.isDebugEnabled()) {
427 log.debug("isExposePropertiesDisabled(Context) - [true]");
428 }
429 return true;
430 }
431
432 public boolean isExposePropertiesEnabled(Context context) {
433 if (context != null && context.containsKey(PROPERTIES_EXPOSE_KEY)) {
434 boolean returnboolean = MapUtils.getString(context,
435 PROPERTIES_EXPOSE_KEY, "true").equals("false") ? false
436 : true;
437 debug("isExposePropertiesEnabled(Context) - [" + returnboolean + "]");
438 return returnboolean;
439 }
440 if (properties != null && properties.containsKey(PROPERTIES_EXPOSE_KEY)) {
441 boolean returnboolean = MapUtils.getString(properties,
442 PROPERTIES_EXPOSE_KEY, "true").equals("false") ? false
443 : true;
444 debug("isExposePropertiesEnabled(Context) - [" + returnboolean + "]");
445 return returnboolean;
446 }
447 debug("isExposePropertiesEnabled(Context) - [false]");
448 return false;
449 }
450
451 public static boolean isInheritPropertiesDisabled(Context context) {
452 if (context != null && context.containsKey(PROPERTIES_INHERIT_KEY)) {
453 boolean returnboolean = MapUtils.getString(context,
454 PROPERTIES_INHERIT_KEY, "true").equals("true") ? false
455 : true;
456 if (log.isDebugEnabled()) {
457 log.debug("isInheritPropertiesDisabled(Context) - [" + returnboolean + "]");
458 }
459 return returnboolean;
460 }
461 if (log.isDebugEnabled()) {
462 log.debug("isInheritPropertiesDisabled(Context) - [true]");
463 }
464 return true;
465 }
466
467 public boolean isInheritPropertiesEnabled(Context context) {
468 if (context != null && context.containsKey(PROPERTIES_INHERIT_KEY)) {
469 boolean returnboolean = MapUtils.getString(context,
470 PROPERTIES_INHERIT_KEY, "true").equals("false") ? false
471 : true;
472 debug("isInheritPropertiesEnabled(Context) - [" + returnboolean + "]");
473 return returnboolean;
474 }
475 if (properties != null && properties.containsKey(PROPERTIES_INHERIT_KEY)) {
476 boolean returnboolean = MapUtils.getString(properties,
477 PROPERTIES_INHERIT_KEY, "true").equals("false") ? false
478 : true;
479 debug("isInheritPropertiesEnabled(Context) - [" + returnboolean + "]");
480 return returnboolean;
481 }
482 debug("isInheritPropertiesEnabled(Context) - [false]");
483 return false;
484 }
485
486 public static boolean isPropertiesSettingDisabled(Context context) {
487 if (context != null && context.containsKey(PROPERTIES_SETTING_KEY)) {
488 boolean returnboolean = MapUtils.getString(context,
489 PROPERTIES_SETTING_KEY, "true").equals("false") ? true
490 : false;
491 if (log.isDebugEnabled()) {
492 log.debug("isPropertiesSettingDisabled(Context) - [" + returnboolean + "]");
493 }
494 return returnboolean;
495 }
496
497 if (log.isDebugEnabled()) {
498 log.debug("isPropertiesSettingDisabled(Context) - [false]");
499 }
500 return false;
501 }
502
503 public boolean isPropertiesSettingEnabled(Context context) {
504 if (context != null && context.containsKey(PROPERTIES_SETTING_KEY)) {
505 boolean returnboolean = MapUtils.getString(context,
506 PROPERTIES_SETTING_KEY, "true").equals("false") ? false
507 : true;
508 debug("isPropertiesSettingEnabled(Context) - [" + returnboolean + "]");
509 return returnboolean;
510 }
511 if (properties != null && properties.containsKey(PROPERTIES_SETTING_KEY)) {
512 boolean returnboolean = MapUtils.getString(properties,
513 PROPERTIES_SETTING_KEY, "true").equals("false") ? false
514 : true;
515 debug("isPropertiesSettingEnabled(Context) - [" + returnboolean + "]");
516 return returnboolean;
517 }
518
519 if (log.isDebugEnabled()) {
520 log.debug("isPropertiesSettingEnabled(Context) - [true]");
521 }
522 return true;
523 }
524
525 public static String getPropertiesKey(Context context) {
526 String returnString = context != null ? MapUtils.getString(context,
527 PROPERTIES_KEY, DEFAULT_PROPERTIES_KEY)
528 : DEFAULT_PROPERTIES_KEY;
529 if (log.isDebugEnabled()) {
530 log.debug("getPropertiesKey(Context) - [" + returnString + "]");
531 }
532 return returnString;
533 }
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572 public void setConfigAndProperties(Context context, Command command, String cmdName) throws Exception {
573
574 logTypesReset(command);
575 debug("setConfigAndProperties(Context context, Command command, String cmdName) - Attempting to set config and properties references of " + processedTypeLog + "[" + cmdName +"]");
576 if (command instanceof Manager && isActive(cmdName) && isConfigSettingEnabled(context)) {
577 ((Manager)command ).setConfig(config);
578 debug("setConfigAndProperties(Context context, Command command, String cmdName) - Processed setting config reference of " + processedTypeLog + "[" + cmdName +"]");
579 } else {
580 debug("setConfigAndProperties(Context context, Command command, String cmdName) - Not processed setting properties reference of " + processedTypeLog + "[" + cmdName +"]");
581 }
582 if (command instanceof Manager && isActive(cmdName) && isPropertiesSettingEnabled(context)) {
583 ((Manager)command ).setProperties(new Properties(properties));
584 debug("setConfigAndProperties(Context context, Command command, String cmdName) - Processed setting properties reference of " + processedTypeLog + "[" + cmdName +"]");
585 } else {
586 debug("setConfigAndProperties(Context context, Command command, String cmdName) - Not processed setting properties reference of " + processedTypeLog + "[" + cmdName +"]");
587 }
588 }
589
590
591
592
593 public boolean execute(Context context) throws Exception {
594
595 for (Iterator<String> iter = getCommandNames(); iter.hasNext();) {
596 String cmdName = iter.next();
597
598 Command command = getCommand(cmdName);
599 logTypesReset(command);
600 debug("execute(Context) - Attempting to process " + processedTypeLog + "[" + cmdName +"]");
601
602 if (isActive(cmdName)) {
603 setConfigAndProperties(context, command, cmdName);
604 debug("execute(Context) - Processing " + processedTypeLog + "[" + cmdName +"]");
605 try {
606 executeAgainstContexts(context, command, cmdName);
607 } catch (Exception e) {
608 logTypesReset(command);
609 log.error("execute(Context) - ERROR when processing " + processedTypeLog + "[" + cmdName + "]", e);
610 if ( ! isLenient(cmdName)) {
611 throw e;
612 }
613 }
614 debug("execute(Context) - Processed " + processedTypeLog + "[" + cmdName +"]");
615 }
616 }
617 return false;
618 }
619
620
621
622
623 private void executeAgainstContexts(Context context, Command command, String cmdName) throws Exception {
624 boolean availableContext = false;
625 for (Iterator<String> iterator = getContextsNames(); iterator.hasNext();) {
626 String ctxtName = iterator.next();
627 debug("executeAgainstContexts(Context, Command, String)" +
628 " - Attempting to process " + processedTypeLog + "[" + cmdName +
629 "] with context[" + ctxtName +"]");
630
631 testedTypeLog = "Context";
632 if (isActive(ctxtName)) {
633 availableContext = true;
634 Context ctxt = contexts.get(ctxtName);
635 expose(context, ctxt, ctxtName);
636 try {
637 debug("executeAgainstContexts(Context, Command, String)" +
638 " - Processing " + processedTypeLog + "[" + cmdName + "] with context[" +
639 ctxtName +"]");
640 command.execute(ctxt);
641 debug("executeAgainstContexts(Context, Command, String)" +
642 " - Processed " + processedTypeLog + "[" + cmdName + "] with context[" +
643 ctxtName +"]");
644 } catch (Exception e) {
645 log.error("executeAgainstContexts(Context, Command, String)" +
646 " - ERROR when processing " + processedTypeLog + "[" + cmdName + "] with context[" +
647 ctxtName +"]", e);
648 if ( ! isLenient(ctxtName)) {
649
650 throw e;
651 }
652 }
653 }
654 }
655 if (! availableContext) {
656 executeAgainstNewContext(context, command, cmdName);
657 }
658 }
659
660
661
662
663 private void executeAgainstNewContext(Context context, Command command, String cmdName) throws Exception {
664 debug("executeAgainstNewContext(Context, Command, String)" +
665 " - *** No available context found when processing " + processedTypeLog +
666 "[" + cmdName + "] ***");
667 logTypesReset(command);
668 if (isNullContextEnabled(cmdName)) {
669 debug("executeAgainstNewContext(Context, Command, String)" +
670 " - Attempting to process " + processedTypeLog + "[" + cmdName +
671 "] against NULL context");
672 command.execute(null);
673 debug("executeAgainstNewContext(Context, Command, String)" +
674 " - Processed " + processedTypeLog + "[" + cmdName +
675 "] against NULL context");
676 } else {
677 debug("executeAgainstNewContext(Context, Command, String)" +
678 "- Attempting to process " + processedTypeLog + "[" + cmdName +"] against EMPTY context{ContextBase}");
679 Context emptyCtxt = new ContextBase();
680 expose(context, emptyCtxt, "New context");
681 command.execute(emptyCtxt);
682 debug("executeAgainstNewContext(Context, Command, String)" +
683 "- Processed " + processedTypeLog + "[" + cmdName +"] against EMPTY context{ContextBase}");
684 }
685 }
686 /***
687 * @return Returns the parent.
688 */
689 public Manager getParent() {
690 return parent;
691 }
692 /***
693 * @param parent The parent to set.
694 */
695 public void setParent(Manager parent) {
696 this.parent = parent;
697 }
698
699 public static boolean isExposeContextEnabled(Context context) {
700 if (log.isDebugEnabled()) {
701 log.debug("isExposeContextEnabled(Context) - start");
702 }
703
704 if (context != null) {
705 boolean returnboolean = !MapUtils.getString(context,
706 CONTEXT_EXPOSE_KEY, "true").equals("false");
707 if (log.isDebugEnabled()) {
708 log.debug("isExposeContextEnabled(Context) - end");
709 }
710 return returnboolean;
711 }
712
713 if (log.isDebugEnabled()) {
714 log.debug("isExposeContextEnabled(Context) - end");
715 }
716 return false;
717 }
718
719 public static boolean isInheritContextEnabled(Context context) {
720 if (log.isDebugEnabled()) {
721 log.debug("isInheritContextEnabled(Context) - start");
722 }
723
724 if (context != null) {
725 boolean returnboolean = !MapUtils.getString(context,
726 CONTEXT_INHERIT_KEY, "true").equals("false");
727 if (log.isDebugEnabled()) {
728 log.debug("isInheritContextEnabled(Context) - end");
729 }
730 return returnboolean;
731 }
732
733 if (log.isDebugEnabled()) {
734 log.debug("isInheritContextEnabled(Context) - end");
735 }
736 return false;
737 }
738
739 public static String getContextKey(Context context) {
740 return context != null ? MapUtils.getString(context, CONTEXT_KEY, DEFAULT_CONTEXT_KEY) : DEFAULT_CONTEXT_KEY;
741 }
742
743
744
745
746 public void expose(Context parent, Context ctxt, String ctxtName) throws Exception {
747 debug("expose(Context,Context,String) - Attempting to expose configuration document for " + processedTypeLog + "[" + ctxtName +"]");
748 if (ctxt != null && isActive(ctxtName) && isExposeConfigEnabled(parent) && isInheritConfigEnabled(ctxt)) {
749 ctxt.put(getConfigKey(parent), getConfig());
750 debug("expose(Context,Context,String) - Processed exposing configuration document for " + processedTypeLog
751 + "[" + ctxtName +"] under key[" + getConfigKey(parent) + "]");
752 }else {
753 debug("expose(Context,Context,String) - Not processed exposing configuration document for " + processedTypeLog
754 + "[" + ctxtName +"] under key[" + getConfigKey(parent) + "]");
755 }
756 debug("expose(Context,Context,String) - Attempting to expose properties for " + processedTypeLog + "[" + ctxtName +"]");
757 if (ctxt != null && isActive(ctxtName) && isExposePropertiesEnabled(parent) && isInheritPropertiesEnabled(ctxt)) {
758 ctxt.put(getPropertiesKey(parent), getProperties());
759 debug("expose(Context,Context,String) - Processed exposing properties for " + processedTypeLog
760 + "[" + ctxtName +"] under key[" + getPropertiesKey(parent) + "]");
761 }else {
762 debug("expose(Context,Context,String) - Not processed exposing properties for " + processedTypeLog
763 + "[" + ctxtName +"] under key[" + getPropertiesKey(parent) + "]");
764 }
765 debug("expose(Context,Context,String) - Attempting to expose parent context for " + processedTypeLog + "[" + ctxtName +"]");
766 if (ctxt != null && isActive(ctxtName) && isExposeContextEnabled(parent) && isInheritContextEnabled(ctxt)) {
767 ctxt.put(getContextKey(parent), parent);
768 debug("expose(Context,Context,String) - Processed exposing properties for " + processedTypeLog
769 + "[" + ctxtName +"] under key[" + getContextKey(parent) + "]");
770 }else {
771 debug("expose(Context,Context,String) - Not processed exposing properties for " + processedTypeLog
772 + "[" + ctxtName +"] under key[" + getContextKey(parent) + "]");
773 }
774 }
775 }