Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.Name


        }

        // Otherwise, we have to create the property, so first find a valid property definition ...
        SessionCache cache = sessionCache();
        MutableCachedNode node = mutable();
        Name primaryType = node.getPrimaryType(cache);
        Set<Name> mixinTypes = node.getMixinTypes(cache);
        NodeTypes nodeTypes = session.nodeTypes();
        JcrPropertyDefinition defn = null;
        defn = nodeTypes.findPropertyDefinition(session, primaryType, mixinTypes, name, values, !skipProtectedValidation,
                                                skipReferenceValidation);
View Full Code Here


        throws AccessDeniedException, RepositoryException {
        try {
            Collection<AbstractJcrProperty> result = new LinkedList<AbstractJcrProperty>();
            while (propertyIterator.hasNext()) {
                Property property = propertyIterator.next();
                Name propertyName = property.getName();
                AbstractJcrProperty jcrProp = getProperty(propertyName);
                if (jcrProp != null) result.add(jcrProp);
            }
            return result;
        } catch (AccessControlException e) {
View Full Code Here

        if (nameGlobs.length == 0) return JcrEmptyPropertyIterator.INSTANCE;

        List<?> patterns = createPatternsFor(nameGlobs);
        if (patterns.size() == 1 && patterns.get(0) instanceof String) {
            // This is a literal, so just look up by name ...
            Name literal = nameFrom((String)patterns.get(0));
            AbstractJcrProperty prop = getProperty(literal);
            if (prop == null) return JcrEmptyPropertyIterator.INSTANCE;
            return new JcrPropertyIterator(Collections.singletonList((javax.jcr.Property)prop));
        }
        Iterator<Property> propIter = node().getProperties(patterns, sessionCache());
View Full Code Here

        SessionCache cache = sessionCache();
        NodeTypes nodeTypes = session().nodeTypes();
        try {
            CachedNode node = node();
            // Check the primary type ...
            Name primaryTypeName = node.getPrimaryType(cache);
            if (nodeTypes.isTypeOrSubtype(primaryTypeName, nodeTypeName)) return true;
            // Check the mixins ...
            Set<Name> mixinTypes = node.getMixinTypes(cache);
            if (nodeTypes.isTypeOrSubtype(mixinTypes, nodeTypeName)) return true;
        } catch (ItemNotFoundException e) {
View Full Code Here

        MutableCachedNode node = mutable();
        SessionCache cache = sessionCache();
        if (nodeType.hasPropertyDefinitions()) {
            for (JcrPropertyDefinition propDefn : nodeType.allPropertyDefinitions()) {
                if (propDefn.isAutoCreated() && !propDefn.isProtected()) {
                    Name propName = propDefn.getInternalName();
                    Property autoCreatedProp = node.getProperty(propName, cache);
                    if (autoCreatedProp == null) {
                        // We have to 'auto-create' the property ...
                        JcrValue[] defaultValues = propDefn.getDefaultValues();
                        if (defaultValues != null) { // may be empty
                            if (propDefn.isMultiple()) {
                                setProperty(propDefn.getInternalName(), defaultValues, propDefn.getRequiredType(), true);
                            } else {
                                assert propDefn.getDefaultValues().length == 1;
                                // don't skip constraint checks or protected checks
                                setProperty(propDefn.getInternalName(), defaultValues[0], false, false, false, false);
                            }
                        }
                        // otherwise, we don't care
                    }
                }
            }
        }

        if (nodeType.hasChildNodeDefinitions()) {
            ChildReferences refs = null;
            for (JcrNodeDefinition nodeDefn : nodeType.allChildNodeDefinitions()) {
                if (nodeDefn.isAutoCreated() && !nodeDefn.isProtected()) {
                    Name nodeName = nodeDefn.getInternalName();
                    if (refs == null) refs = node.getChildReferences(cache);
                    if (refs.getChildCount(nodeName) == 0) {
                        JcrNodeType defaultPrimaryType = nodeDefn.getDefaultPrimaryType();
                        assert defaultPrimaryType != null;
                        Name primaryType = defaultPrimaryType.getInternalName();
                        addChildNode(nodeName, primaryType, null, false, false);
                    }
                }
            }
        }
View Full Code Here

        if (isRoot()) {
            throw new ConstraintViolationException(JcrI18n.setPrimaryTypeOnRootNodeIsNotSupported.text());
        }

        Name newPrimaryTypeName = nameFrom(nodeTypeName);
        NodeTypes nodeTypes = session.nodeTypes();
        if (newPrimaryTypeName.equals(getPrimaryTypeName())) return;

        final JcrNodeType newPrimaryType = nodeTypes.getNodeType(newPrimaryTypeName);
        // validate the new primary type
        if (newPrimaryType == null) {
            throw new NoSuchNodeTypeException(JcrI18n.typeNotFound.text(newPrimaryType));
        }
        if (newPrimaryType.isMixin()) {
            throw new ConstraintViolationException(JcrI18n.cannotUseMixinTypeAsPrimaryType.text(nodeTypeName));
        }
        if (newPrimaryType.isAbstract()) {
            throw new ConstraintViolationException(JcrI18n.primaryTypeCannotBeAbstract.text(newPrimaryType));
        }

        // Make sure that all existing properties will have a valid property definition with the new primary type ...
        SessionCache cache = sessionCache();
        CachedNode node = node();
        Name oldPrimaryType = node.getPrimaryType(cache);
        Set<Name> mixinTypeNames = node.getMixinTypes(cache);
        Iterator<Property> iter = node.getProperties(cache);
        while (iter.hasNext()) {
            Property prop = iter.next();
            try {
                createJcrProperty(prop, newPrimaryTypeName, mixinTypeNames);
            } catch (ConstraintViolationException e) {
                // Change the message ...
                String propName = readable(prop.getName());
                I18n msg = JcrI18n.unableToChangePrimaryTypeDueToPropertyDefinition;
                throw new ConstraintViolationException(msg.text(location(), oldPrimaryType, newPrimaryTypeName, propName), e);
            }
        }

        // Check that this would not violate the parent's child node type definitions ...
        Name nodeName = node.getName(cache);
        CachedNode parent = getParent().node();
        Name primaryType = parent.getPrimaryType(cache);
        Set<Name> mixins = parent.getMixinTypes(cache);
        // The node is already a child, so create a counter that returns the count as if it were not a child ...
        SiblingCounter siblingCounter = SiblingCounter.alter(SiblingCounter.create(parent, cache), -1);
        boolean skipProtected = true;
        NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(primaryType, mixins);
View Full Code Here

        if (!canAddMixin(mixinName)) {
            throw new ConstraintViolationException(JcrI18n.cannotAddMixin.text(mixinName));
        }
        if (isNodeType(mixinName)) return;
        boolean wasReferenceable = isReferenceable();
        Name mixinTypeName = nameFrom(mixinName);

        // Change the mixin types property (atomically, even if some other operation snuck in and added the mixin) ...
        SessionCache cache = sessionCache();
        MutableCachedNode mutable = mutable();
        mutable.addMixin(cache, mixinTypeName);
View Full Code Here

    public static PropertyDefinitionId fromString( String definition,
                                                   NameFactory factory ) {
        String[] parts = definition.split("/");
        String nodeTypeNameString = parts[0];
        String propertyDefinitionNameString = parts[1];
        Name nodeTypeName = factory.create(nodeTypeNameString);
        Name propertyDefinitionName = factory.create(propertyDefinitionNameString);
        int propertyType = org.modeshape.jcr.api.PropertyType.valueFromName(parts[2]);
        boolean allowsMultiple = parts[3].charAt(0) == '*';
        return new PropertyDefinitionId(nodeTypeName, propertyDefinitionName, propertyType, allowsMultiple);
    }
View Full Code Here

    }

    @Override
    public JcrNodeType getNodeType( String nodeTypeName ) throws NoSuchNodeTypeException, RepositoryException {
        session.checkLive();
        Name ntName = context().getValueFactories().getNameFactory().create(nodeTypeName);
        JcrNodeType type = nodeTypes().getNodeType(ntName);
        if (type != null) {
            type = type.with(context(), session);
            return type;
        }
View Full Code Here

     * @return true if the named node type does exist, or false otherwise
     * @see NodeTypes#hasNodeType(Name)
     */
    @Override
    public boolean hasNodeType( String nodeTypeName ) {
        Name ntName = context().getValueFactories().getNameFactory().create(nodeTypeName);
        return nodeTypes().hasNodeType(ntName);
    }
View Full Code Here

TOP

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

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.