001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site (http://www.enhydra.org/).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: MasterScreen.java,v 1.1 2006-09-11 12:30:02 sinisa Exp $
022: */
023: package org.enhydra.barracuda.config;
024:
025: import java.io.*;
026: import java.util.*;
027: import java.lang.ref.*;
028: import java.net.*;
029: import javax.servlet.*;
030: import javax.servlet.http.*;
031:
032: import org.apache.log4j.*;
033: import org.w3c.dom.*;
034: import org.w3c.dom.html.*;
035:
036: import org.enhydra.barracuda.config.events.*;
037: import org.enhydra.barracuda.config.xmlc.*;
038: import org.barracudamvc.core.comp.*;
039: import org.barracudamvc.core.event.*;
040: import org.barracudamvc.core.event.helper.*;
041: import org.barracudamvc.core.forms.*;
042: import org.barracudamvc.core.util.dom.*;
043: import org.barracudamvc.core.util.srv.*;
044: import org.barracudamvc.core.view.*;
045: import org.barracudamvc.plankton.data.*;
046: import org.barracudamvc.plankton.http.*;
047:
048: /**
049: * This class represents the master Barracuda config screen. It is stored
050: * in the users session on a per-locale basis, and is used kind of as a
051: * master repository for objects that make up the system.
052: */
053: public class MasterScreen {
054:
055: //public constants
056: protected static final Logger logger = Logger
057: .getLogger(MasterScreen.class.getName());
058: public static final String KEY = MasterScreen.class.getName()
059: + ".Key";
060:
061: public Document dom = null;
062: public EventGateway egRoot = null;
063: public BComponent bcRoot = null;
064: public TabsModel tabsModel = null;
065: public TemplateModel masterModel = null;
066: public TemplateModel compModel = null;
067: public TemplateModel dataModel = null;
068: public TemplateModel domModel = null;
069: public TemplateModel eventModel = null;
070: public TemplateModel formsModel = null;
071: public TemplateModel utilModel = null;
072: public TemplateModel viewModel = null;
073: public Locale locale = null;
074:
075: //------------------- MasterScreen ---------------------------
076: public MasterScreen(EventGateway iegRoot, Locale ilocale) {
077: if (logger.isDebugEnabled())
078: logger.debug("Creating new ConfigScreen object");
079:
080: //save a copy of the locale
081: egRoot = iegRoot;
082: locale = ilocale;
083:
084: //load the localized DOM template
085: try {
086: dom = DefaultDOMLoader.getGlobalInstance().getDOM(
087: ConfigHTML.class, locale);
088: } catch (IOException e) {
089: logger.fatal("Fatal Error loading DOM template:", e);
090: }
091:
092: //create the root component
093: bcRoot = new BComponent();
094:
095: //create the tab template
096: BTemplate btTabs = new BTemplate();
097: bcRoot.addChild(btTabs);
098: //...create the views (we're storing directives in separate file)
099: try {
100: Properties props = new Properties();
101: props.load(this .getClass().getResourceAsStream(
102: "Config.directives"));
103: Node node = dom.getElementById("ConfigTabs");
104: TemplateView tv = new DefaultTemplateView(node, "id",
105: new MapStateMap(props));
106: btTabs.addView(tv);
107: } catch (IOException e) {
108: logger.fatal("Fatal err loading properties file:", e);
109: }
110: //...create the models
111: //......Master model
112: MasterConfig masterConfig = (MasterConfig) SimpleServiceFinder
113: .findInstance(MasterConfig.class, egRoot,
114: SimpleServiceFinder.DOWNSTREAM);
115: if (masterConfig != null) {
116: masterModel = masterConfig.getModel();
117: btTabs.addModel(masterModel);
118: }
119: //......Tabs model
120: tabsModel = new TabsModel(btTabs);
121: btTabs.addModel(tabsModel);
122: //......Comp screen model
123: CompConfig compConfig = (CompConfig) SimpleServiceFinder
124: .findInstance(CompConfig.class, egRoot,
125: SimpleServiceFinder.DOWNSTREAM);
126: if (compConfig != null) {
127: compModel = compConfig.getModel();
128: btTabs.addModel(compModel);
129: }
130: //......Data screen model
131: DataConfig dataConfig = (DataConfig) SimpleServiceFinder
132: .findInstance(DataConfig.class, egRoot,
133: SimpleServiceFinder.DOWNSTREAM);
134: if (dataConfig != null) {
135: dataModel = dataConfig.getModel();
136: btTabs.addModel(dataModel);
137: }
138: //......Dom screen model
139: DomConfig domConfig = (DomConfig) SimpleServiceFinder
140: .findInstance(DomConfig.class, egRoot,
141: SimpleServiceFinder.DOWNSTREAM);
142: if (domConfig != null) {
143: domModel = domConfig.getModel();
144: btTabs.addModel(domModel);
145: }
146: //......Event screen model
147: EventConfig eventConfig = (EventConfig) SimpleServiceFinder
148: .findInstance(EventConfig.class, egRoot,
149: SimpleServiceFinder.DOWNSTREAM);
150: if (eventConfig != null) {
151: eventModel = eventConfig.getModel();
152: btTabs.addModel(eventModel);
153: }
154: //......Forms screen model
155: FormsConfig formsConfig = (FormsConfig) SimpleServiceFinder
156: .findInstance(FormsConfig.class, egRoot,
157: SimpleServiceFinder.DOWNSTREAM);
158: if (formsConfig != null) {
159: formsModel = formsConfig.getModel();
160: btTabs.addModel(formsModel);
161: }
162: //......Util screen model
163: UtilConfig utilConfig = (UtilConfig) SimpleServiceFinder
164: .findInstance(UtilConfig.class, egRoot,
165: SimpleServiceFinder.DOWNSTREAM);
166: if (utilConfig != null) {
167: utilModel = utilConfig.getModel();
168: btTabs.addModel(utilModel);
169: }
170: //......View screen model
171: ViewConfig viewConfig = (ViewConfig) SimpleServiceFinder
172: .findInstance(ViewConfig.class, egRoot,
173: SimpleServiceFinder.DOWNSTREAM);
174: if (viewConfig != null) {
175: viewModel = viewConfig.getModel();
176: btTabs.addModel(viewModel);
177: }
178: }
179: }
|