Package com.volantis.mcs.devices.policy

Examples of com.volantis.mcs.devices.policy.PolicyDescriptor


    // javadoc inherited
    public PolicyDescriptor getPolicyDescriptor(String policyName, Locale locale)
            throws DeviceRepositoryException {

        PolicyDescriptor descriptor = null;

        if (policyName != null &&
                getCachedPolicyNames().contains(policyName)) {
            // get the right cache
            Map nameToDescriptor =
View Full Code Here


    }


    public PolicyDescriptor getPolicyDescriptor(String policyName, Locale locale)
            throws DeviceRepositoryException {
        PolicyDescriptor descriptor = null;

        if (getCachedAccessiblePolicyNames().contains(policyName)) {
            final AbstractDeviceRepositoryAccessor abstractAccessor =
                ((AbstractDeviceRepositoryAccessor) accessor);
            final PolicyDescriptorAccessor descriptorAccessor =
View Full Code Here

                }

                for (Iterator iter = policyDescriptors.iterator();
                     iter.hasNext();) {

                    final PolicyDescriptor policyDescriptor =
                        (PolicyDescriptor) iter.next();
                    // Write the descriptors to the destination for this policy.
                    try {
                        dstAccessor.addPolicyDescriptor(policyName,
                                policyDescriptor);
View Full Code Here

        // for each policy namee.
        RepositoryEnumeration names = accessor.enumerateDevicePolicyNames();
        try {
            while (names.hasNext()) {
                String policyName = (String) names.next();
                PolicyDescriptor policyDescriptor;
                try {
                    policyDescriptor = accessor.retrievePolicyDescriptor(
                            policyName, Locale.getDefault());
                } catch (RepositoryException e) {
                    throw new RepositoryException(
                            exceptionLocalizer.format(
                                    "cannot-read-policy-descriptor",
                                    policyName),
                            e);
                }
                descriptors.put(policyName, policyDescriptor);
            }
        } finally {
            names.close();
        }

        // Now get a list of all the policies we found a descriptor for...
        List policyList = new ArrayList(descriptors.keySet());
        // And sort it for easy comparison purposes.
        Collections.sort(policyList);

        // Finally iterate over the sorted list of policies, dumping the
        // related descriptor for each one.
        Iterator itr = policyList.iterator();
        while (itr.hasNext()) {
            String policy = (String) itr.next();
            PolicyDescriptor descriptor = (PolicyDescriptor)
                    descriptors.get(policy);

            info("localized-message",
                         new Object[] {policy + "->" + descriptor});
        }
View Full Code Here

            DeviceRepository repository = ProjectDeviceRepositoryAccessor
                    .getProjectDeviceRepository(context);
            Iterator policyNames = repository.getDevicePolicyNames().iterator();
            while (policyNames.hasNext()) {
                String policyName = (String) policyNames.next();
                PolicyDescriptor policyDescriptor =
                        repository.getPolicyDescriptor(policyName,
                                Locale.getDefault());
                if (policyDescriptor != null) {
                    if (policyDescriptor.getPolicyType()
                            instanceof SelectionPolicyType) {
                        namesToDescriptors.put(policyName, policyDescriptor);
                        policies.add(policyName);
                    }
                } else {
                    // Should never happen.
                    throw new IllegalStateException(
                            "Policy descriptor cannot be found for " +
                                    policyName);
                }
            }
        } catch (IOException ioe) {
            EclipseCommonPlugin.logError(BuilderPlugin.getDefault(),
                    getClass(), ioe);
        } catch (DeviceRepositoryException dre) {
            EclipseCommonPlugin.logError(BuilderPlugin.getDefault(),
                    getClass(), dre);
        }

        addNullDescriptor(namesToDescriptors, policies);

        combo.setLabelProvider(new LabelProvider() {
            public String getText(Object o) {
                String policyName = (String) o;
                PolicyDescriptor descriptor = (PolicyDescriptor)
                        namesToDescriptors.get(policyName);
                return descriptor.getPolicyDescriptiveName();
            }
        });

        combo.setContentProvider(new ArrayContentProvider());
        combo.setInput(policies);

        combo.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection =
                        (IStructuredSelection) combo.getSelection();
                String policyName = (String) selection.getFirstElement();
                PolicyDescriptor descriptor = (PolicyDescriptor)
                        namesToDescriptors.get(policyName);
                SelectionPolicyType policyType =
                        (SelectionPolicyType) descriptor.getPolicyType();
                context.setCategoryValues(policyType.getKeywords());

                BeanProxy model = (BeanProxy) context.getInteractionModel();
                Proxy categorisationScheme = model.getPropertyProxy(
                        PolicyModel.CATEGORISATION_SCHEME);

                if (!ObjectHelper.equals(policyName,
                        categorisationScheme.getModelObject())) {
                    Operation setSchemeOp = categorisationScheme
                            .prepareSetModelObjectOperation(policyName);
                    context.executeOperation(setSchemeOp);
                }
            }
        });

        BeanProxy model = (BeanProxy) context.getInteractionModel();
        final Proxy categorisationScheme =
                model.getPropertyProxy(PolicyModel.CATEGORISATION_SCHEME);
        String selectedPolicy = (String) categorisationScheme.getModelObject();
        if (selectedPolicy != null) {
            combo.setSelection(new StructuredSelection(selectedPolicy));
            PolicyDescriptor descriptor = (PolicyDescriptor)
                    namesToDescriptors.get(selectedPolicy);
            SelectionPolicyType policyType =
                    (SelectionPolicyType) descriptor.getPolicyType();
            context.setCategoryValues(policyType.getKeywords());
        }

        categorisationScheme.addListener(new InteractionEventListenerAdapter() {
            protected void interactionEvent(InteractionEvent event) {
                String selectedPolicy =
                        (String) categorisationScheme.getModelObject();
                if (selectedPolicy != null) {
                    combo.setSelection(new StructuredSelection(selectedPolicy));
                    PolicyDescriptor descriptor = (PolicyDescriptor)
                            namesToDescriptors.get(selectedPolicy);
                    SelectionPolicyType policyType =
                            (SelectionPolicyType) descriptor.getPolicyType();
                    context.setCategoryValues(policyType.getKeywords());
                }
            }
        }, false);
    }
