org.apache.sling.api.resource.ResourceWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aem-sdk-api Show documentation
Show all versions of aem-sdk-api Show documentation
The Adobe Experience Manager SDK
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sling.api.resource;
import java.util.Iterator;
import org.jetbrains.annotations.NotNull;
/**
* The ResourceWrapper
is a wrapper for any Resource
* delegating all method calls to the wrapped resource by default. Extensions of
* this class may overwrite any method to return different values as
* appropriate.
*/
public class ResourceWrapper implements Resource {
/** the wrapped resource */
private final @NotNull Resource resource;
/**
* Creates a new wrapper instance delegating all method calls to the given
* resource
.
* @param resource The resource to wrap
*/
public ResourceWrapper(@NotNull final Resource resource) {
this.resource = resource;
}
/**
* Returns the Resource
wrapped by this instance. This method
* can be overwritten by subclasses if required. All methods implemented by
* this class use this method to get the resource object.
* @return The resource wrapped by this instance.
*/
public @NotNull Resource getResource() {
return resource;
}
/**
* Returns the value of calling getPath
on the
* {@link #getResource() wrapped resource}.
*/
@Override
public @NotNull String getPath() {
return getResource().getPath();
}
/**
* Returns the value of calling getName
on the
* {@link #getResource() wrapped resource}.
*
* @since 2.1.0 (Sling API Bundle 2.1.0)
*/
@Override
public @NotNull String getName() {
return getResource().getName();
}
/**
* Returns the value of calling getParent
on the
* {@link #getResource() wrapped resource}.
*
* @since 2.1.0 (Sling API Bundle 2.1.0)
*/
@Override
public Resource getParent() {
return getResource().getParent();
}
/**
* Returns the value of calling getChild
on the
* {@link #getResource() wrapped resource}.
*
* @since 2.1.0 (Sling API Bundle 2.1.0)
*/
@Override
public Resource getChild(@NotNull String relPath) {
return getResource().getChild(relPath);
}
/**
* Returns the value of calling listChildren
on the
* {@link #getResource() wrapped resource}.
*
* @since 2.1.0 (Sling API Bundle 2.1.0)
*/
@Override
public @NotNull Iterator listChildren() {
return getResource().listChildren();
}
/**
* @see org.apache.sling.api.resource.Resource#getChildren()
*/
@Override
public @NotNull Iterable getChildren() {
return getResource().getChildren();
}
/**
* Returns the value of calling getResourceMetadata
on the
* {@link #getResource() wrapped resource}.
*/
@Override
public @NotNull ResourceMetadata getResourceMetadata() {
return getResource().getResourceMetadata();
}
/**
* Returns the value of calling getResourceResolver
on the
* {@link #getResource() wrapped resource}.
*/
@Override
public @NotNull ResourceResolver getResourceResolver() {
return getResource().getResourceResolver();
}
/**
* Returns the value of calling getResourceType
on the
* {@link #getResource() wrapped resource}.
*/
@Override
public @NotNull String getResourceType() {
return getResource().getResourceType();
}
/**
* Returns the value of calling getResourceSuperType
on the
* {@link #getResource() wrapped resource}.
*/
@Override
public String getResourceSuperType() {
return getResource().getResourceSuperType();
}
/**
* Returns the value of calling hasChildren
on the
* {@link #getResource() wrapped resource}.
*
* @since 2.4.4 (Sling API Bundle 2.5.0)
*/
@Override
public boolean hasChildren() {
return getResource().hasChildren();
}
/**
* Returns the value of calling isResourceType
on the
* {@link #getResource() wrapped resource}.
*
* @since 2.1.0 (Sling API Bundle 2.1.0)
*/
@Override
public boolean isResourceType(final String resourceType) {
return getResource().isResourceType(resourceType);
}
/**
* Returns the value of calling adaptTo
on the
* {@link #getResource() wrapped resource}.
*/
@Override
@SuppressWarnings("null")
public AdapterType adaptTo(@NotNull Class type) {
return getResource().adaptTo(type);
}
/**
* @see org.apache.sling.api.resource.Resource#getValueMap()
*/
@Override
public @NotNull ValueMap getValueMap() {
return getResource().getValueMap();
}
/**
* Returns a string representation of this wrapper consisting of the class'
* simple name, the {@link #getResourceType() resource type} and
* {@link #getPath() path} as well as the string representation of the
* {@link #getResource() wrapped resource}.
*/
@Override
public String toString() {
final String simpleName = getClass().getSimpleName();
final String className = (simpleName.length() > 0) ? simpleName : getClass().getName();
return className + ", type=" + getResourceType()
+ ", path=" + getPath() + ", resource=[" + getResource() + "]";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy