Search in sources :

Example 11 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeImpl method setMixinTypesProperty.

void setMixinTypesProperty(Set<Name> mixinNames) throws RepositoryException {
    NodeState thisState = data.getNodeState();
    // get or create jcr:mixinTypes property
    PropertyImpl prop;
    if (thisState.hasPropertyName(NameConstants.JCR_MIXINTYPES)) {
        prop = (PropertyImpl) itemMgr.getItem(new PropertyId(thisState.getNodeId(), NameConstants.JCR_MIXINTYPES));
    } else {
        // find definition for the jcr:mixinTypes property and create property
        PropertyDefinitionImpl def = getApplicablePropertyDefinition(NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true, true);
        prop = createChildProperty(NameConstants.JCR_MIXINTYPES, PropertyType.NAME, def);
    }
    if (mixinNames.isEmpty()) {
        // purge empty jcr:mixinTypes property
        removeChildProperty(NameConstants.JCR_MIXINTYPES);
        return;
    }
    // call internalSetValue for setting the jcr:mixinTypes property
    // to avoid checking of the 'protected' flag
    InternalValue[] vals = new InternalValue[mixinNames.size()];
    Iterator<Name> iter = mixinNames.iterator();
    int cnt = 0;
    while (iter.hasNext()) {
        vals[cnt++] = InternalValue.create(iter.next());
    }
    prop.internalSetValue(vals, PropertyType.NAME);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyId(org.apache.jackrabbit.core.id.PropertyId) Name(org.apache.jackrabbit.spi.Name)

Example 12 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeImpl method getReferences.

/**
 * {@inheritDoc}
 */
public PropertyIterator getReferences(String name) throws RepositoryException {
    // check state of this instance
    sanityCheck();
    try {
        if (stateMgr.hasNodeReferences(getNodeId())) {
            NodeReferences refs = stateMgr.getNodeReferences(getNodeId());
            // refs.getReferences() returns a list of PropertyId's
            List<PropertyId> idList = refs.getReferences();
            if (name != null) {
                Name qName;
                try {
                    qName = sessionContext.getQName(name);
                } catch (NameException e) {
                    throw new RepositoryException("invalid property name: " + name, e);
                }
                ArrayList<PropertyId> filteredList = new ArrayList<PropertyId>(idList.size());
                for (PropertyId propId : idList) {
                    if (propId.getName().equals(qName)) {
                        filteredList.add(propId);
                    }
                }
                idList = filteredList;
            }
            return new LazyItemIterator(sessionContext, idList);
        } else {
            // there are no references, return empty iterator
            return PropertyIteratorAdapter.EMPTY;
        }
    } catch (ItemStateException e) {
        String msg = "Unable to retrieve REFERENCE properties that refer to " + id;
        log.debug(msg);
        throw new RepositoryException(msg, e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ArrayList(java.util.ArrayList) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) Name(org.apache.jackrabbit.spi.Name) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 13 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeImpl method getOrCreateProperty.

/**
 * @param name
 * @param type
 * @param multiValued
 * @param exactTypeMatch
 * @param status
 * @return
 * @throws ConstraintViolationException if no applicable property definition
 *                                      could be found
 * @throws RepositoryException          if another error occurs
 */
protected synchronized PropertyImpl getOrCreateProperty(Name name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException {
    status.clear();
    if (isNew() && !hasProperty(name)) {
        // this is a new node and the property does not exist yet
        // -> no need to check item manager
        PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
        PropertyImpl prop = createChildProperty(name, type, def);
        status.set(CREATED);
        return prop;
    }
    /*
         * Please note, that this implementation does not win a price for beauty
         * or speed. It's never a good idea to use exceptions for semantical
         * control flow.
         * However, compared to the previous version, this one is thread save
         * and makes the test/get block atomic in respect to transactional
         * commits. the test/set can still fail.
         *
         * Old Version:

            NodeState thisState = (NodeState) state;
            if (thisState.hasPropertyName(name)) {
                /**
                 * the following call will throw ItemNotFoundException if the
                 * current session doesn't have read access
                 /
                return getProperty(name);
            }
            [...create block...]

        */
    PropertyId propId = new PropertyId(getNodeId(), name);
    try {
        return (PropertyImpl) itemMgr.getItem(propId);
    } catch (AccessDeniedException ade) {
        throw new ItemNotFoundException(name.toString());
    } catch (ItemNotFoundException e) {
        // does not exist yet or has been removed transiently:
        // find definition for the specified property and (re-)create property
        PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
        PropertyImpl prop;
        if (stateMgr.hasTransientItemStateInAttic(propId)) {
            // remove from attic
            try {
                stateMgr.disposeTransientItemStateInAttic(stateMgr.getAttic().getItemState(propId));
            } catch (ItemStateException ise) {
                // shouldn't happen because we checked if it is in the attic
                throw new RepositoryException(ise);
            }
            prop = (PropertyImpl) itemMgr.getItem(propId);
            PropertyState state = (PropertyState) prop.getOrCreateTransientItemState();
            state.setMultiValued(multiValued);
            state.setType(type);
            getNodeState().addPropertyName(name);
        } else {
            prop = createChildProperty(name, type, def);
        }
        status.set(CREATED);
        return prop;
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) ItemNotFoundException(javax.jcr.ItemNotFoundException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 14 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class BatchedItemOperations method createPropertyState.

/**
 * Creates a new property based on the given definition.
 * <p>
 * Note that access rights are <b><i>not</i></b> enforced!
 * <p>
 * <b>Precondition:</b> the state manager needs to be in edit mode.
 *
 * @param parent
 * @param propName
 * @param type
 * @param def
 * @return
 * @throws ItemExistsException
 * @throws RepositoryException
 */
public PropertyState createPropertyState(NodeState parent, Name propName, int type, QPropertyDefinition def) throws ItemExistsException, RepositoryException {
    // check for name collisions with existing properties
    if (parent.hasPropertyName(propName)) {
        PropertyId errorId = new PropertyId(parent.getNodeId(), propName);
        throw new ItemExistsException(safeGetJCRPath(errorId));
    }
    // create property
    PropertyState prop = stateMgr.createNew(propName, parent.getNodeId());
    if (def.getRequiredType() != PropertyType.UNDEFINED) {
        prop.setType(def.getRequiredType());
    } else if (type != PropertyType.UNDEFINED) {
        prop.setType(type);
    } else {
        prop.setType(PropertyType.STRING);
    }
    prop.setMultiValued(def.isMultiple());
    // compute system generated values if necessary
    new NodeTypeInstanceHandler(session.getUserID()).setDefaultValues(prop, parent, def);
    // now add new property entry to parent
    parent.addPropertyName(propName);
    // store parent
    stateMgr.store(parent);
    return prop;
}
Also used : ItemExistsException(javax.jcr.ItemExistsException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 15 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class HierarchyManagerImpl method resolvePath.

// -------------------------------------------------------< implementation >
/**
 * Internal implementation that iteratively resolves a path into an item.
 *
 * @param elements path elements
 * @param next index of next item in <code>elements</code> to inspect
 * @param id id of item at path <code>elements[0]</code>..<code>elements[next - 1]</code>
 * @param typesAllowed one of <code>RETURN_ANY</code>, <code>RETURN_NODE</code>
 *                     or <code>RETURN_PROPERTY</code>
 * @return id or <code>null</code>
 * @throws ItemStateException if an intermediate item state is not found
 * @throws MalformedPathException if building an intermediate path fails
 */
protected ItemId resolvePath(Path.Element[] elements, int next, ItemId id, int typesAllowed) throws ItemStateException, MalformedPathException {
    PathBuilder builder = new PathBuilder();
    for (int i = 0; i < next; i++) {
        builder.addLast(elements[i]);
    }
    for (int i = next; i < elements.length; i++) {
        Path.Element elem = elements[i];
        NodeId parentId = (NodeId) id;
        id = null;
        Name name = elem.getName();
        int index = elem.getIndex();
        if (index == 0) {
            index = 1;
        }
        int typeExpected = typesAllowed;
        if (i < elements.length - 1) {
            // intermediate items must always be nodes
            typeExpected = RETURN_NODE;
        }
        NodeState parentState = (NodeState) getItemState(parentId);
        if ((typeExpected & RETURN_NODE) != 0) {
            ChildNodeEntry nodeEntry = getChildNodeEntry(parentState, name, index);
            if (nodeEntry != null) {
                id = nodeEntry.getId();
            }
        }
        if (id == null && (typeExpected & RETURN_PROPERTY) != 0) {
            if (parentState.hasPropertyName(name) && (index <= 1)) {
                // property
                id = new PropertyId(parentState.getNodeId(), name);
            }
        }
        if (id == null) {
            break;
        }
        builder.addLast(elements[i]);
        pathResolved(id, builder);
    }
    return id;
}
Also used : Path(org.apache.jackrabbit.spi.Path) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Aggregations

PropertyId (org.apache.jackrabbit.core.id.PropertyId)59 Name (org.apache.jackrabbit.spi.Name)29 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 NodeState (org.apache.jackrabbit.core.state.NodeState)23 RepositoryException (javax.jcr.RepositoryException)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)16 InternalValue (org.apache.jackrabbit.core.value.InternalValue)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 HashSet (java.util.HashSet)10 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)7 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ItemId (org.apache.jackrabbit.core.id.ItemId)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)4