Package org.jvnet.hk2.internal

Examples of org.jvnet.hk2.internal.Utilities$ClazzPhantomReference


* @author Kohsuke Kawaguchi
*/
public class Creators {
    @SuppressWarnings("unchecked")
    public static <T> Creator<T> create(Class<T> c, Habitat habitat, MultiMap<String,String> metadata) {
        Factory f = c.getAnnotation(Factory.class);
        if (f != null) {
            return new FactoryCreator<T>(c,f.value(),habitat,metadata);
        }

        Inhabitant factory = habitat.getInhabitantByAnnotation(FactoryFor.class, c.getName());
        if (factory!=null) {
            return new FactoryCreator<T>(c,factory,habitat,metadata);
View Full Code Here


      public boolean inhabitantIndexChanged(EventType eventType, Habitat habitat,
          Inhabitant<?> i, String index, String name, Object service) {

        // for each FactoryFor component, insert inhabitant for components created by the factory
        if (index.equals(FactoryFor.class.getName())) {
            FactoryFor ff = i.type().getAnnotation(FactoryFor.class);
            Class<?> targetClass = ff.value();
            FactoryCreator target = new FactoryCreator(targetClass, i, habitat, MultiMap.<String,String>emptyMap());
            habitat.add(target);
            habitat.addIndex(target, targetClass.getName(), null);
        }
       
View Full Code Here

        V result;
       
        if (type.isArray()) {
            result = getArrayInjectValue(habitat, component, onBehalfOf, target, genericType, type);
        } else {
          Inject inject = target.getAnnotation(Inject.class);
          if (Types.isSubClassOf(type, Holder.class)){
              result = getHolderInjectValue(habitat, component, onBehalfOf, target, genericType, type, inject);
          } else {
              if (habitat.isContract(type)) {
                  result = getServiceInjectValue(habitat, component, onBehalfOf, target, genericType, type, inject);
View Full Code Here

      Set<String> indicies) {
    AbstractInhabitantImpl<?> i = new LazyInhabitant(habitat, classLoader, typeName, metadata, lead);
    if (contains(indicies, RunLevel.class.getName())) {
      // this is a RunLevel service, we need to load type in order to get
      // more type information about it, namely it's environment and actual RunLevel id
      RunLevel rl = i.getAnnotation(RunLevel.class);
      assert(null != rl) : typeName + " is a problem; " + i + " has no RunLevel annotation";
      assert(!i.isInstantiated()) : "inhabitant should not be active: " + i;

      // get the appropriate RLS for this RunLevel
      RunLevelService<?> rls = runLevelServices.get(habitat, rl);
      InhabitantListener listener = InhabitantListener.class.isInstance(rls) ?
          InhabitantListener.class.cast(rls) : null;

      // wrap the inhabitant with a RunLevelInhabitant
      int runLevel = rl.value();
     
      // construct the runLevel inhabitant
      i = new RunLevelInhabitant(i, runLevel, rls.getState(), listener);
    }
   
View Full Code Here

   * @param target
   * @param injectedVal
   */
  static void validate(Object target, Object injectedVal) {
      if (null != injectedVal) {
          RunLevel targetRL = AbstractInhabitantImpl.getAnnotation(target.getClass(), RunLevel.class, false);
          RunLevel injectedValRL = AbstractInhabitantImpl.getAnnotation(injectedVal.getClass(), RunLevel.class, false);
          if (null == targetRL && null != injectedValRL) {
              throw new ComponentException("invalid dependency from a non-RunLevel instance " +
                  target + " to a RunLevel instance " + injectedVal);
        }
    }
View Full Code Here

  /**
   * Creates a {@link Inhabitant} by wrapping {@link Creator} to handle scoping right.
   */
  public static <T> Inhabitant<T> wrapByScope(Class<T> c, Creator<T> creator, Habitat habitat) {
      Scoped scoped = c.getAnnotation(Scoped.class);
      if (scoped==null) {
          return new SingletonInhabitant<T>(creator); // treated as singleton
      }

      Class<? extends Scope> scopeClass = scoped.value();

      return wrapByScope(creator, habitat, scopeClass);
  }
View Full Code Here

        if (vi != null) {
            visibility = vi.value();
        }
       
        String classAnalysisName = null;
        Service service = constant.getClass().getAnnotation(Service.class);
        if (service != null) {
            classAnalysisName = service.analyzer();
        }
       
        return new ConstantActiveDescriptor<T>(
                constant,
                contractsAsSet,
View Full Code Here

    /**
     * Constructor used by subclasses when instantiated by HK2.
     * ProgramOptions and Environment are injected.  name is set here.
     */
    protected CLICommand() {
        Service service = this.getClass().getAnnotation(Service.class);

        if (service == null)
            name = "unknown-command";   // should never happen
        else
            name = service.name();
    }
View Full Code Here

        final ClassLoader cl = getClassLoader();
        try {
            Class<T> c = (Class<T>) cl.loadClass(typeName);
            return c;
        } catch (ClassNotFoundException e) {
            throw new ComponentException("Failed to load "+typeName+" from " + cl, e);
        }
    }
View Full Code Here

                            continue;   // comment

                        return; // found the next line
                    }
                } catch (IOException e) {
                    throw new ComponentException("Failed to parse line " + lineNumber + " of " + systemId,e);
                }
            }

            public InhabitantParser next() {
                fetch();
View Full Code Here

TOP

Related Classes of org.jvnet.hk2.internal.Utilities$ClazzPhantomReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.