Search in sources :

Example 16 with QPropertyDefinition

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

the class ItemDefinitionProviderImpl method getMatchingPropDef.

private static QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type) {
    QPropertyDefinition match = null;
    for (int i = 0; i < defs.length; i++) {
        QItemDefinition qDef = defs[i];
        if (!qDef.definesNode()) {
            QPropertyDefinition pd = (QPropertyDefinition) qDef;
            int reqType = pd.getRequiredType();
            // match type
            if (reqType == PropertyType.UNDEFINED || type == PropertyType.UNDEFINED || reqType == type) {
                if (match == null) {
                    match = pd;
                } else {
                    // the one we've already got
                    if (match.getRequiredType() != pd.getRequiredType()) {
                        if (match.getRequiredType() == PropertyType.UNDEFINED) {
                            // found better match
                            match = pd;
                        }
                    } else {
                        if (match.isMultiple() && !pd.isMultiple()) {
                            // found better match
                            match = pd;
                        }
                    }
                }
                if (match.getRequiredType() != PropertyType.UNDEFINED && !match.isMultiple()) {
                    // found best possible match, get outta here
                    return match;
                }
            }
        }
    }
    return match;
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Example 17 with QPropertyDefinition

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

the class NodeTypeManagerImpl method getPropertyDefinition.

/**
     * Retrieve the <code>PropertyDefinition</code> for the given
     * <code>QPropertyDefinition</code>.
     *
     * @param def
     * @return
     */
@Override
public PropertyDefinition getPropertyDefinition(QPropertyDefinition def) {
    synchronized (pdCache) {
        PropertyDefinition pdi = pdCache.get(def);
        if (pdi == null) {
            pdi = new PropertyDefinitionImpl(def, this, getNamePathResolver(), valueFactory);
            pdCache.put(def, pdi);
        }
        return pdi;
    }
}
Also used : PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 18 with QPropertyDefinition

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

the class ItemDefinitionProviderImpl method getMatchingPropDef.

private static QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type, boolean multiValued, boolean throwWhenAmbiguous) throws ConstraintViolationException {
    QPropertyDefinition match = null;
    for (int i = 0; i < defs.length; i++) {
        QItemDefinition qDef = defs[i];
        if (!qDef.definesNode()) {
            QPropertyDefinition pd = (QPropertyDefinition) qDef;
            int reqType = pd.getRequiredType();
            // match type
            if (reqType == PropertyType.UNDEFINED || type == PropertyType.UNDEFINED || reqType == type) {
                // match multiValued flag
                if (multiValued == pd.isMultiple()) {
                    // found match
                    if (pd.getRequiredType() != PropertyType.UNDEFINED) {
                        if (match != null && throwWhenAmbiguous) {
                            throw new ConstraintViolationException("ambiguous property definitions found: " + match + " vs " + pd);
                        }
                        // thus obviously specified a String.
                        if (match == null || match.getRequiredType() != PropertyType.STRING) {
                            // found best possible match
                            match = pd;
                        }
                    } else {
                        if (match == null) {
                            match = pd;
                        }
                    }
                }
            }
        }
    }
    return match;
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Example 19 with QPropertyDefinition

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

the class NodeImpl method createChildProperty.

/**
     * Creates a new property with the given name and <code>type</code> hint and
     * property definition. If the given property definition is not of type
     * <code>UNDEFINED</code>, then it takes precedence over the
     * <code>type</code> hint.
     *
     * @param name the name of the property to create.
     * @param type the type hint.
     * @param def  the associated property definition.
     * @return the property instance.
     * @throws RepositoryException if the property cannot be created.
     */
protected synchronized PropertyImpl createChildProperty(Name name, int type, PropertyDefinitionImpl def) throws RepositoryException {
    // create a new property state
    PropertyState propState;
    try {
        QPropertyDefinition propDef = def.unwrap();
        if (def.getRequiredType() != PropertyType.UNDEFINED) {
            type = def.getRequiredType();
        }
        propState = stateMgr.createTransientPropertyState(getNodeId(), name, ItemState.STATUS_NEW);
        propState.setType(type);
        propState.setMultiValued(propDef.isMultiple());
        // compute system generated values if necessary
        String userId = sessionContext.getSessionImpl().getUserID();
        new NodeTypeInstanceHandler(userId).setDefaultValues(propState, data.getNodeState(), propDef);
    } catch (ItemStateException ise) {
        String msg = "failed to add property " + name + " to " + this;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
    // create Property instance wrapping new property state
    // NOTE: since the property is not yet connected to its parent, avoid
    // calling ItemManager#getItem(ItemId) which may include a permission
    // check (with subsequent usage of the hierarachy-mgr -> error).
    // just let the mgr create the new property that is known to exist and
    // which has not been accessed before.
    PropertyImpl prop = (PropertyImpl) itemMgr.createItemInstance(propState);
    // modify the state of 'this', i.e. the parent node
    NodeState thisState = (NodeState) getOrCreateTransientItemState();
    // add new property entry
    thisState.addPropertyName(name);
    return prop;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) RepositoryException(javax.jcr.RepositoryException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 20 with QPropertyDefinition

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

the class VirtualNodeTypeStateProvider method createNodeTypeState.

/**
     * Creates a node type state
     *
     * @param parent
     * @param ntDef
     * @return
     * @throws RepositoryException
     */
private VirtualNodeState createNodeTypeState(VirtualNodeState parent, QNodeTypeDefinition ntDef) throws RepositoryException {
    NodeId id = calculateStableId(ntDef.getName().toString());
    VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), id, NameConstants.NT_NODETYPE);
    // add properties
    ntState.setPropertyValue(NameConstants.JCR_NODETYPENAME, InternalValue.create(ntDef.getName()));
    ntState.setPropertyValues(NameConstants.JCR_SUPERTYPES, PropertyType.NAME, InternalValue.create(ntDef.getSupertypes()));
    ntState.setPropertyValue(NameConstants.JCR_ISMIXIN, InternalValue.create(ntDef.isMixin()));
    ntState.setPropertyValue(NameConstants.JCR_HASORDERABLECHILDNODES, InternalValue.create(ntDef.hasOrderableChildNodes()));
    if (ntDef.getPrimaryItemName() != null) {
        ntState.setPropertyValue(NameConstants.JCR_PRIMARYITEMNAME, InternalValue.create(ntDef.getPrimaryItemName()));
    }
    // add property defs
    QPropertyDefinition[] propDefs = ntDef.getPropertyDefs();
    for (int i = 0; i < propDefs.length; i++) {
        VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i], ntDef, i);
        ntState.addChildNodeEntry(NameConstants.JCR_PROPERTYDEFINITION, pdState.getNodeId());
        // add as hard reference
        ntState.addStateReference(pdState);
    }
    // add child node defs
    QNodeDefinition[] cnDefs = ntDef.getChildNodeDefs();
    for (int i = 0; i < cnDefs.length; i++) {
        VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i], ntDef, i);
        ntState.addChildNodeEntry(NameConstants.JCR_CHILDNODEDEFINITION, cnState.getNodeId());
        // add as hard reference
        ntState.addStateReference(cnState);
    }
    return ntState;
}
Also used : VirtualNodeState(org.apache.jackrabbit.core.virtual.VirtualNodeState) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) NodeId(org.apache.jackrabbit.core.id.NodeId) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

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