Sziasztok!<div><br></div><div>Egy üzleti alkalmazásban körülbelül 100 komponensel dolgozunk, a koponensek konfigurációs fájlai annotálva vannak a felületen megjelenő neveikkel, valamint egyéb attribútumokkal. A JDK 6 beépített annotáció feldolgozójával szeretnénk ezeknek a komponenseknek a nevét kigyűjteni egy listába. A komponensek között létezik egy primitív hierarchia: vannak bizonyos komponensek, amik rendelkeznek "al-komponensekkel", ezek konfigurációs fájlában egy @XmlElements listában vannak felsorolva az al-komponensek azonosítói, valahogy így:</div>
<div><br></div><div><pre class="lang-java prettyprint" style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">public</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">ComponentConfig</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
<br> </span><span class="lit" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">@XmlElements</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">({</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="lit" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">@XmlElement</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">type </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">Sample1</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> name </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="str" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"sample-1-config"</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">),</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="lit" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">@XmlElement</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">type </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">Sample2</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> name </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="str" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"sample-2-config"</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">),</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="lit" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">@XmlElement</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">type </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">Sample3</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> name </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="str" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"sample-3-config"</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">),</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">})</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
<br> </span><span class="com" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//...</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span></code></pre></div><div>Az egyes @XmlElement annotációk "name" paraméterét szeretnék elérni, de az alábbi kóddal sajnos nem sikerül:</div>
<div><br></div><div><pre class="lang-java prettyprint" style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">List</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><?</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">extends</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">AnnotationMirror</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">></span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> annotationMirrors </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> element</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">getAnnotationMirrors</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">();</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">for</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">AnnotationMirror</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> mirror </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> annotationMirrors</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="kwd" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">if</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">mirror</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">getAnnotationType</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">().</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">toString</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">().</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">equals</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">XML_ELEMENT</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">))</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="typ" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175)">System</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">out</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">println</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">getAnnotationValueMapValueOfName</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">mirror</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">));</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
nodes</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">add</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">getAnnotationValueMapValueOfName</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">mirror</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">));</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span class="pln" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>
</span><span class="pun" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span></code></pre></div><div>Ez lenne a problémám, remélem tudtok segíteni. :) A megfejtés jutalma 25 pont a <a href="http://stackoverflow.com/questions/11772516/how-to-access-xmlelement-values-in-apt">stackoverflow</a>-n. :D</div>