Exemple #1
0
 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;
 }
Exemple #2
0
 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;
 }
Exemple #3
0
  /**
   * 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;
  }
Exemple #4
0
    @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;
    }
Exemple #5
0
  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;
  }
Exemple #6
0
 /**
  * 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);
 }