[seam-issues] [JBoss JIRA] Issue Comment Edited: (SEAMXML-25) Introduce s:values tag

Jozef Hartinger (JIRA) jira-events at lists.jboss.org
Fri Mar 18 07:18:45 EDT 2011


    [ https://issues.jboss.org/browse/SEAMXML-25?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588834#comment-12588834 ] 

Jozef Hartinger edited comment on SEAMXML-25 at 3/18/11 7:17 AM:
-----------------------------------------------------------------

I implemented both approaches. To demonstrate the problem better, here's the code you currently need to write to configure a cavalry with two knights:

{code:xml}
<test:Cavalry>
    <test:knights>
        <value>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Ace" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="sharp" />
                    </value>
                </test:sword>
            </test:Knight>
        </value>
        <value>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Apples" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="blunt" />
                    </value>
                </test:sword>
            </test:Knight>
        </value>
    </test:knights>
</test:Cavalry>
{code}

With the first approach, the <values> element is introduced, which can be used when an initial value of a collection is set making the configuration file a little less verbose. This change is implemented at https://github.com/jharting/seam-config/tree/SEAMXML-25-values

{code:xml}
<test:Cavalry>
    <test:knights>
        <values>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Ace" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="sharp" />
                    </value>
                </test:sword>
            </test:Knight>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Apples" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="blunt" />
                    </value>
                </test:sword>
            </test:Knight>
        </values>
    </test:knights>
</test:Cavalry>
{code}

Alternatively, the <value> element can be omitted completely, making the configuration a lot more similar to the Seam 2 components.xml file. (Actually, the only case when the <value> is needed is when setting a collection / array field with primitive / String types, since you need to be able to separate the values within the text of an element somehow)
This approach is implemented at https://github.com/jharting/seam-config/tree/SEAMXML-25
Note that although this change is quite radical, it is completely backward-compatible and one can still use the <value> element if needed. This change only makes the element optional in most of the possible some cases.

{code:xml}
<test:Cavalry>
    <test:knights>
        <test:Knight>
            <test:horse>
                <test:Horse name="Ace" />
            </test:horse>
            <test:sword>
                <test:Sword type="sharp" />
            </test:sword>
        </test:Knight>
        <test:Knight>
            <test:horse>
                <test:Horse name="Apples" />
            </test:horse>
            <test:sword>
                <test:Sword type="blunt" />
            </test:sword>
        </test:Knight>
    </test:knights>
</test:Cavalry>
{code}

Stuart, please review the code and let me know which alternative you prefer.


      was (Author: jharting):
    I implemented both approaches. To demonstrate the problem better, here's the code you currently need to write to configure a cavalry with two knights:

{code:xml}
<test:Cavalry>
    <test:knights>
        <value>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Ace" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="sharp" />
                    </value>
                </test:sword>
            </test:Knight>
        </value>
        <value>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Apples" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="blunt" />
                    </value>
                </test:sword>
            </test:Knight>
        </value>
    </test:knights>
</test:Cavalry>
{code}

With the first approach, the <values> element is introduced, which can be used when an initial value of a collection is set making the configuration file a little less verbose. This change is implemented at https://github.com/jharting/seam-config/tree/SEAMXML-25-values

{code:xml}
<test:Cavalry>
    <test:knights>
        <values>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Ace" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="sharp" />
                    </value>
                </test:sword>
            </test:Knight>
            <test:Knight>
                <test:horse>
                    <value>
                        <test:Horse name="Apples" />
                    </value>
                </test:horse>
                <test:sword>
                    <value>
                        <test:Sword type="blunt" />
                    </value>
                </test:sword>
            </test:Knight>
        </values>
    </test:knights>
</test:Cavalry>
{code}

Alternatively, the <value> element can be omitted completely, making the configuration a lot more similar to the Seam 2 components.xml file. (Actually, the only case when the <value> is needed is when setting a collection / array field with primitive / String types, since you need to be able to separate the values within the text of an element somehow)
This approach is implemented at https://github.com/jharting/seam-config/tree/SEAMXML-25-values 
Note that although this change is quite radical, it is completely backward-compatible and one can still use the <value> element if needed. This change only makes the element optional in most of the possible some cases.

{code:xml}
<test:Cavalry>
    <test:knights>
        <test:Knight>
            <test:horse>
                <test:Horse name="Ace" />
            </test:horse>
            <test:sword>
                <test:Sword type="sharp" />
            </test:sword>
        </test:Knight>
        <test:Knight>
            <test:horse>
                <test:Horse name="Apples" />
            </test:horse>
            <test:sword>
                <test:Sword type="blunt" />
            </test:sword>
        </test:Knight>
    </test:knights>
</test:Cavalry>
{code}

Stuart, please review the code and let me know which alternative you prefer.

  
> Introduce s:values tag
> ----------------------
>
>                 Key: SEAMXML-25
>                 URL: https://issues.jboss.org/browse/SEAMXML-25
>             Project: Seam Config
>          Issue Type: Feature Request
>          Components: XML Provider
>    Affects Versions: 3.0.0.Beta1
>            Reporter: Jozef Hartinger
>            Assignee: Stuart Douglas
>            Priority: Minor
>             Fix For: Future
>
>
> Currently, it is quite verbose to populate a collection with configured object instances using the XML module.
> For example:
> Foo is a class having a collection (bars) of Bars
> <e:Foo>
>    <e:bars>
>       <s:value>
>          <e:Bar id="1"/>
>       </s:value>
>       <s:value>
>          <e:Bar id="2"/>
>       </s:value>
>       <s:value>
>          <e:Bar id="3"/>
>       </s:value>
>       <s:value>
>          <e:Bar id="4"/>
>       </s:value>
>    </e:bars>
> </e:Foo>
> If the s:values tag is introduced, it'll make the configuration less verbose
> <e:Foo>
>    <e:bars>
>       <s:values>
>          <e:Bar id="1"/>
>          <e:Bar id="2"/>
>          <e:Bar id="3"/>
>          <e:Bar id="4"/>
>       </s:values>
>    </e:bars>
> </e:Foo>

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the seam-issues mailing list