Changeset 6851 for SRUServer


Ignore:
Timestamp:
11/26/15 12:45:26 (8 years ago)
Author:
Oliver Schonefeld
Message:
  • add convenience method to SRURequest to automatically cast query to a supplied type
Location:
SRUServer/trunk/src/main/java/eu/clarin/sru/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequest.java

    r6821 r6851  
    105105     * <em>searchRetrieve</em> requests.
    106106     *
    107      * @return the parsed query as an AST or <code>null</code> if not a
    108      *         <em>searchRetrieve</em> request
     107     * @return an {@link SRUQuery} instance tailored for the used queryType or
     108     *         <code>null</code> if not a <em>searchRetrieve</em> request
    109109     */
    110110    public SRUQuery<?> getQuery();
     111
     112
     113    /**
     114     * Get the <em>query</em> parameter of this request. Only available for
     115     * <em>searchRetrieve</em> requests. This convenience method tried to cast
     116     * the query object to the supplied type.
     117     *
     118     * @param type
     119     *            Class representing the Java data type to convert the query to.
     120     * @return an {@link SRUQuery} instance tailored for the used queryType or
     121     *         <code>null</code> if not a <em>searchRetrieve</em> request
     122     * @throws ClassCastException
     123     *             if conversion is not supported, type is <code>null</code> or
     124     *             another error occurs
     125     */
     126    public <T extends SRUQuery<?>> T getQuery(Class<T> type);
    111127
    112128
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequestImpl.java

    r6842 r6851  
    815815
    816816    @Override
     817    public <T extends SRUQuery<?>> T getQuery(Class<T> type) {
     818        if (type == null) {
     819            throw new ClassCastException("type == null");
     820        }
     821        // cast() is null-safe
     822        return type.cast(query);
     823    }
     824
     825
     826    @Override
    817827    public boolean isQueryType(String queryType) {
    818828        if ((queryType != null) && (query != null)) {
Note: See TracChangeset for help on using the changeset viewer.