Search in sources :

Example 71 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class SessionImporter method importProperty.

/**
     *
     * @param pi
     * @param parentState
     * @param resolver
     * @throws RepositoryException
     * @throws ConstraintViolationException
     */
private void importProperty(PropInfo pi, NodeState parentState, NamePathResolver resolver) throws RepositoryException, ConstraintViolationException {
    Name propName = pi.getName();
    TextValue[] tva = pi.getValues();
    int infoType = pi.getType();
    PropertyState propState = null;
    QPropertyDefinition def = null;
    NodeEntry parentEntry = (NodeEntry) parentState.getHierarchyEntry();
    PropertyEntry pEntry = parentEntry.getPropertyEntry(propName);
    if (pEntry != null) {
        // a property with that name already exists...
        try {
            PropertyState existing = pEntry.getPropertyState();
            def = existing.getDefinition();
            if (def.isProtected()) {
                // skip protected property
                log.debug("skipping protected property " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
                return;
            }
            if (def.isAutoCreated() && (existing.getType() == infoType || infoType == PropertyType.UNDEFINED) && def.isMultiple() == existing.isMultiValued()) {
                // this property has already been auto-created, no need to create it
                propState = existing;
            } else {
                throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
            }
        } catch (ItemNotFoundException e) {
        // property doesn't exist any more
        // -> ignore
        }
    }
    Name[] parentNtNames = parentState.getAllNodeTypeNames();
    if (def == null) {
        // there's no property with that name, find applicable definition
        if (tva.length == 1) {
            // could be single- or multi-valued (n == 1)
            def = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, propName, infoType);
        } else {
            // can only be multi-valued (n == 0 || n > 1)
            def = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, propName, infoType, true);
        }
        if (def.isProtected()) {
            // skip protected property
            log.debug("skipping protected property " + propName);
            return;
        }
    }
    // retrieve the target property type needed for creation of QValue(s)
    // including an eventual conversion. the targetType is then needed for
    // setting/updating the type of the property-state.
    int targetType = def.getRequiredType();
    if (targetType == PropertyType.UNDEFINED) {
        if (infoType == PropertyType.UNDEFINED) {
            targetType = PropertyType.STRING;
        } else {
            targetType = infoType;
        }
    }
    QValue[] values = getPropertyValues(pi, targetType, def.isMultiple(), resolver);
    if (propState == null) {
        // create new property
        Operation ap = AddProperty.create(parentState, propName, targetType, def, values);
        stateMgr.execute(ap);
        propState = parentEntry.getPropertyEntry(propName).getPropertyState();
    } else {
        // modify value of existing property
        Operation sp = SetPropertyValue.create(propState, values, targetType);
        stateMgr.execute(sp);
    }
    // store reference for later resolution
    if (propState.getType() == PropertyType.REFERENCE) {
        refTracker.processedReference(propState);
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) Name(org.apache.jackrabbit.spi.Name) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) ItemExistsException(javax.jcr.ItemExistsException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 72 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class SessionItemStateManager method visit.

/**
     * @see OperationVisitor#visit(SetMixin)
     */
public void visit(SetMixin operation) throws ConstraintViolationException, AccessDeniedException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    // NOTE: nodestate is only modified upon save of the changes!
    Name[] mixinNames = operation.getMixinNames();
    NodeState nState = operation.getNodeState();
    NodeEntry nEntry = nState.getNodeEntry();
    // assert the existence of the property entry and set the array of
    // mixinNames to be set on the corresponding property state
    PropertyEntry mixinEntry = nEntry.getPropertyEntry(NameConstants.JCR_MIXINTYPES);
    if (mixinNames.length > 0) {
        // update/create corresponding property state
        if (mixinEntry != null) {
            // execute value of existing property
            PropertyState pState = mixinEntry.getPropertyState();
            setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME, operation.getOptions());
        } else {
            // create new jcr:mixinTypes property
            ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
            QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState.getAllNodeTypeNames(), NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true);
            QValue[] mixinValue = getQValues(mixinNames, qValueFactory);
            addPropertyState(nState, pd.getName(), pd.getRequiredType(), mixinValue, pd, operation.getOptions());
        }
        nState.markModified();
        transientStateMgr.addOperation(operation);
    } else if (mixinEntry != null) {
        // remove the jcr:mixinTypes property state if already present
        PropertyState pState = mixinEntry.getPropertyState();
        removeItemState(pState, operation.getOptions());
        nState.markModified();
        transientStateMgr.addOperation(operation);
    }
