Source Code Cross Referenced for QuestionRecord.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jndi » provider » dns » 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 » Apache Harmony Java SE » org package » org.apache.harmony.jndi.provider.dns 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author Alexei Y. Zakharov
021:         * @version $Revision: 1.1.2.4 $
022:         */package org.apache.harmony.jndi.provider.dns;
023:
024:        import org.apache.harmony.jndi.internal.nls.Messages;
025:
026:        /**
027:         * Represents domain protocol Question Record
028:         * 
029:         * @see RFC 1035
030:         */
031:        public class QuestionRecord {
032:
033:            /** domain name */
034:            private String qName;
035:
036:            /** type of query */
037:            private int qType;
038:
039:            /** class of query */
040:            private int qClass;
041:
042:            /** Empty constructor */
043:            public QuestionRecord() {
044:            }
045:
046:            /**
047:             * Constructs new question record with given parameters
048:             * 
049:             * @param qName
050:             *            domain name
051:             * @param qType
052:             *            question record type
053:             * @param qClass
054:             *            question record class
055:             */
056:            public QuestionRecord(String qName, int qType, int qClass) {
057:                this .qName = qName;
058:                this .qType = qType;
059:                this .qClass = qClass;
060:            }
061:
062:            /**
063:             * Creates a sequence of bytes that represents the current question record.
064:             * 
065:             * @param buffer
066:             *            the buffer in which the result byte sequence will be written
067:             * @param startIdx
068:             *            the index in the buffer to start at
069:             * @return updated index of the buffer array
070:             */
071:            public int writeBytes(byte[] buffer, int startIdx)
072:                    throws DomainProtocolException {
073:                int idx = startIdx;
074:
075:                // basic checkings
076:                if (buffer == null) {
077:                    // jndi.32=buffer is null
078:                    throw new DomainProtocolException(Messages
079:                            .getString("jndi.32")); //$NON-NLS-1$
080:                }
081:                if (startIdx >= buffer.length || startIdx < 0) {
082:                    throw new ArrayIndexOutOfBoundsException();
083:                }
084:                // write the name
085:                idx = ProviderMgr.writeName(qName, buffer, idx);
086:                // QTYPE
087:                idx = ProviderMgr.write16Int(qType, buffer, idx);
088:                // QCLASS
089:                idx = ProviderMgr.write16Int(qClass, buffer, idx);
090:                return idx;
091:            }
092:
093:            // getters and setters methods
094:
095:            /**
096:             * Parses given sequence of bytes and constructs a question record from it.
097:             * 
098:             * @param mesBytes
099:             *            the byte array that should be parsed
100:             * @param startIdx
101:             *            an index of <code>mesBytes</code> array to start the parsing
102:             *            at
103:             * @param resultQR
104:             *            an object the result of the operation will be stored into
105:             * @return updated index of <code>mesBytes</code> array
106:             * @throws DomainProtocolException
107:             *             if something went wrong
108:             */
109:            public static int parseRecord(byte[] mesBytes, int startIdx,
110:                    QuestionRecord resultQR) throws DomainProtocolException {
111:                int idx = startIdx;
112:                StringBuffer nameSB = new StringBuffer();
113:
114:                if (resultQR == null) {
115:                    // jndi.33=Given resultQR is null
116:                    throw new NullPointerException(Messages
117:                            .getString("jndi.33")); //$NON-NLS-1$
118:                }
119:                // name
120:                idx = ProviderMgr.parseName(mesBytes, idx, nameSB);
121:                resultQR.setQName(nameSB.toString());
122:                // QTYPE
123:                resultQR.setQType(ProviderMgr.parse16Int(mesBytes, idx));
124:                idx += 2;
125:                // QCLASS
126:                resultQR.setQClass(ProviderMgr.parse16Int(mesBytes, idx));
127:                idx += 2;
128:                return idx;
129:            }
130:
131:            @Override
132:            public String toString() {
133:                StringBuffer sb = new StringBuffer();
134:                String qClassStr, qTypeStr;
135:
136:                if (qType > 0 && qType < 256) {
137:                    qTypeStr = ProviderConstants.rrTypeNames[qType];
138:                } else {
139:                    qTypeStr = String.valueOf(qType);
140:                }
141:                if (qClass > 0 && qClass < 256) {
142:                    qClassStr = ProviderConstants.rrClassNames[qClass];
143:                } else {
144:                    qClassStr = String.valueOf(qClass);
145:                }
146:                sb.append(qClassStr);
147:                sb.append(" "); //$NON-NLS-1$
148:                sb.append(qTypeStr);
149:                sb.append(" "); //$NON-NLS-1$
150:                sb.append(qName);
151:                return sb.toString();
152:            }
153:
154:            /**
155:             * @return Returns the qClass.
156:             */
157:            public int getQClass() {
158:                return qClass;
159:            }
160:
161:            /**
162:             * @param class1
163:             *            The qClass to set.
164:             */
165:            public void setQClass(int class1) {
166:                qClass = class1;
167:            }
168:
169:            /**
170:             * @return Returns the qName.
171:             */
172:            public String getQName() {
173:                return qName;
174:            }
175:
176:            /**
177:             * @param name
178:             *            The qName to set.
179:             */
180:            public void setQName(String name) {
181:                qName = name;
182:            }
183:
184:            /**
185:             * @return Returns the qType.
186:             */
187:            public int getQType() {
188:                return qType;
189:            }
190:
191:            /**
192:             * @param type
193:             *            The qType to set.
194:             */
195:            public void setQType(int type) {
196:                qType = type;
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.