KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joseki > server > processors > OneArgProcessor


1 /*
2  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

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 /** General template for any operation that takes exactly one model as argument
14  * @author Andy Seaborne
15  * @version $Id: OneArgProcessor.java,v 1.7 2004/04/30 14:13:11 andy_seaborne Exp $
16  */

17 public abstract class OneArgProcessor extends ProcessorCom
18 {
19     static final Log logger = LogFactory.getLog(ZeroArgProcessor.class.getName()) ;
20
21     
22     public OneArgProcessor(String JavaDoc n, int lockNeeded, int mutating)
23     {
24         super(n, lockNeeded, mutating) ;
25     }
26
27     public int argsNeeded() { return Processor.ARGS_ONE ; }
28
29     /**
30      * @see org.joseki.server.Processor#exec(Request)
31      */

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                 // Use only first arg - or should we cal for all args and return
46
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 JavaDoc 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         //return emptyModel ;
79
}
80     
81     public abstract Model execOneArg(ModelSource src, Model arg, Request request)
82         throws RDFException, ExecutionException ;
83 }
84
85
86 /*
87  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
88  * All rights reserved.
89  *
90  * Redistribution and use in source and binary forms, with or without
91  * modification, are permitted provided that the following conditions
92  * are met:
93  * 1. Redistributions of source code must retain the above copyright
94  * notice, this list of conditions and the following disclaimer.
95  * 2. Redistributions in binary form must reproduce the above copyright
96  * notice, this list of conditions and the following disclaimer in the
97  * documentation and/or other materials provided with the distribution.
98  * 3. The name of the author may not be used to endorse or promote products
99  * derived from this software without specific prior written permission.
100  *
101  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
102  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
103  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
104  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
105  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
106  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
107  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
108  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
109  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
110  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
111  */

112
Popular Tags