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

Ian Boston commented on SLING-2477:
-----------------------------------

(apologies for saying "consensus" earlier).

To summarise both approaches.

name{type} approach:
-------------------------------
The Valid mappings for property names are:
Valid Property name type combinations:
    property name: JCR Type, java Type
    name{byte}: long, byte
    name{short}: long, short 
    name{int}: long, int 
    name{float}: double, float
    name{char}: string, char
    name: string, string
    name: long, long
    name: double, double
    name: boolean, boolean

If any {type} JCR type mapping not in this list is found, the whole config is 
rejected.

When writing back:
    If the java type is one of byte,short,int, float,char then all matching 
properties of the form "name" and "name{type}" are deleted and a property of 
the form name{byte|short|int|float|char} is created of the appropriate type. 
(reusing existing if possible).
    If the java type is one of string, long, double, boolean then all matching 
properties of the form "name" and "name{type}" are deleted and a property of 
the form "name" is created with the appropriate type (if "name" of the 
appropriate types exists, its reused)


Conversion from sling:OsgiConfig storage to OutputStream or Writer will:
    where the type is {byte}, {short}, {int}, {float}, {char} change the name 
to remove the {type} and write out in x"*", s"*", i"*", f"*", c"*" format.
    where the type is long, double, boolean keep the name and write out in 
l"*",d"*",b"*" format
    where the type is string and matches the value matches the pattern 
/^([TIiLlFfDdSsXxCcBb])\"(.*)\"/ keep the name and write the value out as T"*" 
ie T"T"text""
    where the type is string and does not match the pattern 
/^([TIiLlFfDdSsXxCcBb])\"(.*)\"/ keep the name and write the value out.

Conversion from InputStream or Reader will read I"100" format and write 
name{type} format.
   where the value matches /^([IiFfSsXxCc])\"(.*)\"/ create a propery with 
name{int|float|short|byte|char} and write the encoded value.
   where the value matches /^([TLlDdBb])\"(.*)\"/ create a property of type 
string,long,double,boolean and set the raw value.
   where there is no match, create a property of the same name, type string and 
write the raw value.

In all cases where special handling has to be performed for arrays.

 

I"100" approach:
--------------------------------------------
Name, JCR Types, Java type

    name: long, long
    name: double, double
    name: boolean, boolean
    name: string, string where no match found for 
/^([TIiLlFfDdSsXxCcBb])\"(.*)\"/
    name: string, string where matching for /^(T)\"(.*)\"/
    name: string, integer where matching for /^([Ii])\"(.*)\"/
    name: string, float where matching for /^([Ff])\"(.*)\"/
    name: string, short where matching for /^([Ss])\"(.*)\"/
    name: string, byte where matching for /^([Xx])\"(.*)\"/
    name: string, character where matching for /^([Cc])\"(.*)\"/

(optional if write back is not to change the type of a property from what a 
user set the value to)
    name: string, long where matching for /^([Ll])\"(.*)\"/
    name: string, double where matching for /^([Dd])\"(.*)\"/
    name: string, boolean where matching for /^([Bb])\"(.*)\"/



Write back:
   If the name exists and is a string then the appropriate I"100" format is 
used.
   For types of string matching  /^([TIiLlFfDdSsXxCcBb])\"(.*)\"/ the value is 
encoded as T"<value>"
   For types of long, double, boolean if the name does not exist an appropriate 
JCR property is created.
   For all other types a string property is created with the appropriate I"100" 
format.

Conversion from sling:OsgiConfig to OutputStream or Writer will convert types 
long, double, boolean to the I"100" format, no name conversion required.
Conversion from InputStream or Reader will
   where the value matches  /^([LlDdBb])\"(.*)\"/ create a jcr property of the 
same name and type long, double, boolean with the extracted value, if the 
property exists and is a string, reuse it with the string format.
   for all other values create a string property of the same name and set the 
value.

In all cases where special handling has to be performed for arrays.

--------------------------------------------------------

My view (non binding :)) having just written the above is that the I"100" 
approach requires fewer rules and transitions to implement than the name{type} 
approach, which will require good unit test coverage to ensure a user can 
always edit a sling:OsgiConfig node and its properties, without ending up in a 
invalid state.

I will create a Jira to track documentation of whatever approach is chosen 
since AFAICT neither are documented.


                
> Configuration via sling:OsgiConfig nodes does not support all types
> -------------------------------------------------------------------
>
>                 Key: SLING-2477
>                 URL: https://issues.apache.org/jira/browse/SLING-2477
>             Project: Sling
>          Issue Type: Bug
>          Components: Installer
>    Affects Versions: JCR Installer 3.1.2
>            Reporter: Alexander Klimetschek
>            Assignee: Ian Boston
>         Attachments: SLING-2477.patch
>
>
> Most notably, the common "service.ranking" needs to be an Integer, while the 
> jcr property mapping only allows for "Long" types at the moment. The problem 
> is that JCR has a smaller set of property types than the OSGi config admin 
> (JCR: String, Boolean, Long, Double, Decimal; OSGi: String, Boolean, Long, 
> Integer, Float, Double, and probably more differences...).
> Similarly to properties files (which do it in the value like 
> 'service.ranking=I"-10000"' with I=Integer), there must be a way to 
> explicitly specify the type regardless of the JCR type. For example, encoding 
> it in the property name like "service.ranking{int}".

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to