Source Code Cross Referenced for PropertyPermission.java in  » Apache-Harmony-Java-SE » java-package » java » 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 » Apache Harmony Java SE » java package » java.util 
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:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package java.util;
019:
020:        import java.io.IOException;
021:        import java.io.ObjectInputStream;
022:        import java.io.ObjectOutputStream;
023:        import java.io.ObjectStreamField;
024:        import java.security.BasicPermission;
025:        import java.security.Permission;
026:        import java.security.PermissionCollection;
027:
028:        import org.apache.harmony.luni.util.Util;
029:
030:        /**
031:         * PropertyPermission objects represent permission to access system properties.
032:         */
033:        public final class PropertyPermission extends BasicPermission {
034:            private static final long serialVersionUID = 885438825399942851L;
035:
036:            transient private boolean read, write;
037:
038:            /**
039:             * Constructs a new instance of this class.
040:             * 
041:             * @param name
042:             *            java.lang.String the (possibly wildcarded) name of the
043:             *            property.
044:             * @param actions
045:             *            java.lang.String the actions which are applicable to it.
046:             */
047:            public PropertyPermission(String name, String actions) {
048:                super (name);
049:                decodeActions(actions);
050:            }
051:
052:            private void decodeActions(String actions) {
053:                StringTokenizer tokenizer = new StringTokenizer(Util
054:                        .toASCIILowerCase(actions), " \t\n\r,"); //$NON-NLS-1$
055:                while (tokenizer.hasMoreTokens()) {
056:                    String token = tokenizer.nextToken();
057:                    if (token.equals("read")) { //$NON-NLS-1$
058:                        read = true;
059:                    } else if (token.equals("write")) { //$NON-NLS-1$
060:                        write = true;
061:                    } else {
062:                        throw new IllegalArgumentException();
063:                    }
064:                }
065:                if (!read && !write) {
066:                    throw new IllegalArgumentException();
067:                }
068:            }
069:
070:            /**
071:             * Compares the argument to the receiver, and answers true if they represent
072:             * the <em>same</em> object using a class specific comparison. In this
073:             * case, the receiver must be for the same property as the argument, and
074:             * must have the same actions.
075:             * 
076:             * @param o
077:             *            the object to compare with this object
078:             * @return <code>true</code> if the object is the same as this object
079:             *         <code>false</code> if it is different from this object
080:             * @see #hashCode
081:             */
082:            @Override
083:            public boolean equals(Object o) {
084:                if (super .equals(o)) {
085:                    PropertyPermission pp = (PropertyPermission) o;
086:                    return read == pp.read && write == pp.write;
087:                }
088:                return false;
089:            }
090:
091:            /**
092:             * Answers the actions associated with the receiver. The result will be
093:             * either "read", "write", or "read,write".
094:             * 
095:             * @return String the actions associated with the receiver.
096:             */
097:            @Override
098:            public String getActions() {
099:                return read ? (write ? "read,write" : "read") : "write"; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
100:            }
101:
102:            /**
103:             * Answers an integer hash code for the receiver. Any two objects which
104:             * answer <code>true</code> when passed to <code>equals</code> must
105:             * answer the same value for this method.
106:             * 
107:             * @return the receiver's hash
108:             * 
109:             * @see #equals
110:             */
111:            @Override
112:            public int hashCode() {
113:                return super .hashCode();
114:            }
115:
116:            /**
117:             * Indicates whether the argument permission is implied by the receiver.
118:             * 
119:             * @return boolean <code>true</code> if the argument permission is implied
120:             *         by the receiver, and <code>false</code> if it is not.
121:             * @param permission
122:             *            java.security.Permission the permission to check
123:             */
124:            @Override
125:            public boolean implies(Permission permission) {
126:                if (super .implies(permission)) {
127:                    PropertyPermission pp = (PropertyPermission) permission;
128:                    return (read || !pp.read) && (write || !pp.write);
129:                }
130:                return false;
131:            }
132:
133:            /**
134:             * Answers a new PermissionCollection for holding permissions of this class.
135:             * Answer null if any permission collection can be used.
136:             * 
137:             * @return a new PermissionCollection or null
138:             * 
139:             * see java.security.BasicPermissionCollection
140:             */
141:            @Override
142:            public PermissionCollection newPermissionCollection() {
143:                return new PropertyPermissionCollection();
144:            }
145:
146:            private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
147:                    "actions", String.class) }; //$NON-NLS-1$
148:
149:            private void writeObject(ObjectOutputStream stream)
150:                    throws IOException {
151:                ObjectOutputStream.PutField fields = stream.putFields();
152:                fields.put("actions", getActions()); //$NON-NLS-1$
153:                stream.writeFields();
154:            }
155:
156:            private void readObject(ObjectInputStream stream)
157:                    throws IOException, ClassNotFoundException {
158:                ObjectInputStream.GetField fields = stream.readFields();
159:                String actions = (String) fields.get("actions", ""); //$NON-NLS-1$ //$NON-NLS-2$
160:                decodeActions(actions);
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.