Source Code Cross Referenced for PyArgParser.java in  » Scripting » jython » com » ziclix » python » sql » util » 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 » Scripting » jython » com.ziclix.python.sql.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jython Database Specification API 2.0
003:         *
004:         * $Id: PyArgParser.java 2414 2005-02-23 04:26:23Z bzimmer $
005:         *
006:         * Copyright (c) 2001 brian zimmer <bzimmer@ziclix.com>
007:         *
008:         */
009:        package com.ziclix.python.sql.util;
010:
011:        import org.python.core.Py;
012:        import org.python.core.PyObject;
013:
014:        import java.util.HashMap;
015:        import java.util.Map;
016:
017:        /**
018:         * Parse the args and kws for a method call.
019:         *
020:         * @author brian zimmer
021:         * @version $Revision: 2414 $
022:         */
023:        public class PyArgParser extends Object {
024:
025:            /**
026:             * Field keywords
027:             */
028:            protected Map keywords;
029:
030:            /**
031:             * Field arguments
032:             */
033:            protected PyObject[] arguments;
034:
035:            /**
036:             * Construct a parser with the arguments and keywords.
037:             */
038:            public PyArgParser(PyObject[] args, String[] kws) {
039:
040:                this .keywords = new HashMap();
041:                this .arguments = null;
042:
043:                parse(args, kws);
044:            }
045:
046:            /**
047:             * Method parse
048:             *
049:             * @param args
050:             * @param kws
051:             */
052:            protected void parse(PyObject[] args, String[] kws) {
053:
054:                // walk backwards through the kws and build the map
055:                int largs = args.length;
056:
057:                if (kws != null) {
058:                    for (int i = kws.length - 1; i >= 0; i--) {
059:                        keywords.put(kws[i], args[--largs]);
060:                    }
061:                }
062:
063:                this .arguments = new PyObject[largs];
064:
065:                System.arraycopy(args, 0, this .arguments, 0, largs);
066:            }
067:
068:            /**
069:             * How many keywords?
070:             */
071:            public int numKw() {
072:                return this .keywords.keySet().size();
073:            }
074:
075:            /**
076:             * Does the keyword exist?
077:             */
078:            public boolean hasKw(String kw) {
079:                return this .keywords.containsKey(kw);
080:            }
081:
082:            /**
083:             * Return the value for the keyword, raise a KeyError if the keyword does
084:             * not exist.
085:             */
086:            public PyObject kw(String kw) {
087:
088:                if (!hasKw(kw)) {
089:                    throw Py.KeyError(kw);
090:                }
091:
092:                return (PyObject) this .keywords.get(kw);
093:            }
094:
095:            /**
096:             * Return the value for the keyword, return the default if the keyword does
097:             * not exist.
098:             */
099:            public PyObject kw(String kw, PyObject def) {
100:
101:                if (!hasKw(kw)) {
102:                    return def;
103:                }
104:
105:                return (PyObject) this .keywords.get(kw);
106:            }
107:
108:            /**
109:             * Get the array of keywords.
110:             */
111:            public String[] kws() {
112:                return (String[]) this .keywords.keySet().toArray(new String[0]);
113:            }
114:
115:            /**
116:             * Get the number of arguments.
117:             */
118:            public int numArg() {
119:                return this .arguments.length;
120:            }
121:
122:            /**
123:             * Return the argument at the given index, raise an IndexError if out of range.
124:             */
125:            public PyObject arg(int index) {
126:
127:                if ((index >= 0) && (index <= this .arguments.length - 1)) {
128:                    return this .arguments[index];
129:                }
130:
131:                throw Py.IndexError("index out of range");
132:            }
133:
134:            /**
135:             * Return the argument at the given index, or the default if the index is out of range.
136:             */
137:            public PyObject arg(int index, PyObject def) {
138:
139:                if ((index >= 0) && (index <= this .arguments.length - 1)) {
140:                    return this.arguments[index];
141:                }
142:
143:                return def;
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.