Search in sources :

Example 46 with QPropertyDefinition

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

the class NodeTypeImpl method canSetProperty.

/**
     * {@inheritDoc}
     */
public boolean canSetProperty(String propertyName, Value value) {
    if (value == null) {
        // setting a property to null is equivalent of removing it
        return canRemoveItem(propertyName);
    }
    try {
        Name name = resolver.getQName(propertyName);
        QPropertyDefinition def;
        try {
            // try to get definition that matches the given value type
            def = ent.getApplicablePropertyDef(name, value.getType(), false);
        } catch (ConstraintViolationException cve) {
            // fallback: ignore type
            def = ent.getApplicablePropertyDef(name, PropertyType.UNDEFINED, false);
        }
        if (def.isProtected()) {
            return false;
        }
        if (def.isMultiple()) {
            return false;
        }
        int targetType;
        if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
            // type conversion required
            targetType = def.getRequiredType();
        } else {
            // no type conversion required
            targetType = value.getType();
        }
        // perform type conversion as necessary and create InternalValue
        // from (converted) Value
        InternalValue internalValue;
        if (targetType != value.getType()) {
            // type conversion required
            Value targetVal = ValueHelper.convert(value, targetType, valueFactory);
            internalValue = InternalValue.create(targetVal, resolver, store);
        } else {
            // no type conversion required
            internalValue = InternalValue.create(value, resolver, store);
        }
        EffectiveNodeType.checkSetPropertyValueConstraints(def, new InternalValue[] { internalValue });
        return true;
    } catch (NameException be) {
    // implementation specific exception, fall through
    } catch (RepositoryException re) {
    // fall through
    }
    return false;
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name)

Example 47 with QPropertyDefinition

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

the class NodeTypeWriter method addNodeTypeDef.

/**
     * Builds a node type definition element under the current element.
     *
     * @param def node type definition
     * @throws RepositoryException       if the default property values
     *                                   cannot be serialized
     * @throws NamespaceException if the node type definition contains
     *                                   invalid namespace references
     */
private void addNodeTypeDef(QNodeTypeDefinition def) throws NamespaceException, RepositoryException {
    builder.startElement(Constants.NODETYPE_ELEMENT);
    // simple attributes
    builder.setAttribute(Constants.NAME_ATTRIBUTE, resolver.getJCRName(def.getName()));
    builder.setAttribute(Constants.ISMIXIN_ATTRIBUTE, def.isMixin());
    builder.setAttribute(Constants.ISQUERYABLE_ATTRIBUTE, def.isQueryable());
    builder.setAttribute(Constants.ISABSTRACT_ATTRIBUTE, def.isAbstract());
    builder.setAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE, def.hasOrderableChildNodes());
    // primary item name
    Name item = def.getPrimaryItemName();
    if (item != null) {
        builder.setAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE, resolver.getJCRName(item));
    } else {
        builder.setAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE, "");
    }
    // supertype declarations
    Name[] supertypes = def.getSupertypes();
    if (supertypes.length > 0) {
        builder.startElement(Constants.SUPERTYPES_ELEMENT);
        for (Name supertype : supertypes) {
            builder.addContentElement(Constants.SUPERTYPE_ELEMENT, resolver.getJCRName(supertype));
        }
        builder.endElement();
    }
    // property definitions
    QPropertyDefinition[] properties = def.getPropertyDefs();
    for (QPropertyDefinition property : properties) {
        addPropDef(property);
    }
    // child node definitions
    QNodeDefinition[] nodes = def.getChildNodeDefs();
    for (QNodeDefinition node : nodes) {
        addChildNodeDef(node);
    }
    builder.endElement();
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 48 with QPropertyDefinition

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

the class PropertyTypeRegistry method nodeTypeRegistered.

public void nodeTypeRegistered(Name ntName) {
    try {
        QNodeTypeDefinition def = registry.getNodeTypeDef(ntName);
        QPropertyDefinition[] propDefs = def.getPropertyDefs();
        synchronized (typeMapping) {
            for (QPropertyDefinition propDef : propDefs) {
                int type = propDef.getRequiredType();
                if (!propDef.definesResidual() && type != PropertyType.UNDEFINED) {
                    Name name = propDef.getName();
                    // only remember defined property types
                    TypeMapping[] types = typeMapping.get(name);
                    if (types == null) {
                        types = new TypeMapping[1];
                    } else {
                        TypeMapping[] tmp = new TypeMapping[types.length + 1];
                        System.arraycopy(types, 0, tmp, 0, types.length);
                        types = tmp;
                    }
                    types[types.length - 1] = new TypeMapping(ntName, type, propDef.isMultiple());
                    typeMapping.put(name, types);
                }
            }
        }
    } catch (NoSuchNodeTypeException e) {
        log.error("Unable to get newly registered node type definition for name: " + ntName);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 49 with QPropertyDefinition

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

the class TestAll method testDoubleProperty.

/** Test for the <code>double</code> property definition type. */
public void testDoubleProperty() {
    QPropertyDefinition def = getPropDef("propertyNodeType", "doubleProperty");
    assertEquals("doubleProperty requiredType", PropertyType.DOUBLE, def.getRequiredType());
    assertEquals("doubleProperty valueConstraints", 3, def.getValueConstraints().length);
    assertEquals("doubleProperty valueConstraints[0]", "[,0.0)", (def.getValueConstraints())[0].getString());
    assertEquals("doubleProperty valueConstraints[1]", "(1.0,2.0)", (def.getValueConstraints())[1].getString());
    assertEquals("doubleProperty valueConstraints[2]", "(3.0,]", (def.getValueConstraints())[2].getString());
    assertEquals("doubleProperty defaultValues", 1, def.getDefaultValues().length);
    assertEquals("doubleProperty defaultValues[0]", "1.5", getDefaultValue(def, 0));
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition)

Example 50 with QPropertyDefinition

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

the class TestAll method testMultipleProperty.

/** Test for the <code>multiple</code> property definition attribute. */
public void testMultipleProperty() {
    QPropertyDefinition def = getPropDef("propertyNodeType", "multipleProperty");
    assertEquals("multipleProperty multiple", true, def.isMultiple());
}
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