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


001:        /*
002:         	(c) Copyright 2007, 2008 Hewlett-Packard Development Company, LP
003:         	All rights reserved.
004:         	$Id: NodeCreateUtils.java,v 1.2 2008/01/02 12:05:32 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.graph.test;
008:
009:        import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
010:        import com.hp.hpl.jena.graph.Node;
011:        import com.hp.hpl.jena.graph.impl.LiteralLabel;
012:        import com.hp.hpl.jena.rdf.model.AnonId;
013:        import com.hp.hpl.jena.shared.*;
014:
015:        /**
016:         Creating nodes from string specifications.
017:         */
018:        public class NodeCreateUtils {
019:            /**
020:                Returns a Node described by the string, primarily for testing purposes.
021:                The string represents a URI, a numeric literal, a string literal, a bnode label,
022:                or a variable.        
023:                <ul>
024:                <li> 'some text' :: a string literal with that text
025:                <li> 'some text'someLanguage:: a string literal with that text and language
026:                <li> 'some text'someURI:: a typed literal with that text and datatype
027:                <li> digits :: a literal [OF WHAT TYPE] with that [numeric] value
028:                <li> _XXX :: a bnode with an AnonId built from _XXX
029:                <li> ?VVV :: a variable with name VVV
030:                <li> &PPP :: to be done
031:                <li> name:stuff :: the URI; name may be expanded using the Extended map
032:                </ul>
033:                @param x the string describing the node
034:                @return a node of the appropriate type with the appropriate label
035:             */
036:            public static Node create(String x) {
037:                return create(PrefixMapping.Extended, x);
038:            }
039:
040:            /**
041:            Returns a Node described by the string, primarily for testing purposes.
042:            The string represents a URI, a numeric literal, a string literal, a bnode label,
043:            or a variable.        
044:            <ul>
045:            <li> 'some text' :: a string literal with that text
046:            <li> 'some text'someLanguage:: a string literal with that text and language
047:            <li> 'some text'someURI:: a typed literal with that text and datatype
048:            <li> digits :: a literal [OF WHAT TYPE] with that [numeric] value
049:            <li> _XXX :: a bnode with an AnonId built from _XXX
050:            <li> ?VVV :: a variable with name VVV
051:            <li> &PPP :: to be done
052:            <li> name:stuff :: the URI; name may be expanded using the Extended map
053:            </ul>
054:            
055:            @param pm the PrefixMapping for translating pre:X strings
056:            @param x the string encoding the node to create
057:            @return a node with the appropriate type and label
058:             */
059:            public static Node create(PrefixMapping pm, String x) {
060:                if (x.equals(""))
061:                    throw new JenaException(
062:                            "Node.create does not accept an empty string as argument");
063:                char first = x.charAt(0);
064:                if (first == '\'' || first == '\"')
065:                    return Node.createLiteral(newString(pm, first, x));
066:                if (Character.isDigit(first))
067:                    return Node.createLiteral(x, "", XSDDatatype.XSDinteger);
068:                if (first == '_')
069:                    return Node.createAnon(new AnonId(x));
070:                if (x.equals("??"))
071:                    return Node.ANY;
072:                if (first == '?')
073:                    return Node.createVariable(x.substring(1));
074:                if (first == '&')
075:                    return Node.createURI("q:" + x.substring(1));
076:                int colon = x.indexOf(':');
077:                String d = pm.getNsPrefixURI("");
078:                return colon < 0 ? Node.createURI((d == null ? "eh:/" : d) + x)
079:                        : Node.createURI(pm.expandPrefix(x));
080:            }
081:
082:            public static String unEscape(String spelling) {
083:                if (spelling.indexOf('\\') < 0)
084:                    return spelling;
085:                StringBuffer result = new StringBuffer(spelling.length());
086:                int start = 0;
087:                while (true) {
088:                    int b = spelling.indexOf('\\', start);
089:                    if (b < 0)
090:                        break;
091:                    result.append(spelling.substring(start, b));
092:                    result.append(unEscape(spelling.charAt(b + 1)));
093:                    start = b + 2;
094:                }
095:                result.append(spelling.substring(start));
096:                return result.toString();
097:            }
098:
099:            public static char unEscape(char ch) {
100:                switch (ch) {
101:                case '\\':
102:                case '\"':
103:                case '\'':
104:                    return ch;
105:                case 'n':
106:                    return '\n';
107:                case 's':
108:                    return ' ';
109:                case 't':
110:                    return '\t';
111:                default:
112:                    return 'Z';
113:                }
114:            }
115:
116:            public static LiteralLabel literal(PrefixMapping pm,
117:                    String spelling, String langOrType) {
118:                String content = unEscape(spelling);
119:                int colon = langOrType.indexOf(':');
120:                return colon < 0 ? new LiteralLabel(content, langOrType, false)
121:                        : LiteralLabel.createLiteralLabel(content, "", Node
122:                                .getType(pm.expandPrefix(langOrType)));
123:            }
124:
125:            public static LiteralLabel newString(PrefixMapping pm, char quote,
126:                    String nodeString) {
127:                int close = nodeString.lastIndexOf(quote);
128:                return literal(pm, nodeString.substring(1, close), nodeString
129:                        .substring(close + 1));
130:            }
131:        }
132:
133:        /*
134:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
135:         * All rights reserved.
136:         *
137:         * Redistribution and use in source and binary forms, with or without
138:         * modification, are permitted provided that the following conditions
139:         * are met:
140:         * 1. Redistributions of source code must retain the above copyright
141:         *    notice, this list of conditions and the following disclaimer.
142:         * 2. Redistributions in binary form must reproduce the above copyright
143:         *    notice, this list of conditions and the following disclaimer in the
144:         *    documentation and/or other materials provided with the distribution.
145:         * 3. The name of the author may not be used to endorse or promote products
146:         *    derived from this software without specific prior written permission.
147:         *
148:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
149:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
150:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
151:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
152:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
153:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
154:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
155:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
157:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.