Source Code Cross Referenced for PropertiesAttribute.java in  » Web-Server » Jigsaw » org » w3c » tools » resources » upgrade » 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 » Web Server » Jigsaw » org.w3c.tools.resources.upgrade 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // PropertiesAttribute.java
002:        // $Id: PropertiesAttribute.java,v 1.4 2000/08/16 21:37:56 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1996.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.tools.resources.upgrade;
007:
008:        import java.io.DataInputStream;
009:        import java.io.DataOutputStream;
010:        import java.io.IOException;
011:
012:        import java.util.Enumeration;
013:
014:        import org.w3c.util.ArrayDictionary;
015:
016:        /**
017:         * The generic description of an PropertiesAttribute.
018:         * A PropertiesAttribute instance holds a String to String mapping, it
019:         * should be used only with care, since people may act on a reference to
020:         * it.
021:         */
022:
023:        public class PropertiesAttribute extends Attribute {
024:
025:            /**
026:             * Get the pickled length of that string.
027:             */
028:
029:            private int getPickleLength(String str) {
030:                int strlen = str.length();
031:                int utflen = 0;
032:
033:                for (int i = 0; i < strlen; i++) {
034:                    int c = str.charAt(i);
035:                    if ((c >= 0x0001) && (c <= 0x007F)) {
036:                        utflen++;
037:                    } else if (c > 0x07FF) {
038:                        utflen += 3;
039:                    } else {
040:                        utflen += 2;
041:                    }
042:                }
043:                return utflen + 2;
044:            }
045:
046:            /**
047:             * Is the given object a valid PropertiesAttribute value ?
048:             * @param obj The object to test.
049:             * @return A boolean <strong>true</strong> if value is valid.
050:             */
051:
052:            public boolean checkValue(Object obj) {
053:                return (obj == null) || (obj instanceof  ArrayDictionary);
054:            }
055:
056:            /**
057:             * Get the number of bytes required to save that attribute value.
058:             * @param The value about to be pickled.
059:             * @return The number of bytes needed to pickle that value.
060:             */
061:
062:            public final int getPickleLength(Object value) {
063:                ArrayDictionary a = (ArrayDictionary) value;
064:                Enumeration e = a.keys();
065:                int s = 4;
066:                while (e.hasMoreElements()) {
067:                    String key = (String) e.nextElement();
068:                    s += getPickleLength(key);
069:                    s += getPickleLength((String) a.get(key));
070:                }
071:                return s;
072:            }
073:
074:            /**
075:             * Pickle a property list to the given output stream.
076:             * @param out The output stream to pickle to.
077:             * @param obj The object to pickle.
078:             * @exception IOException If some IO error occured.
079:             */
080:
081:            public void pickle(DataOutputStream out, Object o)
082:                    throws IOException {
083:                ArrayDictionary a = (ArrayDictionary) o;
084:                Enumeration e = a.keys();
085:                int s = a.size();
086:                out.writeInt(s);
087:                while (--s >= 0) {
088:                    String key = (String) e.nextElement();
089:                    out.writeUTF(key);
090:                    out.writeUTF((String) a.get(key));
091:                }
092:            }
093:
094:            /**
095:             * Unpickle an string from the given input stream.
096:             * @param in The input stream to unpickle from.
097:             * @return An instance of String.
098:             * @exception IOException If some IO error occured.
099:             */
100:
101:            public Object unpickle(DataInputStream in) throws IOException {
102:                int s = in.readInt();
103:                ArrayDictionary a = new ArrayDictionary(s, 5);
104:                while (--s >= 0) {
105:                    String k = in.readUTF();
106:                    String v = in.readUTF();
107:                    a.put(k, v);
108:                }
109:                return a;
110:            }
111:
112:            /**
113:             * Create a description for a generic property list attribute.
114:             * @param name The attribute name.
115:             * @param def The default value for these attributes.
116:             * @param flags The associated flags.
117:             */
118:
119:            public PropertiesAttribute(String name, String def, Integer flags) {
120:                super (name, def, flags);
121:                this .type = "java.lang.String";
122:            }
123:
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.