1 5 6 package org.joseki.server.processors; 7 8 import java.util.* ; 9 import org.apache.commons.logging.* ; 10 import org.joseki.server.*; 11 import com.hp.hpl.jena.rdf.model.*; 12 13 17 public abstract class OneArgProcessor extends ProcessorCom 18 { 19 static final Log logger = LogFactory.getLog(ZeroArgProcessor.class.getName()) ; 20 21 22 public OneArgProcessor(String n, int lockNeeded, int mutating) 23 { 24 super(n, lockNeeded, mutating) ; 25 } 26 27 public int argsNeeded() { return Processor.ARGS_ONE ; } 28 29 32 public Model exec(Request request) throws ExecutionException 33 { 34 ModelSource src = request.getModelSource() ; 35 if ( super.mutatingOp && src.isImmutable() ) 36 throw new ExecutionException(ExecutionError.rcImmutableModel, "Immutable Model") ; 37 38 boolean needsEndOperation = false ; 39 try { 40 src.startOperation(readOnlyLock) ; 41 needsEndOperation = true ; 42 try { 43 List graphs = request.getDataArgs() ; 44 Model resultModel = null ; 45 for ( Iterator iter = graphs.iterator() ; iter.hasNext() ; ) 47 { 48 Model graph = (Model)iter.next() ; 49 Model r = execOneArg(src, graph, request) ; 50 if ( resultModel == null ) 51 resultModel = r ; 52 else 53 resultModel.add(r) ; 54 } 55 return resultModel ; 56 57 } catch (RDFException ex) 58 { 59 src.abortOperation() ; 60 logger.trace("RDFException: "+ex.getMessage() ) ; 61 throw new ExecutionException(ExecutionError.rcInternalError, null) ; 62 } 63 catch (Exception ex) 64 { 65 needsEndOperation = false ; 66 src.abortOperation() ; 67 logger.trace("Exception: "+ex.getMessage() ) ; 68 throw new ExecutionException(ExecutionError.rcInternalError, null) ; 69 } 70 } finally 71 { 72 if ( needsEndOperation ) 73 { 74 needsEndOperation = false ; 75 src.endOperation(); 76 } 77 } 78 } 80 81 public abstract Model execOneArg(ModelSource src, Model arg, Request request) 82 throws RDFException, ExecutionException ; 83 } 84 85 86 112 | Popular Tags |