Search in sources :

Example 1 with PropertyDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate in project jackrabbit-oak by apache.

the class SessionImpl method getItemInternal.

@CheckForNull
private ItemImpl<?> getItemInternal(@Nonnull String oakPath) throws RepositoryException {
    checkAlive();
    ItemDelegate item = sd.getItem(oakPath);
    if (item instanceof NodeDelegate) {
        return NodeImpl.createNode((NodeDelegate) item, sessionContext);
    } else if (item instanceof PropertyDelegate) {
        return new PropertyImpl((PropertyDelegate) item, sessionContext);
    } else {
        return null;
    }
}
Also used : NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) ItemDelegate(org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate) CheckForNull(javax.annotation.CheckForNull)

Example 2 with PropertyDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate in project jackrabbit-oak by apache.

the class NodeImpl method setMixins.

/**
     * Simplified implementation of the {@link org.apache.jackrabbit.api.JackrabbitNode#setMixins(String[])}
     * method that adds all mixin types that are not yet present on this node
     * and removes all mixins that are no longer contained in the specified
     * array. Note, that this implementation will not work exactly like the
     * variant in Jackrabbit 2.x which first created the effective node type
     * and adjusted the set of child items accordingly.
     *
     * @param mixinNames
     * @throws RepositoryException
     */
@Override
public void setMixins(String[] mixinNames) throws RepositoryException {
    final Set<String> oakTypeNames = newLinkedHashSet();
    for (String mixinName : mixinNames) {
        oakTypeNames.add(getOakName(checkNotNull(mixinName)));
    }
    sessionDelegate.performVoid(new ItemWriteOperation<Void>("setMixins") {

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut()) {
                throw new VersionException(format("Cannot set mixin types. Node [%s] is checked in.", getNodePath()));
            }
            // check for NODE_TYPE_MANAGEMENT permission here as we cannot
            // distinguish between a combination of removeMixin and addMixin
            // and Node#remove plus subsequent addNode when it comes to
            // autocreated properties like jcr:create, jcr:uuid and so forth.
            PropertyDelegate mixinProp = dlg.getPropertyOrNull(JCR_MIXINTYPES);
            if (mixinProp != null) {
                sessionContext.getAccessManager().checkPermissions(dlg.getTree(), mixinProp.getPropertyState(), Permissions.NODE_TYPE_MANAGEMENT);
            }
        }

        @Override
        public void performVoid() throws RepositoryException {
            dlg.setMixins(oakTypeNames);
        }
    });
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionException(javax.jcr.version.VersionException) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate)

Example 3 with PropertyDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate in project jackrabbit-oak by apache.

the class NodeImpl method createNode.

@Nonnull
public static NodeImpl<? extends NodeDelegate> createNode(@Nonnull NodeDelegate delegate, @Nonnull SessionContext context) throws RepositoryException {
    PropertyDelegate pd = delegate.getPropertyOrNull(JCR_PRIMARYTYPE);
    String type = pd != null ? pd.getString() : null;
    if (JcrConstants.NT_VERSION.equals(type)) {
        VersionManagerDelegate vmd = VersionManagerDelegate.create(context.getSessionDelegate());
        return new VersionImpl(vmd.createVersion(delegate), context);
    } else if (JcrConstants.NT_VERSIONHISTORY.equals(type)) {
        VersionManagerDelegate vmd = VersionManagerDelegate.create(context.getSessionDelegate());
        return new VersionHistoryImpl(vmd.createVersionHistory(delegate), context);
    } else {
        return new NodeImpl<NodeDelegate>(delegate, context);
    }
}
Also used : VersionHistoryImpl(org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl) VersionManagerDelegate(org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate) VersionImpl(org.apache.jackrabbit.oak.jcr.version.VersionImpl) Nonnull(javax.annotation.Nonnull)

Aggregations

PropertyDelegate (org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate)3 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)2 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 RepositoryException (javax.jcr.RepositoryException)1 VersionException (javax.jcr.version.VersionException)1 ItemDelegate (org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate)1 VersionManagerDelegate (org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate)1 VersionHistoryImpl (org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl)1 VersionImpl (org.apache.jackrabbit.oak.jcr.version.VersionImpl)1