001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2005 Klaus Bartz
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.izforge.izpack.util.os;
023
024import com.izforge.izpack.util.TargetFactory;
025
026/**
027 * This class provides on windows a registry handler. All classes which needs registry access should
028 * be use only one handler.
029 * 
030 * @author Klaus Bartz
031 * 
032 */
033public class RegistryDefaultHandler
034{
035
036    private static RegistryHandler registryHandler = null;
037
038    private static boolean initialized = false;
039
040    /**
041     * Default constructor. No instance of this class should be created.
042     */
043    private RegistryDefaultHandler()
044    {
045        super();
046    }
047
048    public synchronized static final RegistryHandler getInstance()
049    {
050        if (!initialized)
051        {
052            try
053            {
054                // Load the system dependant handler.
055                registryHandler = (RegistryHandler) (TargetFactory.getInstance()
056                        .makeObject("com.izforge.izpack.util.os.RegistryHandler"));
057                // Switch to the default handler to use one for complete logging.
058                registryHandler = registryHandler.getDefaultHandler();
059            }
060            catch (Throwable exception)
061            {
062                registryHandler = null; // 
063            }
064            initialized = true;
065        }
066        if (registryHandler != null && (!registryHandler.good() || !registryHandler.doPerform()))
067            registryHandler = null;
068
069        return (registryHandler);
070    }
071}