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


001:        package org.ontoware.rdfreactor.runtime;
002:
003:        import java.util.Map;
004:        import java.util.WeakHashMap;
005:
006:        import org.ontoware.rdf2go.exception.ModelRuntimeException;
007:        import org.ontoware.rdf2go.model.Model;
008:        import org.ontoware.rdf2go.model.node.DatatypeLiteral;
009:        import org.ontoware.rdf2go.model.node.LanguageTagLiteral;
010:        import org.ontoware.rdf2go.model.node.Node;
011:        import org.ontoware.rdf2go.model.node.Resource;
012:        import org.ontoware.rdf2go.model.node.URI;
013:        import org.ontoware.rdf2go.model.node.Variable;
014:        import org.ontoware.rdf2go.model.node.impl.URIImpl;
015:        import org.ontoware.rdf2go.vocabulary.RDF;
016:
017:        /**
018:         * 
019:         * Java Object <---> Node, Resource
020:         * 
021:         * TODO: test weak references
022:         * 
023:         * @author voelkel
024:         * 
025:         */
026:        public class FORD {
027:
028:            private static WeakHashMap<Resource, Object> r2o = new WeakHashMap<Resource, Object>();
029:
030:            private static WeakHashMap<Object, Resource> o2r = new WeakHashMap<Object, Resource>();
031:
032:            private static WeakHashMap<Object, Model> o2m = new WeakHashMap<Object, Model>();
033:
034:            public static Object create(Model model, Class returnType,
035:                    Resource name, boolean write) {
036:
037:                try {
038:                    Object o = returnType.newInstance();
039:
040:                    // check for RDF annotation
041:                    if (write) {
042:                        try {
043:                            URI rdfsClassURI = getRDFasURI(o);
044:                            model.addStatement(name, RDF.type, rdfsClassURI);
045:                            // now forget the annotation and never us it again?
046:                        } catch (ModelRuntimeException e) {
047:                            throw new RuntimeException(e);
048:                        }
049:                    }
050:                    r2o.put(name, o);
051:                    o2r.put(o, name);
052:                    o2m.put(o, model);
053:                    return o;
054:                } catch (InstantiationException e) {
055:                    // TODO Auto-generated catch block
056:                    throw new RuntimeException(e);
057:                } catch (IllegalAccessException e) {
058:                    // TODO Auto-generated catch block
059:                    throw new RuntimeException(e);
060:                }
061:
062:            }
063:
064:            public static URI getRDFasURI(Object o)
065:                    throws ModelRuntimeException {
066:                String annotation = o.getClass().getAnnotation(
067:                        org.ontoware.rdfreactor.annotation.RDF.class).value();
068:                return new URIImpl(annotation);
069:            }
070:
071:            public static Object get(Object obj, URI p, Class returnType) {
072:                try {
073:                    return Bridge.getValue(o2m.get(obj), o2r.get(obj), p,
074:                            returnType);
075:                } catch (RDFDataException e) {
076:                    // TODO Auto-generated catch block
077:                    throw new RuntimeException(e);
078:                } catch (ModelRuntimeException e) {
079:                    // TODO Auto-generated catch block
080:                    throw new RuntimeException(e);
081:                }
082:            }
083:
084:            public static void set(Object obj, URI p, Object value) {
085:                Bridge.setValue(o2m.get(obj), o2r.get(obj), p, toNode(value));
086:            }
087:
088:            public static void add(Object obj, URI p, Object value) {
089:                // TODO Auto-generated method stub
090:
091:            }
092:
093:            public static Node toNode(Object o) {
094:                return null;
095:                // IMPROVE
096:            }
097:
098:            public static void remove(Object obj, URI p, Object value) {
099:                // TODO Auto-generated method stub
100:
101:            }
102:
103:            public static Object[] getAll(Object obj, URI p, Class<?> returnType) {
104:                // TODO Auto-generated method stub
105:                return null;
106:            }
107:
108:            public static Object[] getAllInstances(Object obj,
109:                    Class<?> returnType) {
110:                // TODO use annot
111:                return null;
112:            }
113:
114:            public static Map<URI, Object> asMap(Object obj) {
115:                return new ReactorMap(o2m.get(obj), o2r.get(obj));
116:            }
117:
118:            public static boolean removeAll(Object obj, URI p) {
119:                Resource r = o2r.get(obj);
120:                Model m = o2m.get(r);
121:
122:                try {
123:                    return Bridge.removeAllValues(m, r, p);
124:                } catch (Exception e) {
125:                    throw new RuntimeException(e);
126:                }
127:
128:            }
129:
130:            /**
131:             * @param model
132:             *            RDF2Go model
133:             * @return true if any statement (this,*,*) is contained in given model
134:             */
135:            public static boolean in(Object obj, Model model) {
136:                try {
137:                    return model.contains(o2r.get(obj), Variable.ANY,
138:                            Variable.ANY);
139:                } catch (Exception e) {
140:                    throw new RuntimeException(e);
141:                }
142:            }
143:
144:            public static Model getModel(Object obj) {
145:                return o2m.get(obj);
146:            }
147:
148:            /**
149:             * remove all (this, rdf:type, ANY) statements
150:             */
151:            public void delete(Object obj) {
152:                try {
153:                    ResourceUtils.delete(o2m.get(obj), o2r.get(obj));
154:                } catch (Exception e) {
155:                    throw new RuntimeException(e);
156:                }
157:            }
158:
159:            //	/**
160:            //	 * @param prop
161:            //	 *            property URI
162:            //	 * @param o
163:            //	 * @return a statement (this, uri, object) and thus bridges the gap between
164:            //	 *         the OO and RDF worlds.
165:            //	 */
166:            //	public Statement getStatement(Object obj, URI p, Object o) {
167:            //		return Bridge.getStatement(o2m.get(obj), o2r.get(obj), p, o);
168:            //	}
169:
170:            public boolean equals(Object obj, Object other) {
171:
172:                if (obj instanceof  ResourceEntity) {
173:                    ResourceEntity resourceEntity = (ResourceEntity) obj;
174:                    if (other instanceof  URI)
175:                        return resourceEntity.getResource().equals(other);
176:                    else if (other instanceof  ResourceEntity)
177:                        return resourceEntity.getResource().equals(
178:                                ((ResourceEntity) other).getResource());
179:                    else
180:                        return false;
181:                } else if (obj instanceof  URI) {
182:                    // return true if o has same uri
183:                    if (other instanceof  ResourceEntity) {
184:                        return ((ResourceEntity) other).getResource().equals(
185:                                obj);
186:                    } else if (other instanceof  URI) {
187:                        return obj.equals(other);
188:                    } else
189:                        return false;
190:                } else if (obj instanceof  String) {
191:                    // return true if o has same value
192:                    return obj.toString().equals(other.toString());
193:                } else if (obj instanceof  LanguageTagLiteral
194:                        || obj instanceof  DatatypeLiteral) {
195:                    // IMPROVE: better literal handling
196:                    return obj.equals(other);
197:                } else
198:                    // o is never == blank node or variable
199:                    return false;
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.