Package gov.nasa.arc.mct.platform.spi

Examples of gov.nasa.arc.mct.platform.spi.Platform


     * @param assetClass the type of asset desired
     * @param <A> the type of asset desired
     * @return an object of the desired type (or null if none is available)
     */
    public <A> A getAsset(Class<A> assetClass) {
        Platform platform = PlatformAccess.getPlatform();
        if (platform != null) {
            CoreComponentRegistry registry = platform.getComponentRegistry();
            if (registry != null) {
                return registry.getAsset(this, assetClass);
            }
        }
        return null;
View Full Code Here


        actionContext = (ActionContextImpl) context;
        return getTargetComponent(actionContext) != null;
    }

    private boolean isComponentWriteableByUser(AbstractComponent component) {
        Platform p = PlatformAccess.getPlatform();
        PolicyContext policyContext = new PolicyContext();
        policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), component);
        policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
        String inspectionKey = PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey();
        return p.getPolicyManager().execute(inspectionKey, policyContext).getStatus();
    }
View Full Code Here

        if (cannotSave.isEmpty()) {
            return true;
        }
       
        // Get references to platform and window manager; these will be used a few times
        Platform platform = PlatformAccess.getPlatform();
        WindowManager windowManager = platform.getWindowManager();
       
        // Can only complete action if there are no components which cannot be removed
        String confirm = BUNDLE.getString("SaveConfirm");
        String abort = BUNDLE.getString("SaveAbort");
        String[] options = { confirm, abort };
View Full Code Here

                                }
                            });
                            return;
                        }

                        Platform platform = PlatformAccess.getPlatform();
                        PersistenceProvider persistenceService = platform.getPersistenceProvider();
                        CoreComponentRegistry componentRegistry = platform.getComponentRegistry();
                        AbstractComponent mySandbox = componentRegistry.newInstance(MineTaxonomyComponent.class.getName());
                        ComponentInitializer mysandboxCapability = mySandbox.getCapability(ComponentInitializer.class);
                        mysandboxCapability.setCreator(userId);
                        mysandboxCapability.setOwner(userId);
                        mySandbox.setDisplayName("My Sandbox");
View Full Code Here

    }
   
    private void handleWarnings(Collection<AbstractComponent> toDelete, Collection<AbstractComponent> toRemove,
            Collection<AbstractComponent> cannotRemove) {
        // Get references to platform and window manager; these will be used a few times
        Platform platform = PlatformAccess.getPlatform();
        WindowManager windowManager = platform.getWindowManager();
       
        // Can only complete action if there are no components which cannot be removed
        if (cannotRemove.isEmpty()) {
            String confirm = bundle.getString("DeleteAllCoreText");
            String abort = bundle.getString("DeleteAllAbortText");
            String[] options = { confirm, abort };

            // Issue a warning dialog to the user
            Map<String, Object> hints = new HashMap<String, Object>();
            hints.put(WindowManagerImpl.PARENT_COMPONENT, actionContext.getWindowManifestation());
            hints.put(WindowManagerImpl.OPTION_TYPE, OptionBox.YES_NO_OPTION);
            hints.put(WindowManagerImpl.MESSAGE_TYPE, OptionBox.WARNING_MESSAGE);
            hints.put(WindowManagerImpl.MESSAGE_OBJECT, buildWarningPanel(toDelete, toRemove));
            String choice = windowManager.showInputDialog(
                    WARNING, //title
                    "", // message - will be overridden by custom object
                    options, // options
                    null, // default option
                    hints); // hints
           
            // Complete the action, if the user has confirmed it
            if (confirm.equals(choice)) {
                for (AbstractComponent delete : toDelete) {
                    windowManager.closeWindows(delete.getComponentId());
                }
                platform.getPersistenceProvider().delete(toDelete);
            }           
        } else {      
            // Some components cannot be removed safely - let the user know this
            String ok = bundle.getString("DeleteAllErrorConfirm");
            Map<String, Object> hints = new HashMap<String, Object>();
View Full Code Here

        oldPlatform = PlatformAccess.getPlatform();
       
        ExecutionResult trueResult = new ExecutionResult(null, true, null);
        PolicyManager mockPolicyManager = Mockito.mock(PolicyManager.class);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext>any())).thenReturn(trueResult);
        Platform mockPlatform = Mockito.mock(Platform.class);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider);
        Mockito.when(mockPersistenceProvider.getReferencedComponents(Mockito.any(AbstractComponent.class))).thenReturn(Collections.<AbstractComponent>emptyList());
       
        new PlatformAccess().setPlatform(mockPlatform);
        new gov.nasa.arc.mct.platform.spi.PlatformAccess().setPlatform(mockPlatform);
    }
View Full Code Here

    }
   
    @Test
    public void testNewCollection() {
        // Environment setup: platform, collection provider, lock manager, and component registry.
        Platform mockPlatform = Mockito.mock(Platform.class);       

        // Also need a sandbox
        AbstractComponent mockSandbox = Mockito.mock(AbstractComponent.class);
        Mockito.when(mockPlatform.getMySandbox()).thenReturn(mockSandbox);
       
        MockComponentRegistry registry = new MockComponentRegistry();
       
        // Set the platform SPI
        PlatformAccess platformAccess = new PlatformAccess();
View Full Code Here

   
    @SuppressWarnings("deprecation")
    @Test
    public void testDeprecatedMethods() {
        // Verify that deprecated methods are redirected to getAsset
        Platform oldPlatform = PlatformAccess.getPlatform();
        Platform mockPlatform = Mockito.mock(Platform.class);
        CoreComponentRegistry mockRegistry = Mockito.mock(CoreComponentRegistry.class);
        Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockRegistry);
        new PlatformAccess().setPlatform(mockPlatform);
       
        ComponentTypeInfo info;
        info = new ComponentTypeInfo("","",AbstractComponent.class);
        info.getIcon();
View Full Code Here

    }
   
    @Test
    public void testGetAsset() {
        // Verify that getAsset is robust to null platform, etc
        Platform oldPlatform = PlatformAccess.getPlatform();
        Platform mockPlatform = Mockito.mock(Platform.class);
        CoreComponentRegistry mockRegistry = Mockito.mock(CoreComponentRegistry.class);
        Icon mockIcon = Mockito.mock(Icon.class);
       
        TypeInfo<?> info = new TypeInfo<TypeInfoTest>(TypeInfoTest.class){};
       
        // Try with a null platform - should fail to retrieve asset
        new PlatformAccess().setPlatform(null);
        Assert.assertNull(info.getAsset(Icon.class));       
       
        // Try with a platform but no registry - should fail to retrieve asset
        new PlatformAccess().setPlatform(mockPlatform);
        Assert.assertNull(info.getAsset(Icon.class));       
              
        // Try with a mock registry (but no assets) - should fail to retrieve
        Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockRegistry);
        Assert.assertNull(info.getAsset(Icon.class));       
               
        // Try with a mock registry that has the requested asset - should retrieve it
        Mockito.when(mockRegistry.getAsset(info, Icon.class)).thenReturn(mockIcon);
        Assert.assertEquals(info.getAsset(Icon.class), mockIcon);       
View Full Code Here

        Mockito.when(componentA.getId()).thenReturn("1");
        Mockito.when(componentB.getId()).thenReturn("2");
               
        reset();
       
        Platform mockPlatform = Mockito.mock(Platform.class);

        PlatformAccess access = new PlatformAccess();
        access.setPlatform(mockPlatform);
        Mockito.when(mockPlatform.getRootComponent()).thenReturn(rootComponent);  
        Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistence);
    }
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.platform.spi.Platform

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.