KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > joseki > HttpExecuteModel


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

5
6 package com.hp.hpl.jena.joseki;
7
8 import org.apache.commons.logging.* ;
9 import java.net.* ;
10 import java.io.* ;
11
12 import com.hp.hpl.jena.rdf.model.*;
13 import org.joseki.*;
14
15 /**
16  * @author Andy Seaborne
17  * @version $Id: HttpExecuteModel.java,v 1.2 2004/04/30 14:13:13 andy_seaborne Exp $
18  */

19 /** Common code for performing an HTTP operation which takes a single
20  * model as argument.
21  *
22  * @see HttpAdd
23  * @see HttpRemove
24  * @see HttpQuery
25  * @author Andy Seaborne
26  * @version $Id: HttpExecuteModel.java,v 1.2 2004/04/30 14:13:13 andy_seaborne Exp $
27  */

28
29 public class HttpExecuteModel extends HttpExecute
30 {
31     private static Log log = LogFactory.getLog(HttpExecuteModel.class.getName()) ;
32     
33     private Model model = null ;
34     
35     /** Usual way to contruct the request
36      * @param target
37      * @param opName
38      * @throws MalformedURLException
39      */

40     
41     protected HttpExecuteModel(String JavaDoc target, String JavaDoc opName)
42         throws MalformedURLException
43     { super(target, opName) ; }
44     
45     /** Allow 2 stage constructor because subclasses may wish to
46      * compute before setting the URL (@see setURL)
47      */

48     protected HttpExecuteModel() { super(); }
49     
50     
51     /** Send the single model argument. Will use UTF-8.
52      * @param mediaType MIME type (no charset) to be used.
53      * @param out The OutputStream to use
54      */

55     
56     protected void onSend(String JavaDoc mediaType, OutputStream out)
57     {
58         model.write(out, Joseki.getWriterType(mediaType)) ;
59     }
60     
61     public Model getModel()
62     {
63         ensureModel() ;
64         return model ;
65     }
66     
67     public void setModel(Model m)
68     {
69         if ( model != null )
70             log.warn("Replacing allocated model") ;
71         model = m ;
72     }
73     
74     // Not called "add" because the underlying operation, like HttpRemove,
75
// may not wish to call it "add".
76

77     protected void collect(Statement s)
78     {
79         ensureModel() ;
80         model.add(s) ;
81     }
82     
83     protected void collect(Model m)
84     {
85         ensureModel() ;
86         model.add(m) ;
87     }
88     
89     
90     private void ensureModel()
91     {
92         if ( model == null )
93             // ModelFactory.createNonreifyingModel??
94
model = ModelFactory.createDefaultModel() ;
95     }
96 }
97
98
99 /*
100  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
101  * All rights reserved.
102  *
103  * Redistribution and use in source and binary forms, with or without
104  * modification, are permitted provided that the following conditions
105  * are met:
106  * 1. Redistributions of source code must retain the above copyright
107  * notice, this list of conditions and the following disclaimer.
108  * 2. Redistributions in binary form must reproduce the above copyright
109  * notice, this list of conditions and the following disclaimer in the
110  * documentation and/or other materials provided with the distribution.
111  * 3. The name of the author may not be used to endorse or promote products
112  * derived from this software without specific prior written permission.
113  *
114  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
115  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
116  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
117  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
118  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
119  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
120  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
121  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
123  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124  */

125
126
Popular Tags