
com.lyncode.xoai.serviceprovider.ServiceProvider Maven / Gradle / Ivy
The newest version!
/**
* Copyright 2012 Lyncode
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* client://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lyncode.xoai.serviceprovider;
import com.lyncode.xoai.model.oaipmh.*;
import com.lyncode.xoai.serviceprovider.exceptions.*;
import com.lyncode.xoai.serviceprovider.handler.*;
import com.lyncode.xoai.serviceprovider.lazy.ItemIterator;
import com.lyncode.xoai.serviceprovider.model.Context;
import com.lyncode.xoai.serviceprovider.parameters.GetRecordParameters;
import com.lyncode.xoai.serviceprovider.parameters.ListIdentifiersParameters;
import com.lyncode.xoai.serviceprovider.parameters.ListMetadataParameters;
import com.lyncode.xoai.serviceprovider.parameters.ListRecordsParameters;
import java.util.Iterator;
public class ServiceProvider {
private Context context;
private ListMetadataFormatsHandler listMetadataFormatsHandler;
private IdentifyHandler identifyHandler;
private GetRecordHandler getRecordHandler;
public ServiceProvider (Context context) {
this.context = context;
identifyHandler = new IdentifyHandler(context);
listMetadataFormatsHandler = new ListMetadataFormatsHandler(context);
getRecordHandler = new GetRecordHandler(context);
}
public Identify identify () {
return identifyHandler.handle();
}
public Iterator listMetadataFormats () {
return listMetadataFormatsHandler.handle(ListMetadataParameters.request()).iterator();
}
public Iterator listMetadataFormats (ListMetadataParameters parameters) {
return listMetadataFormatsHandler.handle(parameters).iterator();
}
public Record getRecord (GetRecordParameters parameters) throws BadArgumentException, IdDoesNotExistException, CannotDisseminateFormatException {
if (!parameters.areValid())
throw new BadArgumentException("GetRecord verb requires identifier and metadataPrefix parameters");
return getRecordHandler.handle(parameters);
}
public Iterator listRecords (ListRecordsParameters parameters) throws BadArgumentException {
if (!parameters.areValid())
throw new BadArgumentException("ListRecords verb requires the metadataPrefix");
return new ItemIterator(new ListRecordHandler(context, parameters));
}
public Iterator listIdentifiers (ListIdentifiersParameters parameters) throws BadArgumentException {
if (!parameters.areValid())
throw new BadArgumentException("ListIdentifiers verb requires the metadataPrefix");
return new ItemIterator(new ListIdentifierHandler(context, parameters));
}
public Iterator listSets () throws NoSetHierarchyException {
try {
return new ItemIterator(new ListSetsHandler(context));
} catch (EncapsulatedKnownException ex) {
throw get(ex, NoSetHierarchyException.class);
}
}
private boolean instanceOf (EncapsulatedKnownException exception, Class exceptionClass) {
return exceptionClass.isInstance(exception.getCause());
}
private T get (EncapsulatedKnownException ex, Class exceptionClass) {
if (instanceOf(ex, exceptionClass))
return (T) ex.getCause();
else
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy