示例#1
0
文件: Dom.java 项目: hk2-project/hk2
 public <T> T nodeByTypeElement(Class<T> baseType) {
   int len = children.size();
   for (int i = 0; i < len; i++) {
     Child child = children.get(i);
     if (child instanceof NodeChild) {
       NodeChild nc = (NodeChild) child;
       if (model.elements.containsKey(nc.name)) continue; // match with named
       if (baseType.isAssignableFrom(nc.dom.getImplementationClass()))
         return baseType.cast(nc.dom.get());
     }
   }
   return null;
 }
示例#2
0
文件: Dom.java 项目: hk2-project/hk2
 public static <T extends Annotation> T digAnnotation(
     Class<?> target, Class<T> annotationType, List<Class<? extends Annotation>> visited) {
   T result = target.getAnnotation(annotationType);
   if (result == null) {
     for (Annotation a : target.getAnnotations()) {
       if (!visited.contains(a.annotationType())) {
         visited.add(a.annotationType());
         result = digAnnotation(a.annotationType(), annotationType, visited);
         if (result != null) {
           return result;
         }
       }
     }
   }
   return result;
 }
示例#3
0
文件: Dom.java 项目: hk2-project/hk2
  /**
   * Picks up all node elements that are assignable to the given type, except those who are matched
   * by other named elements in the model.
   *
   * <p>Used to implement {@code FromElement("*")}.
   */
  public List<Dom> domNodeByTypeElements(Class baseType) {
    List<Dom> r = new ArrayList<Dom>();

    int len = children.size();
    for (int i = 0; i < len; i++) {
      Child child = children.get(i);
      if (child instanceof NodeChild) {
        NodeChild nc = (NodeChild) child;
        if (model.elements.containsKey(nc.name)) continue; // match with named
        if (baseType.isAssignableFrom(nc.dom.getImplementationClass())) r.add(nc.dom);
      }
    }
    return r;
  }
示例#4
0
文件: Dom.java 项目: hk2-project/hk2
    @Override
    public ConfigBeanProxy compute(final Class<?> proxyType) throws ComputationErrorException {

      ClassLoader cl;
      if (System.getSecurityManager() != null) {
        cl =
            AccessController.doPrivileged(
                new PrivilegedAction<ClassLoader>() {
                  @Override
                  public ClassLoader run() {
                    return proxyType.getClassLoader();
                  }
                });
      } else {
        cl = proxyType.getClassLoader();
      }

      ConfigBeanProxy retVal =
          (ConfigBeanProxy) Proxy.newProxyInstance(cl, new Class[] {proxyType}, dom);

      return retVal;
    }
示例#5
0
文件: Dom.java 项目: hk2-project/hk2
  private ActiveDescriptor<Dom> addWithAlias(
      ServiceLocator locator,
      AbstractActiveDescriptor<?> descriptor,
      Class<?> contract,
      String name) {
    ActiveDescriptor<Dom> added = ServiceLocatorUtilities.findOneDescriptor(locator, descriptor);

    if (added == null) {
      if (ConfigBean.class.isAssignableFrom(this.getClass())) {
        if (!descriptor.getAdvertisedContracts().contains(ConfigBean.class.getName())) {
          descriptor.addContractType(ConfigBean.class);
        }
      }

      added = ServiceLocatorUtilities.addOneDescriptor(locator, descriptor);
    }

    AliasDescriptor<Dom> alias = new AliasDescriptor<Dom>(locator, added, contract.getName(), name);

    ServiceLocatorUtilities.addOneDescriptor(locator, alias);

    return added;
  }
示例#6
0
文件: Dom.java 项目: hk2-project/hk2
 /**
  * Creates a strongly-typed proxy to access values in this {@link Dom} object, by using the
  * specified interface type as the proxy type.
  */
 public <T extends ConfigBeanProxy> T createProxy(final Class<T> proxyType) {
   ConfigBeanProxy retVal = proxyCache.compute(proxyType);
   return proxyType.cast(retVal);
 }