Source Code Cross Referenced for ModelReifier.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » rdf » model » impl » 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 » Jena 2.5.5 » com.hp.hpl.jena.rdf.model.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        	(c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:        	[see end of file]
004:        	$Id: ModelReifier.java,v 1.23 2008/01/02 12:05:05 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.rdf.model.impl;
008:
009:        import com.hp.hpl.jena.rdf.model.*;
010:        import com.hp.hpl.jena.shared.*;
011:        import com.hp.hpl.jena.graph.*;
012:        import com.hp.hpl.jena.graph.compose.*;
013:        import com.hp.hpl.jena.graph.impl.GraphBase;
014:        import com.hp.hpl.jena.util.iterator.*;
015:
016:        /**
017:         This class impedance-matches the reification requests of Model[Com] to the operations
018:         supplied by it's Graph's Reifier.
019:        
020:         @author kers 
021:         */
022:        public class ModelReifier {
023:            private ModelCom model;
024:            public Reifier reifier;
025:
026:            /**
027:                DEVEL. setting this _true_ means that nodes that reify statements
028:                will drag their reification quads into other nodes when they are
029:                added to them inside statements.
030:             */
031:            private static boolean copyingReifications = false;
032:
033:            /**
034:                establish the internal state of this ModelReifier: the associated
035:                Model[Com] and its graph's Reifier.
036:             */
037:            public ModelReifier(ModelCom model) {
038:                this .model = model;
039:                this .reifier = model.asGraph().getReifier();
040:            }
041:
042:            public ReificationStyle getReificationStyle() {
043:                return reifier.getStyle();
044:            }
045:
046:            /**
047:                Answer a version of the model, but with all its reifiying statements
048:                added.
049:                @param m a model that may have reified statements
050:                @return a new model, the union of m and the reification statements of m
051:             */
052:            public static Model withHiddenStatements(Model m) {
053:                Graph mGraph = m.getGraph();
054:                Graph hiddenTriples = getHiddenTriples(m);
055:                return new ModelCom(new DisjointUnion(mGraph, hiddenTriples));
056:            }
057:
058:            /**
059:            	@param mGraph
060:            	@return
061:             */
062:            protected static Graph getHiddenTriples(Model m) {
063:                Graph mGraph = m.getGraph();
064:                final Reifier r = mGraph.getReifier();
065:                return new GraphBase() {
066:                    public ExtendedIterator graphBaseFind(TripleMatch m) {
067:                        return r.findEither(m, true);
068:                    }
069:                };
070:            }
071:
072:            /**
073:                Answer a model that consists of the hidden reification statements of this model.
074:                @return a new model containing the hidden statements of this model
075:             */
076:            public Model getHiddenStatements() {
077:                return new ModelCom(getHiddenTriples(model));
078:            }
079:
080:            /**
081:                Answer a fresh reification of a statement associated with a fresh bnode.
082:                @param s a Statement to reifiy
083:                @return a reified statement object who's name is a new bnode
084:             */
085:            public ReifiedStatement createReifiedStatement(Statement s) {
086:                return createReifiedStatement(null, s);
087:            }
088:
089:            /**
090:                Answer a reification of  a statement with a given uri. If that uri 
091:                already reifies a distinct Statement, throw an AlreadyReifiedException.
092:                @param uri the URI of the resource which will reify <code>s</code>
093:                @param s the Statement to reify
094:                @return a reified statement object associating <code>uri</code> with <code>s</code>.
095:                @throws AlreadyReifiedException if uri already reifies something else. 
096:             */
097:            public ReifiedStatement createReifiedStatement(String uri,
098:                    Statement s) {
099:                return ReifiedStatementImpl.create(model, uri, s);
100:            }
101:
102:            /**
103:                Find any existing reified statement that reifies a givem statement. If there isn't one,
104:                create one.
105:                @param s a Statement for which to find [or create] a reification
106:                @return a reification for s, re-using an existing one if possible
107:             */
108:            public Resource getAnyReifiedStatement(Statement s) {
109:                RSIterator it = listReifiedStatements(s);
110:                if (it.hasNext())
111:                    try {
112:                        return it.nextRS();
113:                    } finally {
114:                        it.close();
115:                    }
116:                else
117:                    return createReifiedStatement(s);
118:            }
119:
120:            /**
121:                Answer true iff a given statement is reified in this model
122:                @param s the statement for which a reification is sought
123:                @return true iff s has a reification in this model
124:             */
125:            public boolean isReified(FrontsTriple s) {
126:                return reifier.hasTriple(s.asTriple());
127:            }
128:
129:            /**
130:                Remove all the reifications of a given statement in this model, whatever
131:                their associated resources.
132:                @param s the statement whose reifications are to be removed
133:             */
134:            public void removeAllReifications(FrontsTriple s) {
135:                reifier.remove(s.asTriple());
136:            }
137:
138:            /**
139:                Remove a given reification from this model. Other reifications of the same statement
140:                are untouched.
141:                @param rs the reified statement to be removed
142:             */
143:            public void removeReification(ReifiedStatement rs) {
144:                reifier.remove(rs.asNode(), rs.getStatement().asTriple());
145:            }
146:
147:            /**
148:                Answer an iterator that iterates over all the reified statements
149:                in this model.
150:                @return an iterator over all the reifications of the model.
151:             */
152:            public RSIterator listReifiedStatements() {
153:                return new RSIteratorImpl(findReifiedStatements());
154:            }
155:
156:            /**
157:                Answer an iterator that iterates over all the reified statements in
158:                this model that reify a given statement.
159:                @param s the statement whose reifications are sought.
160:                @return an iterator over the reifications of s.
161:             */
162:            public RSIterator listReifiedStatements(FrontsTriple s) {
163:                return new RSIteratorImpl(findReifiedStatements(s.asTriple()));
164:            }
165:
166:            /**
167:                the triple (s, p, o) has been asserted into the model. Any reified statements
168:                among them need to be added to this model.
169:             */
170:            public void noteIfReified(RDFNode s, RDFNode p, RDFNode o) {
171:                if (copyingReifications) {
172:                    noteIfReified(s);
173:                    noteIfReified(p);
174:                    noteIfReified(o);
175:                }
176:            }
177:
178:            /**
179:                If _n_ is a ReifiedStatement, create a local copy of it, which
180:                will force the underlying reifier to take note of the mapping.
181:             */
182:            private void noteIfReified(RDFNode n) {
183:                if (n.canAs(ReifiedStatement.class)) {
184:                    ReifiedStatement rs = (ReifiedStatement) n
185:                            .as(ReifiedStatement.class);
186:                    createReifiedStatement(rs.getURI(), rs.getStatement());
187:                }
188:            }
189:
190:            /**
191:                A mapper that maps modes to their corresponding ReifiedStatement objects. This
192:                cannot be static: getRS cannot be static, because the mapping is model-specific.
193:             */
194:            protected final Map1 mapToRS = new Map1() {
195:                public Object map1(Object node) {
196:                    return getRS((Node) node);
197:                }
198:            };
199:
200:            private ExtendedIterator findReifiedStatements() {
201:                return reifier.allNodes().mapWith(mapToRS);
202:            }
203:
204:            private ExtendedIterator findReifiedStatements(Triple t) {
205:                return reifier.allNodes(t).mapWith(mapToRS);
206:            }
207:
208:            /**
209:                Answer a ReifiedStatement that is based on the given node. 
210:                @param n the node which represents the reification (and is bound to some triple t)
211:                @return a ReifiedStatement associating the resource of n with the statement of t.    
212:             */
213:            private ReifiedStatement getRS(Node n) {
214:                return ReifiedStatementImpl.createExistingReifiedStatement(
215:                        model, n);
216:            }
217:        }
218:
219:        /*
220:         (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
221:         All rights reserved.
222:
223:         Redistribution and use in source and binary forms, with or without
224:         modification, are permitted provided that the following conditions
225:         are met:
226:
227:         1. Redistributions of source code must retain the above copyright
228:         notice, this list of conditions and the following disclaimer.
229:
230:         2. Redistributions in binary form must reproduce the above copyright
231:         notice, this list of conditions and the following disclaimer in the
232:         documentation and/or other materials provided with the distribution.
233:
234:         3. The name of the author may not be used to endorse or promote products
235:         derived from this software without specific prior written permission.
236:
237:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
238:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
239:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
240:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
241:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
242:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
246:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
247:         */
ww__w._j__a__v__a___2s_.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.