Exemplo n.º 1
0
  @Override
  public Set<DefDescriptor<?>> find(DescriptorFilter matcher) {
    final String filterKey = matcher.toString();
    Set<DefRegistry<?>> registries = delegateRegistries.getRegistries(matcher);
    Set<DefDescriptor<?>> matched = Sets.newHashSet();

    for (DefRegistry<?> reg : registries) {
      //
      // This could be a little dangerous, but unless we force all of our
      // registries to implement find, this is necessary.
      //
      if (reg.hasFind()) {
        Set<DefDescriptor<?>> registryResults = null;

        if (reg.isCacheable()) {
          // cache results per registry
          String cacheKey = filterKey + "|" + reg.toString();
          registryResults = descriptorFilterCache.getIfPresent(cacheKey);
          if (registryResults == null) {
            registryResults = reg.find(matcher);
            descriptorFilterCache.put(cacheKey, registryResults);
          }
        } else {
          registryResults = reg.find(matcher);
        }

        matched.addAll(registryResults);
      }
    }
    if (localDescs != null) {
      for (DefDescriptor<? extends Definition> desc : localDescs) {
        if (matcher.matchDescriptor(desc)) {
          matched.add(desc);
        }
      }
    }

    return matched;
  }
Exemplo n.º 2
0
 @Override
 public <D extends Definition> Set<DefDescriptor<D>> find(DefDescriptor<D> matcher) {
   Set<DefDescriptor<D>> matched;
   if (matcher.getNamespace().equals("*")) {
     matched = new LinkedHashSet<DefDescriptor<D>>();
     String qualifiedNamePattern = null;
     switch (matcher.getDefType()) {
       case CONTROLLER:
       case TESTSUITE:
       case MODEL:
       case RENDERER:
       case HELPER:
       case STYLE:
       case TYPE:
       case PROVIDER:
       case SECURITY_PROVIDER:
         qualifiedNamePattern = "%s://%s.%s";
         break;
       case ATTRIBUTE:
       case LAYOUT:
       case LAYOUT_ITEM:
       case TESTCASE:
       case APPLICATION:
       case COMPONENT:
       case INTERFACE:
       case EVENT:
       case DOCUMENTATION:
       case LAYOUTS:
       case NAMESPACE:
       case THEME:
         qualifiedNamePattern = "%s://%s:%s";
         break;
       case ACTION:
         // TODO: FIXME
         throw new AuraRuntimeException("Find on ACTION defs not supported.");
     }
     for (String namespace : delegateRegistries.getAllNamespaces()) {
       String qualifiedName =
           String.format(
               qualifiedNamePattern,
               matcher.getPrefix() != null ? matcher.getPrefix() : "*",
               namespace,
               matcher.getName() != null ? matcher.getName() : "*");
       @SuppressWarnings("unchecked")
       DefDescriptor<D> namespacedMatcher =
           (DefDescriptor<D>)
               DefDescriptorImpl.getInstance(
                   qualifiedName, matcher.getDefType().getPrimaryInterface());
       DefRegistry<D> registry = getRegistryFor(namespacedMatcher);
       if (registry != null) {
         matched.addAll(registry.find(namespacedMatcher));
       }
     }
   } else {
     matched = getRegistryFor(matcher).find(matcher);
   }
   if (localDescs != null) {
     DescriptorFilter filter = new DescriptorFilter(matcher.getQualifiedName());
     for (DefDescriptor<? extends Definition> desc : localDescs) {
       if (filter.matchDescriptor(desc)) {
         @SuppressWarnings("unchecked")
         DefDescriptor<D> localDesc = (DefDescriptor<D>) desc;
         matched.add(localDesc);
       }
     }
   }
   return matched;
 }
Exemplo n.º 3
0
 @Override
 public boolean namespaceExists(String ns) {
   return delegateRegistries.getAllNamespaces().contains(ns);
 }
Exemplo n.º 4
0
 /** only used by admin tools to view all registries */
 public DefRegistry<?>[] getAllRegistries() {
   return delegateRegistries.getAllRegistries();
 }
Exemplo n.º 5
0
 /**
  * This figures out based on prefix what registry this component is for, it could return null if
  * the prefix is not found.
  */
 @SuppressWarnings("unchecked")
 private <T extends Definition> DefRegistry<T> getRegistryFor(DefDescriptor<T> descriptor) {
   return (DefRegistry<T>) delegateRegistries.getRegistryFor(descriptor);
 }