Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
<copyright> Copyright (c) 2011-2012 Springsite BV (The Netherlands) and others 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: Martin Taal - Initial API and implementation </copyright> $Id: EntityManagerProvider.java,v 1.7 2011/09/26 19:48:10 mtaal Exp $
package org.eclipse.emf.texo.component;
Central factory for internal components used by Texo. The registry in this class can be used to override the implementation classes used by Texo internally. Initially the registry is empty, meaning that the requested implementation class is used. User specific code can set the implementation class by calling register(java.lang.Class,java.lang.Class).

Author(s):
Martin Taal
public class ComponentProvider implements TexoStaticSingleton {
  private static ComponentProvider instance = new ComponentProvider();
  public static ComponentProvider getInstance() {
    return ;
  }
  public static void setInstance(ComponentProvider instance) {
    . = instance;
  }
  private Map<Class<?>, Class<?>> registry = new HashMap<Class<?>, Class<?>>();

  
Create a new instance of the requested class using the internal registry.
  public <T extends Object> T newInstance(Class<T> clz) {
    return newInstance(clznullnull);
  }

  
Create a new instance of the requested class using the internal registry.
  @SuppressWarnings("unchecked")
  public <T extends Object> T newInstance(Class<T> clzClass<?>[] argTypesObject[] args) {
    Class<?> implementationClass = getImplementation(clz);
    if (implementationClass == null) {
      implementationClass = clz;
    }
    try {
      if (args == null) {
        return (T) implementationClass.newInstance();
      }
      return (T) implementationClass.getConstructor(argTypes).newInstance(args);
    } catch (Exception e) {
      throw new IllegalArgumentException(e);
    }
  }

  
Register the implementation class for a certain texo class. Note, if there is already an entry in the registry for the texoClass, then it will be overwritten.
  public void register(Class<?> texoClassClass<?> implementationClass) {
    // TODO: handle the case that there is already an entry...
    .put(texoClassimplementationClass);
  }

  
Return the current registered implementation.
  @SuppressWarnings("unchecked")
  public <T extends ObjectClass<T> getImplementation(Class<T> clz) {
    return (Class<T>) .get(clz);
  }
New to GrepCode? Check out our FAQ X