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


001:        /******************************************************************
002:         * File:        TypeMapper.java
003:         * Created by:  Dave Reynolds
004:         * Created on:  07-Dec-02
005:         * 
006:         * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007:         * [See end of file]
008:         * $Id: TypeMapper.java,v 1.10 2008/01/02 12:10:24 andy_seaborne Exp $
009:         *****************************************************************/package com.hp.hpl.jena.datatypes;
010:
011:        import java.util.HashMap;
012:        import java.util.Iterator;
013:
014:        import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
015:        import com.hp.hpl.jena.datatypes.xsd.impl.XMLLiteralType;
016:        import com.hp.hpl.jena.shared.impl.JenaParameters;
017:
018:        /**
019:         * The TypeMapper provides a global registry of known datatypes.
020:         * The datatypes can be retrieved by their URI or from the java class
021:         * that is used to represent them.
022:         * 
023:         * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
024:         * @version $Revision: 1.10 $ on $Date: 2008/01/02 12:10:24 $
025:         */
026:        public class TypeMapper {
027:
028:            //=======================================================================
029:            // Statics
030:
031:            /**
032:             * Return the single global instance of the TypeMapper.
033:             * Done this way rather than simply making the static
034:             * field directly accessible to allow us to dynamically
035:             * replace the entire mapper table if needed.
036:             */
037:            public static TypeMapper getInstance() {
038:                return theTypeMap;
039:            }
040:
041:            /**
042:             * The single global instance of the TypeMapper
043:             */
044:            private static TypeMapper theTypeMap;
045:
046:            /**
047:             * Static initializer. Adds builtin datatypes to the mapper.
048:             */
049:            static {
050:                theTypeMap = new TypeMapper();
051:                theTypeMap.registerDatatype(XMLLiteralType.theXMLLiteralType);
052:                XSDDatatype.loadXSDSimpleTypes(theTypeMap);
053:            }
054:
055:            //=======================================================================
056:            // Variables
057:
058:            /** Map from uri to datatype */
059:            private HashMap uriToDT = new HashMap();
060:
061:            /** Map from java class to datatype */
062:            private HashMap classToDT = new HashMap();
063:
064:            //=======================================================================
065:            // Methods
066:
067:            /**
068:             * Version of getTypeByName which will treat unknown URIs as typed
069:             * literals but with just the default implementation
070:             * 
071:             * @param uri the URI of the desired datatype
072:             * @return Datatype the datatype definition
073:             * registered at uri, if there is no such registered type it
074:             * returns a new instance of the default datatype implementation, if the
075:             * uri is null it returns null (indicating a plain RDF literal).
076:             */
077:            public RDFDatatype getSafeTypeByName(String uri) {
078:                RDFDatatype dtype = (RDFDatatype) uriToDT.get(uri);
079:                if (dtype == null) {
080:                    if (uri == null) {
081:                        // Plain literal
082:                        return null;
083:                    } else {
084:                        // Uknown datatype
085:                        if (JenaParameters.enableSilentAcceptanceOfUnknownDatatypes) {
086:                            dtype = new BaseDatatype(uri);
087:                            registerDatatype(dtype);
088:                        } else {
089:                            throw new DatatypeFormatException(
090:                                    "Attempted to created typed literal using an unknown datatype - "
091:                                            + uri);
092:                        }
093:                    }
094:                }
095:                return dtype;
096:            }
097:
098:            /**
099:             * Lookup a known datatype. An unkown datatype or a datatype with uri null
100:             * will return null will mean that the value will be treated as a old-style plain literal.
101:             * 
102:             * @param uri the URI of the desired datatype
103:             * @return Datatype the datatype definition of null if not known.
104:             */
105:            public RDFDatatype getTypeByName(String uri) {
106:                return (RDFDatatype) uriToDT.get(uri);
107:            }
108:
109:            /**
110:             * Method getTypeByValue. Look up a datatype suitable for representing
111:             * the given java value object.
112:             * 
113:             * @param value a value instance to be represented
114:             * @return Datatype a datatype whose value space matches the java class
115:             * of <code>value</code>
116:             */
117:            public RDFDatatype getTypeByValue(Object value) {
118:                return (RDFDatatype) classToDT.get(value.getClass());
119:            }
120:
121:            /**
122:             * List all the known datatypes 
123:             */
124:            public Iterator listTypes() {
125:                return uriToDT.values().iterator();
126:            }
127:
128:            /**
129:             * Register a new datatype
130:             */
131:            public void registerDatatype(RDFDatatype type) {
132:                uriToDT.put(type.getURI(), type);
133:                Class jc = type.getJavaClass();
134:                if (jc != null) {
135:                    classToDT.put(jc, type);
136:                }
137:            }
138:
139:            // Temporary development code
140:            public static void main(String[] args) {
141:                for (Iterator iter = theTypeMap.listTypes(); iter.hasNext();) {
142:                    RDFDatatype dt = (RDFDatatype) iter.next();
143:                    System.out.println(" - " + dt);
144:                }
145:            }
146:        }
147:
148:        /*
149:         (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
150:         All rights reserved.
151:
152:         Redistribution and use in source and binary forms, with or without
153:         modification, are permitted provided that the following conditions
154:         are met:
155:
156:         1. Redistributions of source code must retain the above copyright
157:         notice, this list of conditions and the following disclaimer.
158:
159:         2. Redistributions in binary form must reproduce the above copyright
160:         notice, this list of conditions and the following disclaimer in the
161:         documentation and/or other materials provided with the distribution.
162:
163:         3. The name of the author may not be used to endorse or promote products
164:         derived from this software without specific prior written permission.
165:
166:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
167:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
168:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
169:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
170:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
171:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
172:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
173:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
174:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
175:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
176:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.