View Full Code Here

        SelectionPolicyType selectionType = new SelectionPolicyType() {
            public List getKeywords() {
                return new ArrayList();
            }
        };
        final PolicyDescriptor nullDescriptor =
                POLICY_DESCRIPTOR_FACTORY
                        .createPolicyDescriptor(selectionType, "");
        namesToDescriptors.put("", nullDescriptor);
        policies.add("");
View Full Code Here

                            DeviceRepositoryFactory.getDefaultInstance();
                URL deviceRepositoryUrl = file.toURL();
                DeviceRepository repository = factory.getDeviceRepository(
                        deviceRepositoryUrl, null);

                PolicyDescriptor descriptor =
                        repository.getPolicyDescriptor(null, Locale.getDefault());
                assertNull("Policy descriptor should not be found", descriptor);

                // todo this code is commented cause the expected value should be null (currently a DeviceRepositoryException is thrown which is wrong).
//        descriptor = repository.getPolicyDescriptor("not here");
//        assertNull("Policy descriptor should not be found", descriptor);

                descriptor = repository.getPolicyDescriptor(
                        "output.charset.default", Locale.getDefault());
                assertNotNull("Policy descriptor should be found", descriptor);
                assertTrue("Type should match", descriptor instanceof DefaultPolicyDescriptor);
                assertEquals("Type should match", "Output charset (default)",
                        descriptor.getPolicyDescriptiveName());
                assertEquals("Category should match", "output",
                        descriptor.getCategoryName());
            }
        });
    }
View Full Code Here

                // Try getting the value from a device repository with the
                // experimental policies non-accessible
                {
                    DeviceRepository repository = getDeviceRepository(deviceRepositoryUrl, false);

                    PolicyDescriptor descriptor = repository.getPolicyDescriptor(
                            "x-experimental-policy", Locale.getDefault());
                    assertNull("Policy descriptor should not be found", descriptor);
                }

                // Try getting the value from a device repository with the
                // experimental policies accessible
                {
                    DeviceRepository repository = getDeviceRepository(deviceRepositoryUrl, true);

                    PolicyDescriptor descriptor = repository.getPolicyDescriptor(
                            "x-experimental-policy", Locale.getDefault());
                    assertNotNull("Policy descriptor should be found", descriptor);
                }
            }
        });
