Source Code Cross Referenced for StatementImpl.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 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:        	[See end of file]
004:        	$Id: StatementImpl.java,v 1.32 2008/01/02 12:04:57 andy_seaborne Exp $
005:         */
006:        package com.hp.hpl.jena.rdf.model.impl;
007:
008:        import com.hp.hpl.jena.rdf.model.*;
009:        import com.hp.hpl.jena.enhanced.*;
010:        import com.hp.hpl.jena.shared.*;
011:
012:        import com.hp.hpl.jena.graph.*;
013:
014:        /** An implementation of Statement.
015:         *
016:         * @author  bwm
017:         * @version  $Name:  $ $Revision: 1.32 $ $Date: 2008/01/02 12:04:57 $
018:         */
019:        public class StatementImpl extends StatementBase implements  Statement {
020:
021:            protected Resource subject;
022:            protected Property predicate;
023:            protected RDFNode object;
024:
025:            /** Creates new StatementImpl */
026:            public StatementImpl(Resource subject, Property predicate,
027:                    RDFNode object, ModelCom model) {
028:                super (model);
029:                this .subject = (Resource) subject.inModel(model);
030:                this .predicate = (Property) predicate.inModel(model);
031:                this .object = object.inModel(model);
032:            }
033:
034:            // TODO fix this hack
035:            protected static ModelCom empty = (ModelCom) ModelFactory
036:                    .createDefaultModel();
037:
038:            public StatementImpl(Resource subject, Property predicate,
039:                    RDFNode object) {
040:                super (empty);
041:                this .subject = (Resource) subject.inModel(model);
042:                this .predicate = (Property) predicate.inModel(model);
043:                this .object = object.inModel(model);
044:            }
045:
046:            /**
047:             * create a Statement from the triple _t_ in the enhanced graph _eg_. The
048:             * Statement has subject, predicate, and object corresponding to those of
049:             * _t_.
050:             */
051:            public static Statement toStatement(Triple t, ModelCom eg) {
052:                Resource s = new ResourceImpl(t.getSubject(), eg);
053:                Property p = new PropertyImpl(t.getPredicate(), eg);
054:                RDFNode o = createObject(t.getObject(), eg);
055:                return new StatementImpl(s, p, o, eg);
056:            }
057:
058:            public Resource getSubject() {
059:                return subject;
060:            }
061:
062:            public Property getPredicate() {
063:                return predicate;
064:            }
065:
066:            public RDFNode getObject() {
067:                return object;
068:            }
069:
070:            public Statement getStatementProperty(Property p) {
071:                return asResource().getRequiredProperty(p);
072:            }
073:
074:            public Resource getResource() {
075:                return mustBeResource(object);
076:            }
077:
078:            public Resource getResource(ResourceF f) {
079:                return f.createResource(getResource());
080:            }
081:
082:            public Statement getProperty(Property p) {
083:                return getResource().getRequiredProperty(p);
084:            }
085:
086:            /**
087:                get the object field of this statement, insisting that it be a Literal.
088:                If it isn't, throw LiteralRequiredException.
089:             */
090:            public Literal getLiteral() {
091:                if (object instanceof  Literal) {
092:                    return (Literal) object;
093:                } else {
094:                    throw new LiteralRequiredException(object);
095:                }
096:            }
097:
098:            public Object getObject(ObjectF f) {
099:                try {
100:                    return f.createObject(getLiteral().toString());
101:                } catch (Exception e) {
102:                    throw new JenaException(e);
103:                }
104:            }
105:
106:            /** I suspect that this is now not pulling its weight. */
107:            private EnhNode get(Class interf) {
108:                return (EnhNode) object.as(interf);
109:            }
110:
111:            public Bag getBag() {
112:                return (Bag) get(Bag.class);
113:            }
114:
115:            public Alt getAlt() {
116:                return (Alt) get(Alt.class);
117:            }
118:
119:            public Seq getSeq() {
120:                return (Seq) get(Seq.class);
121:            }
122:
123:            /** it turns out to be handy to return the new StatementImpl as the result */
124:            protected StatementImpl replace(RDFNode n) {
125:                StatementImpl s = new StatementImpl(subject, predicate, n,
126:                        model);
127:                model.remove(this ).add(s);
128:                return s;
129:            }
130:
131:            /**
132:                .equals() defers to .sameAs so we only get the complexity of one cast.
133:             */
134:            public boolean equals(Object o) {
135:                return o instanceof  Statement && sameAs((Statement) o);
136:            }
137:
138:            /**
139:                sameAs - is this statement equal to the statement o? We can't assume
140:                o is a StatementImpl
141:             */
142:            private final boolean sameAs(Statement o) {
143:                return subject.equals(o.getSubject())
144:                        && predicate.equals(o.getPredicate())
145:                        && object.equals(o.getObject());
146:            }
147:
148:            public int hashCode() {
149:                return asTriple().hashCode();
150:            }
151:
152:            public Resource asResource() {
153:                return model.getAnyReifiedStatement(this );
154:            }
155:
156:            public Statement remove() {
157:                model.remove(this );
158:                return this ;
159:            }
160:
161:            public void removeReification() {
162:                model.removeAllReifications(this );
163:            }
164:
165:            public Triple asTriple() {
166:                return Triple.create(subject.asNode(), predicate.asNode(),
167:                        object.asNode());
168:            }
169:
170:            /**
171:                returns an array of triples corresponding to the array of statements; ie
172:                the i'th element of the result is the i'th element of the input as a triple.
173:                @param statements the array of statements to convert
174:                @return the corresponding array of triples
175:             */
176:            public static Triple[] asTriples(Statement[] statements) {
177:                Triple[] triples = new Triple[statements.length];
178:                for (int i = 0; i < statements.length; i += 1)
179:                    triples[i] = statements[i].asTriple();
180:                return triples;
181:            }
182:
183:            public boolean isReified() {
184:                return model.isReified(this );
185:            }
186:
187:            /**
188:                create a ReifiedStatement corresponding to this Statement
189:             */
190:            public ReifiedStatement createReifiedStatement() {
191:                return ReifiedStatementImpl.create(this );
192:            }
193:
194:            /**
195:                create a ReifiedStatement corresponding to this Statement
196:                and with the given _uri_.
197:             */
198:            public ReifiedStatement createReifiedStatement(String uri) {
199:                return ReifiedStatementImpl.create((ModelCom) this .getModel(),
200:                        uri, this );
201:            }
202:
203:            public RSIterator listReifiedStatements() {
204:                return model.listReifiedStatements(this );
205:            }
206:
207:            /**
208:                create an RDF node which might be a literal, or not.
209:             */
210:            public static RDFNode createObject(Node n, EnhGraph g) {
211:                return n.isLiteral() ? (RDFNode) new LiteralImpl(n, g)
212:                        : new ResourceImpl(n, g);
213:            }
214:
215:        }
216:
217:        /*
218:         (c) Copyright 2000, 2001, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
219:         All rights reserved.
220:        
221:         Redistribution and use in source and binary forms, with or without
222:         modification, are permitted provided that the following conditions
223:         are met:
224:         1. Redistributions of source code must retain the above copyright
225:         notice, this list of conditions and the following disclaimer.
226:         2. Redistributions in binary form must reproduce the above copyright
227:         notice, this list of conditions and the following disclaimer in the
228:         documentation and/or other materials provided with the distribution.
229:         3. The name of the author may not be used to endorse or promote products
230:         derived from this software without specific prior written permission.
231:        
232:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
233:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
234:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
235:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
236:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
237:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
239:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
240:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
242:         */
w___w_w._j__a_v_a__2_s._c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.