001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.defaults;
031:
032: import java.util.logging.Logger;
033:
034: import com.jeta.forms.colormgr.ColorManager;
035: import com.jeta.forms.colormgr.DefaultColorManager;
036: import com.jeta.forms.gui.common.FormUtils;
037: import com.jeta.forms.gui.form.DefaultFormComponentFactory;
038: import com.jeta.forms.gui.form.FormComponentFactory;
039: import com.jeta.forms.logger.ConsoleHandler;
040: import com.jeta.forms.logger.FormsLogger;
041: import com.jeta.forms.project.RuntimeProjectManager;
042: import com.jeta.forms.store.bean.BeanSerializerFactory;
043: import com.jeta.forms.store.bean.DefaultBeanSerializerFactory;
044: import com.jeta.open.registry.JETARegistry;
045:
046: /**
047: * This class loads the JETARegistry with default objects required by the Forms
048: * runtime system.
049: *
050: * @author Jeff Tassin
051: */
052: public class DefaultInitializer {
053: /**
054: * Flag that is stored in the JETARegistry to indicate that we've performed
055: * initialization. This is needed in case initialize() is called multiple
056: * times.
057: */
058: private static final String INIT_FLAG = "forms.initialized";
059:
060: /**
061: * Initializes the components needed by the Forms system.
062: */
063: public static void initialize() {
064: synchronized (DefaultInitializer.class) {
065: Boolean binit = (Boolean) JETARegistry.lookup(INIT_FLAG);
066: if (!Boolean.TRUE.equals(binit)) {
067: /** required for the forms framework */
068: com.jeta.open.defaults.DefaultInitializer.initialize();
069: JETARegistry.rebind(ColorManager.COMPONENT_ID,
070: new DefaultColorManager());
071: JETARegistry.rebind(RuntimeProjectManager.COMPONENT_ID,
072: new RuntimeProjectManager());
073: JETARegistry.rebind(BeanSerializerFactory.COMPONENT_ID,
074: new DefaultBeanSerializerFactory());
075: JETARegistry.rebind(FormComponentFactory.COMPONENT_ID,
076: new DefaultFormComponentFactory());
077: JETARegistry.rebind(INIT_FLAG, Boolean.TRUE);
078:
079: try {
080: /**
081: * Initialize the logging system only if debugging.
082: */
083: if (FormUtils.isDebug()) {
084: Logger logger = Logger
085: .getLogger(FormsLogger.LOGGER_NAME);
086: if (logger != null) {
087: logger
088: .setLevel(java.util.logging.Level.FINEST);
089: ConsoleHandler handler = new ConsoleHandler();
090: logger.addHandler(handler);
091: }
092: }
093: } catch (Exception e) {
094: e.printStackTrace();
095: }
096:
097: }
098: }
099: }
100: }
|