Source Code Cross Referenced for TestChannelCmd.java in  » Scripting » jacl » tcl » lang » 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 » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * TestChannelCmd.java --
003:         *
004:         * Copyright (c) 2001 Bruce A. Johnson
005:         *
006:         * See the file "license.terms" for information on usage and
007:         * redistribution of this file, and for a DISCLAIMER OF ALL
008:         * WARRANTIES.
009:         * 
010:         * RCS: @(#) $Id: TestChannelCmd.java,v 1.4 2006/01/26 19:49:19 mdejong Exp $
011:         *
012:         */
013:
014:        package tcl.lang;
015:
016:        import java.util.Map;
017:        import java.util.HashMap;
018:        import java.util.Iterator;
019:        import java.io.IOException;
020:
021:        /**
022:         * This class implements the built-in "testchannel" command in Tcl.
023:         */
024:
025:        class TestChannelCmd implements  Command {
026:            // FIXME: The C implementation in Tcl 8.4 seems to support
027:            // a number of additional options
028:
029:            static final private String validCmds[] = { "info",
030:                    "inputbuffered", "name", "open", "outputbuffered",
031:                    "queuedcr", "refcount", "type" };
032:
033:            static final int OPT_INFO = 0;
034:            static final int OPT_INPUTBUFFERED = 1;
035:            static final int OPT_NAME = 2;
036:            static final int OPT_OPEN = 3;
037:            static final int OPT_OUTPUTBUFFERED = 4;
038:            static final int OPT_QUEUEDCR = 5;
039:            static final int OPT_REFCOUNT = 6;
040:            static final int OPT_TYPE = 7;
041:
042:            /**
043:             * This procedure is invoked to process the "testchannel" Tcl command.
044:             * See the user documentation for details on what it does.
045:             *
046:             * @param interp the current interpreter.
047:             * @param argv command arguments.
048:             */
049:
050:            public void cmdProc(Interp interp, TclObject argv[])
051:                    throws TclException {
052:                Channel chan;
053:
054:                if (argv.length == 2) {
055:                    if (!argv[1].toString().equals("open")) {
056:                        throw new TclNumArgsException(interp, 1, argv,
057:                                "only option open can have two args");
058:                    }
059:                } else if (argv.length != 3) {
060:                    throw new TclNumArgsException(interp, 1, argv,
061:                            "command channelId");
062:                }
063:
064:                if (argv.length == 2) {
065:                    // return list of all name/value pairs for this channelId
066:                    HashMap chanTable = TclIO.getInterpChanTable(interp);
067:                    TclObject list = TclList.newInstance();
068:
069:                    for (Iterator iter = chanTable.entrySet().iterator(); iter
070:                            .hasNext();) {
071:                        Map.Entry entry = (Map.Entry) iter.next();
072:                        chan = (Channel) entry.getValue();
073:                        TclList.append(interp, list, TclString.newInstance(chan
074:                                .getChanName()));
075:                    }
076:                    interp.setResult(list);
077:                    return;
078:                }
079:                chan = TclIO.getChannel(interp, argv[2].toString());
080:                if (chan == null) {
081:                    throw new TclException(interp,
082:                            "can not find channel named \""
083:                                    + argv[2].toString() + "\"");
084:                }
085:
086:                int index = TclIndex.get(interp, argv[1], validCmds, "option",
087:                        0);
088:                switch (index) {
089:                case OPT_INFO: {
090:                    TclObject list = TclList.newInstance();
091:                    TclList.append(interp, list, argv[2]); // 0
092:                    TclList.append(interp, list, TclString.newInstance(chan
093:                            .getChanType())); // 1
094:
095:                    if (chan.isReadOnly() || chan.isReadWrite()) {
096:                        TclList.append(interp, list, TclString
097:                                .newInstance("read")); // 2
098:                    } else {
099:                        TclList.append(interp, list, TclString.newInstance(""));
100:                    }
101:
102:                    if (chan.isWriteOnly() || chan.isReadWrite()) {
103:                        TclList.append(interp, list, TclString
104:                                .newInstance("write")); // 3
105:                    } else {
106:                        TclList.append(interp, list, TclString.newInstance(""));
107:                    }
108:
109:                    if (chan.getBlocking()) {
110:                        TclList.append(interp, list, TclString
111:                                .newInstance("blocking")); // 4
112:                    } else {
113:                        TclList.append(interp, list, TclString
114:                                .newInstance("nonblocking"));
115:                    }
116:
117:                    if (chan.getBuffering() == TclIO.BUFF_FULL) {
118:                        TclList.append(interp, list, TclString
119:                                .newInstance("full")); // 5
120:                    } else if (chan.getBuffering() == TclIO.BUFF_LINE) {
121:                        TclList.append(interp, list, TclString
122:                                .newInstance("line"));
123:                    } else {
124:                        TclList.append(interp, list, TclString
125:                                .newInstance("none"));
126:                    }
127:
128:                    if (chan.isBgFlushScheduled()) {
129:                        TclList.append(interp, list, TclString
130:                                .newInstance("async_flush")); // 6
131:                    } else {
132:                        TclList.append(interp, list, TclString.newInstance(""));
133:                    }
134:
135:                    if (chan.eof()) {
136:                        TclList.append(interp, list, TclString
137:                                .newInstance("eof")); // 7
138:                    } else {
139:                        TclList.append(interp, list, TclString.newInstance(""));
140:                    }
141:
142:                    if (chan.isBlocked(interp)) {
143:                        TclList.append(interp, list, TclString
144:                                .newInstance("blocked")); // 8
145:                    } else {
146:                        TclList.append(interp, list, TclString
147:                                .newInstance("unblocked"));
148:                    }
149:
150:                    int translation = chan.getInputTranslation();
151:
152:                    if (translation == TclIO.TRANS_AUTO) {
153:                        TclList.append(interp, list, TclString
154:                                .newInstance("auto")); // 9
155:
156:                        TclList.append(interp, list, TclString.newInstance(chan
157:                                .inputSawCR() ? "queued_cr" : "")); // 10
158:                    } else if (translation == TclIO.TRANS_LF) {
159:                        TclList.append(interp, list, TclString
160:                                .newInstance("lf"));
161:                        TclList.append(interp, list, TclString.newInstance(""));
162:                    } else if (translation == TclIO.TRANS_CR) {
163:                        TclList.append(interp, list, TclString
164:                                .newInstance("cr"));
165:                        TclList.append(interp, list, TclString.newInstance(""));
166:                    } else if (translation == TclIO.TRANS_CRLF) {
167:                        TclList.append(interp, list, TclString
168:                                .newInstance("crlf"));
169:                        TclList.append(interp, list, TclString.newInstance(""));
170:                    }
171:
172:                    translation = chan.getOutputTranslation();
173:
174:                    if (translation == TclIO.TRANS_AUTO) {
175:                        TclList.append(interp, list, TclString
176:                                .newInstance("auto")); // 11
177:                    } else if (translation == TclIO.TRANS_LF) {
178:                        TclList.append(interp, list, TclString
179:                                .newInstance("lf"));
180:                    } else if (translation == TclIO.TRANS_CR) {
181:                        TclList.append(interp, list, TclString
182:                                .newInstance("cr"));
183:                    } else if (translation == TclIO.TRANS_CRLF) {
184:                        TclList.append(interp, list, TclString
185:                                .newInstance("crlf"));
186:                    }
187:
188:                    TclList.append(interp, list, TclInteger.newInstance(chan
189:                            .getNumBufferedInputBytes())); // 12
190:
191:                    TclList.append(interp, list, TclInteger.newInstance(chan
192:                            .getNumBufferedOutputBytes())); // 13
193:
194:                    try {
195:                        TclList.append(interp, list, TclInteger
196:                                .newInstance((int) chan.tell())); // 14
197:                    } catch (IOException e) {
198:                        throw new TclException(interp, e.toString());
199:                    }
200:
201:                    TclList.append(interp, list, TclInteger.newInstance(chan
202:                            .getRefCount())); // 15
203:
204:                    interp.setResult(list);
205:                    break;
206:                }
207:                case OPT_INPUTBUFFERED: {
208:                    interp.setResult(chan.getNumBufferedInputBytes());
209:                    break;
210:                }
211:                case OPT_NAME: {
212:                    interp.setResult(chan.getChanName());
213:                    break;
214:                }
215:                case OPT_OUTPUTBUFFERED: {
216:                    interp.setResult(chan.getNumBufferedOutputBytes());
217:                    break;
218:                }
219:                case OPT_QUEUEDCR: {
220:                    interp.setResult(chan.inputSawCR());
221:                    break;
222:                }
223:                case OPT_REFCOUNT: {
224:                    interp.setResult(chan.getRefCount());
225:                    break;
226:                }
227:                case OPT_TYPE: {
228:                    interp.setResult(chan.getChanType());
229:                    break;
230:                }
231:                default: {
232:                    throw new TclRuntimeError("TestChannel.cmdProc() error: "
233:                            + "incorrect index returned from TclIndex.get()");
234:                }
235:                }
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.