Package org.jboss.dna.graph.session

Examples of org.jboss.dna.graph.session.ValidationException


                if (isRoot) {
                    try {
                        definition = nodeTypes().getRootNodeDefinition();
                    } catch (RepositoryException e) {
                        // Shouldn't really happen ...
                        throw new ValidationException(e.getMessage(), e);
                    }
                } else {
                    Name childName = node.getName();
                    Node<JcrNodePayload, JcrPropertyPayload> parent = node.getParent();
                    JcrNodePayload parentInfo = parent.getPayload();
                    int numExistingChildrenWithSameName = parent.getChildrenCount(childName);
                    // The children include this node, so we need to subtract one from the count so that the
                    // number of existing children is either 0 (if there are no other SNS nodes) or 1+
                    // (if there are at least 2 SNS nodes)
                    --numExistingChildrenWithSameName;
                    definition = nodeTypes().findChildNodeDefinition(parentInfo.getPrimaryTypeName(),
                                                                     parentInfo.getMixinTypeNames(),
                                                                     childName,
                                                                     primaryTypeName,
                                                                     numExistingChildrenWithSameName,
                                                                     false);
                }
            }
            if (definition == null) {
                String msg = JcrI18n.nodeDefinitionCouldNotBeDeterminedForNode.text(readable(node.getPath()),
                                                                                    workspaceName(),
                                                                                    sourceName());
                throw new ValidationException(msg);
            }

            // ------------------------------------------------------
            // Set the node's properties ...
            // ------------------------------------------------------
            boolean referenceable = false;

            // Start with the primary type ...
            JcrNodeType primaryType = nodeTypes().getNodeType(primaryTypeName);
            if (primaryType == null) {
                Path path = location.getPath();
                String msg = JcrI18n.missingNodeTypeForExistingNode.text(readable(primaryTypeName),
                                                                         readable(path),
                                                                         workspaceName(),
                                                                         sourceName());
                throw new ValidationException(msg);
            }
            if (primaryType.isNodeType(JcrMixLexicon.REFERENCEABLE)) referenceable = true;

            // The process the mixin types ...
            Property mixinTypesProperty = graphProperties.get(JcrLexicon.MIXIN_TYPES);
View Full Code Here


            // Is this node referenceable ...
            boolean referenceable = false;
            try {
                referenceable = isReferenceable(node);
            } catch (RepositoryException e) {
                throw new ValidationException(e.getLocalizedMessage());
            }
            for (org.jboss.dna.graph.session.GraphSession.PropertyInfo<JcrPropertyPayload> property : node.getProperties()) {
                if (property.getName().equals(JcrLexicon.UUID) && !referenceable) continue;
                JcrPropertyPayload propPayload = property.getPayload();
                JcrPropertyDefinition definition = findBestPropertyDefintion(primaryTypeName,
                                                                             mixinTypeNames,
                                                                             property.getProperty(),
                                                                             propPayload.getPropertyType(),
                                                                             property.getProperty().isSingle(),
                                                                             false);
                if (definition == null) {
                    throw new ValidationException(JcrI18n.noDefinition.text("property",
                                                                            readable(property.getName()),
                                                                            readable(node.getPath()),
                                                                            readable(primaryTypeName),
                                                                            readable(mixinTypeNames)));
                }

                satisfiedProperties.add(definition);
            }

            for (org.jboss.dna.graph.session.GraphSession.Node<JcrNodePayload, JcrPropertyPayload> child : node.getChildren()) {
                int snsCount = node.getChildrenCount(child.getName());
                JcrNodeDefinition definition = nodeTypes().findChildNodeDefinition(primaryTypeName,
                                                                                   mixinTypeNames,
                                                                                   child.getName(),
                                                                                   child.getPayload().getPrimaryTypeName(),
                                                                                   snsCount,
                                                                                   false);
                if (definition == null) {
                    throw new ValidationException(JcrI18n.noDefinition.text("child node",
                                                                            readable(child.getName()),
                                                                            readable(node.getPath()),
                                                                            readable(primaryTypeName),
                                                                            readable(mixinTypeNames)));
                }
                satisfiedChildNodes.add(definition);
            }

            JcrNodeType primaryType = nodeTypes().getNodeType(primaryTypeName);
            for (JcrPropertyDefinition definition : primaryType.getPropertyDefinitions()) {
                if (definition.isMandatory() && !definition.isProtected() && !satisfiedProperties.contains(definition)) {
                    throw new ValidationException(JcrI18n.noDefinition.text("property",
                                                                            definition.getName(),
                                                                            readable(node.getPath()),
                                                                            readable(primaryTypeName),
                                                                            readable(mixinTypeNames)));
                }
            }
            for (JcrNodeDefinition definition : primaryType.getChildNodeDefinitions()) {
                if (definition.isMandatory() && !definition.isProtected() && !satisfiedChildNodes.contains(definition)) {
                    throw new ValidationException(JcrI18n.noDefinition.text("child node",
                                                                            definition.getName(),
                                                                            readable(node.getPath()),
                                                                            readable(primaryTypeName),
                                                                            readable(mixinTypeNames)));
                }
            }

            if (mixinTypeNames != null) {
                for (Name mixinTypeName : mixinTypeNames) {
                    JcrNodeType mixinType = nodeTypes().getNodeType(mixinTypeName);
                    for (JcrPropertyDefinition definition : mixinType.getPropertyDefinitions()) {
                        if (definition.isMandatory() && !definition.isProtected() && !satisfiedProperties.contains(definition)) {
                            throw new ValidationException(JcrI18n.noDefinition.text("child node",
                                                                                    definition.getName(),
                                                                                    readable(node.getPath()),
                                                                                    readable(primaryTypeName),
                                                                                    readable(mixinTypeNames)));
                        }
                    }
                    for (JcrNodeDefinition definition : mixinType.getChildNodeDefinitions()) {
                        if (definition.isMandatory() && !definition.isProtected() && !satisfiedChildNodes.contains(definition)) {
                            throw new ValidationException(JcrI18n.noDefinition.text("child node",
                                                                                    definition.getName(),
                                                                                    readable(node.getPath()),
                                                                                    readable(primaryTypeName),
                                                                                    readable(mixinTypeNames)));
                        }
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.session.ValidationException

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.