You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Felix Meschberger (JIRA)" <ji...@apache.org> on 2007/12/03 12:02:43 UTC

[jira] Commented: (SLING-109) Replace Resource.getRawData and .getObject methods by better API

    [ https://issues.apache.org/jira/browse/SLING-109?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12547792 ] 

Felix Meschberger commented on SLING-109:
-----------------------------------------

After some more discussion on the list (see link in the initial comment) highlighting sortcomings this interface extension model such as missing extensibility and keeping a single point reference to the JCR API in the new NodeProvider interface, we seem to settle on a further possibility: Define a new adapter method in the Resource interface:

     <AdapterType> AdapterType adaptTo(Class<AdapterType> adapterType);

This method returns the resource adapted to another type. This allows the implementation to dynamically support adapters upon support. For example the microsling JcrNodeResource might implement the method as follows (simplified, ignoring exceptions) :

    <AdapterType> AdapterType adaptTo(Class<AdapterType> adapterType) {
        if (adapterType == Node.class) {
            return (AdapterType) node;
        } else if (adapterType == InputStream.class) {
            return (AdapterType) getInputStream();
        }
        return null;
    }

The Sling JcrNodeResoure supporting URLs and object mapping might be :

    <AdapterType> AdapterType adaptTo(Class<AdapterType> adapterType) {
        if (adapterType == Node.class) {
            return (AdapterType) node;
        } else if (adapterType == InputStream.class) {
            return (AdapterType) getInputStream();
        } else if (adapterType == URL.class) {
            return (AdapterType) getURL();
        } else if (adapterType == Object.class || adapterType.isInstance(getObject())) {
            return (AdapterType) getObject();
        }
        return null;
    }


> Replace Resource.getRawData and .getObject methods by better API
> ----------------------------------------------------------------
>
>                 Key: SLING-109
>                 URL: https://issues.apache.org/jira/browse/SLING-109
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>            Reporter: Felix Meschberger
>            Assignee: Felix Meschberger
>             Fix For: 2.0.0
>
>
> David brought up an issue on the dev list [1] regarding the Resource.getRawData() method. In short, David suggests to replace the getRawData method with a signature, which more closely reflects the definition of Sling as a web application framework for JCR. The general consesus on the list is that the getRawData() method is badly named and that we should have a method which shows the JCR integration yet does not tie the API too much into JCR.
> So I propose the following:
>   > Remove the getRawData() and getObject() methods from the Resource interface
>   > Add new interfaces NodeResource and ObjectResource:
>     // resources backed by JCR nodes
>     public interface NodeResource extends Resource {
>         Node getNode();
>     }
>     // resources mapped using JCR OCM for example
>     public interface ObjectResource extends Resource {
>         Object getObject();
>     }
> This way, we have the Resource interfaces completely storage-agnostic and provide for a wide range of extensions, such as an URLResource, which may be backed by a URL such as an entry in an OSGi bundle.
> [1] http://www.mail-archive.com/sling-dev@incubator.apache.org/msg00906.html

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.