jsr-333
  1. jsr-333
  2. JSR_333-18

Add convenient access to property value from node

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: api
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      18

      Description

      In Apache Sling we added a method that allows access to the Value of a property
      in a convenient way.

      http://sling.apache.org/apidocs/sling5/org/apache/sling/api/resource/ValueMap.html

      I would like to propose that we add something similar to the Node interface that
      allows access (potentially even straight to the string representation of the value).

        Activity

        Hide
        Peeter Piegaze added a comment -

        Trying again:

        public <T> T getPropertyAs(String propertyName, Class<T> type);

        public <T> T getPropertyAs(String propertyName, T defaultValue);

        public String getPropertyAsString(String propertyName);

        public <T> T[] getPropertyAsArray(String propertyName, Class<T> type);

        public String[] getPropertyAsArray(String propertyName);

        Show
        Peeter Piegaze added a comment - Trying again: public <T> T getPropertyAs(String propertyName, Class<T> type); public <T> T getPropertyAs(String propertyName, T defaultValue); public String getPropertyAsString(String propertyName); public <T> T[] getPropertyAsArray(String propertyName, Class<T> type); public String[] getPropertyAsArray(String propertyName);
        Hide
        stefan_guggisberg added a comment -

        the naming is IMO inconsistent, e.g.

        String getPropertyAsString(String propertyName);

        vs

        String[] getPropertyAsArray(String propertyName);

        supporting MVPs makes it IMO unfortunately kind of
        awkward and counterintuitive. what is the expected
        result of calling getPropertyAsArray on a SVP and
        getPropertyAs on a MVP?

        since i can't come up with a better/more elegant way
        of supporting the original proposal i'm voting -0 for
        this proposal.

        Show
        stefan_guggisberg added a comment - the naming is IMO inconsistent, e.g. String getPropertyAsString(String propertyName); vs String[] getPropertyAsArray(String propertyName); supporting MVPs makes it IMO unfortunately kind of awkward and counterintuitive. what is the expected result of calling getPropertyAsArray on a SVP and getPropertyAs on a MVP? since i can't come up with a better/more elegant way of supporting the original proposal i'm voting -0 for this proposal.
        Hide
        thomasmueller2 added a comment -

        Personally, I would prefer the much simpler method name "get":
        public <T> T get(String propertyName, Class<T> type);
        public <T> T get(String propertyName, T defaultValue);

        I don't think I would use special methods for String, instead I would use:
        String s = n.get("name", "");

        But if you prefer not to use "get":

        This is OK:
        String s = n.getPropertyAs("name", String.class);
        String s = n.getPropertyAsString("name");

        This sounds weird:
        String s = n.getPropertyAs("name", "-");
        what about:
        String s = n.getPropertyWithDefault("name", "-");

        This method isn't required:
        public <T> T[] getPropertyAsArray(String propertyName, Class<T> type);
        String[] s = n.getPropertyAsArray("names", String.class);
        because it is already available using
        public <T> T getPropertyAs(String propertyName, Class<T> type):
        String[] s = n.getPropertyAs("names", String[].class);

        I believe the following method isn't important:
        public String[] getPropertyAsArray(String propertyName);
        but if you think it is, then it should be:
        public String[] getPropertyAsStringArray(String propertyName);

        Show
        thomasmueller2 added a comment - Personally, I would prefer the much simpler method name "get": public <T> T get(String propertyName, Class<T> type); public <T> T get(String propertyName, T defaultValue); I don't think I would use special methods for String, instead I would use: String s = n.get("name", ""); But if you prefer not to use "get": This is OK: String s = n.getPropertyAs("name", String.class); String s = n.getPropertyAsString("name"); This sounds weird: String s = n.getPropertyAs("name", "-"); what about: String s = n.getPropertyWithDefault("name", "-"); This method isn't required: public <T> T[] getPropertyAsArray(String propertyName, Class<T> type); String[] s = n.getPropertyAsArray("names", String.class); because it is already available using public <T> T getPropertyAs(String propertyName, Class<T> type): String[] s = n.getPropertyAs("names", String[].class); I believe the following method isn't important: public String[] getPropertyAsArray(String propertyName); but if you think it is, then it should be: public String[] getPropertyAsStringArray(String propertyName);
        Hide
        Peeter Piegaze added a comment -

        Ok then (getting back to this long-hibernating topic), I propose to add the following methods to Node:

        public <T> T getPropertyAs(String propertyName, Class<T> type);

        public String getPropertyAsString(String propertyName)

        public String[] getPropertyAsStringArray(String propertyName);

        public <T> T getPropertyWithDefault(String propertyName, T defaultValue);

        Show
        Peeter Piegaze added a comment - Ok then (getting back to this long-hibernating topic), I propose to add the following methods to Node: public <T> T getPropertyAs(String propertyName, Class<T> type); public String getPropertyAsString(String propertyName) public String[] getPropertyAsStringArray(String propertyName); public <T> T getPropertyWithDefault(String propertyName, T defaultValue);
        Hide
        Peeter Piegaze added a comment -

        Fixed as suggested by Thomas.

        Show
        Peeter Piegaze added a comment - Fixed as suggested by Thomas.

          People

          • Assignee:
            Peeter Piegaze
            Reporter:
            uncled
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: