Package org.auraframework.system

Examples of org.auraframework.system.MasterDefRegistry


    private DefRegistry<Definition> getRegistry(@NonNull String namespace) {
        Set<String> prefixes = Sets.newHashSet();
        Set<DefType> types = Sets.newHashSet();
        Set<DefDescriptor<?>> descriptors;
        List<Definition> defs = Lists.newArrayList();
        MasterDefRegistry mdr = Aura.getContextService().getCurrentContext().getDefRegistry();
        DescriptorFilter root_nsf = new DescriptorFilter(namespace,
                "COMPONENT,APPLICATION,EVENT,INTERFACE,LIBRARY,THEME,DOCUMENTATION,TESTSUITE,NAMESPACE,LAYOUTS,LAYOUT");
        Map<DefDescriptor<?>, Definition> filtered;
        Set<String> namespaces = Sets.newHashSet(namespace);
        //
        // Fetch all matching descriptors for our 'root' definitions.
        //
        descriptors = mdr.find(root_nsf);
        // HACK! this should go away with: W-2368045
        descriptors.add(Aura.getDefinitionService().getDefDescriptor("markup://"+namespace, NamespaceDef.class));
        for (DefDescriptor<?> desc : descriptors) {
            Definition def = null;
            try {
                def = mdr.getDef(desc);
                if (def == null) {
                    logger.error("Unable to find "+desc+"@"+desc.getDefType());
                    error = true;
                }
            } catch (QuickFixException qfe) {
                logger.error(qfe);
                error = true;
            }
        }
        //
        // Now filter the compiled set on the namespace.
        //
        Set<DefDescriptor<?>> empty = Sets.newHashSet();
        filtered = mdr.filterRegistry(empty);
        logger.debug("******************************************* "+namespace+" ******************************");
        for (Map.Entry<DefDescriptor<?>,Definition> entry : filtered.entrySet()) {
            DefDescriptor<?> desc = entry.getKey();
            Definition def = entry.getValue();
            // We ignore null here as we don't care about dead ends during compile.
View Full Code Here


        return context.getDefRegistry().find(matcher);
    }

    @Override
    public void save(Definition def) throws QuickFixException {
        MasterDefRegistry defRegistry = Aura.getContextService().getCurrentContext().getDefRegistry();

        ContextService contextService = Aura.getContextService();
        contextService.assertEstablished();
       
        def.validateDefinition();
       
    defRegistry.save(def);
    }
View Full Code Here

     */
    @Override
    public void updateLoaded(DefDescriptor<?> loading) throws QuickFixException, ClientOutOfSyncException {
        ContextService contextService = Aura.getContextService();
        AuraContext context;
        MasterDefRegistry mdr;
        Set<DefDescriptor<?>> loaded = Sets.newHashSet();
        Set<DefDescriptor<?>> prev = Sets.newHashSet();
        Set<DefDescriptor<?>> remove = null;

        contextService.assertEstablished();
        context = contextService.getCurrentContext();
        mdr = context.getDefRegistry();
        if (context.getPreloadedDefinitions() == null) {
            //
            // TODO (optimize): we could reverse this set randomly to try
            // to sanitize the list in opposite directions. No need to be
            // exact (hard to test though).
            //
            for (Map.Entry<DefDescriptor<?>, String> entry : context.getClientLoaded().entrySet()) {
                DefDescriptor<?> descriptor = entry.getKey();
                if (loaded.contains(descriptor)) {
                    context.dropLoaded(descriptor);
                } else {
                    // validate the uid.
                    String uid = entry.getValue();
                    String tuid = null;
                    QuickFixException qfe = null;

                    if (uid == null) {
                        // If we are given a null, bounce out.
                        throw new ClientOutOfSyncException(descriptor + ": missing UID ");
                    }
                    try {
                        tuid = mdr.getUid(uid, descriptor);
                    } catch (QuickFixException broke) {
                        //
                        // See note above. This is how we enforce precedence of ClientOutOfSyncException
                        //
                        qfe = broke;
                    }
                    if (!uid.equals(tuid)) {
                        throw new ClientOutOfSyncException(descriptor + ": mismatched UIDs " + uid + " != " + tuid);
                    }
                    if (qfe != null) {
                        throw qfe;
                    }
                    Set<DefDescriptor<?>> deps = mdr.getDependencies(uid);
                    loaded.addAll(deps);
                    for (DefDescriptor<?> x : prev) {
                        if (deps.contains(x)) {
                            if (remove == null) {
                                remove = Sets.newHashSet();
                            }
                            remove.add(x);
                        }
                    }
                    prev.add(descriptor);
                }
            }
            context.setPreloadedDefinitions(loaded);
        } else {
            loaded = context.getPreloadedDefinitions();
        }
        if (remove != null) {
            for (DefDescriptor<?> x : remove) {
                context.dropLoaded(x);
            }
        }
        //
        // Now make sure that our current definition is somewhere there
        // If this fails, we will throw an exception, and all will be
        // well.
        //
        if (loading != null && !loaded.contains(loading) && !context.getLoaded().containsKey(loading)) {
            String uid = mdr.getUid(null, loading);

            if (uid == null) {
                throw new DefinitionNotFoundException(loading, null);
            } else {
                context.addLoaded(loading, uid);
View Full Code Here

  public ShowDependenciesModel(final String cmpname) {
    AuraContext context = Aura.getContextService().getCurrentContext();
    DefDescriptor<?> descriptor;
    SortedSet<DefDescriptor<?>> sorted;
    MasterDefRegistry mdr = context.getDefRegistry();
    String uid;

    this.error = true;
    this.items = Lists.newArrayList();
    try {
      Definition def = Aura.getDefinitionService().getDefinition(cmpname,
          DefType.COMPONENT, DefType.APPLICATION);
      if (def == null) {
        this.title = "Unable to find component for input "
            + AuraTextUtil.escapeForHTML(cmpname);
        return;
      }
      descriptor = def.getDescriptor();
      uid = mdr.getUid(null, descriptor);
      sorted = Sets.newTreeSet(mdr.getDependencies(uid));
      this.title = String.format("Dependencies for %s [uid=%s]",
          descriptor.toString(), uid);
      this.error = false;
    } catch (Throwable t) {
      // If we get an exception, try to tell the user what happened.
      this.title = String.format(
          "%s: %s : list of reached components...",
          AuraTextUtil.escapeForHTML(cmpname), t.getMessage());
      sorted = Sets.newTreeSet(mdr.filterRegistry(null).keySet());
    }
   
    try {
      for (DefDescriptor<?> dep : sorted) {
        Map<String, Object> itemData = Maps.newHashMap();
        Definition def = mdr.getDef(dep);
        boolean valid = false;
        String hash = "------";

        if (def != null) {
          valid = def.isValid();
View Full Code Here

            }
        } else {
            desc = descriptor;
        }

        MasterDefRegistry defRegistry = Aura.getDefinitionService().getDefRegistry();
        if (parent != null) {
            // Insure that the parent is allowed to create an instance of this component
            defRegistry.assertAccess(parent.getDescriptor(), desc.getDef());
        }

        LoggingService loggingService = Aura.getLoggingService();
        loggingService.startTimer(LoggingService.TIMER_COMPONENT_CREATION);
        try {
            this.globalId = getNextGlobalId();

            this.attributeSet = new AttributeSetImpl(desc, attributeValueProvider, this);

            if (valueProviders != null) {
                this.valueProviders.putAll(valueProviders);
            }

            this.valueProviders.put(ValueProviderType.VIEW.getPrefix(), attributeSet);

            // def can be null if a definition not found exception was thrown for that definition. Odd.
            if (def != null) {
                ControllerDef cd = def.getDeclaredControllerDef();
                if (cd != null) {
                    // Insure that this def is allowed to create an instance of the controller
                    defRegistry.assertAccess(descriptor, cd);

                    this.valueProviders.put(ValueProviderType.CONTROLLER.getPrefix(), cd);
                }
            }
View Full Code Here

        }
    }

    @Override
    public void appendDependencies(Set<DefDescriptor<?>> dependencies) {
        MasterDefRegistry mdf = Aura.getContextService().getCurrentContext().getDefRegistry();
        Set<DefDescriptor<?>> found = mdf.find(this.dependency);
        if (found.size() == 0) {
            // TODO: QuickFix for broken dependency.
            if (error == null) {
                error = new InvalidDefinitionException("Invalid dependency " + this.dependency, getLocation());
            }
View Full Code Here

        }
       
        AuraContext context = Aura.getContextService().getCurrentContext();
        DefDescriptor<?> referencingDesc = context.getCurrentCallingDescriptor();
      if (referencingDesc != null) {
          MasterDefRegistry registry = Aura.getDefinitionService().getDefRegistry();
        registry.assertAccess(referencingDesc, event);
      }       
    }
View Full Code Here

        for (AttributeDefRef facet : this.facets) {
            facet.validateReferences();
        }

        // TODO: lots more validation an stuff!!!!!!! #W-689596
        MasterDefRegistry registry = Aura.getDefinitionService().getDefRegistry();
        if (extendsDescriptor != null) {
            T parentDef = extendsDescriptor.getDef();

            if (parentDef == null) {
                throw new DefinitionNotFoundException(extendsDescriptor, getLocation());
            }

            if (parentDef.getDescriptor().equals(descriptor)) {
                throw new InvalidDefinitionException(String.format(
                        "%s cannot extend itself", getDescriptor()), getLocation());
            }

            if (!parentDef.isExtensible()) {
                throw new InvalidDefinitionException(String.format(
                        "%s cannot extend non-extensible component %s", getDescriptor(), extendsDescriptor),
                        getLocation());
            }

            registry.assertAccess(descriptor, parentDef);

            SupportLevel support = getSupport();
            DefDescriptor<T> extDesc = extendsDescriptor;
            while (extDesc != null) {
                T extDef = extDesc.getDef();
                if (support.ordinal() > extDef.getSupport().ordinal()) {
                    throw new InvalidDefinitionException(
                            String.format("%s cannot widen the support level to %s from %s's level of %s",
                                    getDescriptor(),
                                    support, extDesc, extDef.getSupport()), getLocation());
                }

                extDesc = (DefDescriptor<T>) extDef.getExtendsDescriptor();
            }
        }

        for (DefDescriptor<InterfaceDef> intf : interfaces) {
            InterfaceDef interfaze = intf.getDef();
            if (interfaze == null) {
                throw new DefinitionNotFoundException(intf, getLocation());
            }

            registry.assertAccess(descriptor, interfaze);
        }

        for (RegisterEventDef def : events.values()) {
            def.validateReferences();
        }

        for (EventHandlerDef def : eventHandlers) {
            def.validateReferences();
        }

        for (ImportDef def : imports) {
            def.validateReferences();
        }

        // have to do all sorts of craaaazy checks here for dupes and matches
        // and bah
        validateExpressionRefs();

        for (ClientLibraryDef def : this.clientLibraries) {
            def.validateReferences();
            registry.assertAccess(descriptor, def);
        }
    }
View Full Code Here

    public void validateReferences() throws QuickFixException {
        super.validateReferences();
        // Validate that any referenced interfaces exist as accessible definitions.
        // If the definition does not exist or isn't accessible, the template definition
        // will be considered invalid.
        MasterDefRegistry registry = Aura.getDefinitionService().getDefRegistry();
        if (!allowedInterfaces.isEmpty()) {
            for (DefDescriptor<InterfaceDef> intf : allowedInterfaces) {
                InterfaceDef interfaze = intf.getDef();
                if (interfaze == null) {
                    throw new DefinitionNotFoundException(intf, getLocation());
                }
                registry.assertAccess(descriptor, interfaze);
            }
        }
    }
View Full Code Here

    private <P extends Definition, D extends P> Set<D> filterAndLoad(Class<D> defType,
            Set<DefDescriptor<?>> dependencies, TempFilter extraFilter) {

        Set<D> out = Sets.newLinkedHashSet();
        MasterDefRegistry mdr = Aura.getContextService().getCurrentContext().getDefRegistry();

        try {
            for (DefDescriptor<?> descriptor : dependencies) {
                if (defType.isAssignableFrom(descriptor.getDefType().getPrimaryInterface())
                        && (extraFilter == null || extraFilter.apply(descriptor))) {
                    @SuppressWarnings("unchecked")
                    DefDescriptor<D> dd = (DefDescriptor<D>) descriptor;
                    out.add(mdr.getDef(dd));
                }
            }
        } catch (QuickFixException qfe) {
            // This should never happen here, by the time we are filtering our set, all dependencies
            // MUST be loaded. If not, we have a serious bug that must be addressed.
View Full Code Here

TOP

Related Classes of org.auraframework.system.MasterDefRegistry

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.