Source Code Cross Referenced for HTTPRepository.java in  » RSS-RDF » sesame » org » openrdf » repository » http » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » sesame » org.openrdf.repository.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 2006-2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.repository.http;
007:
008:        import java.io.File;
009:        import java.io.IOException;
010:
011:        import org.openrdf.http.client.HTTPClient;
012:        import org.openrdf.model.Value;
013:        import org.openrdf.model.ValueFactory;
014:        import org.openrdf.model.impl.ValueFactoryImpl;
015:        import org.openrdf.model.util.LiteralUtil;
016:        import org.openrdf.query.BindingSet;
017:        import org.openrdf.query.QueryEvaluationException;
018:        import org.openrdf.query.TupleQueryResult;
019:        import org.openrdf.query.resultio.TupleQueryResultFormat;
020:        import org.openrdf.repository.Repository;
021:        import org.openrdf.repository.RepositoryConnection;
022:        import org.openrdf.repository.RepositoryException;
023:        import org.openrdf.rio.RDFFormat;
024:
025:        /**
026:         * A repository that serves as a proxy for a remote repository on a Sesame
027:         * server.
028:         * 
029:         * Methods in this class may throw the specific RepositoryException subclasses
030:         * UnautorizedException and NotAllowedException, the semantics of which are
031:         * defined by the HTTP protocol.
032:         * 
033:         * @see org.openrdf.http.protocol.UnauthorizedException
034:         * @see org.openrdf.http.protocol.NotAllowedException
035:         * 
036:         * @author Arjohn Kampman
037:         * @author jeen
038:         * @author Herko ter Horst
039:         */
040:        public class HTTPRepository implements  Repository {
041:
042:            /*-----------*
043:             * Variables *
044:             *-----------*/
045:
046:            /**
047:             * The HTTP client that takes care of the client-server communication.
048:             */
049:            private HTTPClient httpClient;
050:
051:            private File dataDir;
052:
053:            private boolean initialized = false;
054:
055:            /*--------------*
056:             * Constructors *
057:             *--------------*/
058:
059:            private HTTPRepository() {
060:                httpClient = new HTTPClient();
061:                httpClient.setValueFactory(new ValueFactoryImpl());
062:            }
063:
064:            public HTTPRepository(String serverURL, String repositoryID) {
065:                this ();
066:                httpClient.setServerURL(serverURL);
067:                httpClient.setRepositoryID(repositoryID);
068:            }
069:
070:            public HTTPRepository(String repositoryURL) {
071:                this ();
072:                httpClient.setRepositoryURL(repositoryURL);
073:            }
074:
075:            /*---------*
076:             * Methods *
077:             *---------*/
078:
079:            // httpClient is shared with HTTPConnection
080:            HTTPClient getHTTPClient() {
081:                return httpClient;
082:            }
083:
084:            public void setDataDir(File dataDir) {
085:                this .dataDir = dataDir;
086:            }
087:
088:            public File getDataDir() {
089:                return dataDir;
090:            }
091:
092:            public void initialize() throws RepositoryException {
093:                initialized = true;
094:            }
095:
096:            public void shutDown() throws RepositoryException {
097:                initialized = false;
098:            }
099:
100:            public ValueFactory getValueFactory() {
101:                return httpClient.getValueFactory();
102:            }
103:
104:            public RepositoryConnection getConnection()
105:                    throws RepositoryException {
106:                return new HTTPRepositoryConnection(this );
107:            }
108:
109:            public boolean isWritable() throws RepositoryException {
110:                if (!initialized) {
111:                    throw new IllegalStateException(
112:                            "HTTPRepository not initialized.");
113:                }
114:
115:                boolean isWritable = false;
116:                String repositoryURL = httpClient.getRepositoryURL();
117:
118:                try {
119:                    TupleQueryResult repositoryList = httpClient
120:                            .getRepositoryList();
121:                    try {
122:                        while (repositoryList.hasNext()) {
123:                            BindingSet bindingSet = repositoryList.next();
124:                            Value uri = bindingSet.getValue("uri");
125:
126:                            if (uri != null
127:                                    && uri.stringValue().equals(repositoryURL)) {
128:                                isWritable = LiteralUtil.getBooleanValue(
129:                                        bindingSet.getValue("writable"), false);
130:                                break;
131:                            }
132:                        }
133:                    } catch (QueryEvaluationException e) {
134:                        throw new RepositoryException(e);
135:                    } finally {
136:                        try {
137:                            repositoryList.close();
138:                        } catch (QueryEvaluationException e) {
139:                            throw new RepositoryException(e);
140:                        }
141:                    }
142:                } catch (IOException e) {
143:                    throw new RepositoryException(e);
144:                }
145:
146:                return isWritable;
147:            }
148:
149:            /**
150:             * Sets the preferred serialization format for tuple query results to the
151:             * supplied {@link TupleQueryResultFormat}, overriding the
152:             * {@link HTTPClient}'s default preference. Setting this parameter is not
153:             * necessary in most cases as the {@link HTTPClient} by default indicates a
154:             * preference for the most compact and efficient format available.
155:             * 
156:             * @param format
157:             *        the preferred {@link TupleQueryResultFormat}. If set to 'null' no
158:             *        explicit preference will be stated.
159:             */
160:            public void setPreferredTupleQueryResultFormat(
161:                    TupleQueryResultFormat format) {
162:                httpClient.setPreferredTupleQueryResultFormat(format);
163:            }
164:
165:            /**
166:             * Indicates the current preferred {@link TupleQueryResultFormat}.
167:             * 
168:             * @return The preferred format, of 'null' if no explicit preference is
169:             *         defined.
170:             */
171:            public TupleQueryResultFormat getPreferredTupleQueryResultFormat() {
172:                return httpClient.getPreferredTupleQueryResultFormat();
173:            }
174:
175:            /**
176:             * Sets the preferred serialization format for RDF to the supplied
177:             * {@link RDFFormat}, overriding the {@link HTTPClient}'s default
178:             * preference. Setting this parameter is not necessary in most cases as the
179:             * {@link HTTPClient} by default indicates a preference for the most compact
180:             * and efficient format available.
181:             * <p>
182:             * Use with caution: if set to a format that does not support context
183:             * serialization any context info contained in the query result will be lost.
184:             * 
185:             * @param format
186:             *        the preferred {@link RDFFormat}. If set to 'null' no explicit
187:             *        preference will be stated.
188:             */
189:            public void setPreferredRDFFormat(RDFFormat format) {
190:                httpClient.setPreferredRDFFormat(format);
191:            }
192:
193:            /**
194:             * Indicates the current preferred {@link RDFFormat}.
195:             * 
196:             * @return The preferred format, of 'null' if no explicit preference is
197:             *         defined.
198:             */
199:            public RDFFormat getPreferredRDFFormat() {
200:                return httpClient.getPreferredRDFFormat();
201:            }
202:
203:            /**
204:             * Set the username and password to use for authenticating with the remote
205:             * repository.
206:             * 
207:             * @param username
208:             *        the username. Setting this to null will disable authentication.
209:             * @param password
210:             *        the password. Setting this to null will disable authentication.
211:             */
212:            public void setUsernameAndPassword(String username, String password) {
213:                httpClient.setUsernameAndPassword(username, password);
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.