Source Code Cross Referenced for RemoteRepositoryManager.java in  » RSS-RDF » sesame » org » openrdf » repository » manager » 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.manager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.repository.manager;
007:
008:        import java.io.IOException;
009:        import java.net.MalformedURLException;
010:        import java.net.URL;
011:        import java.util.ArrayList;
012:        import java.util.Collection;
013:        import java.util.List;
014:
015:        import org.openrdf.http.client.HTTPClient;
016:        import org.openrdf.http.protocol.UnauthorizedException;
017:        import org.openrdf.model.util.LiteralUtil;
018:        import org.openrdf.query.BindingSet;
019:        import org.openrdf.query.QueryEvaluationException;
020:        import org.openrdf.query.TupleQueryResult;
021:        import org.openrdf.repository.Repository;
022:        import org.openrdf.repository.RepositoryException;
023:        import org.openrdf.repository.config.RepositoryConfigException;
024:        import org.openrdf.repository.config.RepositoryConfigUtil;
025:        import org.openrdf.repository.http.HTTPRepository;
026:
027:        /**
028:         * A manager for {@link Repository}s that reside on a remote server. This
029:         * repository manager allows one to access repositories over HTTP similar to how
030:         * local repositories are accessed using the {@link LocalRepositoryManager}.
031:         * 
032:         * @author Arjohn Kampman
033:         */
034:        public class RemoteRepositoryManager extends RepositoryManager {
035:
036:            /*-----------*
037:             * Variables *
038:             *-----------*/
039:
040:            /**
041:             * The URL of the remote server, e.g. http://localhost:8080/openrdf-sesame/
042:             */
043:            private String serverURL;
044:
045:            private String username;
046:
047:            private String password;
048:
049:            /*--------------*
050:             * Constructors *
051:             *--------------*/
052:
053:            /**
054:             * Creates a new RepositoryManager that operates on the specfified base
055:             * directory.
056:             * 
057:             * @param baseDir
058:             *        The base directory where data for repositories can be stored, among
059:             *        other things.
060:             */
061:            public RemoteRepositoryManager(String serverURL) {
062:                super ();
063:                this .serverURL = serverURL;
064:            }
065:
066:            /*---------*
067:             * Methods *
068:             *---------*/
069:            /**
070:             * Set the username and password for authenication with the remote server.
071:             * 
072:             * @param username
073:             *        the username
074:             * @param password
075:             *        the password
076:             */
077:            public void setUsernameAndPassword(String username, String password) {
078:                this .username = username;
079:                this .password = password;
080:            }
081:
082:            @Override
083:            protected Repository createSystemRepository()
084:                    throws RepositoryException {
085:                HTTPRepository systemRepository = new HTTPRepository(serverURL,
086:                        SystemRepository.ID);
087:                systemRepository.initialize();
088:                return systemRepository;
089:            }
090:
091:            /**
092:             * Gets the URL of the remote server, e.g.
093:             * "http://localhost:8080/openrdf-sesame/".
094:             */
095:            public String getServerURL() {
096:                return serverURL;
097:            }
098:
099:            @Override
100:            public HTTPRepository getSystemRepository() {
101:                HTTPRepository result = (HTTPRepository) super 
102:                        .getSystemRepository();
103:                result.setUsernameAndPassword(username, password);
104:                return result;
105:            }
106:
107:            /**
108:             * Creates and initializes the repository with the specified ID.
109:             * 
110:             * @param id
111:             *        A repository ID.
112:             * @return The created repository, or <tt>null</tt> if no such repository
113:             *         exists.
114:             * @throws RepositoryConfigException
115:             *         If no repository could be created due to invalid or incomplete
116:             *         configuration data.
117:             */
118:            @Override
119:            protected Repository createRepository(String id)
120:                    throws RepositoryConfigException, RepositoryException {
121:                Repository result = null;
122:
123:                if (RepositoryConfigUtil.hasRepositoryConfig(
124:                        getSystemRepository(), id)) {
125:                    result = new HTTPRepository(serverURL, id);
126:                    result.initialize();
127:                }
128:
129:                return result;
130:            }
131:
132:            @Override
133:            public RepositoryInfo getRepositoryInfo(String id)
134:                    throws RepositoryException {
135:                for (RepositoryInfo repInfo : getAllRepositoryInfos()) {
136:                    if (repInfo.getId().equals(id)) {
137:                        return repInfo;
138:                    }
139:                }
140:
141:                return null;
142:            }
143:
144:            @Override
145:            public Collection<RepositoryInfo> getAllRepositoryInfos(
146:                    boolean skipSystemRepo) throws RepositoryException {
147:                List<RepositoryInfo> result = new ArrayList<RepositoryInfo>();
148:
149:                try {
150:                    HTTPClient httpClient = new HTTPClient();
151:                    httpClient.setServerURL(serverURL);
152:                    httpClient.setUsernameAndPassword(username, password);
153:
154:                    TupleQueryResult responseFromServer = httpClient
155:                            .getRepositoryList();
156:                    while (responseFromServer.hasNext()) {
157:                        BindingSet bindingSet = responseFromServer.next();
158:                        RepositoryInfo repInfo = new RepositoryInfo();
159:
160:                        String id = LiteralUtil.getLabel(bindingSet
161:                                .getValue("id"), null);
162:
163:                        if (skipSystemRepo && id.equals(SystemRepository.ID)) {
164:                            continue;
165:                        }
166:
167:                        String uri = LiteralUtil.getLabel(bindingSet
168:                                .getValue("uri"), null);
169:                        String description = LiteralUtil.getLabel(bindingSet
170:                                .getValue("title"), null);
171:                        boolean readable = LiteralUtil.getBooleanValue(
172:                                bindingSet.getValue("readable"), false);
173:                        boolean writable = LiteralUtil.getBooleanValue(
174:                                bindingSet.getValue("writable"), false);
175:
176:                        try {
177:                            repInfo.setLocation(new URL(uri));
178:                        } catch (MalformedURLException e) {
179:                            logger
180:                                    .warn(
181:                                            "Server reported malformed repository URL: {}",
182:                                            uri);
183:                        }
184:
185:                        repInfo.setId(id);
186:                        repInfo.setDescription(description);
187:                        repInfo.setReadable(readable);
188:                        repInfo.setWritable(writable);
189:
190:                        result.add(repInfo);
191:                    }
192:                } catch (IOException ioe) {
193:                    logger.warn("Unable to retrieve list of repositories", ioe);
194:                    throw new RepositoryException(ioe);
195:                } catch (QueryEvaluationException qee) {
196:                    logger.warn("Unable to retrieve list of repositories", qee);
197:                    throw new RepositoryException(qee);
198:                } catch (UnauthorizedException ue) {
199:                    logger.warn(
200:                            "Not authorized to retrieve list of repositories",
201:                            ue);
202:                    throw new RepositoryException(ue);
203:                } catch (RepositoryException re) {
204:                    logger.warn("Unable to retrieve list of repositories", re);
205:                    throw re;
206:                }
207:
208:                return result;
209:            }
210:
211:            @Override
212:            protected void cleanUpRepository(String repositoryID)
213:                    throws IOException {
214:                // do nothing
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.