Changeset 3934


Ignore:
Timestamp:
04/16/08 18:22:49 (12 years ago)
Author:
curtis
Message:

Progress on metadata store autogenerator. Not ready yet.

Location:
trunk/loci/formats/auto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/auto/MetaEntityList.java

    r3917 r3934  
    7979 
    8080  /** Last node in the path, without markup symbols. Derived from path. */ 
    81   public String last() { 
    82     String path = path(); 
    83     int first = path.lastIndexOf("/") + 1; 
    84     return path.substring(first).replaceAll("[@\\!\\+]", ""); 
    85   } 
     81  public String last() { return last(path()); } 
    8682 
    8783  /** List of indices in the path. Derived from path. */ 
    88   public Vector<String> indices() { 
    89     Vector<String> list = new Vector<String>(); 
    90     StringTokenizer st = new StringTokenizer(path(), "/"); 
    91     int tokens = st.countTokens(); 
    92     for (int i=0; i<tokens; i++) { 
    93       String t = st.nextToken(); 
    94       if (t.endsWith("+")) list.add(t.replaceAll("[@\\!\\+]", "")); 
    95     } 
    96     return list; 
    97   } 
     84  public Vector<String> indices() { return indices(path()); } 
    9885 
    9986  public String indicesList(boolean doTypes, boolean doVars) { 
     
    10289 
    10390  public String indicesList(boolean doTypes, boolean doVars, boolean doLast) { 
    104     StringBuffer sb = new StringBuffer(); 
    105     Vector<String> indices = indices(); 
    106     if (!doLast) indices.remove(indices.size() - 1); // ignore last element 
    107     boolean first = true; 
    108     for (String index : indices) { 
    109       if (first) first = false; 
    110       else sb.append(", "); 
    111       if (doTypes) sb.append("int"); 
    112       if (doTypes && doVars) sb.append(" "); 
    113       if (doVars) sb.append(var(index + "Index")); 
    114     } 
    115     return sb.toString(); 
     91    return indicesList(path(), doTypes, doVars, doLast); 
    11692  } 
    11793 
    11894  /** 
    119    * List of distinct path values for the active version. 
     95   * List of distinct path values for the active version, including sub-paths. 
    12096   * Derived from path values of all entities and properties. 
    12197   */ 
     
    127103      for (String property : e.props.keySet()) { 
    128104        String path = value("path", ver, entity, property); 
    129         if (set.contains(path) || path.equals("-")) continue; 
    130         set.add(path); 
    131         unique.add(path); 
     105        if (path.equals("-")) continue; 
     106        while (true) { 
     107          if (set.contains(path)) break; // already processed this path 
     108          set.add(path); 
     109          unique.add(path); 
     110          int slash = path.lastIndexOf("/"); 
     111          if (slash < 0) break; 
     112          path = path.substring(0, slash); 
     113        } 
    132114      } 
    133115    } 
     
    138120 
    139121  public String type() { return value("type"); } 
     122 
     123  /** Conversion method to call, if any. Derived from type. */ 
     124  public String convert() { 
     125    String type = type(); 
     126    String defaultType = value("type", null, ent, prop); 
     127    if (type.equals(defaultType)) return null; 
     128    return type + "To" + defaultType; 
     129  } 
    140130 
    141131  public String getter() { 
     
    148138    return setter == null ? "set" + name() : setter; 
    149139  } 
    150  
    151   public boolean available() { return !"false".equals(value("available")); } 
    152140 
    153141  // -- MetaEntityList API methods - entities/properties -- 
     
    172160  // -- MetaEntityList API methods - other -- 
    173161 
     162  // NB: These methods could be static, but are instance methods 
     163  // to make it easier for Velocity templates to reference them. 
     164 
    174165  /** Converts name in CamelCase to variable in variableCase. */ 
    175166  public String var(String s) { 
    176     // NB: This method could be static, but is an instance method 
    177     // to make it easier for Velocity templates to reference it. 
    178167    char[] c = s.toCharArray(); 
    179168    for (int i=0; i<c.length; i++) { 
     
    187176  } 
    188177 
     178  /** Gets the last node in the given path, without markup symbols. */ 
     179  public String last(String path) { 
     180    int first = path.lastIndexOf("/") + 1; 
     181    return path.substring(first).replaceAll("[@\\!\\+]", ""); 
     182  } 
     183 
     184  /** List of indices in the given path. */ 
     185  public Vector<String> indices(String path) { 
     186    Vector<String> list = new Vector<String>(); 
     187    StringTokenizer st = new StringTokenizer(path, "/"); 
     188    int tokens = st.countTokens(); 
     189    for (int i=0; i<tokens; i++) { 
     190      String t = st.nextToken(); 
     191      if (t.endsWith("+")) list.add(t.replaceAll("[@\\!\\+]", "")); 
     192    } 
     193    return list; 
     194  } 
     195 
     196  public String indicesList(String path, 
     197    boolean doTypes, boolean doVars, boolean doLast) 
     198  { 
     199    StringBuffer sb = new StringBuffer(); 
     200    Vector<String> indices = indices(path); 
     201    if (!doLast) indices.remove(indices.size() - 1); // ignore last element 
     202    boolean first = true; 
     203    for (String index : indices) { 
     204      if (first) first = false; 
     205      else sb.append(", "); 
     206      if (doTypes) sb.append("int"); 
     207      if (doTypes && doVars) sb.append(" "); 
     208      if (doVars) sb.append(var(index + "Index")); 
     209    } 
     210    return sb.toString(); 
     211  } 
    189212} 
  • trunk/loci/formats/auto/OMEXMLMetadata.vm

    r3917 r3934  
    11// 
    2 // $id 
     2// $q.id() 
    33// 
    44 
     
    3434 
    3535#if ($q.legacy()) 
    36 import $basePackage.*; 
     36import $q.basePackage().*; 
    3737#end##if legacy 
    3838import $q.basePackage().$q.subPackage().*; 
     
    9393  /* @see loci.formats.meta.MetadataRetrieve#get$entity.name()Count($entity.indicesList(true, false, false)) */ 
    9494  public int get$entity.name()Count($entity.indicesList(true, true, false)) { 
    95     return 0;//TEMP! 
     95    if (true) return 0;//TEMP! 
    9696#if ($q.path() == "-") 
    9797    // NB: $entity.name() unsupported for schema version $version 
     
    114114 
    115115  // - $entity property retrieval - 
    116 #foreach ($prop in $entity.props()) 
     116#foreach ($prop in $q.props()) 
    117117#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 
     118#set ($convert = $q.convert()) 
     119#set ($var = $q.var($q.last())) 
     120#set ($get = $q.getter()); 
     121 
     122  /* @see loci.formats.meta.MetadataRetrieve#get$entity$prop$q.indicesList(true, false)) */ 
     123  public $q.type() get$entity$prop($q.indicesList(true, true)) { 
     124#if ($q.path() == "-") 
     125    // NB: $prop unsupported for schema version $q.version() 
    128126    return null; 
    129127#else 
    130128    ${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()); 
     129#if ($convert != null) 
     130    return $lastVar == null ? null : $convert(${lastVar}.$q.getter()); $lastVar${mappedName}To$q.type()(${lastVar}.$mappedPrefix$mappedName()); 
    133131#else 
    134132    return $lastVar == null ? null : ${lastVar}.$mappedPrefix$mappedName(); 
     
    143141  /* @see loci.formats.meta.MetadataStore#setRoot(Object) */ 
    144142  public void createRoot() { 
    145 #if ($legacy == "true") 
     143#if ($q.legacy()) 
    146144    try { 
    147145      root = new OMENode(); 
     
    152150#else 
    153151    try { 
    154       root = ome.xml.OMEXMLFactory.newOMENode("$version"); 
     152      root = ome.xml.OMEXMLFactory.newOMENode("$q.version()"); 
    155153    } 
    156154#end##if $legacy 
     
    179177#foreach ($prop in $entity.props()) 
    180178#set ($varName = $prop.varName()) 
    181 #set ($varNameSafe = $prop.varName(true)) 
    182179#set ($mappedName = $prop.mappedName($versionKey)) 
    183180#set ($convert = $mappedName.endsWith("%")) 
    184181#set ($mappedName = $mappedName.replaceAll("%", "")) 
    185182 
    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 
     183  /* @see loci.formats.meta.MetadataStore#set$entity$prop($q.type(), $q.indicesList(true, false)) */ 
     184  public void set$entity$prop($q.type() $varName, $q.indicesList(true, true)) { 
     185#if ($q.path() == "-") 
     186    // NB: $prop unsupported for schema version $q.version() 
    190187#else 
    191188    if ($varName == null) return; 
    192189    ${last}Node $lastVar = get${last}Node($entity.indicesList(false, true), true); 
    193190#if ($convert) 
    194     ${lastVar}.set$mappedName($lastVar${mappedName}From$prop.type()($varNameSafe)); 
    195 #else 
    196     ${lastVar}.set$mappedName($varNameSafe); 
     191    ${lastVar}.set$mappedName($lastVar${mappedName}From$q.type()($varName)); 
     192#else 
     193    ${lastVar}.set$mappedName($varName); 
    197194#end##if $convert 
    198195#end##if "-" 
     
    202199 
    203200  // -- 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) { 
     201#foreach ($path in $q.unique()) 
     202#set ($last = $q.last($path)) 
     203 
     204  // $path 
     205  private ${last}Node get${last}Node($q.indicesList($path, true, true, true), boolean create) { 
    209206    int ndx, count; 
    210207    List list; 
     
    215212#set ($pNode = "OME") 
    216213#set ($multiCount = 0) 
    217 #foreach ($node in $entity.pathNodes($versionKey)) 
     214#foreach ($node in $path.split("\\/")) 
    218215#set ($multi = $node.endsWith("+")) 
    219216#set ($ref = $node.startsWith("@")) 
     
    221218#set ($node = $node.replaceAll("[@!+]", "")) 
    222219#set ($ca = $pVar.equals("ca")) 
    223 #set ($var = $entity.toVarName($node)) 
     220#set ($var = $q.var($node)) 
    224221    // get $node node 
    225222#if ($node.equals("CA")) 
    226223#set ($node = "CustomAttributes") 
    227 #end##if 
     224#end##if CA 
    228225#if ($multi) 
    229 #set ($prop = $entity.indices().get($multiCount)) 
     226#set ($prop = $q.indices($path).get($multiCount)) 
    230227#set ($multiCount = $multiCount + 1) 
    231     ndx = $prop.varName(); 
     228    ndx = ${var}Index; 
    232229#if ($ca) 
    233230    count = ${pVar}.countCAList("$node"); 
    234 #elseif ($legacy == "true") 
     231#elseif ($q.legacy()) 
    235232    count = ${pVar}.count${node}List(); 
    236233#else 
Note: See TracChangeset for help on using the changeset viewer.