Source Code Cross Referenced for MemoryUserDatabaseMBean.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » mbeans » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.mbeans 
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.catalina.mbeans;
019:
020:        import java.util.ArrayList;
021:        import java.util.Iterator;
022:
023:        import javax.management.MBeanException;
024:        import javax.management.MBeanServer;
025:        import javax.management.MalformedObjectNameException;
026:        import javax.management.ObjectName;
027:        import javax.management.RuntimeOperationsException;
028:
029:        import org.apache.catalina.Group;
030:        import org.apache.catalina.Role;
031:        import org.apache.catalina.User;
032:        import org.apache.catalina.UserDatabase;
033:        import org.apache.tomcat.util.modeler.BaseModelMBean;
034:        import org.apache.tomcat.util.modeler.ManagedBean;
035:        import org.apache.tomcat.util.modeler.Registry;
036:
037:        /**
038:         * <p>A <strong>ModelMBean</strong> implementation for the
039:         * <code>org.apache.catalina.users.MemoryUserDatabase</code> component.</p>
040:         *
041:         * @author Craig R. McClanahan
042:         * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
043:         */
044:
045:        public class MemoryUserDatabaseMBean extends BaseModelMBean {
046:
047:            // ----------------------------------------------------------- Constructors
048:
049:            /**
050:             * Construct a <code>ModelMBean</code> with default
051:             * <code>ModelMBeanInfo</code> information.
052:             *
053:             * @exception MBeanException if the initializer of an object
054:             *  throws an exception
055:             * @exception RuntimeOperationsException if an IllegalArgumentException
056:             *  occurs
057:             */
058:            public MemoryUserDatabaseMBean() throws MBeanException,
059:                    RuntimeOperationsException {
060:
061:                super ();
062:
063:            }
064:
065:            // ----------------------------------------------------- Instance Variables
066:
067:            /**
068:             * The configuration information registry for our managed beans.
069:             */
070:            protected Registry registry = MBeanUtils.createRegistry();
071:
072:            /**
073:             * The <code>MBeanServer</code> in which we are registered.
074:             */
075:            protected MBeanServer mserver = MBeanUtils.createServer();
076:
077:            /**
078:             * The <code>ManagedBean</code> information describing this MBean.
079:             */
080:            protected ManagedBean managed = registry
081:                    .findManagedBean("MemoryUserDatabase");
082:
083:            /**
084:             * The <code>ManagedBean</code> information describing Group MBeans.
085:             */
086:            protected ManagedBean managedGroup = registry
087:                    .findManagedBean("Group");
088:
089:            /**
090:             * The <code>ManagedBean</code> information describing Group MBeans.
091:             */
092:            protected ManagedBean managedRole = registry
093:                    .findManagedBean("Role");
094:
095:            /**
096:             * The <code>ManagedBean</code> information describing User MBeans.
097:             */
098:            protected ManagedBean managedUser = registry
099:                    .findManagedBean("User");
100:
101:            // ------------------------------------------------------------- Attributes
102:
103:            /**
104:             * Return the MBean Names of all groups defined in this database.
105:             */
106:            public String[] getGroups() {
107:
108:                UserDatabase database = (UserDatabase) this .resource;
109:                ArrayList results = new ArrayList();
110:                Iterator groups = database.getGroups();
111:                while (groups.hasNext()) {
112:                    Group group = (Group) groups.next();
113:                    results.add(findGroup(group.getGroupname()));
114:                }
115:                return ((String[]) results.toArray(new String[results.size()]));
116:
117:            }
118:
119:            /**
120:             * Return the MBean Names of all roles defined in this database.
121:             */
122:            public String[] getRoles() {
123:
124:                UserDatabase database = (UserDatabase) this .resource;
125:                ArrayList results = new ArrayList();
126:                Iterator roles = database.getRoles();
127:                while (roles.hasNext()) {
128:                    Role role = (Role) roles.next();
129:                    results.add(findRole(role.getRolename()));
130:                }
131:                return ((String[]) results.toArray(new String[results.size()]));
132:
133:            }
134:
135:            /**
136:             * Return the MBean Names of all users defined in this database.
137:             */
138:            public String[] getUsers() {
139:
140:                UserDatabase database = (UserDatabase) this .resource;
141:                ArrayList results = new ArrayList();
142:                Iterator users = database.getUsers();
143:                while (users.hasNext()) {
144:                    User user = (User) users.next();
145:                    results.add(findUser(user.getUsername()));
146:                }
147:                return ((String[]) results.toArray(new String[results.size()]));
148:
149:            }
150:
151:            // ------------------------------------------------------------- Operations
152:
153:            /**
154:             * Create a new Group and return the corresponding MBean Name.
155:             *
156:             * @param groupname Group name of the new group
157:             * @param description Description of the new group
158:             */
159:            public String createGroup(String groupname, String description) {
160:
161:                UserDatabase database = (UserDatabase) this .resource;
162:                Group group = database.createGroup(groupname, description);
163:                try {
164:                    MBeanUtils.createMBean(group);
165:                } catch (Exception e) {
166:                    IllegalArgumentException iae = new IllegalArgumentException(
167:                            "Exception creating group " + group + " MBean");
168:                    iae.initCause(e);
169:                    throw iae;
170:                }
171:                return (findGroup(groupname));
172:
173:            }
174:
175:            /**
176:             * Create a new Role and return the corresponding MBean Name.
177:             *
178:             * @param rolename Group name of the new group
179:             * @param description Description of the new group
180:             */
181:            public String createRole(String rolename, String description) {
182:
183:                UserDatabase database = (UserDatabase) this .resource;
184:                Role role = database.createRole(rolename, description);
185:                try {
186:                    MBeanUtils.createMBean(role);
187:                } catch (Exception e) {
188:                    IllegalArgumentException iae = new IllegalArgumentException(
189:                            "Exception creating role " + role + " MBean");
190:                    iae.initCause(e);
191:                    throw iae;
192:                }
193:                return (findRole(rolename));
194:
195:            }
196:
197:            /**
198:             * Create a new User and return the corresponding MBean Name.
199:             *
200:             * @param username User name of the new user
201:             * @param password Password for the new user
202:             * @param fullName Full name for the new user
203:             */
204:            public String createUser(String username, String password,
205:                    String fullName) {
206:
207:                UserDatabase database = (UserDatabase) this .resource;
208:                User user = database.createUser(username, password, fullName);
209:                try {
210:                    MBeanUtils.createMBean(user);
211:                } catch (Exception e) {
212:                    IllegalArgumentException iae = new IllegalArgumentException(
213:                            "Exception creating user " + user + " MBean");
214:                    iae.initCause(e);
215:                    throw iae;
216:                }
217:                return (findUser(username));
218:
219:            }
220:
221:            /**
222:             * Return the MBean Name for the specified group name (if any);
223:             * otherwise return <code>null</code>.
224:             *
225:             * @param groupname Group name to look up
226:             */
227:            public String findGroup(String groupname) {
228:
229:                UserDatabase database = (UserDatabase) this .resource;
230:                Group group = database.findGroup(groupname);
231:                if (group == null) {
232:                    return (null);
233:                }
234:                try {
235:                    ObjectName oname = MBeanUtils.createObjectName(managedGroup
236:                            .getDomain(), group);
237:                    return (oname.toString());
238:                } catch (MalformedObjectNameException e) {
239:                    IllegalArgumentException iae = new IllegalArgumentException(
240:                            "Cannot create object name for group " + group);
241:                    iae.initCause(e);
242:                    throw iae;
243:                }
244:
245:            }
246:
247:            /**
248:             * Return the MBean Name for the specified role name (if any);
249:             * otherwise return <code>null</code>.
250:             *
251:             * @param rolename Role name to look up
252:             */
253:            public String findRole(String rolename) {
254:
255:                UserDatabase database = (UserDatabase) this .resource;
256:                Role role = database.findRole(rolename);
257:                if (role == null) {
258:                    return (null);
259:                }
260:                try {
261:                    ObjectName oname = MBeanUtils.createObjectName(managedRole
262:                            .getDomain(), role);
263:                    return (oname.toString());
264:                } catch (MalformedObjectNameException e) {
265:                    IllegalArgumentException iae = new IllegalArgumentException(
266:                            "Cannot create object name for role " + role);
267:                    iae.initCause(e);
268:                    throw iae;
269:                }
270:
271:            }
272:
273:            /**
274:             * Return the MBean Name for the specified user name (if any);
275:             * otherwise return <code>null</code>.
276:             *
277:             * @param username User name to look up
278:             */
279:            public String findUser(String username) {
280:
281:                UserDatabase database = (UserDatabase) this .resource;
282:                User user = database.findUser(username);
283:                if (user == null) {
284:                    return (null);
285:                }
286:                try {
287:                    ObjectName oname = MBeanUtils.createObjectName(managedUser
288:                            .getDomain(), user);
289:                    return (oname.toString());
290:                } catch (MalformedObjectNameException e) {
291:                    IllegalArgumentException iae = new IllegalArgumentException(
292:                            "Cannot create object name for user " + user);
293:                    iae.initCause(e);
294:                    throw iae;
295:                }
296:
297:            }
298:
299:            /**
300:             * Remove an existing group and destroy the corresponding MBean.
301:             *
302:             * @param groupname Group name to remove
303:             */
304:            public void removeGroup(String groupname) {
305:
306:                UserDatabase database = (UserDatabase) this .resource;
307:                Group group = database.findGroup(groupname);
308:                if (group == null) {
309:                    return;
310:                }
311:                try {
312:                    MBeanUtils.destroyMBean(group);
313:                    database.removeGroup(group);
314:                } catch (Exception e) {
315:                    IllegalArgumentException iae = new IllegalArgumentException(
316:                            "Exception destroying group " + group + " MBean");
317:                    iae.initCause(e);
318:                    throw iae;
319:                }
320:
321:            }
322:
323:            /**
324:             * Remove an existing role and destroy the corresponding MBean.
325:             *
326:             * @param rolename Role name to remove
327:             */
328:            public void removeRole(String rolename) {
329:
330:                UserDatabase database = (UserDatabase) this .resource;
331:                Role role = database.findRole(rolename);
332:                if (role == null) {
333:                    return;
334:                }
335:                try {
336:                    MBeanUtils.destroyMBean(role);
337:                    database.removeRole(role);
338:                } catch (Exception e) {
339:                    IllegalArgumentException iae = new IllegalArgumentException(
340:                            "Exception destroying role " + role + " MBean");
341:                    iae.initCause(e);
342:                    throw iae;
343:                }
344:
345:            }
346:
347:            /**
348:             * Remove an existing user and destroy the corresponding MBean.
349:             *
350:             * @param username User name to remove
351:             */
352:            public void removeUser(String username) {
353:
354:                UserDatabase database = (UserDatabase) this .resource;
355:                User user = database.findUser(username);
356:                if (user == null) {
357:                    return;
358:                }
359:                try {
360:                    MBeanUtils.destroyMBean(user);
361:                    database.removeUser(user);
362:                } catch (Exception e) {
363:                    IllegalArgumentException iae = new IllegalArgumentException(
364:                            "Exception destroying user " + user + " MBean");
365:                    iae.initCause(e);
366:                    throw iae;
367:                }
368:
369:            }
370:
371:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.