Search in sources :

Example 11 with QPropertyDefinition

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

the class NodeTypeDefinitionFactory method create.

/**
     * Create a new JCR node type definition from the given
     * <code>QNodeTypeDefinition</code>.
     *
     * @param qNtd A SPI node type definition.
     * @return the corresponding JCR node type definition.
     * @throws RepositoryException if an error occurs.
     */
@SuppressWarnings("unchecked")
public NodeTypeDefinition create(QNodeTypeDefinition qNtd) throws RepositoryException {
    NodeTypeTemplate nt = ntMgr.createNodeTypeTemplate();
    nt.setName(getJCRName(qNtd.getName()));
    nt.setDeclaredSuperTypeNames(getJCRNames(qNtd.getSupertypes()));
    nt.setAbstract(qNtd.isAbstract());
    nt.setMixin(qNtd.isMixin());
    nt.setOrderableChildNodes(qNtd.hasOrderableChildNodes());
    nt.setPrimaryItemName(getJCRName(qNtd.getPrimaryItemName()));
    nt.setQueryable(qNtd.isQueryable());
    List nodeDefs = nt.getNodeDefinitionTemplates();
    for (QNodeDefinition qNd : qNtd.getChildNodeDefs()) {
        nodeDefs.add(create(qNd));
    }
    List propDefs = nt.getPropertyDefinitionTemplates();
    for (QPropertyDefinition qPd : qNtd.getPropertyDefs()) {
        propDefs.add(create(qPd));
    }
    return nt;
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) List(java.util.List) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition)

Example 12 with QPropertyDefinition

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

the class QNodeTypeDefinitionImpl method createQPropertyDefinitions.

private static QPropertyDefinition[] createQPropertyDefinitions(Name declName, PropertyDefinition[] pds, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    if (pds == null || pds.length == 0) {
        return QPropertyDefinition.EMPTY_ARRAY;
    }
    QPropertyDefinition[] declaredPropDefs = new QPropertyDefinition[pds.length];
    for (int i = 0; i < pds.length; i++) {
        PropertyDefinition propDef = pds[i];
        Name name = propDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(propDef.getName());
        // check if propDef provides declaring node type and if it matches 'this' one.
        if (propDef.getDeclaringNodeType() != null) {
            if (!declName.equals(resolver.getQName(propDef.getDeclaringNodeType().getName()))) {
                throw new RepositoryException("Property definition specified invalid declaring nodetype: " + propDef.getDeclaringNodeType().getName() + ", but should be " + declName);
            }
        }
        QValue[] defVls = propDef.getDefaultValues() == null ? QValue.EMPTY_ARRAY : ValueFormat.getQValues(propDef.getDefaultValues(), resolver, qValueFactory);
        String[] jcrConstraints = propDef.getValueConstraints();
        QValueConstraint[] constraints = QValueConstraint.EMPTY_ARRAY;
        if (jcrConstraints != null && jcrConstraints.length > 0) {
            constraints = new QValueConstraint[jcrConstraints.length];
            for (int j = 0; j < constraints.length; j++) {
                constraints[j] = ValueConstraint.create(propDef.getRequiredType(), jcrConstraints[j], resolver);
            }
        }
        declaredPropDefs[i] = new QPropertyDefinitionImpl(name, declName, propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), defVls, propDef.isMultiple(), propDef.getRequiredType(), constraints, propDef.getAvailableQueryOperators(), propDef.isFullTextSearchable(), propDef.isQueryOrderable());
    }
    return declaredPropDefs;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition)

Example 13 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 14 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)

Example 15 with QPropertyDefinition

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

the class TestAll method testCopyItem.

/** Test for the <code>copy</code> parent version action. */
public void testCopyItem() {
    QPropertyDefinition def = getPropDef("itemNodeType", "copyItem");
    assertEquals("copyItem onParentVersion", OnParentVersionAction.COPY, def.getOnParentVersion());
}
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