Changeset 5943


Ignore:
Timestamp:
02/19/10 10:17:30 (10 years ago)
Author:
callan
Message:

#464 Added LuraWave service

  • Stub in stubs component for com.luratech.lwf.lwfDecoder
  • Test cases for missing and available LuraWave service
  • Adjusted dependencies on LuraWave codec and LuraWave reflected universe
Location:
branches/cleanup
Files:
10 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/build.properties

    r5941 r5943  
    2222                               ${lib.dir}/slf4j-api-1.5.10.jar:\ 
    2323                               ${lib.dir}/slf4j-log4j12-1.5.10.jar:\ 
     24                               ${lib.dir}/stubs.jar:\ 
    2425                               ${lib.dir}/testng-5.11-jdk15.jar 
    2526# Used by TestNG suite that tests the absence of classes from ome-xml.jar 
     
    5859                               ${lib.dir}/slf4j-api-1.5.10.jar:\ 
    5960                               ${lib.dir}/slf4j-log4j12-1.5.10.jar:\ 
     61                               ${lib.dir}/stubs.jar:\ 
    6062                               ${lib.dir}/testng-5.11-jdk15.jar 
    6163# Used by TestNG suite that tests the absence of class from netcdf-4.0.jar 
     
    8183                               ${lib.dir}/slf4j-api-1.5.10.jar:\ 
    8284                               ${lib.dir}/slf4j-log4j12-1.5.10.jar:\ 
     85                               ${lib.dir}/stubs.jar:\ 
    8386                               ${lib.dir}/testng-5.11-jdk15.jar 
    8487# Used by TestNG suite that tests the absence of class from jai_imageio.jar 
    8588component.classpath.nojai    = ${artifact.dir}/loci-common.jar:\ 
     89                               ${artifact.dir}/mdbtools-java.jar:\ 
     90                               ${artifact.dir}/ome-io.jar:\ 
     91                               ${artifact.dir}/ome-xml.jar:\ 
     92                               ${artifact.dir}/poi-loci.jar:\ 
     93                               ${lib.dir}/forms-1.3.0.jar:\ 
     94                               ${lib.dir}/log4j-1.2.15.jar:\ 
     95                               ${lib.dir}/slf4j-api-1.5.10.jar:\ 
     96                               ${lib.dir}/slf4j-log4j12-1.5.10.jar:\ 
     97                               ${lib.dir}/testng-5.11-jdk15.jar 
     98# Used by TestNG suite that tests the absence of class from stubs.jar 
     99component.classpath.nolurawave = ${artifact.dir}/loci-common.jar:\ 
    86100                               ${artifact.dir}/mdbtools-java.jar:\ 
    87101                               ${artifact.dir}/ome-io.jar:\ 
  • branches/cleanup/components/bio-formats/build.xml

    r5939 r5943  
    1515  <target name="test" 
    1616    depends="jar,compile-tests,test-no-mdb,test-no-netcdf,test-no-ome-xml, 
    17     test-no-poi,test-no-ome-io,test-no-jai" 
     17    test-no-poi,test-no-ome-io,test-no-jai,test-no-lurawave" 
    1818    description="run tests" if="doTests"> 
    1919    <testng classpath="${test-classes.dir}:${classes.dir}:${component.classpath}" 
     
    8989    </testng> 
    9090  </target> 
     91 
     92  <target name="test-no-lurawave" depends="compile-tests" 
     93    description="run missing LuraWave JAR tests" if="doTests"> 
     94    <copy tofile="${build.dir}/testng.xml" overwrite="true" 
     95      file="${tests.dir}/loci/formats/utests/testng-no-lurawave.xml"/> 
     96    <testng classpath= 
     97      "${test-classes.dir}:${classes.dir}:${component.classpath.nolurawave}"> 
     98      <xmlfileset file="${build.dir}/testng.xml"/> 
     99      <jvmarg value="-mx${testng.memory}"/> 
     100    </testng> 
     101  </target> 
    91102</project> 
  • branches/cleanup/components/bio-formats/src/loci/formats/codec/LuraWaveCodec.java

    r5552 r5943  
    3030import loci.common.DataTools; 
    3131import loci.common.RandomAccessInputStream; 
    32 import loci.common.ReflectException; 
    33 import loci.common.ReflectedUniverse; 
     32import loci.common.services.DependencyException; 
     33import loci.common.services.ServiceException; 
     34import loci.common.services.ServiceFactory; 
    3435import loci.formats.FormatException; 
    3536import loci.formats.MissingLibraryException; 
     37import loci.formats.services.LuraWaveService; 
     38import loci.formats.services.LuraWaveServiceImpl; 
    3639 
    3740/** 
     
    5154  // -- Constants -- 
    5255 
    53   /** System property to check for the LuraWave license code. */ 
    54   public static final String LICENSE_PROPERTY = "lurawave.license"; 
    55  
    56   /** Message displayed if the LuraWave LWF decoder library is not found. */ 
    57   public static final String NO_LURAWAVE_MSG = 
    58     "The LuraWave decoding library, lwf_jsdk2.6.jar, is required to decode " + 
    59     "this file.\r\nPlease make sure it is present in your classpath."; 
    60  
    61   /** Message to display if no LuraWave license code is given. */ 
    62   public static final String NO_LICENSE_MSG = 
    63     "No LuraWave license code was specified.\r\nPlease set one in the " + 
    64     LICENSE_PROPERTY + " system property (e.g., with -D" + LICENSE_PROPERTY + 
    65     "=XXXX from the command line)."; 
    66  
    67   /** Message to display if an invalid LuraWave license code is given. */ 
    68   public static final String INVALID_LICENSE_MSG = "Invalid license code: "; 
    69  
    7056  // -- Static fields -- 
    7157 
    72   /** True iff the LuraWave decoding library is not available. */ 
    73   protected static boolean noLuraWave; 
     58  // -- Fields -- 
    7459 
    75   /** License code for LuraWave decoding library. */ 
    76   protected static String licenseCode; 
     60  private LuraWaveService service; 
    7761 
    78   /** Reflected universe for LuraWave decoding library calls. */ 
    79   private static ReflectedUniverse r; 
     62  // -- Codec API methods -- 
    8063 
    81   // -- Static initializer -- 
    82  
    83   static { 
    84     r = new ReflectedUniverse(); 
     64  /** 
     65   * Default constructor. 
     66   * @throws FormatException If there is an error initializing LuraWave 
     67   * services. 
     68   */ 
     69  public LuraWaveCodec() throws FormatException { 
    8570    try { 
    86       r.exec("import com.luratech.lwf.lwfDecoder"); 
    87       r.setVar("-1", -1); 
    88       r.setVar("1", 1); 
    89       r.setVar("1024", 1024); 
    90       r.setVar("0", 0); 
     71      ServiceFactory factory = new ServiceFactory(); 
     72      service = factory.getInstance(LuraWaveService.class); 
    9173    } 
    92     catch (ReflectException exc) { 
    93       noLuraWave = true; 
     74    catch (DependencyException e) { 
     75      throw new MissingLibraryException(LuraWaveServiceImpl.NO_LURAWAVE_MSG, e); 
    9476    } 
    9577  } 
    96  
    97   // -- Codec API methods -- 
    9878 
    9979  /* @see Codec#compress(byte[], CodecOptions) */ 
     
    122102    throws FormatException 
    123103  { 
    124     if (noLuraWave) throw new MissingLibraryException(NO_LURAWAVE_MSG); 
    125     licenseCode = System.getProperty(LICENSE_PROPERTY); 
    126     if (licenseCode == null) throw new FormatException(NO_LICENSE_MSG); 
    127     r.setVar("stream", 
    128       new BufferedInputStream(new ByteArrayInputStream(buf), 4096)); 
     104    BufferedInputStream stream =  
     105      new BufferedInputStream(new ByteArrayInputStream(buf), 4096); 
    129106    try { 
    130       r.setVar("licenseCode", licenseCode); 
    131       r.exec("lwf = new lwfDecoder(stream, null, licenseCode)"); 
     107      service.initialize(stream); 
    132108    } 
    133     catch (ReflectException exc) { 
    134       throw new FormatException(INVALID_LICENSE_MSG + licenseCode, exc); 
     109    catch (DependencyException e) { 
     110      throw new FormatException(LuraWaveServiceImpl.NO_LICENSE_MSG, e); 
     111    } 
     112    catch (ServiceException e) { 
     113      throw new FormatException(LuraWaveServiceImpl.INVALID_LICENSE_MSG, e); 
     114    } 
     115    catch (IOException e) { 
     116      throw new FormatException(e); 
    135117    } 
    136118 
    137     int w = 0, h = 0; 
    138  
    139     try { 
    140       w = ((Integer) r.exec("lwf.getWidth()")).intValue(); 
    141       h = ((Integer) r.exec("lwf.getHeight()")).intValue(); 
    142     } 
    143     catch (ReflectException exc) { 
    144       throw new FormatException("Could not retrieve image dimensions", exc); 
    145     } 
     119    int w = service.getWidth(); 
     120    int h = service.getHeight(); 
    146121 
    147122    int nbits = 8 * (options.maxBytes / (w * h)); 
     
    150125      byte[] image8 = new byte[w * h]; 
    151126      try { 
    152         r.setVar("image8", image8); 
    153         r.exec("lwf.decodeToMemoryGray8(image8, -1, 1024, 0)"); 
     127        service.decodeToMemoryGray8(image8, -1, 1024, 0); 
    154128      } 
    155       catch (ReflectException exc) { 
    156         throw new FormatException("Could not decode LuraWave data", exc); 
     129      catch (ServiceException e) { 
     130        throw new FormatException(LuraWaveServiceImpl.INVALID_LICENSE_MSG, e); 
    157131      } 
    158132      return image8; 
     
    161135      short[] image16 = new short[w * h]; 
    162136      try { 
    163         r.setVar("image16", image16); 
    164         r.setVar("w", w); 
    165         r.setVar("h", h); 
    166         r.exec("lwf.decodeToMemoryGray16(image16, " + 
    167           "0, -1, 1024, 0, 1, w, 0, 0, w, h)"); 
     137        service.decodeToMemoryGray16(image16, 0, -1, 1024, 0, 1, w, 0, 0, w, h); 
    168138      } 
    169       catch (ReflectException exc) { 
    170         throw new FormatException("Could not decode LuraWave data", exc); 
     139      catch (ServiceException e) { 
     140        throw new FormatException(LuraWaveServiceImpl.INVALID_LICENSE_MSG, e); 
    171141      } 
    172142 
  • branches/cleanup/components/bio-formats/test/loci/formats/utests/testng.xml

    r5941 r5943  
    44        <classes> 
    55            <class name="loci.formats.utests.JAIIIOServiceTest"/> 
     6            <class name="loci.formats.utests.LuraWaveServiceTest"/> 
    67            <class name="loci.formats.utests.MDBServiceTest"/> 
    78            <class name="loci.formats.utests.NetCDFServiceTest"/> 
  • branches/cleanup/components/common/src/loci/common/services/services.properties

    r5938 r5943  
    1818# implementation in ome-io component) 
    1919loci.formats.services.OMEReaderWriterService=loci.ome.io.services.OMEReaderWriterServiceImpl 
     20# LuraWave decoder service (interface and implementation in bio-formats 
     21# component; depends on stubs.jar for compilation) 
     22loci.formats.services.LuraWaveService=loci.formats.services.LuraWaveServiceImpl 
  • branches/cleanup/components/loci-plugins/src/loci/plugins/config/FlexWidgets.java

    r5093 r5943  
    3434import javax.swing.event.DocumentListener; 
    3535 
    36 import loci.formats.codec.LuraWaveCodec; 
     36import loci.common.services.DependencyException; 
     37import loci.common.services.ServiceFactory; 
     38import loci.formats.services.LuraWaveService; 
     39import loci.formats.services.LuraWaveServiceImpl; 
    3740 
    3841/** 
     
    5760 
    5861  public FlexWidgets() { 
     62    LuraWaveService service; 
     63    try { 
     64      ServiceFactory factory = new ServiceFactory(); 
     65      service = factory.getInstance(LuraWaveService.class); 
     66    } 
     67    catch (DependencyException e) { 
     68      throw new RuntimeException(e); 
     69    } 
     70     
    5971    // get license code from ImageJ preferences 
    60     String prefCode = Prefs.get(LuraWaveCodec.LICENSE_PROPERTY, null); 
    61     String propCode = System.getProperty(LuraWaveCodec.LICENSE_PROPERTY); 
     72    String prefCode = Prefs.get(LuraWaveServiceImpl.LICENSE_PROPERTY, null); 
     73    String propCode = service.getLicenseCode(); 
    6274    String code = ""; 
    6375    if (prefCode != null) code = prefCode; 
     
    100112  private void documentUpdate(DocumentEvent e) { 
    101113    String code = licenseBox.getText(); 
    102     Prefs.set(LuraWaveCodec.LICENSE_PROPERTY, code); 
     114    Prefs.set(LuraWaveServiceImpl.LICENSE_PROPERTY, code); 
    103115  } 
    104116 
  • branches/cleanup/components/loci-plugins/src/loci/plugins/util/LuraWave.java

    r5093 r5943  
    2929import ij.gui.GenericDialog; 
    3030import loci.formats.FormatException; 
    31 import loci.formats.codec.LuraWaveCodec; 
     31import loci.formats.services.LuraWaveServiceImpl; 
    3232 
    3333/** 
     
    4848  /** Reads LuraWave license code from ImageJ preferences, if available. */ 
    4949  public static String initLicenseCode() { 
    50     String code = Prefs.get(LuraWaveCodec.LICENSE_PROPERTY, null); 
    51     if (code != null) System.setProperty(LuraWaveCodec.LICENSE_PROPERTY, code); 
     50    String code = Prefs.get(LuraWaveServiceImpl.LICENSE_PROPERTY, null); 
     51    if (code != null) { 
     52      System.setProperty(LuraWaveServiceImpl.LICENSE_PROPERTY, code); 
     53    } 
    5254    return code; 
    5355  } 
     
    5961  public static boolean isLicenseCodeException(FormatException exc) { 
    6062    String msg = exc == null ? null : exc.getMessage(); 
    61     return msg != null && (msg.equals(LuraWaveCodec.NO_LICENSE_MSG) || 
    62       msg.startsWith(LuraWaveCodec.INVALID_LICENSE_MSG)); 
     63    return msg != null && (msg.equals(LuraWaveServiceImpl.NO_LICENSE_MSG) || 
     64      msg.startsWith(LuraWaveServiceImpl.INVALID_LICENSE_MSG)); 
    6365  } 
    6466 
     
    7476    if (gd.wasCanceled()) return null; 
    7577    code = gd.getNextString(); 
    76     if (code != null) Prefs.set(LuraWaveCodec.LICENSE_PROPERTY, code); 
     78    if (code != null) Prefs.set(LuraWaveServiceImpl.LICENSE_PROPERTY, code); 
    7779    return code; 
    7880  } 
  • branches/cleanup/jar/.classpath

    r5896 r5943  
    2525        <classpathentry exported="true" kind="lib" path="slf4j-api-1.5.10.jar"/> 
    2626        <classpathentry exported="true" kind="lib" path="slf4j-log4j12-1.5.10.jar"/> 
     27        <classpathentry exported="true" kind="lib" path="stubs.jar"/> 
    2728        <classpathentry exported="true" kind="lib" path="testng-5.11-jdk15.jar"/> 
    2829        <classpathentry exported="true" kind="lib" path="velocity-1.6.3-dep.jar"/> 
Note: See TracChangeset for help on using the changeset viewer.