KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > ControlsManager


1 /*
2  * Magnolia and its source-code is licensed under the LGPL.
3  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
4  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
5  * you are required to provide proper attribution to obinary.
6  * If you reproduce or distribute the document without making any substantive modifications to its content,
7  * please use the following attribution line:
8  *
9  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
10  *
11  */

12 package info.magnolia.cms.gui.dialog;
13
14 import info.magnolia.cms.beans.config.ObservedManager;
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.core.ItemType;
17 import info.magnolia.cms.util.ClassUtil;
18 import info.magnolia.cms.util.FactoryUtil;
19
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27 /**
28  * @author Fabrizio Giustina
29  * @version $Revision: 6895 $ ($Author: philipp $)
30  */

31 public final class ControlsManager extends ObservedManager {
32
33     /**
34      * Logger
35      */

36     private static Logger log = LoggerFactory.getLogger(ControlsManager.class);
37
38     /**
39      * Node data name for control class.
40      */

41     private static final String JavaDoc DATA_CONTROL_CLASS = "class"; //$NON-NLS-1$
42

43     /**
44      * Node data name for control name.
45      */

46     private static final String JavaDoc DATA_CONTROL_NAME = "name"; //$NON-NLS-1$
47

48     /**
49      * Registers dialog controls.
50      */

51     protected void onRegister(Content configNode) {
52         log.info("Config : loading dialog controls configuration"); //$NON-NLS-1$
53

54         Iterator JavaDoc iterator = configNode.getChildren(ItemType.CONTENTNODE).iterator();
55
56         while (iterator.hasNext()) {
57             Content controlNode = (Content) iterator.next();
58
59             if (log.isDebugEnabled()) {
60                 log.debug("Initializing control [{}]", controlNode); //$NON-NLS-1$
61
}
62
63             String JavaDoc classNodeData = controlNode.getNodeData(DATA_CONTROL_CLASS).getString();
64             String JavaDoc nameNodeData = controlNode.getNodeData(DATA_CONTROL_NAME).getString();
65
66             if (StringUtils.isEmpty(nameNodeData)) {
67                 nameNodeData = controlNode.getName();
68             }
69
70             if (StringUtils.isEmpty(classNodeData) || StringUtils.isEmpty(nameNodeData)) {
71                 log.warn("Config : Can't add custom control with name [{}] and class [{}] specified in node [{}]", //$NON-NLS-1$
72
new Object JavaDoc[]{nameNodeData, classNodeData, controlNode.getName()});
73                 continue;
74             }
75             Class JavaDoc controlClass = null;
76
77             try {
78                 controlClass = ClassUtil.classForName(classNodeData);
79             }
80             catch (ClassNotFoundException JavaDoc e) {
81                 log.error("Config : Failed to load dialog control with class [" + classNodeData + "]", e); //$NON-NLS-1$
82
continue;
83             }
84
85             if (!DialogControl.class.isAssignableFrom(controlClass)) {
86                 log.error("Config : Invalid class specified for control [{}]: does not implement DialogControl", //$NON-NLS-1$
87
nameNodeData);
88                 continue;
89             }
90
91             DialogFactory.registerDialog(nameNodeData, controlClass);
92
93         }
94     }
95
96     /**
97      * @return Returns the instance.
98      */

99     public static ControlsManager getInstance() {
100         return (ControlsManager) FactoryUtil.getSingleton(ControlsManager.class);
101     }
102
103     protected void onClear() {
104     }
105
106 }
107
Popular Tags