Source Code Cross Referenced for UserPeerManager.java in  » Web-Framework » TURBINE » org » apache » turbine » services » security » torque » 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 » TURBINE » org.apache.turbine.services.security.torque 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.apache.turbine.services.security.torque;
0002:
0003:        /*
0004:         * Licensed to the Apache Software Foundation (ASF) under one
0005:         * or more contributor license agreements.  See the NOTICE file
0006:         * distributed with this work for additional information
0007:         * regarding copyright ownership.  The ASF licenses this file
0008:         * to you under the Apache License, Version 2.0 (the
0009:         * "License"); you may not use this file except in compliance
0010:         * with the License.  You may obtain a copy of the License at
0011:         *
0012:         *   http://www.apache.org/licenses/LICENSE-2.0
0013:         *
0014:         * Unless required by applicable law or agreed to in writing,
0015:         * software distributed under the License is distributed on an
0016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0017:         * KIND, either express or implied.  See the License for the
0018:         * specific language governing permissions and limitations
0019:         * under the License.
0020:         */
0021:
0022:        import java.beans.PropertyDescriptor;
0023:
0024:        import java.util.ArrayList;
0025:        import java.util.Iterator;
0026:        import java.util.List;
0027:
0028:        import org.apache.commons.configuration.Configuration;
0029:
0030:        import org.apache.commons.logging.Log;
0031:        import org.apache.commons.logging.LogFactory;
0032:
0033:        import org.apache.torque.TorqueException;
0034:        import org.apache.torque.om.Persistent;
0035:        import org.apache.torque.util.BasePeer;
0036:        import org.apache.torque.util.Criteria;
0037:
0038:        import org.apache.turbine.om.security.User;
0039:        import org.apache.turbine.services.InitializationException;
0040:        import org.apache.turbine.services.security.TurbineSecurity;
0041:        import org.apache.turbine.util.security.DataBackendException;
0042:
0043:        /**
0044:         * This class capsulates all direct Peer access for the User entities.
0045:         * It allows the exchange of the default Turbine supplied TurbineUserPeer
0046:         * class against a custom class.
0047:         *
0048:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
0049:         * @version $Id: UserPeerManager.java 534527 2007-05-02 16:10:59Z tv $
0050:         */
0051:
0052:        public class UserPeerManager implements  UserPeerManagerConstants {
0053:            /** Serial UID */
0054:            private static final long serialVersionUID = 6943046259921811593L;
0055:
0056:            /** The class of the Peer the TorqueSecurityService uses */
0057:            private static Class userPeerClass = null;
0058:
0059:            /** The class name of the objects returned by the configured peer. */
0060:            private static Class userObject = null;
0061:
0062:            /** The name of the Table used for Group Object queries  */
0063:            private static String tableName = null;
0064:
0065:            /** The name of the column used as "Name" Column */
0066:            private static String nameColumn = null;
0067:
0068:            /** The name of the column used as "Id" Column */
0069:            private static String idColumn = null;
0070:
0071:            /** The name of the column used as "Password" Column */
0072:            private static String passwordColumn = null;
0073:
0074:            /** The name of the column used as "First name" Column */
0075:            private static String firstNameColumn = null;
0076:
0077:            /** The name of the column used as "Last name" Column */
0078:            private static String lastNameColumn = null;
0079:
0080:            /** The name of the column used as "Email" Column */
0081:            private static String emailColumn = null;
0082:
0083:            /** The name of the column used as "Confirm" Column */
0084:            private static String confirmColumn = null;
0085:
0086:            /** The name of the column used as "create date" Column */
0087:            private static String createDateColumn = null;
0088:
0089:            /** The name of the column used as "last login" Column */
0090:            private static String lastLoginColumn = null;
0091:
0092:            /** The name of the column used as "objectdata" Column */
0093:            private static String objectdataColumn = null;
0094:
0095:            /** The "Name" property descriptor */
0096:            private static PropertyDescriptor namePropDesc = null;
0097:
0098:            /** The "Id" property descriptor */
0099:            private static PropertyDescriptor idPropDesc = null;
0100:
0101:            /** The "Password" property descriptor */
0102:            private static PropertyDescriptor passwordPropDesc = null;
0103:
0104:            /** The "First name" property descriptor */
0105:            private static PropertyDescriptor firstNamePropDesc = null;
0106:
0107:            /** The "Last name" property descriptor */
0108:            private static PropertyDescriptor lastNamePropDesc = null;
0109:
0110:            /** The "Email" property descriptor */
0111:            private static PropertyDescriptor emailPropDesc = null;
0112:
0113:            /** The "Confirm" property descriptor */
0114:            private static PropertyDescriptor confirmPropDesc = null;
0115:
0116:            /** The "create date" property descriptor */
0117:            private static PropertyDescriptor createDatePropDesc = null;
0118:
0119:            /** The "last login" property descriptor */
0120:            private static PropertyDescriptor lastLoginPropDesc = null;
0121:
0122:            /** The "objectdata" property descriptor */
0123:            private static PropertyDescriptor objectdataPropDesc = null;
0124:
0125:            /** Logging */
0126:            static Log log = LogFactory.getLog(UserPeerManager.class);
0127:
0128:            /**
0129:             * Initializes the UserPeerManager, loading the class object for the
0130:             * Peer used to retrieve User objects
0131:             *
0132:             * @param conf The configuration object used to configure the Manager
0133:             *
0134:             * @exception InitializationException A problem occured during
0135:             *            initialization
0136:             */
0137:
0138:            public static void init(Configuration conf)
0139:                    throws InitializationException {
0140:                String userPeerClassName = conf.getString(USER_PEER_CLASS_KEY,
0141:                        USER_PEER_CLASS_DEFAULT);
0142:                String userObjectName = null;
0143:
0144:                try {
0145:                    userPeerClass = Class.forName(userPeerClassName);
0146:
0147:                    tableName = (String) userPeerClass.getField("TABLE_NAME")
0148:                            .get(null);
0149:
0150:                    //
0151:                    // We have either an user configured Object class or we use the
0152:                    // default as supplied by the Peer class
0153:                    //
0154:
0155:                    // Default from Peer, can be overridden
0156:
0157:                    userObject = getPersistenceClass();
0158:
0159:                    userObjectName = conf.getString(USER_CLASS_KEY, userObject
0160:                            .getName());
0161:
0162:                    // Maybe the user set a new value...
0163:                    userObject = Class.forName(userObjectName);
0164:
0165:                    /* If any of the following Field queries fails, the user
0166:                     * subsystem is unusable. So check this right here at init time,
0167:                     * which saves us much time and hassle if it fails...
0168:                     */
0169:
0170:                    nameColumn = (String) userPeerClass.getField(
0171:                            conf.getString(USER_NAME_COLUMN_KEY,
0172:                                    USER_NAME_COLUMN_DEFAULT)).get(null);
0173:
0174:                    idColumn = (String) userPeerClass.getField(
0175:                            conf.getString(USER_ID_COLUMN_KEY,
0176:                                    USER_ID_COLUMN_DEFAULT)).get(null);
0177:
0178:                    passwordColumn = (String) userPeerClass.getField(
0179:                            conf.getString(USER_PASSWORD_COLUMN_KEY,
0180:                                    USER_PASSWORD_COLUMN_DEFAULT)).get(null);
0181:
0182:                    firstNameColumn = (String) userPeerClass.getField(
0183:                            conf.getString(USER_FIRST_NAME_COLUMN_KEY,
0184:                                    USER_FIRST_NAME_COLUMN_DEFAULT)).get(null);
0185:
0186:                    lastNameColumn = (String) userPeerClass.getField(
0187:                            conf.getString(USER_LAST_NAME_COLUMN_KEY,
0188:                                    USER_LAST_NAME_COLUMN_DEFAULT)).get(null);
0189:
0190:                    emailColumn = (String) userPeerClass.getField(
0191:                            conf.getString(USER_EMAIL_COLUMN_KEY,
0192:                                    USER_EMAIL_COLUMN_DEFAULT)).get(null);
0193:
0194:                    confirmColumn = (String) userPeerClass.getField(
0195:                            conf.getString(USER_CONFIRM_COLUMN_KEY,
0196:                                    USER_CONFIRM_COLUMN_DEFAULT)).get(null);
0197:
0198:                    createDateColumn = (String) userPeerClass.getField(
0199:                            conf.getString(USER_CREATE_COLUMN_KEY,
0200:                                    USER_CREATE_COLUMN_DEFAULT)).get(null);
0201:
0202:                    lastLoginColumn = (String) userPeerClass.getField(
0203:                            conf.getString(USER_LAST_LOGIN_COLUMN_KEY,
0204:                                    USER_LAST_LOGIN_COLUMN_DEFAULT)).get(null);
0205:
0206:                    objectdataColumn = (String) userPeerClass.getField(
0207:                            conf.getString(USER_OBJECTDATA_COLUMN_KEY,
0208:                                    USER_OBJECTDATA_COLUMN_DEFAULT)).get(null);
0209:
0210:                    namePropDesc = new PropertyDescriptor(
0211:                            conf.getString(USER_NAME_PROPERTY_KEY,
0212:                                    USER_NAME_PROPERTY_DEFAULT), userObject);
0213:
0214:                    idPropDesc = new PropertyDescriptor(conf.getString(
0215:                            USER_ID_PROPERTY_KEY, USER_ID_PROPERTY_DEFAULT),
0216:                            userObject);
0217:
0218:                    passwordPropDesc = new PropertyDescriptor(conf.getString(
0219:                            USER_PASSWORD_PROPERTY_KEY,
0220:                            USER_PASSWORD_PROPERTY_DEFAULT), userObject);
0221:
0222:                    firstNamePropDesc = new PropertyDescriptor(conf.getString(
0223:                            USER_FIRST_NAME_PROPERTY_KEY,
0224:                            USER_FIRST_NAME_PROPERTY_DEFAULT), userObject);
0225:
0226:                    lastNamePropDesc = new PropertyDescriptor(conf.getString(
0227:                            USER_LAST_NAME_PROPERTY_KEY,
0228:                            USER_LAST_NAME_PROPERTY_DEFAULT), userObject);
0229:
0230:                    emailPropDesc = new PropertyDescriptor(conf.getString(
0231:                            USER_EMAIL_PROPERTY_KEY,
0232:                            USER_EMAIL_PROPERTY_DEFAULT), userObject);
0233:
0234:                    confirmPropDesc = new PropertyDescriptor(conf.getString(
0235:                            USER_CONFIRM_PROPERTY_KEY,
0236:                            USER_CONFIRM_PROPERTY_DEFAULT), userObject);
0237:
0238:                    createDatePropDesc = new PropertyDescriptor(conf.getString(
0239:                            USER_CREATE_PROPERTY_KEY,
0240:                            USER_CREATE_PROPERTY_DEFAULT), userObject);
0241:
0242:                    lastLoginPropDesc = new PropertyDescriptor(conf.getString(
0243:                            USER_LAST_LOGIN_PROPERTY_KEY,
0244:                            USER_LAST_LOGIN_PROPERTY_DEFAULT), userObject);
0245:
0246:                    objectdataPropDesc = new PropertyDescriptor(conf.getString(
0247:                            USER_OBJECTDATA_PROPERTY_KEY,
0248:                            USER_OBJECTDATA_PROPERTY_DEFAULT), userObject);
0249:                } catch (Exception e) {
0250:                    if (userPeerClassName == null || userPeerClass == null) {
0251:                        throw new InitializationException(
0252:                                "Could not find UserPeer class ("
0253:                                        + userPeerClassName + ")", e);
0254:                    }
0255:                    if (tableName == null) {
0256:                        throw new InitializationException(
0257:                                "Failed to get the table name from the Peer object",
0258:                                e);
0259:                    }
0260:
0261:                    if (userObject == null || userObjectName == null) {
0262:                        throw new InitializationException(
0263:                                "Failed to get the object type from the Peer object",
0264:                                e);
0265:                    }
0266:
0267:                    if (nameColumn == null || namePropDesc == null) {
0268:                        throw new InitializationException("UserPeer "
0269:                                + userPeerClassName
0270:                                + " has no name column information!", e);
0271:                    }
0272:                    if (idColumn == null || idPropDesc == null) {
0273:                        throw new InitializationException("UserPeer "
0274:                                + userPeerClassName
0275:                                + " has no id column information!", e);
0276:                    }
0277:                    if (passwordColumn == null || passwordPropDesc == null) {
0278:                        throw new InitializationException("UserPeer "
0279:                                + userPeerClassName
0280:                                + " has no password column information!", e);
0281:                    }
0282:                    if (firstNameColumn == null || firstNamePropDesc == null) {
0283:                        throw new InitializationException("UserPeer "
0284:                                + userPeerClassName
0285:                                + " has no firstName column information!", e);
0286:                    }
0287:                    if (lastNameColumn == null || lastNamePropDesc == null) {
0288:                        throw new InitializationException("UserPeer "
0289:                                + userPeerClassName
0290:                                + " has no lastName column information!", e);
0291:                    }
0292:                    if (emailColumn == null || emailPropDesc == null) {
0293:                        throw new InitializationException("UserPeer "
0294:                                + userPeerClassName
0295:                                + " has no email column information!", e);
0296:                    }
0297:                    if (confirmColumn == null || confirmPropDesc == null) {
0298:                        throw new InitializationException("UserPeer "
0299:                                + userPeerClassName
0300:                                + " has no confirm column information!", e);
0301:                    }
0302:                    if (createDateColumn == null || createDatePropDesc == null) {
0303:                        throw new InitializationException("UserPeer "
0304:                                + userPeerClassName
0305:                                + " has no createDate column information!", e);
0306:                    }
0307:                    if (lastLoginColumn == null || lastLoginPropDesc == null) {
0308:                        throw new InitializationException("UserPeer "
0309:                                + userPeerClassName
0310:                                + " has no lastLogin column information!", e);
0311:                    }
0312:                    if (objectdataColumn == null || objectdataPropDesc == null) {
0313:                        throw new InitializationException("UserPeer "
0314:                                + userPeerClassName
0315:                                + " has no objectdata column information!", e);
0316:                    }
0317:                }
0318:            }
0319:
0320:            /**
0321:             * Get the name of this table.
0322:             *
0323:             * @return A String with the name of the table.
0324:             */
0325:            public static String getTableName() {
0326:                return tableName;
0327:            }
0328:
0329:            /**
0330:             * Returns the fully qualified name of the Column to
0331:             * use as the Name Column for a group
0332:             *
0333:             * @return A String containing the column name
0334:             */
0335:            public static String getNameColumn() {
0336:                return nameColumn;
0337:            }
0338:
0339:            /**
0340:             * Returns the fully qualified name of the Column to
0341:             * use as the Id Column for a group
0342:             *
0343:             * @return A String containing the column id
0344:             */
0345:            public static String getIdColumn() {
0346:                return idColumn;
0347:            }
0348:
0349:            /**
0350:             * Returns the fully qualified name of the Column to
0351:             * use as the Password Column for a role
0352:             *
0353:             * @return A String containing the column name
0354:             */
0355:            public static String getPasswordColumn() {
0356:                return passwordColumn;
0357:            }
0358:
0359:            /**
0360:             * Returns the fully qualified name of the Column to
0361:             * use as the FirstName Column for a role
0362:             *
0363:             * @return A String containing the column name
0364:             */
0365:            public static String getFirstNameColumn() {
0366:                return firstNameColumn;
0367:            }
0368:
0369:            /**
0370:             * Returns the fully qualified name of the Column to
0371:             * use as the LastName Column for a role
0372:             *
0373:             * @return A String containing the column name
0374:             */
0375:            public static String getLastNameColumn() {
0376:                return lastNameColumn;
0377:            }
0378:
0379:            /**
0380:             * Returns the fully qualified name of the Column to
0381:             * use as the Email Column for a role
0382:             *
0383:             * @return A String containing the column name
0384:             */
0385:            public static String getEmailColumn() {
0386:                return emailColumn;
0387:            }
0388:
0389:            /**
0390:             * Returns the fully qualified name of the Column to
0391:             * use as the Confirm Column for a role
0392:             *
0393:             * @return A String containing the column name
0394:             */
0395:            public static String getConfirmColumn() {
0396:                return confirmColumn;
0397:            }
0398:
0399:            /**
0400:             * Returns the fully qualified name of the Column to
0401:             * use as the CreateDate Column for a role
0402:             *
0403:             * @return A String containing the column name
0404:             */
0405:            public static String getCreateDateColumn() {
0406:                return createDateColumn;
0407:            }
0408:
0409:            /**
0410:             * Returns the fully qualified name of the Column to
0411:             * use as the LastLogin Column for a role
0412:             *
0413:             * @return A String containing the column name
0414:             */
0415:            public static String getLastLoginColumn() {
0416:                return lastLoginColumn;
0417:            }
0418:
0419:            /**
0420:             * Returns the fully qualified name of the Column to
0421:             * use as the objectdata Column for a role
0422:             *
0423:             * @return A String containing the column name
0424:             */
0425:            public static String getObjectdataColumn() {
0426:                return objectdataColumn;
0427:            }
0428:
0429:            /**
0430:             * Returns the full name of a column.
0431:             *
0432:             * @param name The column to fully qualify
0433:             *
0434:             * @return A String with the full name of the column.
0435:             */
0436:            public static String getColumnName(String name) {
0437:                StringBuffer sb = new StringBuffer();
0438:                sb.append(getTableName());
0439:                sb.append(".");
0440:                sb.append(name);
0441:                return sb.toString();
0442:            }
0443:
0444:            /**
0445:             * Returns the full name of a column.
0446:             *
0447:             * @param name The column to fully qualify
0448:             *
0449:             * @return A String with the full name of the column.
0450:             * @deprecated use getColumnName(String name)
0451:             */
0452:            public String getFullColumnName(String name) {
0453:                return getColumnName(name);
0454:            }
0455:
0456:            /**
0457:             * Returns a new, empty object for the underlying peer.
0458:             * Used to create a new underlying object
0459:             *
0460:             * @return A new object which is compatible to the Peer
0461:             *         and can be used as a User object
0462:             *
0463:             */
0464:
0465:            public static Persistent newPersistentInstance() {
0466:                Persistent obj = null;
0467:
0468:                if (userObject == null) {
0469:                    // This can happen if the Turbine wants to determine the
0470:                    // name of the anonymous user before the security service
0471:                    // has been initialized. In this case, the Peer Manager
0472:                    // has not yet been inited and the userObject is still
0473:                    // null. Return null in this case.
0474:                    //
0475:                    return obj;
0476:                }
0477:
0478:                try {
0479:                    obj = (Persistent) userObject.newInstance();
0480:                } catch (Exception e) {
0481:                    log.error("Could not instantiate a user object", e);
0482:                    obj = null;
0483:                }
0484:                return obj;
0485:            }
0486:
0487:            /**
0488:             * Checks if a User is defined in the system. The name
0489:             * is used as query criteria.
0490:             *
0491:             * @param user The User to be checked.
0492:             * @return <code>true</code> if given User exists in the system.
0493:             * @throws DataBackendException when more than one User with
0494:             *         the same name exists.
0495:             * @throws Exception A generic exception.
0496:             */
0497:            public static boolean checkExists(User user)
0498:                    throws DataBackendException, Exception {
0499:                Criteria criteria = new Criteria();
0500:
0501:                criteria.addSelectColumn(getIdColumn());
0502:
0503:                criteria.add(getNameColumn(), user.getName());
0504:
0505:                List results = BasePeer.doSelect(criteria);
0506:
0507:                if (results.size() > 1) {
0508:                    throw new DataBackendException("Multiple users named '"
0509:                            + user.getName() + "' exist!");
0510:                }
0511:                return (results.size() == 1);
0512:            }
0513:
0514:            /**
0515:             * Returns a List of all User objects.
0516:             *
0517:             * @return A List with all users in the system.
0518:             * @exception Exception A generic exception.
0519:             */
0520:            public static List selectAllUsers() throws Exception {
0521:                Criteria criteria = new Criteria();
0522:                criteria.addAscendingOrderByColumn(getLastNameColumn());
0523:                criteria.addAscendingOrderByColumn(getFirstNameColumn());
0524:                criteria.setIgnoreCase(true);
0525:                return doSelect(criteria);
0526:            }
0527:
0528:            /**
0529:             * Returns a List of all confirmed User objects.
0530:             *
0531:             * @return A List with all confirmed users in the system.
0532:             * @exception Exception A generic exception.
0533:             */
0534:            public static List selectAllConfirmedUsers() throws Exception {
0535:                Criteria criteria = new Criteria();
0536:
0537:                criteria.add(getConfirmColumn(), User.CONFIRM_DATA);
0538:                criteria.addAscendingOrderByColumn(getLastNameColumn());
0539:                criteria.addAscendingOrderByColumn(getFirstNameColumn());
0540:                criteria.setIgnoreCase(true);
0541:                return doSelect(criteria);
0542:            }
0543:
0544:            /*
0545:             * ========================================================================
0546:             *
0547:             * WARNING! Do not read on if you have a weak stomach. What follows here
0548:             * are some abominations thanks to the braindead static peers of Torque
0549:             * and the rigidity of Java....
0550:             *
0551:             * ========================================================================
0552:             *
0553:             */
0554:
0555:            /**
0556:             * Calls buildCriteria(User user) in the configured UserPeer. If you get
0557:             * a ClassCastException in this routine, you put a User object into this
0558:             * method which can't be cast into an object for the TorqueSecurityService. This is a
0559:             * configuration error most of the time.
0560:             *
0561:             * @param user An object which implements the User interface
0562:             *
0563:             * @return A criteria for the supplied user object
0564:             */
0565:
0566:            public static Criteria buildCriteria(User user) {
0567:                Criteria crit;
0568:
0569:                try {
0570:                    Class[] clazz = new Class[] { userObject };
0571:                    Object[] params = new Object[] { ((TorqueUser) user)
0572:                            .getPersistentObj() };
0573:
0574:                    crit = (Criteria) userPeerClass.getMethod("buildCriteria",
0575:                            clazz).invoke(null, params);
0576:                } catch (Exception e) {
0577:                    crit = null;
0578:                }
0579:
0580:                return crit;
0581:            }
0582:
0583:            /**
0584:             * Invokes doUpdate(Criteria c) on the configured Peer Object
0585:             *
0586:             * @param criteria  A Criteria Object
0587:             *
0588:             * @exception TorqueException A problem occured.
0589:             */
0590:
0591:            public static void doUpdate(Criteria criteria)
0592:                    throws TorqueException {
0593:                try {
0594:                    Class[] clazz = new Class[] { Criteria.class };
0595:                    Object[] params = new Object[] { criteria };
0596:
0597:                    userPeerClass.getMethod("doUpdate", clazz).invoke(null,
0598:                            params);
0599:                } catch (Exception e) {
0600:                    throw new TorqueException("doUpdate failed", e);
0601:                }
0602:            }
0603:
0604:            /**
0605:             * Invokes doInsert(Criteria c) on the configured Peer Object
0606:             *
0607:             * @param criteria  A Criteria Object
0608:             *
0609:             * @exception TorqueException A problem occured.
0610:             */
0611:
0612:            public static void doInsert(Criteria criteria)
0613:                    throws TorqueException {
0614:                try {
0615:                    Class[] clazz = new Class[] { Criteria.class };
0616:                    Object[] params = new Object[] { criteria };
0617:
0618:                    userPeerClass.getMethod("doInsert", clazz).invoke(null,
0619:                            params);
0620:                } catch (Exception e) {
0621:                    throw new TorqueException("doInsert failed", e);
0622:                }
0623:            }
0624:
0625:            /**
0626:             * Invokes doSelect(Criteria c) on the configured Peer Object
0627:             *
0628:             * @param criteria  A Criteria Object
0629:             *
0630:             * @return A List of User Objects selected by the Criteria
0631:             *
0632:             * @exception TorqueException A problem occured.
0633:             */
0634:            public static List doSelect(Criteria criteria)
0635:                    throws TorqueException {
0636:                List list;
0637:
0638:                try {
0639:                    Class[] clazz = new Class[] { Criteria.class };
0640:                    Object[] params = new Object[] { criteria };
0641:
0642:                    list = (List) userPeerClass.getMethod("doSelect", clazz)
0643:                            .invoke(null, params);
0644:                } catch (Exception e) {
0645:                    throw new TorqueException("doSelect failed", e);
0646:                }
0647:                List newList = new ArrayList(list.size());
0648:
0649:                //
0650:                // Wrap the returned Objects into TorqueUsers.
0651:                //
0652:                for (Iterator it = list.iterator(); it.hasNext();) {
0653:                    User u = getNewUser((Persistent) it.next());
0654:                    newList.add(u);
0655:                }
0656:
0657:                return newList;
0658:            }
0659:
0660:            /**
0661:             * Invokes doDelete(Criteria c) on the configured Peer Object
0662:             *
0663:             * @param criteria  A Criteria Object
0664:             *
0665:             * @exception TorqueException A problem occured.
0666:             */
0667:            public static void doDelete(Criteria criteria)
0668:                    throws TorqueException {
0669:                try {
0670:                    Class[] clazz = new Class[] { Criteria.class };
0671:                    Object[] params = new Object[] { criteria };
0672:
0673:                    userPeerClass.getMethod("doDelete", clazz).invoke(null,
0674:                            params);
0675:                } catch (Exception e) {
0676:                    throw new TorqueException("doDelete failed", e);
0677:                }
0678:            }
0679:
0680:            /**
0681:             * Invokes setName(String s) on the supplied base object
0682:             *
0683:             * @param obj The object to use for setting the name
0684:             * @param name The Name to set
0685:             */
0686:            public static void setUserName(Persistent obj, String name) {
0687:                if (obj == null) {
0688:                    return;
0689:                }
0690:
0691:                try {
0692:                    Object[] params = new Object[] { name };
0693:                    namePropDesc.getWriteMethod().invoke(obj, params);
0694:                } catch (ClassCastException cce) {
0695:                    String msg = obj.getClass().getName()
0696:                            + " does not seem to be an User Object!";
0697:                    log.error(msg);
0698:                    throw new RuntimeException(msg);
0699:                } catch (Exception e) {
0700:                    log.error(e, e);
0701:                }
0702:            }
0703:
0704:            /**
0705:             * Invokes getName() on the supplied base object
0706:             *
0707:             * @param obj The object to use for getting the name
0708:             *
0709:             * @return A string containing the name
0710:             *
0711:             * @deprecated use getName(obj)
0712:             */
0713:            public static String getUserName(Persistent obj) {
0714:                return getName(obj);
0715:            }
0716:
0717:            /**
0718:             * Invokes getName() on the supplied base object
0719:             *
0720:             * @param obj The object to use for getting the name
0721:             *
0722:             * @return A string containing the name
0723:             */
0724:            public static String getName(Persistent obj) {
0725:                String name = null;
0726:
0727:                if (obj == null) {
0728:                    return null;
0729:                }
0730:
0731:                try {
0732:                    name = (String) namePropDesc.getReadMethod().invoke(obj,
0733:                            new Object[] {});
0734:                } catch (ClassCastException cce) {
0735:                    String msg = obj.getClass().getName()
0736:                            + " does not seem to be an User Object!";
0737:                    log.error(msg);
0738:                    throw new RuntimeException(msg);
0739:                } catch (Exception e) {
0740:                    log.error(e, e);
0741:                }
0742:                return name;
0743:            }
0744:
0745:            /**
0746:             * Invokes setPassword(String s) on the supplied base object
0747:             *
0748:             * @param obj The object to use for setting the password
0749:             * @param password The Password to set
0750:             */
0751:            public static void setUserPassword(Persistent obj, String password) {
0752:                if (obj == null) {
0753:                    return;
0754:                }
0755:
0756:                try {
0757:                    Object[] params = new Object[] { password };
0758:                    passwordPropDesc.getWriteMethod().invoke(obj, params);
0759:                } catch (ClassCastException cce) {
0760:                    String msg = obj.getClass().getName()
0761:                            + " does not seem to be an User Object!";
0762:                    log.error(msg);
0763:                    throw new RuntimeException(msg);
0764:                } catch (Exception e) {
0765:                    log.error(e, e);
0766:                }
0767:            }
0768:
0769:            /**
0770:             * Invokes getPassword() on the supplied base object
0771:             *
0772:             * @param obj The object to use for getting the password
0773:             *
0774:             * @return A string containing the password
0775:             */
0776:            public static String getUserPassword(Persistent obj) {
0777:                String password = null;
0778:
0779:                if (obj == null) {
0780:                    return null;
0781:                }
0782:
0783:                try {
0784:                    password = (String) passwordPropDesc.getReadMethod()
0785:                            .invoke(obj, new Object[] {});
0786:                } catch (ClassCastException cce) {
0787:                    String msg = obj.getClass().getName()
0788:                            + " does not seem to be an User Object!";
0789:                    log.error(msg);
0790:                    throw new RuntimeException(msg);
0791:                } catch (Exception e) {
0792:                    log.error(e, e);
0793:                }
0794:                return password;
0795:            }
0796:
0797:            /**
0798:             * Invokes setFirstName(String s) on the supplied base object
0799:             *
0800:             * @param obj The object to use for setting the first name
0801:             * @param firstName The first name to set
0802:             */
0803:            public static void setUserFirstName(Persistent obj, String firstName) {
0804:                if (obj == null) {
0805:                    return;
0806:                }
0807:
0808:                try {
0809:                    Object[] params = new Object[] { firstName };
0810:                    firstNamePropDesc.getWriteMethod().invoke(obj, params);
0811:                } catch (ClassCastException cce) {
0812:                    String msg = obj.getClass().getName()
0813:                            + " does not seem to be an User Object!";
0814:                    log.error(msg);
0815:                    throw new RuntimeException(msg);
0816:                } catch (Exception e) {
0817:                    log.error(e, e);
0818:                }
0819:            }
0820:
0821:            /**
0822:             * Invokes getFirstName() on the supplied base object
0823:             *
0824:             * @param obj The object to use for getting the first name
0825:             *
0826:             * @return A string containing the first name
0827:             */
0828:            public static String getUserFirstName(Persistent obj) {
0829:                String firstName = null;
0830:
0831:                if (obj == null) {
0832:                    return null;
0833:                }
0834:
0835:                try {
0836:                    firstName = (String) firstNamePropDesc.getReadMethod()
0837:                            .invoke(obj, new Object[] {});
0838:                } catch (ClassCastException cce) {
0839:                    String msg = obj.getClass().getName()
0840:                            + " does not seem to be an User Object!";
0841:                    log.error(msg);
0842:                    throw new RuntimeException(msg);
0843:                } catch (Exception e) {
0844:                    log.error(e, e);
0845:                }
0846:                return firstName;
0847:            }
0848:
0849:            /**
0850:             * Invokes setLastName(String s) on the supplied base object
0851:             *
0852:             * @param obj The object to use for setting the last name
0853:             * @param lastName The Last Name to set
0854:             */
0855:            public static void setUserLastName(Persistent obj, String lastName) {
0856:                if (obj == null) {
0857:                    return;
0858:                }
0859:
0860:                try {
0861:                    Object[] params = new Object[] { lastName };
0862:                    lastNamePropDesc.getWriteMethod().invoke(obj, params);
0863:                } catch (ClassCastException cce) {
0864:                    String msg = obj.getClass().getName()
0865:                            + " does not seem to be an User Object!";
0866:                    log.error(msg);
0867:                    throw new RuntimeException(msg);
0868:                } catch (Exception e) {
0869:                    log.error(e, e);
0870:                }
0871:            }
0872:
0873:            /**
0874:             * Invokes getLastName() on the supplied base object
0875:             *
0876:             * @param obj The object to use for getting the last name
0877:             *
0878:             * @return A string containing the last name
0879:             */
0880:            public static String getUserLastName(Persistent obj) {
0881:                String lastName = null;
0882:
0883:                if (obj == null) {
0884:                    return null;
0885:                }
0886:
0887:                try {
0888:                    lastName = (String) lastNamePropDesc.getReadMethod()
0889:                            .invoke(obj, new Object[] {});
0890:                } catch (ClassCastException cce) {
0891:                    String msg = obj.getClass().getName()
0892:                            + " does not seem to be an User Object!";
0893:                    log.error(msg);
0894:                    throw new RuntimeException(msg);
0895:                } catch (Exception e) {
0896:                    log.error(e, e);
0897:                }
0898:                return lastName;
0899:            }
0900:
0901:            /**
0902:             * Invokes setEmail(String s) on the supplied base object
0903:             *
0904:             * @param obj The object to use for setting the email
0905:             * @param email The Email to set
0906:             */
0907:            public static void setUserEmail(Persistent obj, String email) {
0908:                if (obj == null) {
0909:                    return;
0910:                }
0911:
0912:                try {
0913:                    Object[] params = new Object[] { email };
0914:                    emailPropDesc.getWriteMethod().invoke(obj, params);
0915:                } catch (ClassCastException cce) {
0916:                    String msg = obj.getClass().getName()
0917:                            + " does not seem to be an User Object!";
0918:                    log.error(msg);
0919:                    throw new RuntimeException(msg);
0920:                } catch (Exception e) {
0921:                    log.error(e, e);
0922:                }
0923:            }
0924:
0925:            /**
0926:             * Invokes getEmail() on the supplied base object
0927:             *
0928:             * @param obj The object to use for getting the email
0929:             *
0930:             * @return A string containing the email
0931:             */
0932:            public static String getUserEmail(Persistent obj) {
0933:                String email = null;
0934:
0935:                if (obj == null) {
0936:                    return null;
0937:                }
0938:
0939:                try {
0940:                    email = (String) emailPropDesc.getReadMethod().invoke(obj,
0941:                            new Object[] {});
0942:                } catch (ClassCastException cce) {
0943:                    String msg = obj.getClass().getName()
0944:                            + " does not seem to be an User Object!";
0945:                    log.error(msg);
0946:                    throw new RuntimeException(msg);
0947:                } catch (Exception e) {
0948:                    log.error(e, e);
0949:                }
0950:                return email;
0951:            }
0952:
0953:            /**
0954:             * Invokes setConfirmed(String s) on the supplied base object
0955:             *
0956:             * @param obj The object to use for setting the confirm value
0957:             * @param confirm The confirm value to set
0958:             */
0959:            public static void setUserConfirmed(Persistent obj, String confirm) {
0960:                if (obj == null) {
0961:                    return;
0962:                }
0963:
0964:                try {
0965:                    Object[] params = new Object[] { confirm };
0966:                    confirmPropDesc.getWriteMethod().invoke(obj, params);
0967:                } catch (ClassCastException cce) {
0968:                    String msg = obj.getClass().getName()
0969:                            + " does not seem to be an User Object!";
0970:                    log.error(msg);
0971:                    throw new RuntimeException(msg);
0972:                } catch (Exception e) {
0973:                    log.error(e, e);
0974:                }
0975:            }
0976:
0977:            /**
0978:             * Invokes getConfirmed() on the supplied base object
0979:             *
0980:             * @param obj The object to use for getting the confirm value
0981:             *
0982:             * @return A string containing the confirm value
0983:             */
0984:            public static String getUserConfirmed(Persistent obj) {
0985:                String confirm = null;
0986:
0987:                if (obj == null) {
0988:                    return null;
0989:                }
0990:
0991:                try {
0992:                    confirm = (String) confirmPropDesc.getReadMethod().invoke(
0993:                            obj, new Object[] {});
0994:                } catch (ClassCastException cce) {
0995:                    String msg = obj.getClass().getName()
0996:                            + " does not seem to be an User Object!";
0997:                    log.error(msg);
0998:                    throw new RuntimeException(msg);
0999:                } catch (Exception e) {
1000:                    log.error(e, e);
1001:                }
1002:                return confirm;
1003:            }
1004:
1005:            /**
1006:             * Invokes setCreateDate(java.util.Date date) on the supplied base object
1007:             *
1008:             * @param obj The object to use for setting the create date
1009:             * @param createDate The create date to set
1010:             */
1011:            public static void setUserCreateDate(Persistent obj,
1012:                    java.util.Date createDate) {
1013:                if (obj == null) {
1014:                    return;
1015:                }
1016:
1017:                try {
1018:                    Object[] params = new Object[] { createDate };
1019:                    createDatePropDesc.getWriteMethod().invoke(obj, params);
1020:                } catch (ClassCastException cce) {
1021:                    String msg = obj.getClass().getName()
1022:                            + " does not seem to be an User Object!";
1023:                    log.error(msg);
1024:                    throw new RuntimeException(msg);
1025:                } catch (Exception e) {
1026:                    log.error(e, e);
1027:                }
1028:            }
1029:
1030:            /**
1031:             * Invokes getCreateDate() on the supplied base object
1032:             *
1033:             * @param obj The object to use for getting the create date
1034:             *
1035:             * @return A string containing the create date
1036:             */
1037:            public static java.util.Date getUserCreateDate(Persistent obj) {
1038:                java.util.Date createDate = null;
1039:
1040:                if (obj == null) {
1041:                    return null;
1042:                }
1043:
1044:                try {
1045:                    createDate = (java.util.Date) createDatePropDesc
1046:                            .getReadMethod().invoke(obj, new Object[] {});
1047:                } catch (ClassCastException cce) {
1048:                    String msg = obj.getClass().getName()
1049:                            + " does not seem to be an User Object!";
1050:                    log.error(msg);
1051:                    throw new RuntimeException(msg);
1052:                } catch (Exception e) {
1053:                    log.error(e, e);
1054:                }
1055:                return createDate;
1056:            }
1057:
1058:            /**
1059:             * Invokes setLastLogin(java.util.Date date) on the supplied base object
1060:             *
1061:             * @param obj The object to use for setting the last login daet
1062:             * @param lastLogin The last login date to set
1063:             */
1064:            public static void setUserLastLogin(Persistent obj,
1065:                    java.util.Date lastLogin) {
1066:                if (obj == null) {
1067:                    return;
1068:                }
1069:
1070:                try {
1071:                    Object[] params = new Object[] { lastLogin };
1072:                    lastLoginPropDesc.getWriteMethod().invoke(obj, params);
1073:                } catch (ClassCastException cce) {
1074:                    String msg = obj.getClass().getName()
1075:                            + " does not seem to be an User Object!";
1076:                    log.error(msg);
1077:                    throw new RuntimeException(msg);
1078:                } catch (Exception e) {
1079:                    log.error(e, e);
1080:                }
1081:            }
1082:
1083:            /**
1084:             * Invokes getLastLogin() on the supplied base object
1085:             *
1086:             * @param obj The object to use for getting the last login date
1087:             *
1088:             * @return A string containing the last login date
1089:             */
1090:            public static java.util.Date getUserLastLogin(Persistent obj) {
1091:                java.util.Date lastLogin = null;
1092:
1093:                if (obj == null) {
1094:                    return null;
1095:                }
1096:
1097:                try {
1098:                    lastLogin = (java.util.Date) lastLoginPropDesc
1099:                            .getReadMethod().invoke(obj, new Object[] {});
1100:                } catch (ClassCastException cce) {
1101:                    String msg = obj.getClass().getName()
1102:                            + " does not seem to be an User Object!";
1103:                    log.error(msg);
1104:                    throw new RuntimeException(msg);
1105:                } catch (Exception e) {
1106:                    log.error(e, e);
1107:                }
1108:                return lastLogin;
1109:            }
1110:
1111:            /**
1112:             * Invokes setObjectdata(byte [] date) on the supplied base object
1113:             *
1114:             * @param obj The object to use for setting the last login daet
1115:             * @param objectdata The objectdata to use
1116:             */
1117:            public static void setUserObjectdata(Persistent obj,
1118:                    byte[] objectdata) {
1119:                if (obj == null) {
1120:                    return;
1121:                }
1122:
1123:                try {
1124:                    Object[] params = new Object[] { objectdata };
1125:                    objectdataPropDesc.getWriteMethod().invoke(obj, params);
1126:                } catch (ClassCastException cce) {
1127:                    String msg = obj.getClass().getName()
1128:                            + " does not seem to be an User Object!";
1129:                    log.error(msg);
1130:                    throw new RuntimeException(msg);
1131:                } catch (Exception e) {
1132:                    log.error(e, e);
1133:                }
1134:            }
1135:
1136:            /**
1137:             * Invokes getObjectdata() on the supplied base object
1138:             *
1139:             * @param obj The object to use for getting the last login date
1140:             *
1141:             * @return A string containing the last login date
1142:             */
1143:            public static byte[] getUserObjectdata(Persistent obj) {
1144:                byte[] objectdata = null;
1145:
1146:                if (obj == null) {
1147:                    return null;
1148:                }
1149:
1150:                try {
1151:                    objectdata = (byte[]) objectdataPropDesc.getReadMethod()
1152:                            .invoke(obj, new Object[] {});
1153:                } catch (ClassCastException cce) {
1154:                    String msg = obj.getClass().getName()
1155:                            + " does not seem to be an User Object!";
1156:                    log.error(msg);
1157:                    throw new RuntimeException(msg);
1158:                } catch (Exception e) {
1159:                    log.error(e, e);
1160:                }
1161:                return objectdata;
1162:            }
1163:
1164:            /**
1165:             * Invokes setId(int n) on the supplied base object
1166:             *
1167:             * @param obj The object to use for setting the name
1168:             * @param id The new Id
1169:             */
1170:            public static void setId(Persistent obj, int id) {
1171:                if (obj == null) {
1172:                    return;
1173:                }
1174:
1175:                try {
1176:                    Object[] params = new Object[] { Integer.TYPE };
1177:                    idPropDesc.getWriteMethod().invoke(obj, params);
1178:                } catch (ClassCastException cce) {
1179:                    String msg = obj.getClass().getName()
1180:                            + " does not seem to be an User Object!";
1181:                    log.error(msg);
1182:                    throw new RuntimeException(msg);
1183:                } catch (Exception e) {
1184:                    log.error(e, e);
1185:                }
1186:            }
1187:
1188:            /**
1189:             * Invokes getId() on the supplied base object
1190:             *
1191:             * @param obj The object to use for getting the id
1192:             *
1193:             * @return The Id of this object
1194:             */
1195:            public static Integer getIdAsObj(Persistent obj) {
1196:                Integer id = null;
1197:
1198:                if (obj == null) {
1199:                    return new Integer(0);
1200:                }
1201:
1202:                try {
1203:                    id = (Integer) idPropDesc.getReadMethod().invoke(obj,
1204:                            new Object[] {});
1205:                } catch (ClassCastException cce) {
1206:                    String msg = obj.getClass().getName()
1207:                            + " does not seem to be an User Object!";
1208:                    log.error(msg);
1209:                    throw new RuntimeException(msg);
1210:                } catch (Exception e) {
1211:                    log.error(e, e);
1212:                }
1213:                return id;
1214:            }
1215:
1216:            /**
1217:             * Returns the Class of the configured Object class
1218:             * from the peer
1219:             *
1220:             * @return The class of the objects returned by the configured peer
1221:             *
1222:             */
1223:
1224:            private static Class getPersistenceClass() {
1225:                Class persistenceClass = null;
1226:
1227:                try {
1228:                    Object[] params = new Object[0];
1229:
1230:                    persistenceClass = (Class) userPeerClass.getMethod(
1231:                            "getOMClass", (Class[]) null).invoke(null, params);
1232:                } catch (Exception e) {
1233:                    persistenceClass = null;
1234:                }
1235:
1236:                return persistenceClass;
1237:            }
1238:
1239:            /**
1240:             * Returns a new, configured User Object with
1241:             * a supplied Persistent object at its core
1242:             *
1243:             * @param p The persistent object
1244:             *
1245:             * @return a new, configured User Object
1246:             *
1247:             * @exception Exception Could not create a new Object
1248:             *
1249:             */
1250:
1251:            public static User getNewUser(Persistent p) {
1252:                User u = null;
1253:                try {
1254:                    Class userWrapperClass = TurbineSecurity.getUserClass();
1255:
1256:                    Class[] clazz = new Class[] { Persistent.class };
1257:                    Object[] params = new Object[] { p };
1258:
1259:                    u = (User) userWrapperClass.getConstructor(clazz)
1260:                            .newInstance(params);
1261:                } catch (Exception e) {
1262:                    log
1263:                            .error(
1264:                                    "Could not instantiate a new user from supplied persistent: ",
1265:                                    e);
1266:                }
1267:
1268:                return u;
1269:            }
1270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.