Package org.auraframework.system

Examples of org.auraframework.system.MasterDefRegistry


     */
    @Override
    public void validateReferences() throws QuickFixException {
        super.validateReferences();

        MasterDefRegistry registry = Aura.getDefinitionService().getDefRegistry();
        for (DefDescriptor<InterfaceDef> extended : extendsDescriptors) {
            InterfaceDef def = extended.getDef();
            if (def == null) {
                throw new DefinitionNotFoundException(extended, getLocation());
            }
           
            if (extended.equals(descriptor)) {
                throw new InvalidDefinitionException(String.format("%s cannot extend itself", getDescriptor()),
                        getLocation());
            }
           
            registry.assertAccess(descriptor, def);
        }

        // make sure the registered events actually exist
        for (RegisterEventDef reg : this.events.values()) {
            reg.validateReferences();
View Full Code Here


    @SuppressWarnings("unchecked")
    @Override
    protected void readAttributes() throws QuickFixException {
        AuraContext context = Aura.getContextService().getCurrentContext();
        MasterDefRegistry mdr = context.getDefRegistry();
        context.pushCallingDescriptor(builder.getDescriptor());
        try {
            Mode mode = context.getMode();

            super.readAttributes();
            String controllerName = getAttributeValue(ATTRIBUTE_CONTROLLER);
            DefDescriptor<ControllerDef> controllerDescriptor = null;
            if (controllerName != null) {
                controllerDescriptor = DefDescriptorImpl.getInstance(
                        controllerName, ControllerDef.class);
            } else {
                String apexControllerName = String.format("apex://%s.%sController",
                        defDescriptor.getNamespace(),
                        AuraTextUtil.initCap(defDescriptor.getName()));
                DefDescriptor<ControllerDef> apexDescriptor = DefDescriptorImpl
                        .getInstance(apexControllerName, ControllerDef.class);
                if (mdr.exists(apexDescriptor)) {
                    controllerDescriptor = apexDescriptor;
                }
            }

            if (controllerDescriptor != null) {
                builder.controllerDescriptors.add(controllerDescriptor);
            }

            String modelName = getAttributeValue(ATTRIBUTE_MODEL);
            if (modelName != null) {
                builder.modelDefDescriptor = DefDescriptorImpl.getInstance(
                        modelName, ModelDef.class);
            } else {
                String jsModelName = String.format("js://%s.%s",
                        defDescriptor.getNamespace(), defDescriptor.getName());
                DefDescriptor<ModelDef> jsDescriptor = DefDescriptorImpl
                        .getInstance(jsModelName, ModelDef.class);
                if (mdr.exists(jsDescriptor)) {
                    builder.modelDefDescriptor = jsDescriptor;
                } else {
                    String apexModelName = String.format("apex://%s.%sModel",
                            defDescriptor.getNamespace(),
                            AuraTextUtil.initCap(defDescriptor.getName()));
                    DefDescriptor<ModelDef> apexDescriptor = DefDescriptorImpl
                            .getInstance(apexModelName, ModelDef.class);
                    if (mdr.exists(apexDescriptor)) {
                        builder.modelDefDescriptor = apexDescriptor;
                    }
                }
            }

            // See if there is a clientController that has the same qname.
            String jsDescriptorName = String.format("js://%s.%s",
                    defDescriptor.getNamespace(), defDescriptor.getName());
            DefDescriptor<ControllerDef> jsDescriptor = DefDescriptorImpl
                    .getInstance(jsDescriptorName, ControllerDef.class);
            if (mdr.exists(jsDescriptor)) {
                builder.controllerDescriptors.add(jsDescriptor);
            }

            //
            // TODO: W-1501702
            // Need to handle dual renderers for aura:placeholder
            //
            String rendererName = getAttributeValue(ATTRIBUTE_RENDERER);
            if (rendererName != null) {
                List<String> rendererNames = AuraTextUtil.splitSimpleAndTrim(
                        rendererName, ",", 0);
                for (String renderer : rendererNames) {
                    builder.addRenderer(renderer);
                }

            } else {
                // See if there is a clientRenderer that has the same qname.
                DefDescriptor<RendererDef> jsRendererDescriptor = DefDescriptorImpl
                        .getInstance(jsDescriptorName, RendererDef.class);
                if (mdr.exists(jsRendererDescriptor)) {
                    builder.addRenderer(jsRendererDescriptor.getQualifiedName());
                }
            }

            String helperName = getAttributeValue(ATTRIBUTE_HELPER);
            if (helperName != null) {
                List<String> helperNames = AuraTextUtil.splitSimpleAndTrim(
                        helperName, ",", 0);
                for (String helper : helperNames) {
                    builder.addHelper(helper);
                }

            } else {
                // See if there is a helper that has the same qname.
                DefDescriptor<HelperDef> jsHelperDescriptor = DefDescriptorImpl
                        .getInstance(jsDescriptorName, HelperDef.class);
                if (mdr.exists(jsHelperDescriptor)) {
                    builder.addHelper(jsHelperDescriptor.getQualifiedName());
                }
            }

            DefDescriptor<ResourceDef> jsResourceDescriptor = DefDescriptorImpl
                    .getInstance(jsDescriptorName, ResourceDef.class);
            if (mdr.exists(jsResourceDescriptor)) {
                builder.addResource(jsResourceDescriptor.getQualifiedName());
            }

            // See if there is a style that has the same qname.
            String styleName = getAttributeValue(ATTRIBUTE_STYLE);
            if (AuraTextUtil.isNullEmptyOrWhitespace(styleName)) {
                styleName = String.format("css://%s.%s",
                        defDescriptor.getNamespace(), defDescriptor.getName());
            }
            DefDescriptor<StyleDef> cssDescriptor = DefDescriptorImpl.getInstance(
                    styleName, StyleDef.class);
            if (mdr.exists(cssDescriptor)) {
                builder.styleDescriptor = cssDescriptor;
            }

            DefDescriptor<ResourceDef> cssResourceDescriptor = DefDescriptorImpl.getInstance(styleName,
                    ResourceDef.class);
            if (mdr.exists(cssResourceDescriptor)) {
                builder.addResource(cssResourceDescriptor.getQualifiedName());
            }

            // See if there is a themedef that has the same qname. todo -- add cmpTheme attr as well?
            String themeName = String.format("%s:%s", defDescriptor.getNamespace(), defDescriptor.getName());
            DefDescriptor<ThemeDef> themeDesc = DefDescriptorImpl.getInstance(themeName, ThemeDef.class);
            if (mdr.exists(themeDesc)) {
                builder.cmpThemeDescriptor = themeDesc;
            }

            // Do not consider Javascript Test suite defs in PROD and PRODDEBUG modes.
            if (mode != Mode.PROD && mode != Mode.PRODDEBUG) {
                // See if there is a test suite that has the same qname.
                DefDescriptor<TestSuiteDef> jsTestSuiteDescriptor = DefDescriptorImpl
                        .getInstance(jsDescriptorName, TestSuiteDef.class);
                if (mdr.exists(jsTestSuiteDescriptor)) {
                    builder.testSuiteDefDescriptor = jsTestSuiteDescriptor;
                }
            }
            String extendsName = getAttributeValue(ATTRIBUTE_EXTENDS);
            if (extendsName != null) {
                builder.extendsDescriptor = DefDescriptorImpl.getInstance(
                        extendsName, (Class<T>) defDescriptor.getDefType()
                                .getPrimaryInterface());
            }

            String implementsNames = getAttributeValue(ATTRIBUTE_IMPLEMENTS);
            if (implementsNames != null) {
                for (String implementsName : AuraTextUtil.splitSimple(",",
                        implementsNames)) {
                    builder.interfaces.add(DefDescriptorImpl.getInstance(
                            implementsName.trim(), InterfaceDef.class));
                }
            }

            builder.isAbstract = getBooleanAttributeValue(ATTRIBUTE_ABSTRACT);
            // if a component is abstract, it should be extensible by default
            if (builder.isAbstract
                    && getAttributeValue(ATTRIBUTE_EXTENSIBLE) == null) {
                builder.isExtensible = true;
            } else {
                builder.isExtensible = getBooleanAttributeValue(ATTRIBUTE_EXTENSIBLE);
            }

            String providerName = getAttributeValue(ATTRIBUTE_PROVIDER);

            if (providerName != null) {
                List<String> providerNames = AuraTextUtil.splitSimpleAndTrim(
                        providerName, ",", 0);
                for (String provider : providerNames) {
                    builder.addProvider(provider);
                }
            } else {
                String apexProviderName = String.format("apex://%s.%sProvider",
                        defDescriptor.getNamespace(),
                        AuraTextUtil.initCap(defDescriptor.getName()));
                DefDescriptor<ProviderDef> apexDescriptor = DefDescriptorImpl
                        .getInstance(apexProviderName, ProviderDef.class);
                if (mdr.exists(apexDescriptor)) {
                    builder.addProvider(apexDescriptor.getQualifiedName());
                }
            }

            String templateName = getAttributeValue(ATTRIBUTE_TEMPLATE);
            if (templateName != null) {
                builder.templateDefDescriptor = DefDescriptorImpl.getInstance(
                        templateName, ComponentDef.class);
            }

            DefDescriptor<DocumentationDef> documentationDescriptor = DefDescriptorImpl.getAssociateDescriptor(
                    builder.getDescriptor(), DocumentationDef.class, DefDescriptor.MARKUP_PREFIX);

            if (mdr.exists(documentationDescriptor)) {
                builder.setDocumentation(documentationDescriptor.getQualifiedName());
            }

            DefDescriptor<DesignDef> designDescriptor = DefDescriptorImpl.getAssociateDescriptor(
                    builder.getDescriptor(), DesignDef.class, DefDescriptor.MARKUP_PREFIX);

            if (mdr.exists(designDescriptor)) {
                builder.designDefDescriptor = designDescriptor;
            }

            builder.render = getAttributeValue(ATTRIBUTE_RENDER);
View Full Code Here

    public NamespaceDefTest(String name) {
        super(name);
    }

    public void testGetNamespaceSource() {
        MasterDefRegistry reg = Aura.getContextService().getCurrentContext().getDefRegistry();
        DefinitionService defService = Aura.getDefinitionService();
        DefDescriptor<NamespaceDef> descriptor = defService.getDefDescriptor("test", NamespaceDef.class);
        Source<NamespaceDef> src = reg.getSource(descriptor);
        assertNotNull(src);

        descriptor = DefDescriptorImpl.getInstance("nonExistantNamespace", NamespaceDef.class);
        src = reg.getSource(descriptor);
        assertNull(src);
    }
View Full Code Here

                                                       AddableDef<T> toAdd) throws QuickFixException {
        DefDescriptor<T> dd;
        String uid, ouid;
        Set<DefDescriptor<?>> deps;
        AuraTestingUtil util = getAuraTestingUtil();
        MasterDefRegistry mdr;

        dd = DefDescriptorImpl.getInstance(toAdd.getFQN(tld.getNamespace(), tld.getName()),
                toAdd.getDefClass());
        util.addSourceAutoCleanup(dd, toAdd.getContent());
        mdr = resetDefRegistry();
        uid = mdr.getUid(null, tld);
        assertFalse("UID should change on add for " + dd.getDefType() + "@" + dd, suid.equals(uid));
        deps = mdr.getDependencies(uid);
        assertTrue("dependencies should contain the newly created " + dd.getDefType() + "@" + dd,
                deps.contains(dd));
        ouid = uid;
        util.removeSource(dd);
        mdr = resetDefRegistry();
        uid = mdr.getUid(null, tld);
        assertNotSame("UID should change on removal for " + dd.getDefType() + "@" + dd, ouid, uid);
        deps = mdr.getDependencies(uid);
        assertFalse("dependencies should not contain the deleted " + dd, deps.contains(dd));
    }
View Full Code Here

        AuraTestingUtil util = getAuraTestingUtil();
        String uid;

        DefDescriptor<T> tld = DefDescriptorImpl.getInstance(fqn, clazz);
        util.addSourceAutoCleanup(tld, content);
        MasterDefRegistry mdr = resetDefRegistry();
        // prime the cache.
        uid = mdr.getUid(null, tld);
        assertNotNull(tld + " did not give us a UID", uid);
        for (AddableDef<?> adding : addable) {
            checkAddRemove(tld, uid, adding);
        }
        util.removeSource(tld);
View Full Code Here

     * ClientLibraryServiceImplTest, where we use ClientLibraryService.getUrls()
     *
     * @throws Exception
     */
    public void testGetClientLibraries() throws Exception {
        MasterDefRegistry mdr = getAuraMDR();
        List<ClientLibraryDef> libDefs = mdr.getClientLibraries(null);
        assertNull(libDefs);

        DefDescriptor<ApplicationDef> appDesc = Aura.getDefinitionService().getDefDescriptor(
                "clientLibraryTest:testDependencies", ApplicationDef.class);
        AuraContext cntx = Aura.getContextService().getCurrentContext();
        cntx.setApplicationDescriptor(appDesc);
        Aura.getDefinitionService().updateLoaded(appDesc);

        libDefs = mdr.getClientLibraries(cntx.getUid(appDesc));

        // 13 from clientLibraryTest:testDependencies and its dependencies + 4 from aura:component
        // Update this number when you add new aura:clientLibrary tags to these components
        assertEquals(16, libDefs.size());
    }
View Full Code Here

    }

    public void testAssertAccess_IfGlobalAccessThenPassesCheck() throws Exception {
        when(globalDef.getAccess()).thenReturn(defAccess);
        when(defAccess.isGlobal()).thenReturn(true);
        MasterDefRegistry mdr = getAuraMDR();
        mdr.assertAccess(null, globalDef);

        verify(globalDef).getAccess();
        verify(defAccess).isGlobal();
    }
View Full Code Here

    public void testAssertAccess_IfReferencedByUnsecuredPrefixThenPassesCheck() throws Exception {
        when(globalDef.getAccess()).thenReturn(defAccess);
        when(defAccess.isGlobal()).thenReturn(false);
        when(defAccess.requiresAuthentication()).thenReturn(true);
        when(referencingDesc.getPrefix()).thenReturn("aura");
        MasterDefRegistry mdr = getAuraMDR();
        mdr.assertAccess(referencingDesc, globalDef);

        verify(referencingDesc).getPrefix();
    }
View Full Code Here

        verify(mockAccessCheckCache, times(2)).getIfPresent(anyString());
    }

    public void testExistsCache() throws Exception {
        ConfigAdapter configAdapter = Aura.getConfigAdapter();
        MasterDefRegistry mdr = getAuraMDR();
        MasterDefRegistryImpl mdri = (MasterDefRegistryImpl) mdr;
        Map<DefType, DefDescriptor<?>> defs = addDefsToCaches(mdri);
        Map<DefType, DefDescriptor<?>> nonPrivDefs = addNonPriveledgedDefsToMDR(mdri);
        for (DefDescriptor<?> dd : defs.values()) {
            assertTrue(dd + " should exist.", dd.exists());
        }
        for (DefDescriptor<?> dd : nonPrivDefs.values()) {
            assertTrue(dd + " should exist.", dd.exists());
        }

        DefDescriptor<?> nsDef = defs.get(DefType.NAMESPACE);
        DefDescriptor<?> layoutDef = defs.get(DefType.LAYOUTS);
        DefDescriptor<?> rendererDef = defs.get(DefType.RENDERER);
        DefDescriptor<?> appDef = defs.get(DefType.APPLICATION);
        DefDescriptor<?> controllerDef = defs.get(DefType.CONTROLLER);
        DefDescriptor<?> cmpDef = defs.get(DefType.COMPONENT);

        DefDescriptor<?> npNSDef = nonPrivDefs.get(DefType.NAMESPACE);
        DefDescriptor<?> npLayoutDef = nonPrivDefs.get(DefType.LAYOUTS);
        DefDescriptor<?> npRendererDef = nonPrivDefs.get(DefType.RENDERER);
        DefDescriptor<?> nsAppDef = nonPrivDefs.get(DefType.APPLICATION);
        DefDescriptor<?> nsControllerDef = nonPrivDefs.get(DefType.CONTROLLER);
        DefDescriptor<?> nsCmpDef = nonPrivDefs.get(DefType.COMPONENT);

        // only picking 3 defs to test the ns as they are mostly dupes
        assertTrue(nsDef.getNamespace() + "  should have been isPriveleged",
                configAdapter.isPrivilegedNamespace(nsDef.getNamespace()));
        assertTrue(layoutDef.getNamespace() + "  should have been isPriveleged",
                configAdapter.isPrivilegedNamespace(layoutDef.getNamespace()));
        assertTrue(rendererDef.getNamespace() + "  should have been isPriveleged",
                configAdapter.isPrivilegedNamespace(rendererDef.getNamespace()));

        assertFalse(npLayoutDef.getNamespace() + "  should not have been isPriveleged",
                configAdapter.isPrivilegedNamespace(npLayoutDef.getNamespace()));
        assertFalse(npNSDef.getNamespace() + "  should not have been isPriveleged",
                configAdapter.isPrivilegedNamespace(npNSDef.getNamespace()));
        assertFalse(npRendererDef.getNamespace() + "  should not have been isPriveleged",
                configAdapter.isPrivilegedNamespace(npRendererDef.getNamespace()));

        MasterDefRegistry mdr2 = restartContextGetNewMDR();
        MasterDefRegistryImpl mdri2 = (MasterDefRegistryImpl) mdr2;

        // objects wont be in eists cache yet, just defsCache, need to call exists to prime exists cache

        for (DefDescriptor<?> dd : defs.values()) {
            assertTrue(dd + " should exist.", dd.exists());
        }
        assertTrue("nsDef is in cache", isInExistsCache(nsDef, mdri2));
        assertTrue("LayoutsDef is in cache", isInExistsCache(defs.get(DefType.LAYOUTS), mdri2));
        assertTrue("RendererDef is in cache", isInExistsCache(rendererDef, mdri2));
        assertTrue("app is in cache", isInExistsCache(appDef, mdri2));
        assertTrue("controller is in cache", isInExistsCache(controllerDef, mdri2));
        assertTrue("cmp is in cache", isInExistsCache(cmpDef, mdri2));

        assertFalse("npNSDef is not in cache", isInExistsCache(npNSDef, mdri2));
        assertFalse("npLayoutsDef is not in cache", isInExistsCache(npLayoutDef, mdri2));
        assertFalse("npRendererDef is notin cache", isInExistsCache(npRendererDef, mdri2));
        assertFalse("nsApp is not in cache", isInExistsCache(nsAppDef, mdri2));
        assertFalse("nsController is not in cache", isInExistsCache(nsControllerDef, mdri2));
        assertFalse("nsCmp is not in cache", isInExistsCache(nsCmpDef, mdri2));

        MasterDefRegistry mdr3 = restartContextGetNewMDR();
        MasterDefRegistryImpl mdri3 = (MasterDefRegistryImpl) mdr3;

        assertTrue("nsDef is in cache", isInExistsCache(nsDef, mdri3));
        assertTrue("LayoutsDef is in cache", isInExistsCache(defs.get(DefType.LAYOUTS), mdri3));
        assertTrue("RendererDef is in cache", isInExistsCache(rendererDef, mdri3));
View Full Code Here

        assertFalse("nsCmp is not in cache", isInExistsCache(nsCmpDef, mdri3));
    }

    public void testDefsCache() throws Exception {
        ConfigAdapter configAdapter = Aura.getConfigAdapter();
        MasterDefRegistry mdr = getAuraMDR();
        MasterDefRegistryImpl mdri = (MasterDefRegistryImpl) mdr;
        Map<DefType, DefDescriptor<?>> defs = addDefsToCaches(mdri);
        Map<DefType, DefDescriptor<?>> nonPrivDefs = addNonPriveledgedDefsToMDR(mdri);

        DefDescriptor<?> nsDef = defs.get(DefType.NAMESPACE);
        DefDescriptor<?> layoutDef = defs.get(DefType.LAYOUTS);
        DefDescriptor<?> rendererDef = defs.get(DefType.RENDERER);
        DefDescriptor<?> appDef = defs.get(DefType.APPLICATION);
        DefDescriptor<?> controllerDef = defs.get(DefType.CONTROLLER);
        DefDescriptor<?> cmpDef = defs.get(DefType.COMPONENT);

        DefDescriptor<?> npNSDef = nonPrivDefs.get(DefType.NAMESPACE);
        DefDescriptor<?> npLayoutDef = nonPrivDefs.get(DefType.LAYOUTS);
        DefDescriptor<?> npRendererDef = nonPrivDefs.get(DefType.RENDERER);
        DefDescriptor<?> nsAppDef = nonPrivDefs.get(DefType.APPLICATION);
        DefDescriptor<?> nsControllerDef = nonPrivDefs.get(DefType.CONTROLLER);
        DefDescriptor<?> nsCmpDef = nonPrivDefs.get(DefType.COMPONENT);

        // only picking 3 defs to test the ns as they are mostly dupes
        assertTrue(nsDef.getNamespace() + "  should have been isPriveleged",
                configAdapter.isPrivilegedNamespace(nsDef.getNamespace()));
        assertTrue(layoutDef.getNamespace() + "  should have been isPriveleged",
                configAdapter.isPrivilegedNamespace(layoutDef.getNamespace()));
        assertTrue(rendererDef.getNamespace() + "  should have been isPriveleged",
                configAdapter.isPrivilegedNamespace(rendererDef.getNamespace()));

        assertFalse(npLayoutDef.getNamespace() + "  should not have been isPriveleged",
                configAdapter.isPrivilegedNamespace(npLayoutDef.getNamespace()));
        assertFalse(npNSDef.getNamespace() + "  should not have been isPriveleged",
                configAdapter.isPrivilegedNamespace(npNSDef.getNamespace()));
        assertFalse(npRendererDef.getNamespace() + "  should not have been isPriveleged",
                configAdapter.isPrivilegedNamespace(npRendererDef.getNamespace()));

        assertTrue("nsDef is in cache", isInDefsCache(nsDef, mdri));
        assertTrue("LayoutsDef is in cache", isInDefsCache(layoutDef, mdri));
        assertTrue("RendererDef is in cache", isInDefsCache(rendererDef, mdri));
        assertTrue("app is in cache", isInDefsCache(appDef, mdri));
        assertTrue("controller is in cache", isInDefsCache(controllerDef, mdri));
        assertTrue("cmp is in cache", isInDefsCache(cmpDef, mdri));

        assertFalse("npNSDef is not in cache", isInDefsCache(npNSDef, mdri));
        assertFalse("npLayoutsDef is not in cache", isInDefsCache(npLayoutDef, mdri));
        assertFalse("npRendererDef is not in cache", isInDefsCache(npRendererDef, mdri));
        assertFalse("nsApp is not in cache", isInDefsCache(nsAppDef, mdri));
        assertFalse("nsController is not in cache", isInDefsCache(nsControllerDef, mdri));
        assertFalse("nsCmp is not in cache", isInDefsCache(nsCmpDef, mdri));

        MasterDefRegistry mdr2 = restartContextGetNewMDR();
        MasterDefRegistryImpl mdri2 = (MasterDefRegistryImpl) mdr2;

        assertTrue("nsDef is in cache", isInDefsCache(nsDef, mdri2));
        assertTrue("LayoutsDef is in cache", isInDefsCache(defs.get(DefType.LAYOUTS), mdri2));
        assertTrue("RendererDef is in cache", isInDefsCache(rendererDef, mdri2));
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.