View Full Code Here

        }

        PolicyValue value = null;

        try {
            PolicyDescriptor descriptor =
                    policyDescriptorAccessor.getPolicyDescriptor(
                            policyName, Locale.getDefault());
            if (descriptor != null) {
                PolicyType type = descriptor.getPolicyType();
                if (type instanceof StructurePolicyType) {
                    value = createStructuredPolicyValue(device, policyName,
                            (StructurePolicyType) type);
                } else {
                    try {
View Full Code Here

            InternalJDBCRepository repository = createRepository(defaultProject);
            JDBCDeviceRepositoryAccessor accessor =
                    new JDBCDeviceRepositoryAccessor(repository, location);
            Locale locale = new Locale("en", "GB");

            PolicyDescriptor policyDescriptor;
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "Policy1", locale);
            assertNull("No policy descriptor expected", policyDescriptor);

            // Test the retrieval of a policy descriptor from VMTYPES
            int id = populateWithSimpleTypes(0);
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "Policy1", locale);
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            PolicyType policyType = policyDescriptor.getPolicyType();
            assertTrue("Type should match",
                    policyType instanceof BooleanPolicyType);
            assertEquals("PolicyDescName1",
                policyDescriptor.getPolicyDescriptiveName());
            assertEquals("PolicyHelp1", policyDescriptor.getPolicyHelp());
            assertEquals("en_GB_", policyDescriptor.getLanguage());

            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "Policy2", locale);
            policyType = policyDescriptor.getPolicyType();
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            assertTrue("Type should match",
                    policyType instanceof IntPolicyType);
            assertEquals("PolicyDescName2",
                policyDescriptor.getPolicyDescriptiveName());
            assertEquals("PolicyHelp2", policyDescriptor.getPolicyHelp());
            assertEquals("en_GB_", policyDescriptor.getLanguage());

            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "Policy3", locale);
            policyType = policyDescriptor.getPolicyType();
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            assertTrue("Type should match",
                    policyType instanceof TextPolicyType);
            assertEquals("PolicyDescName3",
                policyDescriptor.getPolicyDescriptiveName());
            assertEquals("PolicyHelp3", policyDescriptor.getPolicyHelp());
            assertEquals("en_GB_", policyDescriptor.getLanguage());

            // Test the retrieval of a policy descriptor from VMTYPES_SELECTION
            id = populateWithSelections(id);
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "SelectionPolicy", locale);
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            policyType = policyDescriptor.getPolicyType();
            assertTrue("Type should match",
                    policyType instanceof SelectionPolicyType);
            assertEquals("SelectionPolicyDescName",
                policyDescriptor.getPolicyDescriptiveName());
            assertEquals("SelectionPolicyHelp", policyDescriptor.getPolicyHelp());
            assertEquals("en_GB_", policyDescriptor.getLanguage());

            SelectionPolicyType selectionType =
                    (SelectionPolicyType)policyType;
            assertEquals("Selections size should match", 2,
                    selectionType.getKeywords().size());
            assertEquals("Selections size should match",
                    "keyword1", selectionType.getKeywords().get(0));
            assertEquals("Selections size should match",
                    "keyword2", selectionType.getKeywords().get(1));

            // Test the retrieval of a policy descriptor from VMTYPES_RANGE
            id = populateWithRanges(id);
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "RangesPolicy", locale);
            policyType = policyDescriptor.getPolicyType();
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            assertTrue("Type should match: " + policyType,
                    policyType instanceof RangePolicyType);
            RangePolicyType rangeType =
                    (RangePolicyType)policyType;

            assertEquals("Selections size should match", 77,
                    rangeType.getMinInclusive());
            assertEquals("Selections size should match", 188,
                    rangeType.getMaxInclusive());

            // Test the retrieval of a policy descriptor from VMTYPES_STRUCTURE
            id = populateWithStructure(id);
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "StructurePolicy", locale);
            policyType = policyDescriptor.getPolicyType();
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            assertTrue("Type should match: " + policyType,
                    policyType instanceof StructurePolicyType);
            StructurePolicyType structureType =
                    (StructurePolicyType)policyType;

            assertTrue("Should contain key: " + "TestFieldname",
                    structureType.getFieldTypes().containsKey("TestFieldname"));
            policyType = (PolicyType)structureType.getFieldTypes().get("TestFieldname");
            assertTrue("Type should match: " + policyType,
                    policyType instanceof BooleanPolicyType);

            // Test the retrieval of a policy descriptor from VMTYPES_SET
            id = populateWithOrderedSet(id);
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "OrderedSetPolicy", locale);
            policyType = policyDescriptor.getPolicyType();
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            assertTrue("Type should match: " + policyType,
                    policyType instanceof OrderedSetPolicyType);
            OrderedSetPolicyType orderedSetType =
                    (OrderedSetPolicyType)policyType;

            policyType = orderedSetType.getMemberPolicyType();
            assertTrue("Type should match: " + policyType,
                    policyType instanceof IntPolicyType);

            repository = createRepository(oneMoreProject);
            accessor =
                    new JDBCDeviceRepositoryAccessor(repository,
                            new DeviceRepositoryLocationImpl(oneMoreProject));

            // Test the retrieval of a policy descriptor from VMTYPES
            populateWithSimpleTypes(0);
            policyDescriptor = accessor.retrievePolicyDescriptor(
                    connection, "Policy1", locale);
            assertNotNull("Policy Descriptor should be found", policyDescriptor);
            policyType = policyDescriptor.getPolicyType();
            assertTrue("Type should match",
                    policyType instanceof BooleanPolicyType);

        } finally {
            removeRepository();
View Full Code Here

TOP

Related Classes of com.volantis.mcs.devices.policy.PolicyDescriptor

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.