All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.mdl.UIDelegateFactoryClient Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id: UIDelegateFactoryClient.java 8621 2011-10-31 20:25:59Z hoenninger $
package at.spardat.xma.mdl;

import java.lang.reflect.Constructor;

import at.spardat.xma.mdl.list.ListDomUIDelegateClient;
import at.spardat.xma.mdl.list.ListDomWMClient;
import at.spardat.xma.mdl.list.ListUIDelegateClient;
import at.spardat.xma.mdl.list.ListWMClient;
import at.spardat.xma.mdl.paging.PagingUIDelegateClient;
import at.spardat.xma.mdl.paging.PagingWMClient;
import at.spardat.xma.mdl.simple.SimpleUIDelegateClient;
import at.spardat.xma.mdl.simple.SimpleWMClient;
import at.spardat.xma.mdl.table.TableUIDelegateClient;
import at.spardat.xma.mdl.table.TableWMClient;
import at.spardat.xma.mdl.tree.TreeUIDelegateClient;
import at.spardat.xma.mdl.tree.TreeWMClient;
import at.spardat.xma.page.PageClient;

/**
 * This class is responsible for creating UIDelegates for all WidgetModels.
 */
public class UIDelegateFactoryClient {

    private static UIDelegateFactoryClient instance;

    /**
     * Constructor is made private, please use getInstance().
     */
    protected UIDelegateFactoryClient() {
    }

    /**
     * Returns an instance of the factory.
     *
     * @return an instance of UIDelegateFactoryClient.
     * @deprecated
     */

    public static UIDelegateFactoryClient getInstance() {
        return new UIDelegateFactoryClient();
    }

    /**
     * Returns an instance of the factory.
     *
     * @return an instance of UIDelegateFactoryClient.
     */
    public static synchronized UIDelegateFactoryClient getInstance(PageClient pageClient) {
        if (instance == null) {
            String factoryClassName = pageClient.getComponent().getSession().getRuntimeProperty("UIDelegateFactoryClient");
            if (factoryClassName != null && factoryClassName.length() > 0) {
                try {
                    Constructor constructor = Class.forName(factoryClassName).getConstructor(new Class[]{});
                    instance = (UIDelegateFactoryClient)constructor.newInstance(new Object[]{});
                } catch (Exception ex) {
                    throw new RuntimeException("UIDelegateFactoryClient with name '"+factoryClassName+"' can not be created", ex);
                }
            } else {
                instance = new UIDelegateFactoryClient();
            }
        }
        return instance;
    }

    /**
     * Returns a newly created UIDelegateClient for a particular WidgetModel.
     *
     * @param model the instance of a WidgetModel which wants its UIDelegateClient to be created.
     * @return newly created UIDelegateClient.
     */
    public UIDelegateClient newUIDelegateFor (WModel model) {
        if (model instanceof SimpleWMClient) return new SimpleUIDelegateClient ((SimpleWMClient)model);
        if (model instanceof ListDomWMClient) return new ListDomUIDelegateClient ((ListDomWMClient)model);
        if (model instanceof TableWMClient) return new TableUIDelegateClient ((TableWMClient)model);
        if (model instanceof TreeWMClient)  return new TreeUIDelegateClient ((TreeWMClient)model);
        if (model instanceof ListWMClient) return new ListUIDelegateClient ((ListWMClient)model);
        if (model instanceof PagingWMClient) return new PagingUIDelegateClient ((PagingWMClient)model);
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy