Source Code Cross Referenced for ConfigPrivilegeLoader.java in  » Web-Framework » JAT » com » jat » business » privileges » 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 Framework » JAT » com.jat.business.privileges 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.business.privileges;
002:
003:        import java.util.Enumeration;
004:        import java.util.Vector;
005:
006:        import com.jat.business.BusinessException;
007:        import com.jat.business.JatUser;
008:        import com.jat.core.config.Config;
009:        import com.jat.core.log.LogManager;
010:
011:        /**
012:         * <p>Title: JAT</p>
013:         * <p>Description: </p>
014:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
015:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
016:         * @author stf
017:         * @version 1.0
018:         * @since 1.2
019:         */
020:
021:        public class ConfigPrivilegeLoader implements  PrivilegesLoader {
022:
023:            public PrivilegeList getPrivileges(JatUser user)
024:                    throws BusinessException {
025:                return this .getPrivileges(user.getProfile());
026:            }
027:
028:            public String getDataSource() {
029:                return "config_privilege";
030:            }
031:
032:            public PrivilegeList getPrivileges(String profile)
033:                    throws BusinessException {
034:                try {
035:                    PrivilegeList privileges = new PrivilegeList(this 
036:                            .getDataSource());
037:                    Vector pKeys = this .getConfig().getSubKeys(SECTION,
038:                            PROFILE_KEY);
039:                    for (Enumeration e = pKeys.elements(); e.hasMoreElements();) {
040:                        String key = (String) e.nextElement();
041:                        String prof = this .getConfig().getValue(SECTION,
042:                                key + PROFILE_NAME);
043:                        if (prof.equalsIgnoreCase(profile)) {
044:                            Vector priKeys = this .getConfig().getSubKeys(
045:                                    SECTION, key + PRIVILEGE_KEY);
046:                            for (Enumeration el = priKeys.elements(); el
047:                                    .hasMoreElements();) {
048:                                String priKey = (String) el.nextElement();
049:                                Privilege privilege = new Privilege(this 
050:                                        .getDataSource());
051:                                privilege.setName(this .getConfig().getValue(
052:                                        SECTION, priKey + PRIVILEGE_NAME));
053:                                String conditionName = null;
054:                                try {
055:                                    conditionName = this .getConfig().getValue(
056:                                            SECTION,
057:                                            priKey + PRIVILEGE_CONDITION);
058:                                } catch (Exception ignored) {
059:                                }
060:                                if (conditionName != null)
061:                                    privilege
062:                                            .setCondition((Privilegeable) Class
063:                                                    .forName(conditionName)
064:                                                    .newInstance());
065:                                privileges.addElement(privilege);
066:                            }
067:                        }
068:                    }
069:                    return privileges;
070:                } catch (Exception ex) {
071:                    throw new BusinessException(this .getClass().getName()
072:                            + "::getPrivileges: " + ex.getMessage());
073:                }
074:            }
075:
076:            public Vector profiles() throws BusinessException {
077:                Vector ret = new Vector();
078:                try {
079:                    PrivilegeList privileges = new PrivilegeList(this 
080:                            .getDataSource());
081:                    Vector pKeys = this .getConfig().getSubKeys(SECTION,
082:                            PROFILE_KEY);
083:                    for (Enumeration e = pKeys.elements(); e.hasMoreElements();) {
084:                        String key = (String) e.nextElement();
085:                        String profile = this .getConfig().getValue(SECTION,
086:                                key + PROFILE_NAME);
087:                        ret.addElement(profile);
088:                    }
089:                    return ret;
090:                } catch (Exception ex) {
091:                    throw new BusinessException(this .getClass().getName()
092:                            + "::profiles: " + ex.getMessage());
093:                }
094:            }
095:
096:            public void persist() throws Exception {
097:                LogManager.sendDebug(this .getClass().getName()
098:                        + "::persist: start");
099:                Config config = this .getConfig();
100:                config.save();
101:                LogManager.sendDebug(this .getClass().getName()
102:                        + "::persist: end");
103:            }
104:
105:            public void remove(Profile profile) throws Exception {
106:                LogManager.sendDebug(this .getClass().getName()
107:                        + "::remove: start for profile: " + profile);
108:                String key = this .getIndexKey(profile.getName());
109:                this .removeProfile(key);
110:                LogManager.sendDebug(this .getClass().getName()
111:                        + "::remove: end");
112:            }
113:
114:            public void update(Profile profile) throws Exception {
115:                LogManager.sendDebug(this .getClass().getName()
116:                        + "::update: start for profile: " + profile);
117:                String key = this .getIndexKey(profile.getName());
118:                this .removeProfile(key);
119:                this .addProfile(profile, key);
120:                LogManager.sendDebug(this .getClass().getName()
121:                        + "::update: end");
122:            }
123:
124:            public void insert(Profile profile) throws Exception {
125:                LogManager.sendDebug(this .getClass().getName()
126:                        + "::insert: start for profile: " + profile);
127:                int index = 1;
128:                String key = null;
129:                while (key == null) {
130:                    String k = PROFILE_KEY + (index++);
131:                    if (!this .getConfig()
132:                            .existsValue(SECTION, k + PROFILE_NAME))
133:                        key = k;
134:                }
135:                this .addProfile(profile, key);
136:                LogManager.sendDebug(this .getClass().getName()
137:                        + "::insert: end");
138:            }
139:
140:            private void addProfile(Profile profile, String key)
141:                    throws Exception {
142:                try {
143:                    Config config = this .getConfig();
144:                    config.addValue(SECTION, key + PROFILE_NAME, profile
145:                            .getName());
146:                    int index = 1;
147:                    for (Enumeration e = profile.getPrivileges().elements(); e
148:                            .hasMoreElements();) {
149:                        Privilege privilege = (Privilege) e.nextElement();
150:                        config.addValue(SECTION, key + PRIVILEGE_KEY + index
151:                                + PRIVILEGE_NAME, privilege.getName());
152:                        if (privilege.getCondition() != null)
153:                            config.addValue(SECTION, key + PRIVILEGE_KEY
154:                                    + index + PRIVILEGE_CONDITION, privilege
155:                                    .getName());
156:                        index++;
157:                    }
158:                } catch (Exception ex) {
159:                    throw new Exception(this .getClass().getName()
160:                            + "::addProfile: exception: " + ex);
161:                }
162:            }
163:
164:            private void removeProfile(String key) throws Exception {
165:                try {
166:                    Config config = this .getConfig();
167:                    config.removeKeys(SECTION, key);
168:                } catch (Exception ex) {
169:                    throw new Exception(this .getClass().getName()
170:                            + "::removeProfile: exception: " + ex);
171:                }
172:            }
173:
174:            private Config getConfig() throws Exception {
175:                String name = Config.getCurrent().getValue(SECTION,
176:                        "config.name");
177:                Config config = Config.getCurrent().getConfig(name);
178:                if (config == null) {
179:                    LogManager.sendError(this .getClass().getName()
180:                            + "::getConfig: exception: Config file " + name
181:                            + " not found");
182:                    throw new Exception("Config file " + name + " not found");
183:                }
184:                return config;
185:            }
186:
187:            private String getIndexKey(String name) throws Exception {
188:                for (Enumeration e = this .getConfig().getSubKeys(SECTION,
189:                        PROFILE_KEY).elements(); e.hasMoreElements();) {
190:                    String key = (String) e.nextElement();
191:                    if (this .getConfig().getValue(SECTION, key + PROFILE_NAME)
192:                            .equalsIgnoreCase(name))
193:                        return key;
194:                }
195:                throw new Exception("config key not found for " + name);
196:            }
197:
198:            public static final String SECTION = "privileges";
199:            public static final String PRIVILEGE_KEY = ".privilege";
200:            public static final String PRIVILEGE_NAME = ".name";
201:            public static final String PRIVILEGE_CONDITION = ".condition";
202:            public static final String PROFILE_KEY = "profile";
203:            public static final String PROFILE_NAME = ".name";
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.