All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.org.jafer.zserver.operations.Search Maven / Gradle / Ivy

/**
 * JAFER Toolkit Poject.
 * Copyright (C) 2002, JAFER Toolkit Project, Oxford University.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package org.jafer.zserver.operations;

import org.jafer.zserver.Session;
import org.jafer.interfaces.Databean;
import org.jafer.util.Config;
import org.jafer.query.QueryException;
import org.jafer.exception.JaferException;
import org.jafer.zserver.operations.OperationException;

import java.util.logging.Level;

import org.w3c.dom.Node;

import z3950.v3.*;
import asn1.*;

class Results {
    public String databaseName = null;
    public int noOfResults = 0;
    JaferException diagnostic = null;
}

/**
 * 

Runs a Z39.50 search on database(s) - resultSets stored in associated Session. * Uses locking on resultSets (databeans) if client has requested concurrent operations.

* @author Antony Corfield; Matthew Dovey; Colin Tatham * @version 1.0 */ public class Search extends Operation { private PDU pduRequest; private PDU pduResponse; public Search(Session session, PDU pduRequest) { super(session, "search"); this.pduRequest = pduRequest; this.pduResponse = new PDU(); } public PDU runOp() throws Exception { pduResponse.c_searchResponse = new SearchResponse(); pduResponse.c_searchResponse.s_referenceId = pduRequest.c_searchRequest.s_referenceId; pduResponse.c_searchResponse.s_resultCount = new ASN1Integer(0); pduResponse.c_searchResponse.s_searchStatus = new ASN1Boolean(false); pduResponse.c_searchResponse.s_nextResultSetPosition = new ASN1Integer(0); pduResponse.c_searchResponse.s_numberOfRecordsReturned = new ASN1Integer(0); pduResponse.c_searchResponse.s_presentStatus = new PresentStatus(); pduResponse.c_searchResponse.s_presentStatus.value = new ASN1Integer(pduResponse.c_searchResponse.s_presentStatus.E_failure); String resultSetName; if (pduRequest.c_searchRequest.s_resultSetName == null) resultSetName = "default"; else { resultSetName = pduRequest.c_searchRequest.s_resultSetName.value.get(); if (getSession().containsDatabean(resultSetName) && !pduRequest.c_searchRequest.s_replaceIndicator.get()) { // diagnostic - resultSetName exists and replace = false throw new OperationException( getName() + " " + Config.getBib1Diagnostic(21) + " (" + " resultSetName: " + resultSetName + ")", getDiagnostic(21, null)); } } String databases[] = new String[pduRequest.c_searchRequest.s_databaseNames.length]; for (int n = 0; n < pduRequest.c_searchRequest.s_databaseNames.length; n++) databases[n] = pduRequest.c_searchRequest.s_databaseNames[n].value.value.get(); Results[] results = search(pduRequest.c_searchRequest.s_query.c_type_1, databases, resultSetName); int total = 0; ASN1Any[] targets = new ASN1Any[results.length]; for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy