Source Code Cross Referenced for PriviAction.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » 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 » org package » org.apache.harmony.luni.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 org.apache.harmony.luni.util;
019:
020:        import java.lang.reflect.AccessibleObject;
021:        import java.security.Policy;
022:        import java.security.PrivilegedAction;
023:        import java.security.Security;
024:
025:        /**
026:         * Helper class to avoid multiple anonymous inner class for
027:         * <code>{@link java.security.AccessController#doPrivileged(PrivilegedAction)}</code>
028:         * calls.
029:         */
030:        public class PriviAction<T> implements  PrivilegedAction<T> {
031:
032:            private Object arg1;
033:
034:            private Object arg2;
035:
036:            private int action;
037:
038:            private static final int GET_SYSTEM_PROPERTY = 1;
039:
040:            private static final int GET_SECURITY_POLICY = 2;
041:
042:            private static final int SET_ACCESSIBLE = 3;
043:
044:            private static final int GET_SECURITY_PROPERTY = 4;
045:
046:            /**
047:             * Creates a PrivilegedAction to get the security property with the given
048:             * name.
049:             * 
050:             * @param property
051:             *            the name of the property
052:             * 
053:             * @see Security#getProperty
054:             */
055:            public static PrivilegedAction<String> getSecurityProperty(
056:                    String property) {
057:                return new PriviAction<String>(GET_SECURITY_PROPERTY, property);
058:            }
059:
060:            private PriviAction(int action, Object arg) {
061:                this .action = action;
062:                this .arg1 = arg;
063:            }
064:
065:            /**
066:             * Creates a PrivilegedAction to get the current security policy object.
067:             * 
068:             * @see Policy#getPolicy
069:             */
070:            public PriviAction() {
071:                action = GET_SECURITY_POLICY;
072:            }
073:
074:            /**
075:             * Creates a PrivilegedAction to disable the access checks to the given
076:             * object.
077:             * 
078:             * @param object
079:             *            the object whose accessible flag will be set to
080:             *            <code>true</code>
081:             * 
082:             * @see AccessibleObject#setAccessible(boolean)
083:             */
084:            public PriviAction(AccessibleObject object) {
085:                action = SET_ACCESSIBLE;
086:                arg1 = object;
087:            }
088:
089:            /**
090:             * Creates a PrivilegedAction to return the value of the system property
091:             * with the given key.
092:             * 
093:             * @param property
094:             *            the key of the system property
095:             * 
096:             * @see System#getProperty(String)
097:             */
098:            public PriviAction(String property) {
099:                action = GET_SYSTEM_PROPERTY;
100:                arg1 = property;
101:            }
102:
103:            /**
104:             * Creates a PrivilegedAction to return the value of the system property
105:             * with the given key.
106:             * 
107:             * @param property
108:             *            the key of the system property
109:             * @param defaultAnswer
110:             *            the return value if the system property does not exist
111:             * 
112:             * @see System#getProperty(String, String)
113:             */
114:            public PriviAction(String property, String defaultAnswer) {
115:                action = GET_SYSTEM_PROPERTY;
116:                arg1 = property;
117:                arg2 = defaultAnswer;
118:            }
119:
120:            /**
121:             * Performs the actual privileged computation as defined by the constructor.
122:             * 
123:             * @see java.security.PrivilegedAction#run()
124:             */
125:            @SuppressWarnings("unchecked")
126:            public T run() {
127:                switch (action) {
128:                case GET_SYSTEM_PROPERTY:
129:                    return (T) System.getProperty((String) arg1, (String) arg2);
130:                case GET_SECURITY_PROPERTY:
131:                    return (T) Security.getProperty((String) arg1);
132:                case GET_SECURITY_POLICY:
133:                    return (T) Policy.getPolicy();
134:                case SET_ACCESSIBLE:
135:                    ((AccessibleObject) arg1).setAccessible(true);
136:                }
137:                return null;
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.