JWare Logo  “Strategies in (*)ability” [iDareMedia] [JWare] [PET] [CI-Dashboard]
<JWare/AntXtras Foundation>

 [home]    [overview] [download] [learning] [problems] [ourplans]    [contacts] [legalese

[guide] $map:UG

home » learning » guides » valueuris » $map: 

The $map: value uri lets you extract elements from and information about map based data objects like the AntX <properties> type. You can also use this handler to get at items stored in any data type based on the Java Properties type. This uri is most useful when you need to dynamically construct a task from client-supplied inputs. In particular, when you need to translate simple key-value pair lists into task-specific sub-components. You must explicitly install this value uri’ handler; read the Examples section to see how this is done.

Parameters

The general form of the uri is: $map:mapref[?[keys|values|size|dump|itemkey][,,delim]] where mapref is a reference to an existing properties data object. You can specify one of four explicit operations or pass in the name of the element to return. dump prints whatever the object’s toString method produces; size returns the number of pairs in the map; keys returns delimited string of the map’s keys; and values returns delimited string of the map’s values. The delim option is only relevant to the keys and values operations; when specified the handler uses it to separate the items in the returned string. If you do not specify either an index or an operation, $map: defaults to the dump operation.

Examples

1) The following snippet declares the default scheme name for the map value uri handler: $map:. This is usually done by an “init” target or at the project’s top level.

    <manageuris action="install">
        <parameter name="map"
            value="com.idaremedia.antx.valueuri.info.MapValueURIHandler"/>
    </manageuris>

2) The following snippet converts the contents of a property map testproperties passed to the macrodef run-programmertests into the specific sub-component <sysproperty> of the <junit> task.

    <macrodef name="run-programmertests">
       <attribute name="testproperties" default=""/>
       ...
          <foreach i="key" list="${$map:@{testproperties}?keys}" mode="local">
              <altertask name="junitrunner" resolveproperties="yes">
                 <sysproperty key="${key}" value="${$map:@{testproperties}?@(key)}"/>
              </altertask>
           </foreach>
          <performtask name="junitrunner"/>
       ...
      </macrodef>

3) The following snippet is a debug helper dumpmap that dumps the current matches of a <propertyset> or <properties> type to the Ant console.

    <macrodef name="dumpmap">
       <attribute name="mapref"/>
       <sequential>
          <echo>${$map:@{mapref}?dump}</echo>
       </sequential>
      </macrodef>

Related Topics

  • MapValueURIHandler implements the $map: uri handler.
  • The $zero: uri lets you check a map to see if it’s empty.
  • The $list: uri lets you manipulate a List-based structure like $map: manipulates a Map-based one.
SourceForge.net Logo
Copyright ©2005-2006 iDare Media, Inc. All rights reserved.
 
JWare/AntXtras uses software developed by and on behalf of the Apache Software Foundation, http://www.apache.org/.
All other product names mentioned on this website are trademarks of their respective owners; refer to full legalese statement.