Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.Property


        public void storeProperties( String id,
                                     Map<Name, Property> properties ) {
            String key = keyFor(id);
            EditableDocument doc = Schematic.newDocument();
            for (Map.Entry<Name, Property> entry : properties.entrySet()) {
                Property property = entry.getValue();
                if (property != null) {
                    translator.setProperty(doc, property, null, null);
                }
            }
            localStore.storeDocument(key, doc);
View Full Code Here


                                      Map<Name, Property> properties ) {
            String key = keyFor(id);
            EditableDocument doc = localStore.edit(key, true);
            assert doc != null;
            for (Map.Entry<Name, Property> propertyEntry : properties.entrySet()) {
                Property property = propertyEntry.getValue();
                if (property != null) {
                    translator.setProperty(doc, property, null, null);
                } else {
                    translator.removeProperty(doc, propertyEntry.getKey(), null, null);
                }
View Full Code Here

                        // Add in the strong and weak referrers (that are outside the import scope) that used to be in the node
                        // before it was replaced ...
                        for (NodeKey key : counts.getStrongReferrers()) {
                            int count = counts.countStrongReferencesFrom(key);
                            for (int i = 0; i != count; ++i) {
                                Property prop = propFactory.create(nameFor(key.toString() + i));
                                referred.addReferrer(cache, prop, key, ReferenceType.STRONG);
                            }
                        }
                        for (NodeKey key : counts.getWeakReferrers()) {
                            int count = counts.countWeakReferencesFrom(key);
                            for (int i = 0; i != count; ++i) {
                                Property prop = propFactory.create(nameFor(key.toString() + i));
                                referred.addReferrer(cache, prop, key, ReferenceType.WEAK);
                            }
                        }
                    }
                }
View Full Code Here

     * @see javax.jcr.Property#getValues()
     */
    @Override
    public JcrValue[] getValues() throws RepositoryException {
        checkSession();
        Property innerProp = property();
        JcrValue[] values = new JcrValue[innerProp.size()];
        Iterator<?> iter = innerProp.iterator();
        for (int ndx = 0; iter.hasNext(); ndx++) {
            values[ndx] = createValue(iter.next());
        }
        return values;
    }
View Full Code Here

            } else {
                literals[i] = null;
            }
        }

        Property newProperty = propertyFactory().create(name(), literals);
        mutable().setProperty(sessionCache(), newProperty);
    }
View Full Code Here

        checkSession();
        checkForLock();
        checkForCheckedOut();

        Property newProperty = null;
        if (values.length != 0) {
            int numValues = values.length;
            Object[] literals = new Object[numValues];
            for (int i = 0; i != numValues; ++i) {
                String value = values[i];
View Full Code Here

    @Override
    public <T> T getAs( Class<T> type ) throws RepositoryException {
        if (!(type.isArray() || type.equals(NodeIterator.class))) {
            throw new ValueFormatException(JcrI18n.unableToConvertPropertyValueToType.text(getPath(), type.getSimpleName()));
        }
        Property property = property();
        try {
            if (String[].class.equals(type)) {
                return type.cast(property.getValuesAsArray(context().getValueFactories().getStringFactory()));
            } else if (Long[].class.equals(type)) {
                return type.cast(property.getValuesAsArray(context().getValueFactories().getLongFactory()));
            } else if (Boolean[].class.equals(type)) {
               return type.cast(property.getValuesAsArray(context().getValueFactories().getBooleanFactory()));
            } else if (Date[].class.equals(type)) {
                final DateTimeFactory dateFactory = context().getValueFactories().getDateFactory();
                Date[] result = property.getValuesAsArray(new Property.ValueTypeTransformer<Date>() {
                    @Override
                    public Date transform( Object value ) {
                        return dateFactory.create(value).toDate();
                    }
                }, Date.class);
                return type.cast(result);
            } else if (Calendar[].class.equals(type)) {
                final DateTimeFactory dateFactory = context().getValueFactories().getDateFactory();
                Calendar[] result = property.getValuesAsArray(new Property.ValueTypeTransformer<Calendar>() {
                    @Override
                    public Calendar transform( Object value ) {
                        return dateFactory.create(value).toCalendar();
                    }
                }, Calendar.class);
                return type.cast(result);
            } else if (DateTime[].class.equals(type)) {
                return type.cast(property.getValuesAsArray(context().getValueFactories().getDateFactory()));
            } else if (Double[].class.equals(type)) {
                return type.cast(property.getValuesAsArray(context().getValueFactories().getDoubleFactory()));
            } else if (BigDecimal[].class.equals(type)) {
                return type.cast(property.getValuesAsArray(context().getValueFactories().getDecimalFactory()));
            } else if (InputStream[].class.equals(type)) {
                final BinaryFactory binaryFactory = context().getValueFactories().getBinaryFactory();
                InputStream[] result = property.getValuesAsArray(new Property.ValueTypeTransformer<InputStream>() {
                    @Override
                    public InputStream transform( Object value ) {
                        try {
                            BinaryValue binaryValue = binaryFactory.create(value);
                            return binaryValue.getStream();
                        } catch (RepositoryException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }, InputStream.class);
                return type.cast(result);
            } else if (Binary[].class.isAssignableFrom(type)) {
                //this should support both ModeShape and JCR binary types because of arrays covariance
                return type.cast(property.getValuesAsArray(context().getValueFactories().getBinaryFactory()));
            } else if (Node[].class.equals(type)) {
                Node[] nodes = property.getValuesAsArray(new Property.ValueTypeTransformer<Node>() {
                    @Override
                    public Node transform( Object value ) {
                        try {
                            return valueToNode(value);
                        } catch (RepositoryException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }, Node.class);
                return type.cast(nodes);
            } else if (NodeIterator.class.equals(type)) {
                Node[] nodes = property.getValuesAsArray(new Property.ValueTypeTransformer<Node>() {
                    @Override
                    public Node transform( Object value ) {
                        try {
                            return valueToNode(value);
                        } catch (RepositoryException e) {
View Full Code Here

     * @param properties the list of properties to which any vendor extension properties should be added
     */
    protected final void parseVendorExtensions( TokenStream tokens,
                                                List<Property> properties ) {
        while (tokens.matches(CndTokenizer.VENDOR_EXTENSION)) {
            Property extension = parseVendorExtension(tokens.consume());
            if (extension != null) properties.add(extension);
        }
    }
View Full Code Here

        boolean synchronous = booleans.create(first(indexDefn, ModeShapeLexicon.SYNCHRONOUS));
        IndexKind kind = IndexKind.valueOf(kindStr);
        String nodeTypeName = strings.create(names.create(first(indexDefn, ModeShapeLexicon.NODE_TYPE_NAME)));
        Map<String, Object> extendedProps = new HashMap<>();
        for (Iterator<Property> props = indexDefn.getProperties(system); props.hasNext();) {
            Property prop = props.next();
            if (NON_EXTENDED_PROPERTIES.contains(prop.getName())) continue;
            if (prop.isSingle()) {
                extendedProps.put(strings.create(prop.getName()), prop);
            } else if (prop.isMultiple()) {
                extendedProps.put(strings.create(prop.getName()), prop);
            }
        }

        Collection<IndexColumnDefinition> columnDefns = new LinkedList<>();
        for (ChildReference ref : indexDefn.getChildReferences(system)) {
View Full Code Here

        if (indexes.getChildReferences(system).hasChild(providerKey)) {
            // The node already exists ...
            providerNode = system.mutable(providerKey);
        } else {
            // Create the new provider node ...
            Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.INDEX_PROVIDER);
            Name providerName = names.create(indexDefn.getProviderName());
            providerNode = indexes.createChild(system, providerKey, providerName, primaryType);
        }
        assert providerNode != null;

        Name name = names.create(indexDefn.getName());
        final NodeKey key = nodeKey(indexes.getKey(), indexDefn);
        MutableCachedNode indexNode = null;
        Set<NodeKey> existingChildKeys = null;

        if (providerNode.getChildReferences(system).hasChild(key)) {
            // The node already exists ...
            if (!updateExisting) return;
            indexNode = system.mutable(key);

            // We'll need to delete any existing column that isn't there anymore ...
            existingChildKeys = new HashSet<NodeKey>();
            for (ChildReference childRef : indexNode.getChildReferences(system)) {
                existingChildKeys.add(childRef.getKey());
            }
        }

        // Define the properties for this index definition ...
        List<Property> properties = new ArrayList<Property>();
        // Add the extended properties first, in case the standard ones overwrite them ...
        for (Map.Entry<String, Object> entry : indexDefn.getIndexProperties().entrySet()) {
            Property prop = createProperty(entry.getKey(), entry.getValue());
            if (prop != null) properties.add(prop);
        }

        // Now do the standard properties ...
        properties.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.INDEX));
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.Property

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.