public Type adaptTo()

in src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java [129:157]


    public <Type> Type adaptTo(Class<Type> type) {
        if (type == Node.class || type == Item.class) {
            return (Type) getNode(); // unchecked cast
        } else if (type == InputStream.class) {
            return (Type) getInputStream(); // unchecked cast
        } else if (type == Map.class || type == ValueMap.class) {
            AccessLogger.incrementUsage(this.getResourceResolver(), "adaptToValueMap", path);
            return (Type) new JcrValueMap(getNode(), this.helper);
        } else if (type == ModifiableValueMap.class) {
            // check write
            try {
                getNode().getSession().checkPermission(getPath(), "set_property");
                return (Type) new JcrModifiableValueMap(getNode(), this.helper);
            } catch (AccessControlException ace) {
                // the user has no write permission, cannot adapt
                LOGGER.debug(
                        "adaptTo(ModifiableValueMap): Cannot set properties on {}",
                        this);
            } catch (RepositoryException e) {
                // some other problem, cannot adapt
                LOGGER.debug(
                        "adaptTo(ModifiableValueMap): Unexpected problem for {}",
                        this);
            }
        }

        // fall back to default implementation
        return super.adaptTo(type);
    }