📄 elementsaccessors.html
字号:
<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 4. Elements Accessors</title><link href="../docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.65.0" name="generator"><link rel="home" href="index.html" title="OGNL Developer Guide"><link rel="up" href="index.html" title="OGNL Developer Guide"><link rel="previous" href="methodAccessors.html" title="Chapter 3. Method Accessors"><link rel="next" href="classReferences.html" title="Chapter 5. Class References"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Chapter 4. Elements Accessors</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="methodAccessors.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><th align="center" width="60%"> </th><td align="right" width="20%"> <a accesskey="n" href="classReferences.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="elementsAccessors"></a>Chapter 4. Elements Accessors</h2></div></div><div></div></div><p>Since iteration is a built-in function of OGNL and many objects support the idea of iterating over the contents of an object (i.e. the <tt class="methodname">object.{ ... }</tt> syntax) OGNL provides a hook into how iteration is done. The
<tt class="classname">ElementsAccessor</tt> interface defines how iteration is done based on a source object. Simple examples could be a <tt class="classname">Collection</tt> elements accessor, which would simply</p><pre class="programlisting">public interface ElementsAccessor
{
public Enumeration getElements( Object target ) throws OgnlException;
}</pre><p>You can set a method accessor on a class-by-class basis using <tt class="methodname">OgnlRuntime.setElementsAccessor()</tt>. There are default elements accessors for <tt class="classname">Object</tt> (which returns an <tt class="classname">Enumeration</tt>
of itself as the only object), <tt class="classname">Map</tt> (which iterates over the values in the <tt class="classname">Map</tt>), and Collection (which uses the collection's <tt class="methodname">iterator()</tt>). One clever use of
<tt class="classname">ElementsAccessor</tt>s is the <tt class="classname">NumberElementsAccessor</tt> class which allows for generating numeric sequences from 0 to the target value. For example the expression <tt class="literal">(100).{ #this }</tt> will
generate a list of 100 integers ranged 0..99.</p></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="methodAccessors.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><td align="center" width="20%"><a accesskey="u" href="index.html"><img src="../images/navigation/up.gif" alt="Up"></a></td><td align="right" width="40%"> <a accesskey="n" href="classReferences.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr><tr><td valign="top" align="left" width="40%">Chapter 3. Method Accessors </td><td align="center" width="20%"><a accesskey="h" href="index.html"><img src="../images/navigation/home.gif" alt="Home"></a></td><td valign="top" align="right" width="40%"> Chapter 5. Class References</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -