Changeset 3483


Ignore:
Timestamp:
12/17/07 14:07:08 (12 years ago)
Author:
curtis
Message:

Fix some bugs in Velocity-based autogenerator.

Location:
trunk/loci/formats/auto
Files:
1 deleted
3 edited

Legend:

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

    r3481 r3483  
    171171      } 
    172172    } 
    173     return new String(c); 
     173    return new String(c).replaceAll("[@!+%]", ""); 
    174174  } 
    175175 
  • trunk/loci/formats/auto/OMEXMLMetadata.vm

    r3481 r3483  
    7272#foreach ($prop in $entity.props()) 
    7373#set ($mappedName = $prop.mappedName($versionKey)) 
     74#set ($convert = $mappedName.endsWith("%")) 
     75#set ($mappedName = $mappedName.replaceAll("%", "")) 
     76#set ($mappedPrefix = $prop.mappedPrefix($versionKey)) 
    7477 
    7578  public $prop.type() get$entity.name()$prop.name()($entity.indicesList(true, true)) { 
     
    7982#else 
    8083    ${last}Node $lastVar = get$last($entity.indicesList(false, true), false); 
    81     return $lastVar == null ? null : ${lastVar}.get$mappedName(); 
     84#if ($convert) 
     85    return $lastVar == null ? null : $lastVar${mappedName}To$prop.type()(${lastVar}.$mappedPrefix$mappedName()); 
     86#else 
     87    return $lastVar == null ? null : ${lastVar}.$mappedPrefix$mappedName(); 
     88#end##if 
    8289#end##if 
    8390  } 
     
    93100    ${last}Node $lastVar = get$last($entity.indicesList(false, true), true); 
    94101#foreach ($prop in $entity.props()) 
     102#set ($varName = $prop.varName()) 
    95103#set ($mappedName = $prop.mappedName($versionKey)) 
    96 #set ($mappedNameVar = $prop.mappedNameVar($versionKey)) 
     104#set ($convert = $mappedName.endsWith("%")) 
     105#set ($mappedName = $mappedName.replaceAll("%", "")) 
     106#set ($mappedVarName = $prop.mappedVarName($versionKey)) 
    97107#if ($mappedName == "-") 
    98108    // NB: $prop.name() unsupported for schema version $version 
    99 #else 
    100     if ($mappedNameVar != null) ${lastVar}.set$mappedName($mappedNameVar); 
     109#elseif ($convert) 
     110    if ($varName != null) ${lastVar}.set$mappedName($lastVar${mappedName}From$prop.type()($varName)); 
     111#else 
     112    if ($varName != null) ${lastVar}.set$mappedName($varName); 
    101113#end##if 
    102114#end##foreach $prop 
  • trunk/loci/formats/auto/Property.java

    r3481 r3483  
    6363 
    6464    // strip off any lower case prefix 
    65     char[] c = name.toCharArray(); 
    66     int i = 0; 
    67     while (i < c.length && c[i] >= 'a' && c[i] <= 'z') i++; 
    68     if (i > 0) { 
    69       prefix = name.substring(0, i); 
    70       name = name.substring(i); 
     65    int prefixIndex = getPrefixIndex(name); 
     66    if (prefixIndex > 0) { 
     67      prefix = name.substring(0, prefixIndex); 
     68      name = name.substring(prefixIndex); 
    7169    } 
    7270    else prefix = "get"; 
    7371 
    74     varName = entity.toVarName(new String(c)); 
     72    varName = entity.toVarName(name); 
    7573  } 
    7674 
     
    8078 
    8179  public String mappedName(String version) { 
    82     String s = (String) nameMap.get(version); 
    83     return s == null ? name : s; 
    84   } 
    85  
    86   public String mappedNameVar(String version) { 
    87     return entity.toVarName(mappedName(version)); 
     80    String mapped = (String) nameMap.get(version); 
     81    if (mapped == null) return name; 
     82    // strip off any lower case prefix 
     83    int prefixIndex = getPrefixIndex(mapped); 
     84    return mapped.substring(prefixIndex); 
    8885  } 
    8986 
     
    9491  public String prefix() { return prefix; } 
    9592 
     93  public String mappedPrefix(String version) { 
     94    String mapped = (String) nameMap.get(version); 
     95    if (mapped == null) return prefix; 
     96    int prefixIndex = getPrefixIndex(mapped); 
     97    return prefixIndex > 0 ? mapped.substring(0, prefixIndex) : "get"; 
     98  } 
     99 
    96100  public String varName() { return varName; } 
     101 
     102  public String mappedVarName(String version) { 
     103    return entity.toVarName(mappedName(version)); 
     104  } 
    97105 
    98106  public void addMappedName(String version, String name) { 
     
    100108  } 
    101109 
     110  // -- Helper methods -- 
     111 
     112  protected int getPrefixIndex(String s) { 
     113    char[] c = s.toCharArray(); 
     114    int i = 0; 
     115    while (i < c.length && c[i] >= 'a' && c[i] <= 'z') i++; 
     116    return i; 
     117  } 
     118 
    102119} 
Note: See TracChangeset for help on using the changeset viewer.