Source Code Cross Referenced for Session.java in  » Search-Engine » semweb4j » org » ontoware » semversion » 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 » Search Engine » semweb4j » org.ontoware.semversion 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 06.09.2005
003:         *
004:         */
005:        package org.ontoware.semversion;
006:
007:        import java.util.Calendar;
008:        import java.util.HashSet;
009:        import java.util.Set;
010:
011:        import org.ontoware.aifbcommons.collection.ClosableIterator;
012:        import org.ontoware.rdf2go.model.Model;
013:        import org.ontoware.rdf2go.model.Statement;
014:        import org.ontoware.rdf2go.model.node.URI;
015:        import org.ontoware.rdf2go.model.node.Variable;
016:        import org.ontoware.rdf2go.model.node.impl.PlainLiteralImpl;
017:        import org.ontoware.rdf2go.vocabulary.RDF;
018:        import org.ontoware.rdf2go.vocabulary.RDFS;
019:        import org.ontoware.rdfreactor.runtime.RDFDataException;
020:        import org.slf4j.Logger;
021:        import org.slf4j.LoggerFactory;
022:
023:        /**
024:         * A Session represents a User logged in into SemVersion. Al operations are done
025:         * via a session, so the author (User) of an operation can be tracked.
026:         * 
027:         * @author voelkel
028:         * 
029:         */
030:        public class Session {
031:
032:            private static final Logger log = LoggerFactory
033:                    .getLogger(Session.class);
034:
035:            private final User user;
036:
037:            private final SemVersion semVersion;
038:
039:            private boolean alive = true;
040:
041:            public Session(User user, SemVersion semVersion) {
042:                this .user = user;
043:                this .semVersion = semVersion;
044:            }
045:
046:            private void checkAlive() {
047:                if (!alive) {
048:                    throw new IllegalStateException(
049:                            "session is no longer alive");
050:                }
051:            }
052:
053:            /**
054:             * Closes the current session.
055:             */
056:            public void close() {
057:                alive = false;
058:            }
059:
060:            /**
061:             * 
062:             * @param label
063:             * @return a new VersionedModel
064:             * @throws DuplicateLabelException if a VersionedModel with this name
065:             *         already exists
066:             */
067:            public VersionedModel createVersionedModel(String label)
068:                    throws DuplicateLabelException {
069:                checkAlive();
070:                VersionedModel vm = getVersionedModel(label);
071:                if (vm != null) {
072:                    throw new DuplicateLabelException("Label '" + label
073:                            + "' exists already. URI: " + vm.getURI());
074:                }
075:
076:                return createVersionedModel(semVersion.getMainModel()
077:                        .newRandomUniqueURI(), label);
078:            }
079:
080:            /**
081:             * @param uri
082:             * @param label
083:             * @return a new VersionedModel with the given URI and given label. Returns
084:             *         null if the label has been used for another VersionedModel
085:             *         already.
086:             */
087:            public VersionedModel createVersionedModel(URI uri, String label) {
088:                checkAlive();
089:                if (getVersionedModel(label) != null) {
090:                    return null;
091:                }
092:                try {
093:                    VersionedModel vmi = new VersionedModel(semVersion
094:                            .getMainModel(), this , uri, true);
095:
096:                    vmi.setLabel(label);
097:                    if (user != null)
098:                        vmi.setUser(user);
099:
100:                    vmi.setCreationTime(Calendar.getInstance());
101:                    return vmi;
102:                } catch (RDFDataException e) {
103:                    throw new RuntimeException(e);
104:                }
105:            }
106:
107:            /**
108:             * @return a new empty, model with a random URI. This can later be commited
109:             *         as a Version.
110:             */
111:            public Model getModel() {
112:                checkAlive();
113:                URI rnd = semVersion.getMainModel().newRandomUniqueURI();
114:                log.debug("get model for " + rnd);
115:                return semVersion.getTripleStore().getTempModel(rnd);
116:            }
117:
118:            /**
119:             * @return the SemVersion implementation.
120:             */
121:            public SemVersion getSemVersion() {
122:                checkAlive();
123:                return semVersion;
124:            }
125:
126:            /**
127:             * @return the User holding this Session.
128:             */
129:            public User getUser() {
130:                checkAlive();
131:                return user;
132:            }
133:
134:            /**
135:             * @param string
136:             * @return the VersionedModel with the specified Label or null if no
137:             *         VersionedModel with that label exists.
138:             */
139:            public VersionedModel getVersionedModel(String label) {
140:                checkAlive();
141:                try {
142:                    ClosableIterator<? extends Statement> iter = getSemVersion()
143:                            .getMainModel().findStatements(Variable.ANY,
144:                                    RDFS.label, new PlainLiteralImpl(label));
145:                    VersionedModel versionedModel = null;
146:                    if (iter.hasNext()) {
147:                        Statement s = iter.next();
148:                        versionedModel = new VersionedModel(getSemVersion()
149:                                .getMainModel(), this , (URI) s.getSubject(),
150:                                false);
151:                        if (iter.hasNext()) {
152:                            log
153:                                    .warn("Multiple versioned models have the same label");
154:                        }
155:                    }
156:                    iter.close();
157:                    return versionedModel;
158:                } catch (Exception e) {
159:                    throw new RuntimeException(e);
160:                }
161:            }
162:
163:            /**
164:             * @param uri
165:             * @return the VersionedModel identified by the given URI or null if no such
166:             *         VersionedModel exists.
167:             */
168:            public VersionedModel getVersionedModel(URI uri) {
169:                checkAlive();
170:                return new VersionedModel(getSemVersion().getMainModel(), this ,
171:                        uri, false);
172:            }
173:
174:            /**
175:             * @return all VersionedModel in the store
176:             */
177:            public VersionedModel[] getVersionedModels() {
178:                checkAlive();
179:                Set<VersionedModel> vmis = new HashSet<VersionedModel>();
180:
181:                try {
182:                    ClosableIterator<? extends Statement> iter = getSemVersion()
183:                            .getMainModel()
184:                            .findStatements(
185:                                    Variable.ANY,
186:                                    RDF.type,
187:                                    org.ontoware.semversion.impl.generated.VersionedModel.RDFS_CLASS);
188:                    while (iter.hasNext()) {
189:                        Statement s = iter.next();
190:                        vmis.add(new VersionedModel(getSemVersion()
191:                                .getMainModel(), this , (URI) s.getSubject(),
192:                                false));
193:                    }
194:                    iter.close();
195:                    return vmis.toArray(new VersionedModel[0]);
196:                } catch (Exception e) {
197:                    throw new RuntimeException(e);
198:                }
199:
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.