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

Revision 3605, 9.3 KB checked in by curtis, 12 years ago (diff)

Initial version of metadata framework with working object references
(i.e., DetectorSettings's Detector and LightSourceSettings's LightSource).

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 ($legacy == "true")
36import $basePackage.*;
37#end##$legacy
38import $basePackage.$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 $version version of OME-XML. It requires the
45 * $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/$id">Trac</a>,
49 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/loci/formats/ome/$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 $class extends OMEXMLMetadata {
55
56  // -- OMEXMLMetadata API methods --
57
58  /* @see OMEXMLMetadata#dumpXML() */
59  public String dumpXML() {
60    if (root == null) return null;
61#if ($legacy == "true")
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 $entities)
89#if ($entity.countable())
90#set ($last = $entity.last($versionKey))
91
92  /* @see loci.formats.meta.MetadataRetrieve#get$entity.name()Count($entity.indicesList(true, false, false)) */
93  public int get$entity.name()Count($entity.indicesList(true, true, false)) {
94#if ($last == "-")
95    // NB: $entity.name() unsupported for schema version $version
96    return -1;
97#else
98    for (int i=0; i<Integer.MAX_VALUE; i++) {
99      if (get$entity.name()($entity.indicesList(false, true).replaceFirst("[a-zA-Z_0-9]+$", "i")) == null) return i;
100    }
101    return -1;
102#end##if "-"
103  }
104#end##if countable
105#end##foreach $entity
106
107  // - Entity retrieval -
108#foreach ($entity in $entities)
109#set ($last = $entity.last($versionKey))
110
111  /* @see loci.formats.meta.MetadataRetrieve#get$entity.name()($entity.indicesList(true, false)) */
112  public Object get$entity.name()($entity.indicesList(true, true)) {
113#if ($last == "-")
114    // NB: $entity.name() unsupported for schema version $version
115    return null;
116#else
117    return get${last}Node($entity.indicesList(false, true), false);
118#end##if "-"
119  }
120#end##foreach $entity
121#foreach ($entity in $entities)
122#set ($last = $entity.last($versionKey))
123#set ($lastVar = $entity.lastVar($versionKey))
124
125  // - $entity.name() property retrieval -
126#foreach ($prop in $entity.props())
127#set ($mappedName = $prop.mappedName($versionKey))
128#set ($convert = $mappedName.endsWith("%"))
129#set ($mappedName = $mappedName.replaceAll("%", ""))
130#set ($mappedPrefix = $prop.mappedPrefix($versionKey))
131
132  /* @see loci.formats.meta.MetadataRetrieve#get$entity.name()$prop.name()($entity.indicesList(true, false)) */
133  public $prop.type(true) get$entity.name()$prop.name()($entity.indicesList(true, true)) {
134#if ($last == "-" || $mappedName == "-")
135    // NB: $prop.name() unsupported for schema version $version
136    return null;
137#else
138    ${last}Node $lastVar = get${last}Node($entity.indicesList(false, true), false);
139#if ($convert)
140    return $lastVar == null ? null : $lastVar${mappedName}To$prop.type()(${lastVar}.$mappedPrefix$mappedName());
141#else
142    return $lastVar == null ? null : ${lastVar}.$mappedPrefix$mappedName();
143#end##if $convert
144#end##if "-"
145  }
146#end##foreach $prop
147#end##foreach $entity
148
149  // -- MetadataStore API methods --
150
151  /* @see loci.formats.meta.MetadataStore#setRoot(Object) */
152  public void createRoot() {
153#if ($legacy == "true")
154    try {
155      root = new OMENode();
156    }
157    catch (javax.xml.transform.TransformerException exc) {
158      LogTools.trace(exc);
159    }
160#else
161    try {
162      root = ome.xml.OMEXMLFactory.newOMENode("$version");
163    }
164#end##if $legacy
165    catch (java.io.IOException exc) { LogTools.trace(exc); }
166    catch (org.xml.sax.SAXException exc) { LogTools.trace(exc); }
167    catch (javax.xml.parsers.ParserConfigurationException exc) {
168      LogTools.trace(exc);
169    }
170  }
171
172  /* @see loci.formats.meta.MetadataStore#setRoot(Object) */
173  public void setRoot(Object root) {
174    if (!(root instanceof OMENode)) {
175      throw new IllegalArgumentException(
176        "Invalid root type: " + root.getClass().getName() + ". " +
177        "This metadata store accepts root objects of type " +
178        OMENode.class.getName());
179    }
180    this.root = (OMENode) root;
181  }
182#foreach ($entity in $entities)
183#set ($last = $entity.last($versionKey))
184#set ($lastVar = $entity.lastVar($versionKey))
185
186  // - $entity.name() property storage -
187#foreach ($prop in $entity.props())
188#set ($varName = $prop.varName())
189#set ($varNameSafe = $prop.varName(true))
190#set ($mappedName = $prop.mappedName($versionKey))
191#set ($convert = $mappedName.endsWith("%"))
192#set ($mappedName = $mappedName.replaceAll("%", ""))
193
194  /* @see loci.formats.meta.MetadataStore#set$entity.name()$prop.name()($prop.type(true), $entity.indicesList(true, false)) */
195  public void set$entity.name()$prop.name()($prop.type(true) $varName, $entity.indicesList(true, true)) {
196#if ($last == "-" || $mappedName == "-")
197    // NB: $prop.name() unsupported for schema version $version
198#else
199    if ($varName == null) return;
200    ${last}Node $lastVar = get${last}Node($entity.indicesList(false, true), true);
201#if ($convert)
202    ${lastVar}.set$mappedName($lastVar${mappedName}From$prop.type()($varNameSafe));
203#else
204    ${lastVar}.set$mappedName($varNameSafe);
205#end##if $convert
206#end##if "-"
207  }
208#end##foreach $prop
209#end##foreach $entity
210
211  // -- Helper methods --
212#foreach ($entity in $unique)
213#set ($last = $entity.last($versionKey))
214
215  // $entity.path($versionKey)
216  private ${last}Node get${last}Node($entity.indicesList(true, true), boolean create) {
217    int ndx, count;
218    List list;
219    // get OME node
220    OMENode ome = (OMENode) root;
221#set ($var = "ome")
222#set ($pVar = "ome")
223#set ($pNode = "OME")
224#set ($multiCount = 0)
225#foreach ($node in $entity.pathNodes($versionKey))
226#set ($multi = $node.endsWith("+"))
227#set ($ref = $node.startsWith("@"))
228#set ($bang = $node.startsWith("@!"))
229#set ($node = $node.replaceAll("[@!+]", ""))
230#set ($ca = $pVar.equals("ca"))
231#set ($var = $entity.toVarName($node))
232    // get $node node
233#if ($node.equals("CA"))
234#set ($node = "CustomAttributes")
235#end##if
236#if ($multi)
237#set ($prop = $entity.indices().get($multiCount))
238#set ($multiCount = $multiCount + 1)
239    ndx = $prop.varName();
240#if ($ca)
241    count = ${pVar}.countCAList("$node");
242#elseif ($legacy == "true")
243    count = ${pVar}.count${node}List();
244#else
245    count = ${pVar}.get${node}Count();
246#end##if $ca, $legacy
247    if (!create && ndx >= count) return null;
248#if ($ref)
249    for (int i=count; i<=ndx; i++) {
250      new ${node}Node(ca).set$pNode($pVar);
251    }
252#else
253    for (int i=count; i<=ndx; i++) new ${node}Node($pVar);
254#end##if $ref
255#if ($ca)
256    list = ${pVar}.getCAList("$node");
257#else
258    list = ${pVar}.get${node}List();
259#end##if $ca
260    ${node}Node $var = (${node}Node) list.get(ndx);
261#else
262#if ($ca || $ref)
263#if ($bang)
264#set ($extra = "By$pNode")
265#else
266#set ($extra = "")
267#end##if $bang
268    ${node}Node $var = null;
269#if ($ca)
270    count = ca.countCAList("$node");
271    if (count >= 1) {
272      $var = (${node}Node) ca.getCAList("$node").get(0);
273    }
274#else
275    count = ${pVar}.count${node}List$extra();
276    if (count >= 1) {
277      $var = (${node}Node) ${pVar}.get${node}List$extra().get(0);
278    }
279#end##if $ca
280#else
281    ${node}Node $var = ${pVar}.get$node();
282#end##if $ca || $ref
283    if ($var == null) {
284      if (!create) return null;
285#if ($ref)
286      $var = new ${node}Node(ca);
287      ${var}.set$pNode($pVar);
288#else
289      $var = new ${node}Node($pVar);
290#end##if $ref
291    }
292#end##if $multi
293#set ($pNode = $node)
294#set ($pVar = $var)
295#end##foreach $node
296    return $var;
297  }
298#end##foreach $entity
299
300}
Note: See TracBrowser for help on using the repository browser.