// else: empty Name array and no mixin-prop-entry (should not occur)
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ItemDefinitionProvider(org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider) Name(org.apache.jackrabbit.spi.Name)

Example 73 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class QNodeTypeDefinitionImpl method getDependencies.

/**
     * {@inheritDoc}
     */
public Collection<Name> getDependencies() {
    if (dependencies == null) {
        Collection<Name> deps = new HashSet<Name>();
        // supertypes
        deps.addAll(Arrays.asList(supertypes));
        // child node definitions
        for (QNodeDefinition childNodeDef : childNodeDefs) {
            // default primary type
            Name ntName = childNodeDef.getDefaultPrimaryType();
            if (ntName != null && !name.equals(ntName)) {
                deps.add(ntName);
            }
            // required primary type
            Name[] ntNames = childNodeDef.getRequiredPrimaryTypes();
            for (Name ntName1 : ntNames) {
                if (ntName1 != null && !name.equals(ntName1)) {
                    deps.add(ntName1);
                }
            }
        }
        // property definitions
        for (QPropertyDefinition propertyDef : propertyDefs) {
            // [WEAK]REFERENCE value constraints
            if (propertyDef.getRequiredType() == PropertyType.REFERENCE || propertyDef.getRequiredType() == PropertyType.WEAKREFERENCE) {
                QValueConstraint[] ca = propertyDef.getValueConstraints();
                if (ca != null) {
                    for (QValueConstraint aCa : ca) {
                        NameFactory factory = NameFactoryImpl.getInstance();
                        Name ntName = factory.create(aCa.getString());
                        if (!name.equals(ntName)) {
                            deps.add(ntName);
                        }
                    }
                }
            }
        }
        dependencies = Collections.unmodifiableCollection(deps);
    }
    return dependencies;
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) HashSet(java.util.HashSet) Name(org.apache.jackrabbit.spi.Name) NameFactory(org.apache.jackrabbit.spi.NameFactory)

Example 74 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class DefinitionUtil method createQNodeTypeDefinition.

static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
    // NOTE: the server should send the namespace-mappings as addition ns-defininitions
    try {
        if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
            builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
            builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
        }
        Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
        if (child != null) {
            ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
            List<Name> qNames = new ArrayList<Name>();
            while (stIter.hasNext()) {
                Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
                qNames.add(st);
            }
            builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
        }
        if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
            builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
            builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
            builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
            builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
        }
        // nodeDefinitions
        ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
        List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
        while (it.hasNext()) {
            nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
        }
        builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
        // propertyDefinitions
        it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
        List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
        while (it.hasNext()) {
            pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
        }
        builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
    } catch (NameException e) {
        log.error(e.getMessage());
        throw new RepositoryException(e);
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Element(org.w3c.dom.Element) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder) Name(org.apache.jackrabbit.spi.Name)

Example 75 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class PropertyImpl method getDefinition.

/**
     * @see javax.jcr.Property#getDefinition()
     */
public PropertyDefinition getDefinition() throws RepositoryException {
    checkStatus();
    QPropertyDefinition qpd = getPropertyState().getDefinition();
    return session.getNodeTypeManager().getPropertyDefinition(qpd);
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition)

Aggregations

QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)81 Name (org.apache.jackrabbit.spi.Name)32 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)22 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)19 RepositoryException (javax.jcr.RepositoryException)14 QValue (org.apache.jackrabbit.spi.QValue)12 QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)9 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)9 ArrayList (java.util.ArrayList)8 Value (javax.jcr.Value)7 InternalValue (org.apache.jackrabbit.core.value.InternalValue)7 ItemExistsException (javax.jcr.ItemExistsException)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)5 PropertyState (org.apache.jackrabbit.core.state.PropertyState)5 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)5 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)5 NodeState (org.apache.jackrabbit.core.state.NodeState)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4