Changeset 4112


Ignore:
Timestamp:
Jan 31, 2008, 10:44:29 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #911: Add support for having file validators and meta data extrators in external jar files.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/appendix/incompatible.xml

    r4093 r4112  
    8282    </listitem>   
    8383    </itemizedlist>
     84   
     85    <bridgehead>Data file types</bridgehead>
     86    <para>
     87      The <methodname>DataFileType.setValidatorClass()</methodname> and
     88      <methodname>DataFileType.setMetadataReaderClass()</methodname> no longer
     89      verifies that the specified class names exists and implements the required interfaces.
     90      This validation will instead happen at commit time. The reason for this change is
     91      the added support for having the validator/meta data reader in external JAR files.
     92      This means that the validation can't happen until both the class names and JAR paths
     93      has been set. If a client application need validation before commit time it should use
     94      <methodname>DataFileType.getValidator()</methodname> and
     95      <methodname>DataFileType.getMetadataReader()</methodname> after the class names and JAR
     96      paths has been set.
     97    </para>
    8498
    8599  </sect1> 
  • trunk/doc/src/docbook/developerdoc/plugin_developer.xml

    r4093 r4112  
    41484148        (ie. they don't have to implement the <interfacename docapi="net.sf.basedb.core.plugin">Plugin</interfacename>
    41494149        interface). This means that you don't have to mess with configuration or
    4150         job parameters. Another difference is that the plug-ins must be installed in
    4151         Tomcat's classpath (ie. in one of the
    4152         <filename>WEB-INF/classes</filename> or <filename>WEB-INF/lib</filename>
    4153         folders).
     4150        job parameters.
    41544151      </para>
    41554152     
  • trunk/src/core/net/sf/basedb/core/DataFileType.java

    r4017 r4112  
    3535import net.sf.basedb.info.ToTransferable;
    3636import net.sf.basedb.util.ClassUtil;
     37import net.sf.basedb.util.JarClassLoader;
    3738
    3839/**
     
    5051public class DataFileType
    5152  extends BasicItem<DataFileTypeData>
    52   implements Nameable, Removable, ToTransferable<DataFileTypeInfo>
     53  implements Nameable, Removable, ToTransferable<DataFileTypeInfo>, Validatable
    5354{
    5455 
     
    103104  public static final int MAX_CLASSNAME_LENGTH = DataFileTypeData.MAX_CLASSNAME_LENGTH;
    104105
     106  /**
     107    The maximum length of the jar paths that can be stored in the database.
     108    @see #setValidatorJarPath(String)
     109    @see #setMetadataReaderJarPath(String)
     110  */
     111  public static final int MAX_JARPATH_LENGTH = DataFileTypeData.MAX_JARPATH_LENGTH;
     112 
    105113  /**
    106114    Create a new data file type.
     
    363371  }
    364372 
     373 
     374
     375  /**
     376    Check that the validator and meta data reader classes implement the
     377    correct interfaces.
     378    @since 2.6
     379  */
     380  @Override
     381  void validate()
     382    throws InvalidDataException, BaseException
     383  {
     384    super.validate();
     385    getValidator();
     386    getMetadataReader();
     387  }
     388
    365389  /**
    366390    @since 2.5
     
    479503      have write permission
    480504    @throws StringTooLongException If the string is longer that {@link #MAX_CLASSNAME_LENGTH}.
    481     @throws InvalidDataException If the named class isn't found or
    482       doesn't implement the <code>DataFileValidator</code> interface.
    483505  */
    484506  public void setValidatorClass(String validatorClass)
    485507  {
    486508    checkPermission(Permission.WRITE);
    487     if (validatorClass != null)
    488     {
    489       try
    490       {
    491         ClassUtil.checkAndLoadClass(null, validatorClass, true, DataFileValidator.class);
    492       }
    493       catch (Throwable t)
    494       {
    495         throw new InvalidDataException(t);
    496       }
    497     }
    498     getData().setValidatorClass(StringUtil.setNullableString(validatorClass, "validatorClass", MAX_EXTENSION_LENGTH));
    499   }
     509    getData().setValidatorClass(StringUtil.setNullableString(validatorClass,
     510        "validatorClass", MAX_CLASSNAME_LENGTH));
     511  }
     512 
     513  /**
     514    Get the path to the JAR file where the validator class is located. If the
     515    path is null the validator must be in the class path.
     516    @return The JAR path or null
     517    @since 2.6
     518  */
     519  public String getValidatorJarPath()
     520  {
     521    return getData().getValidatorJarPath();
     522  }
     523 
     524  /**
     525    Set the path to the JAR file where the validator class is located.
     526    @param validatorJarPath The path to the JAR file or null if the validator is in the class path
     527    @throws PermissionDeniedException If the logged in user doesn't
     528      have write permission
     529    @throws StringTooLongException If the string is longer that {@link #MAX_JARPATH_LENGTH}.
     530    @since 2.6
     531  */
     532  public void setValidatorJarPath(String validatorJarPath)
     533  {
     534    checkPermission(Permission.WRITE);
     535    getData().setValidatorJarPath(StringUtil.setNullableString(validatorJarPath,
     536      "validatorJarPath", MAX_JARPATH_LENGTH));
     537  }
     538 
    500539 
    501540  /**
     
    512551    try
    513552    {
     553      String jarPath = getValidatorJarPath();
     554      ClassLoader loader = jarPath == null ? null :JarClassLoader.getInstance(jarPath);
    514555      validator = (DataFileValidator)ClassUtil.checkAndLoadClass(
    515           null, validatorClass, true, DataFileValidator.class).newInstance();
     556          loader, validatorClass, true, DataFileValidator.class).newInstance();
    516557    }
    517558    catch (Throwable t)
     
    539580      have write permission
    540581    @throws StringTooLongException If the string is longer that {@link #MAX_CLASSNAME_LENGTH}.
    541     @throws InvalidDataException If the named class isn't found or doesn't
    542       implement the <code>DataFileMetadataReader</code> interface
    543582  */
    544583  public void setMetadataReaderClass(String metadataReaderClass)
    545584  {
    546585    checkPermission(Permission.WRITE);
    547     if (metadataReaderClass != null)
    548     {
    549       try
    550       {
    551         ClassUtil.checkAndLoadClass(null, metadataReaderClass, true, DataFileMetadataReader.class);
    552       }
    553       catch (Throwable t)
    554       {
    555         throw new InvalidDataException(t);
    556       }
    557     }
    558586    getData().setMetadataReaderClass(StringUtil.setNullableString(metadataReaderClass,
    559       "metadataReaderClass", MAX_EXTENSION_LENGTH));
    560   }
     587      "metadataReaderClass", MAX_CLASSNAME_LENGTH));
     588  }
     589 
     590  /**
     591    Get the path to the JAR file where the meta data reader class is located. If the
     592    path is null the reader must be in the class path.
     593    @return The JAR path or null
     594    @since 2.6
     595  */
     596  public String getMetadataReaderJarPath()
     597  {
     598    return getData().getMetadataReaderJarPath();
     599  }
     600 
     601  /**
     602    Set the path to the JAR file where the meta data reader class is located.
     603    @param metadataReaderJarPath The path to the JAR file or null if the reader is in the class path
     604    @throws PermissionDeniedException If the logged in user doesn't
     605      have write permission
     606    @throws StringTooLongException If the string is longer that {@link #MAX_JARPATH_LENGTH}.
     607    @since 2.6
     608  */
     609  public void setMetadataReaderJarPath(String metadataReaderJarPath)
     610  {
     611    checkPermission(Permission.WRITE);
     612    getData().setMetadataReaderJarPath(StringUtil.setNullableString(metadataReaderJarPath,
     613      "metadataReaderJarPath", MAX_JARPATH_LENGTH));
     614  }
    561615 
    562616  /**
     
    573627    try
    574628    {
     629      String jarPath = getValidatorJarPath();
     630      ClassLoader loader = jarPath == null ? null : JarClassLoader.getInstance(jarPath);
    575631      reader = (DataFileMetadataReader)ClassUtil.checkAndLoadClass(
    576           null, readerClass, true, DataFileMetadataReader.class).newInstance();
     632          loader, readerClass, true, DataFileMetadataReader.class).newInstance();
    577633    }
    578634    catch (Throwable t)
  • trunk/src/core/net/sf/basedb/core/Install.java

    r4105 r4112  
    107107    method.
    108108  */
    109   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(49).intValue();
     109  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(50).intValue();
    110110 
    111111  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/Update.java

    r4082 r4112  
    574574    </td>
    575575  </tr>
     576  <tr>
     577    <td>50</td>
     578    <td>
     579      <ul>
     580      <li>Added {@link net.sf.basedb.core.data.DataFileTypeData#getValidatorJarPath()}
     581      <li>Added {@link net.sf.basedb.core.data.DataFileTypeData#getMetadataReaderJarPath()}
     582      </ul>
     583      No special database update is needed. Only increase the schema version.
     584    </td>
     585  </tr>
    576586 
    577587  </table>
     
    814824      }
    815825     
     826      if (schemaVersion < 50)
     827      {
     828        if (progress != null) progress.display((int)(49*progress_factor), "Updating schema version: " + schemaVersion + " -> 50...");
     829        schemaVersion = setSchemaVersionInTransaction(session, 50);
     830      }
    816831     
    817832      sc.logout();
  • trunk/src/core/net/sf/basedb/core/data/DataFileTypeData.java

    r3948 r4112  
    147147  }
    148148 
     149  public static final int MAX_JARPATH_LENGTH = 65535;
     150  private String validatorJarPath;
     151  /**
     152    Get the path to the JAR file where the validator class is located. If the
     153    value is null the value must be in the classpath.
     154    @return The path to the JAR file
     155    @hibernate.property column="`validator_jarpath`" type="text" not-null="false"
     156    @since 2.6
     157  */
     158  public String getValidatorJarPath()
     159  {
     160    return validatorJarPath;
     161  }
     162  public void setValidatorJarPath(String validatorJarPath)
     163  {
     164    this.validatorJarPath = validatorJarPath;
     165  }
     166 
     167 
    149168  private String metadataReaderClass;
    150169  /**
     
    161180  {
    162181    this.metadataReaderClass = metadataReaderClass;
     182  }
     183 
     184  private String metadataReaderJarPath;
     185  /**
     186    Get the path to the JAR file where the validator class is located. If the
     187    value is null the value must be in the classpath.
     188    @return The path to the JAR file
     189    @hibernate.property column="`extractor_jarpath`" type="text" not-null="false"
     190    @since 2.6
     191  */
     192  public String getMetadataReaderJarPath()
     193  {
     194    return metadataReaderJarPath;
     195  }
     196  public void setMetadataReaderJarPath(String metadataReaderJarPath)
     197  {
     198    this.metadataReaderJarPath = metadataReaderJarPath;
    163199  }
    164200 
Note: See TracChangeset for help on using the changeset viewer.