source: trunk/loci/formats/auto/OMEXMLMetadata.vm @ 3917

Revision 3917, 9.0 KB checked in by curtis, 12 years ago (diff)

A bunch of work on the loci.formats.meta autogenerator. Not finished yet.

Line 
1//
2// $id
3//
4
5/*
6LOCI Bio-Formats package for reading and converting biological file formats.
7Copyright (C) 2005-@year@ Melissa Linkert, Curtis Rueden, Chris Allan,
8Eric Kjellman and Brian Loranger.
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU Library General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18GNU Library General Public License for more details.
19
20You should have received a copy of the GNU Library General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*/
24
25/*-----------------------------------------------------------------------------
26 *
27 * THIS IS AUTOMATICALLY GENERATED CODE.  DO NOT MODIFY.
28 * Created by $user via MetadataAutogen on $timestamp
29 *
30 *-----------------------------------------------------------------------------
31 */
32
33package loci.formats.ome;
34
35#if ($q.legacy())
36import $basePackage.*;
37#end##if legacy
38import $q.basePackage().$q.subPackage().*;
39import java.util.List;
40import loci.formats.LogTools;
41
42/**
43 * A metadata store implementation for constructing and manipulating OME-XML
44 * DOMs for the $q.version() version of OME-XML. It requires the
45 * $q.basePackage() package to compile (part of ome-java.jar).
46 *
47 * <dl><dt><b>Source code:</b></dt>
48 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/loci/formats/ome/$q.id()">Trac</a>,
49 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/loci/formats/ome/$q.id()">SVN</a></dd></dl>
50 *
51 * @author Curtis Rueden ctrueden at wisc.edu
52 * @author Melissa Linkert linkert at wisc.edu
53 */
54public class $q.className() extends OMEXMLMetadata {
55
56  // -- OMEXMLMetadata API methods --
57
58  /* @see OMEXMLMetadata#dumpXML() */
59  public String dumpXML() {
60    if (root == null) return null;
61#if ($q.legacy())
62    try { return ((OMENode) root).writeOME(false); }
63    catch (javax.xml.transform.TransformerException exc) {
64      LogTools.trace(exc);
65    }
66    catch (java.io.IOException exc) { LogTools.trace(exc); }
67    catch (org.xml.sax.SAXException exc) { LogTools.trace(exc); }
68    catch (javax.xml.parsers.ParserConfigurationException exc) {
69      LogTools.trace(exc);
70    }
71    return null;
72#else
73    try {
74      java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
75      ome.xml.DOMUtil.writeXML(os, root.getDOMElement().getOwnerDocument());
76      return os.toString();
77    }
78    catch (javax.xml.transform.TransformerException exc) {
79      LogTools.trace(exc);
80    }
81    return null;
82#end##if legacy
83  }
84
85  // -- MetadataRetrieve API methods --
86
87  // - Entity counting -
88#foreach ($entity in $q.entities())
89#set ($dummy = $q.setEntity($entity))
90#if ($entity.countable())
91#set ($last = $q.last())
92
93  /* @see loci.formats.meta.MetadataRetrieve#get$entity.name()Count($entity.indicesList(true, false, false)) */
94  public int get$entity.name()Count($entity.indicesList(true, true, false)) {
95    return 0;//TEMP!
96#if ($q.path() == "-")
97    // NB: $entity.name() unsupported for schema version $version
98    return -1;
99#else
100    for (int i=0; i<Integer.MAX_VALUE; i++) {
101      if (get$entity($q.indicesList(false, true).replaceFirst("[a-zA-Z_0-9]+$", "i")) == null) return i;
102    }
103    return -1;
104#end##if "-"
105  }
106#end##if countable
107#end##foreach $entity
108
109  // - Entity retrieval -
110#foreach ($entity in $q.entities())
111#set ($dummy = $q.setEntity($entity))
112#set ($last = $q.last())
113#set ($lastVar = $q.var($last))
114
115  // - $entity property retrieval -
116#foreach ($prop in $entity.props())
117#set ($dummy = $q.setProperty($prop))
118  CTR START HERE
119#set ($mappedName = $q.Name($versionKey))
120#set ($convert = $mappedName.endsWith("%"))
121#set ($mappedName = $mappedName.replaceAll("%", ""))
122#set ($mappedPrefix = $prop.mappedPrefix($versionKey))
123
124  /* @see loci.formats.meta.MetadataRetrieve#get$entity.name()$prop.name()($entity.indicesList(true, false)) */
125  public $prop.type(true) get$entity.name()$prop.name()($entity.indicesList(true, true)) {
126#if ($last == "-" || $mappedName == "-")
127    // NB: $prop.name() unsupported for schema version $version
128    return null;
129#else
130    ${last}Node $lastVar = get${last}Node($entity.indicesList(false, true), false);
131#if ($convert)
132    return $lastVar == null ? null : $lastVar${mappedName}To$prop.type()(${lastVar}.$mappedPrefix$mappedName());
133#else
134    return $lastVar == null ? null : ${lastVar}.$mappedPrefix$mappedName();
135#end##if $convert
136#end##if "-"
137  }
138#end##foreach $prop
139#end##foreach $entity
140
141  // -- MetadataStore API methods --
142
143  /* @see loci.formats.meta.MetadataStore#setRoot(Object) */
144  public void createRoot() {
145#if ($legacy == "true")
146    try {
147      root = new OMENode();
148    }
149    catch (javax.xml.transform.TransformerException exc) {
150      LogTools.trace(exc);
151    }
152#else
153    try {
154      root = ome.xml.OMEXMLFactory.newOMENode("$version");
155    }
156#end##if $legacy
157    catch (java.io.IOException exc) { LogTools.trace(exc); }
158    catch (org.xml.sax.SAXException exc) { LogTools.trace(exc); }
159    catch (javax.xml.parsers.ParserConfigurationException exc) {
160      LogTools.trace(exc);
161    }
162  }
163
164  /* @see loci.formats.meta.MetadataStore#setRoot(Object) */
165  public void setRoot(Object root) {
166    if (!(root instanceof OMENode)) {
167      throw new IllegalArgumentException(
168        "Invalid root type: " + root.getClass().getName() + ". " +
169        "This metadata store accepts root objects of type " +
170        OMENode.class.getName());
171    }
172    this.root = (OMENode) root;
173  }
174#foreach ($entity in $entities)
175#set ($last = $entity.last($versionKey))
176#set ($lastVar = $entity.lastVar($versionKey))
177
178  // - $entity.name() property storage -
179#foreach ($prop in $entity.props())
180#set ($varName = $prop.varName())
181#set ($varNameSafe = $prop.varName(true))
182#set ($mappedName = $prop.mappedName($versionKey))
183#set ($convert = $mappedName.endsWith("%"))
184#set ($mappedName = $mappedName.replaceAll("%", ""))
185
186  /* @see loci.formats.meta.MetadataStore#set$entity.name()$prop.name()($prop.type(true), $entity.indicesList(true, false)) */
187  public void set$entity.name()$prop.name()($prop.type(true) $varName, $entity.indicesList(true, true)) {
188#if ($last == "-" || $mappedName == "-")
189    // NB: $prop.name() unsupported for schema version $version
190#else
191    if ($varName == null) return;
192    ${last}Node $lastVar = get${last}Node($entity.indicesList(false, true), true);
193#if ($convert)
194    ${lastVar}.set$mappedName($lastVar${mappedName}From$prop.type()($varNameSafe));
195#else
196    ${lastVar}.set$mappedName($varNameSafe);
197#end##if $convert
198#end##if "-"
199  }
200#end##foreach $prop
201#end##foreach $entity
202
203  // -- Helper methods --
204#foreach ($entity in $unique)
205#set ($last = $entity.last($versionKey))
206
207  // $entity.path($versionKey)
208  private ${last}Node get${last}Node($entity.indicesList(true, true), boolean create) {
209    int ndx, count;
210    List list;
211    // get OME node
212    OMENode ome = (OMENode) root;
213#set ($var = "ome")
214#set ($pVar = "ome")
215#set ($pNode = "OME")
216#set ($multiCount = 0)
217#foreach ($node in $entity.pathNodes($versionKey))
218#set ($multi = $node.endsWith("+"))
219#set ($ref = $node.startsWith("@"))
220#set ($bang = $node.startsWith("@!"))
221#set ($node = $node.replaceAll("[@!+]", ""))
222#set ($ca = $pVar.equals("ca"))
223#set ($var = $entity.toVarName($node))
224    // get $node node
225#if ($node.equals("CA"))
226#set ($node = "CustomAttributes")
227#end##if
228#if ($multi)
229#set ($prop = $entity.indices().get($multiCount))
230#set ($multiCount = $multiCount + 1)
231    ndx = $prop.varName();
232#if ($ca)
233    count = ${pVar}.countCAList("$node");
234#elseif ($legacy == "true")
235    count = ${pVar}.count${node}List();
236#else
237    count = ${pVar}.get${node}Count();
238#end##if $ca, $legacy
239    if (!create && ndx >= count) return null;
240#if ($ref)
241    for (int i=count; i<=ndx; i++) {
242      new ${node}Node(ca).set$pNode($pVar);
243    }
244#else
245    for (int i=count; i<=ndx; i++) new ${node}Node($pVar);
246#end##if $ref
247#if ($ca)
248    list = ${pVar}.getCAList("$node");
249#else
250    list = ${pVar}.get${node}List();
251#end##if $ca
252    ${node}Node $var = (${node}Node) list.get(ndx);
253#else
254#if ($ca || $ref)
255#if ($bang)
256#set ($extra = "By$pNode")
257#else
258#set ($extra = "")
259#end##if $bang
260    ${node}Node $var = null;
261#if ($ca)
262    count = ca.countCAList("$node");
263    if (count >= 1) {
264      $var = (${node}Node) ca.getCAList("$node").get(0);
265    }
266#else
267    count = ${pVar}.count${node}List$extra();
268    if (count >= 1) {
269      $var = (${node}Node) ${pVar}.get${node}List$extra().get(0);
270    }
271#end##if $ca
272#else
273    ${node}Node $var = ${pVar}.get$node();
274#end##if $ca || $ref
275    if ($var == null) {
276      if (!create) return null;
277#if ($ref)
278      $var = new ${node}Node(ca);
279      ${var}.set$pNode($pVar);
280#else
281      $var = new ${node}Node($pVar);
282#end##if $ref
283    }
284#end##if $multi
285#set ($pNode = $node)
286#set ($pVar = $var)
287#end##foreach $node
288    return $var;
289  }
290#end##foreach $entity
291
292}
Note: See TracBrowser for help on using the repository browser.