Coverage Report - org.apache.turbine.services.security.torque.UserPeerManager
 
Classes in this File Line Coverage Branch Coverage Complexity
UserPeerManager
0%
0/422
0%
0/98
4,391
 
 1  
 package org.apache.turbine.services.security.torque;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.beans.PropertyDescriptor;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 
 28  
 import org.apache.commons.configuration.Configuration;
 29  
 
 30  
 import org.apache.commons.logging.Log;
 31  
 import org.apache.commons.logging.LogFactory;
 32  
 
 33  
 import org.apache.torque.TorqueException;
 34  
 import org.apache.torque.om.Persistent;
 35  
 import org.apache.torque.util.BasePeer;
 36  
 import org.apache.torque.util.Criteria;
 37  
 
 38  
 import org.apache.turbine.om.security.User;
 39  
 import org.apache.turbine.services.InitializationException;
 40  
 import org.apache.turbine.services.security.TurbineSecurity;
 41  
 import org.apache.turbine.util.security.DataBackendException;
 42  
 
 43  
 /**
 44  
  * This class capsulates all direct Peer access for the User entities.
 45  
  * It allows the exchange of the default Turbine supplied TurbineUserPeer
 46  
  * class against a custom class.
 47  
  *
 48  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 49  
  * @version $Id: UserPeerManager.java 1096130 2011-04-23 10:37:19Z ludwig $
 50  
  */
 51  
 
 52  0
 public class UserPeerManager
 53  
     implements UserPeerManagerConstants
 54  
 {
 55  
     /** Serial UID */
 56  
     private static final long serialVersionUID = 6943046259921811593L;
 57  
 
 58  
     /** The class of the Peer the TorqueSecurityService uses */
 59  0
     private static Class userPeerClass = null;
 60  
 
 61  
     /** The class name of the objects returned by the configured peer. */
 62  0
     private static Class userObject = null;
 63  
 
 64  
     /** The name of the Table used for Group Object queries  */
 65  0
     private static String tableName = null;
 66  
 
 67  
     /** The name of the column used as "Name" Column */
 68  0
     private static String nameColumn = null;
 69  
 
 70  
     /** The name of the column used as "Id" Column */
 71  0
     private static String idColumn = null;
 72  
 
 73  
     /** The name of the column used as "Password" Column */
 74  0
     private static String passwordColumn = null;
 75  
 
 76  
     /** The name of the column used as "First name" Column */
 77  0
     private static String firstNameColumn = null;
 78  
 
 79  
     /** The name of the column used as "Last name" Column */
 80  0
     private static String lastNameColumn = null;
 81  
 
 82  
     /** The name of the column used as "Email" Column */
 83  0
     private static String emailColumn = null;
 84  
 
 85  
     /** The name of the column used as "Confirm" Column */
 86  0
     private static String confirmColumn = null;
 87  
 
 88  
     /** The name of the column used as "create date" Column */
 89  0
     private static String createDateColumn = null;
 90  
 
 91  
     /** The name of the column used as "last login" Column */
 92  0
     private static String lastLoginColumn = null;
 93  
 
 94  
     /** The name of the column used as "objectdata" Column */
 95  0
     private static String objectdataColumn = null;
 96  
 
 97  
     /** The "Name" property descriptor */
 98  0
     private static PropertyDescriptor namePropDesc = null;
 99  
 
 100  
     /** The "Id" property descriptor */
 101  0
     private static PropertyDescriptor idPropDesc = null;
 102  
 
 103  
     /** The "Password" property descriptor */
 104  0
     private static PropertyDescriptor passwordPropDesc = null;
 105  
 
 106  
     /** The "First name" property descriptor */
 107  0
     private static PropertyDescriptor firstNamePropDesc = null;
 108  
 
 109  
     /** The "Last name" property descriptor */
 110  0
     private static PropertyDescriptor lastNamePropDesc = null;
 111  
 
 112  
     /** The "Email" property descriptor */
 113  0
     private static PropertyDescriptor emailPropDesc = null;
 114  
 
 115  
     /** The "Confirm" property descriptor */
 116  0
     private static PropertyDescriptor confirmPropDesc = null;
 117  
 
 118  
     /** The "create date" property descriptor */
 119  0
     private static PropertyDescriptor createDatePropDesc = null;
 120  
 
 121  
     /** The "last login" property descriptor */
 122  0
     private static PropertyDescriptor lastLoginPropDesc = null;
 123  
 
 124  
     /** The "objectdata" property descriptor */
 125  0
     private static PropertyDescriptor objectdataPropDesc = null;
 126  
 
 127  
     /** Logging */
 128  0
     static Log log = LogFactory.getLog(UserPeerManager.class);
 129  
 
 130  
     /**
 131  
      * Initializes the UserPeerManager, loading the class object for the
 132  
      * Peer used to retrieve User objects
 133  
      *
 134  
      * @param conf The configuration object used to configure the Manager
 135  
      *
 136  
      * @exception InitializationException A problem occured during
 137  
      *            initialization
 138  
      */
 139  
 
 140  
     public static void init(Configuration conf)
 141  
         throws InitializationException
 142  
     {
 143  0
         String userPeerClassName = conf.getString(USER_PEER_CLASS_KEY,
 144  
                                                   USER_PEER_CLASS_DEFAULT);
 145  0
         String userObjectName = null;
 146  
 
 147  
         try
 148  
         {
 149  0
             userPeerClass = Class.forName(userPeerClassName);
 150  
 
 151  0
             tableName  =
 152  
               (String) userPeerClass.getField("TABLE_NAME").get(null);
 153  
 
 154  
             //
 155  
             // We have either an user configured Object class or we use the
 156  
             // default as supplied by the Peer class
 157  
             //
 158  
 
 159  
             // Default from Peer, can be overridden
 160  
 
 161  0
             userObject = getPersistenceClass();
 162  
 
 163  0
             userObjectName = conf.getString(USER_CLASS_KEY,
 164  
                     userObject.getName());
 165  
 
 166  
             // Maybe the user set a new value...
 167  0
             userObject = Class.forName(userObjectName);
 168  
 
 169  
             /* If any of the following Field queries fails, the user
 170  
              * subsystem is unusable. So check this right here at init time,
 171  
              * which saves us much time and hassle if it fails...
 172  
              */
 173  
 
 174  0
             nameColumn = (String) userPeerClass.getField(
 175  
                 conf.getString(USER_NAME_COLUMN_KEY,
 176  
                                USER_NAME_COLUMN_DEFAULT)
 177  
                 ).get(null);
 178  
 
 179  0
             idColumn = (String) userPeerClass.getField(
 180  
                 conf.getString(USER_ID_COLUMN_KEY,
 181  
                                USER_ID_COLUMN_DEFAULT)
 182  
                 ).get(null);
 183  
 
 184  0
             passwordColumn = (String) userPeerClass.getField(
 185  
                 conf.getString(USER_PASSWORD_COLUMN_KEY,
 186  
                                USER_PASSWORD_COLUMN_DEFAULT)
 187  
                 ).get(null);
 188  
 
 189  0
             firstNameColumn  = (String) userPeerClass.getField(
 190  
                 conf.getString(USER_FIRST_NAME_COLUMN_KEY,
 191  
                                USER_FIRST_NAME_COLUMN_DEFAULT)
 192  
                 ).get(null);
 193  
 
 194  0
             lastNameColumn = (String) userPeerClass.getField(
 195  
                 conf.getString(USER_LAST_NAME_COLUMN_KEY,
 196  
                                USER_LAST_NAME_COLUMN_DEFAULT)
 197  
                 ).get(null);
 198  
 
 199  0
             emailColumn = (String) userPeerClass.getField(
 200  
                 conf.getString(USER_EMAIL_COLUMN_KEY,
 201  
                                USER_EMAIL_COLUMN_DEFAULT)
 202  
                 ).get(null);
 203  
 
 204  0
             confirmColumn    = (String) userPeerClass.getField(
 205  
                 conf.getString(USER_CONFIRM_COLUMN_KEY,
 206  
                                USER_CONFIRM_COLUMN_DEFAULT)
 207  
                 ).get(null);
 208  
 
 209  0
             createDateColumn = (String) userPeerClass.getField(
 210  
                 conf.getString(USER_CREATE_COLUMN_KEY,
 211  
                                USER_CREATE_COLUMN_DEFAULT)
 212  
                 ).get(null);
 213  
 
 214  0
             lastLoginColumn = (String) userPeerClass.getField(
 215  
                 conf.getString(USER_LAST_LOGIN_COLUMN_KEY,
 216  
                                USER_LAST_LOGIN_COLUMN_DEFAULT)
 217  
                 ).get(null);
 218  
 
 219  0
             objectdataColumn = (String) userPeerClass.getField(
 220  
                 conf.getString(USER_OBJECTDATA_COLUMN_KEY,
 221  
                                USER_OBJECTDATA_COLUMN_DEFAULT)
 222  
                 ).get(null);
 223  
 
 224  0
             namePropDesc =
 225  
                 new PropertyDescriptor(conf.getString(
 226  
                                            USER_NAME_PROPERTY_KEY,
 227  
                                            USER_NAME_PROPERTY_DEFAULT),
 228  
                                        userObject);
 229  
 
 230  0
             idPropDesc =
 231  
                 new PropertyDescriptor(conf.getString(
 232  
                                            USER_ID_PROPERTY_KEY,
 233  
                                            USER_ID_PROPERTY_DEFAULT),
 234  
                                        userObject);
 235  
 
 236  0
             passwordPropDesc =
 237  
                 new PropertyDescriptor(conf.getString(
 238  
                                            USER_PASSWORD_PROPERTY_KEY,
 239  
                                            USER_PASSWORD_PROPERTY_DEFAULT),
 240  
                                        userObject);
 241  
 
 242  0
             firstNamePropDesc =
 243  
                 new PropertyDescriptor(conf.getString(
 244  
                                            USER_FIRST_NAME_PROPERTY_KEY,
 245  
                                            USER_FIRST_NAME_PROPERTY_DEFAULT),
 246  
                                        userObject);
 247  
 
 248  0
             lastNamePropDesc   =
 249  
                 new PropertyDescriptor(conf.getString(
 250  
                                            USER_LAST_NAME_PROPERTY_KEY,
 251  
                                            USER_LAST_NAME_PROPERTY_DEFAULT),
 252  
                                        userObject);
 253  
 
 254  0
             emailPropDesc =
 255  
                 new PropertyDescriptor(conf.getString(
 256  
                                            USER_EMAIL_PROPERTY_KEY,
 257  
                                            USER_EMAIL_PROPERTY_DEFAULT),
 258  
                                        userObject);
 259  
 
 260  0
             confirmPropDesc =
 261  
                 new PropertyDescriptor(conf.getString(
 262  
                                            USER_CONFIRM_PROPERTY_KEY,
 263  
                                            USER_CONFIRM_PROPERTY_DEFAULT),
 264  
                                        userObject);
 265  
 
 266  0
             createDatePropDesc =
 267  
                 new PropertyDescriptor(conf.getString(
 268  
                                            USER_CREATE_PROPERTY_KEY,
 269  
                                            USER_CREATE_PROPERTY_DEFAULT),
 270  
                                        userObject);
 271  
 
 272  0
             lastLoginPropDesc  =
 273  
                 new PropertyDescriptor(conf.getString(
 274  
                                            USER_LAST_LOGIN_PROPERTY_KEY,
 275  
                                            USER_LAST_LOGIN_PROPERTY_DEFAULT),
 276  
                                        userObject);
 277  
 
 278  0
             objectdataPropDesc =
 279  
                 new PropertyDescriptor(conf.getString(
 280  
                                            USER_OBJECTDATA_PROPERTY_KEY,
 281  
                                            USER_OBJECTDATA_PROPERTY_DEFAULT),
 282  
                                        userObject);
 283  
         }
 284  0
         catch (Exception e)
 285  
         {
 286  0
             if (userPeerClassName == null || userPeerClass == null)
 287  
             {
 288  0
                 throw new InitializationException(
 289  
                     "Could not find UserPeer class ("
 290  
                     + userPeerClassName + ")", e);
 291  
             }
 292  0
             if (tableName == null)
 293  
             {
 294  0
                 throw new InitializationException(
 295  
                     "Failed to get the table name from the Peer object", e);
 296  
             }
 297  
 
 298  0
             if (userObject == null || userObjectName == null)
 299  
             {
 300  0
                 throw new InitializationException(
 301  
                     "Failed to get the object type from the Peer object", e);
 302  
             }
 303  
 
 304  
 
 305  0
             if (nameColumn == null || namePropDesc == null)
 306  
             {
 307  0
                 throw new InitializationException(
 308  
                     "UserPeer " + userPeerClassName
 309  
                     + " has no name column information!", e);
 310  
             }
 311  0
             if (idColumn == null || idPropDesc == null)
 312  
             {
 313  0
                 throw new InitializationException(
 314  
                     "UserPeer " + userPeerClassName
 315  
                     + " has no id column information!", e);
 316  
             }
 317  0
             if (passwordColumn == null || passwordPropDesc == null)
 318  
             {
 319  0
                 throw new InitializationException(
 320  
                     "UserPeer " + userPeerClassName
 321  
                     + " has no password column information!", e);
 322  
             }
 323  0
             if (firstNameColumn == null || firstNamePropDesc == null)
 324  
             {
 325  0
                 throw new InitializationException(
 326  
                     "UserPeer " + userPeerClassName
 327  
                     + " has no firstName column information!", e);
 328  
             }
 329  0
             if (lastNameColumn == null || lastNamePropDesc == null)
 330  
             {
 331  0
                 throw new InitializationException(
 332  
                     "UserPeer " + userPeerClassName
 333  
                     + " has no lastName column information!", e);
 334  
             }
 335  0
             if (emailColumn == null || emailPropDesc == null)
 336  
             {
 337  0
                 throw new InitializationException(
 338  
                     "UserPeer " + userPeerClassName
 339  
                     + " has no email column information!", e);
 340  
             }
 341  0
             if (confirmColumn == null || confirmPropDesc == null)
 342  
             {
 343  0
                 throw new InitializationException(
 344  
                     "UserPeer " + userPeerClassName
 345  
                     + " has no confirm column information!", e);
 346  
             }
 347  0
             if (createDateColumn == null || createDatePropDesc == null)
 348  
             {
 349  0
                 throw new InitializationException(
 350  
                     "UserPeer " + userPeerClassName
 351  
                     + " has no createDate column information!", e);
 352  
             }
 353  0
             if (lastLoginColumn == null || lastLoginPropDesc == null)
 354  
             {
 355  0
                 throw new InitializationException(
 356  
                     "UserPeer " + userPeerClassName
 357  
                     + " has no lastLogin column information!", e);
 358  
             }
 359  0
             if (objectdataColumn == null || objectdataPropDesc == null)
 360  
             {
 361  0
                 throw new InitializationException(
 362  
                     "UserPeer " + userPeerClassName
 363  
                     + " has no objectdata column information!", e);
 364  
             }
 365  0
         }
 366  0
     }
 367  
 
 368  
     /**
 369  
      * Get the name of this table.
 370  
      *
 371  
      * @return A String with the name of the table.
 372  
      */
 373  
     public static String getTableName()
 374  
     {
 375  0
         return tableName;
 376  
     }
 377  
 
 378  
     /**
 379  
      * Returns the fully qualified name of the Column to
 380  
      * use as the Name Column for a group
 381  
      *
 382  
      * @return A String containing the column name
 383  
      */
 384  
     public static String getNameColumn()
 385  
     {
 386  0
         return nameColumn;
 387  
     }
 388  
 
 389  
     /**
 390  
      * Returns the fully qualified name of the Column to
 391  
      * use as the Id Column for a group
 392  
      *
 393  
      * @return A String containing the column id
 394  
      */
 395  
     public static String getIdColumn()
 396  
     {
 397  0
         return idColumn;
 398  
     }
 399  
 
 400  
     /**
 401  
      * Returns the fully qualified name of the Column to
 402  
      * use as the Password Column for a role
 403  
      *
 404  
      * @return A String containing the column name
 405  
      */
 406  
     public static String getPasswordColumn()
 407  
     {
 408  0
         return passwordColumn;
 409  
     }
 410  
 
 411  
     /**
 412  
      * Returns the fully qualified name of the Column to
 413  
      * use as the FirstName Column for a role
 414  
      *
 415  
      * @return A String containing the column name
 416  
      */
 417  
     public static String getFirstNameColumn()
 418  
     {
 419  0
         return firstNameColumn;
 420  
     }
 421  
 
 422  
     /**
 423  
      * Returns the fully qualified name of the Column to
 424  
      * use as the LastName Column for a role
 425  
      *
 426  
      * @return A String containing the column name
 427  
      */
 428  
     public static String getLastNameColumn()
 429  
     {
 430  0
         return lastNameColumn;
 431  
     }
 432  
 
 433  
     /**
 434  
      * Returns the fully qualified name of the Column to
 435  
      * use as the Email Column for a role
 436  
      *
 437  
      * @return A String containing the column name
 438  
      */
 439  
     public static String getEmailColumn()
 440  
     {
 441  0
         return emailColumn;
 442  
     }
 443  
 
 444  
     /**
 445  
      * Returns the fully qualified name of the Column to
 446  
      * use as the Confirm Column for a role
 447  
      *
 448  
      * @return A String containing the column name
 449  
      */
 450  
     public static String getConfirmColumn()
 451  
     {
 452  0
         return confirmColumn;
 453  
     }
 454  
 
 455  
     /**
 456  
      * Returns the fully qualified name of the Column to
 457  
      * use as the CreateDate Column for a role
 458  
      *
 459  
      * @return A String containing the column name
 460  
      */
 461  
     public static String getCreateDateColumn()
 462  
     {
 463  0
         return createDateColumn;
 464  
     }
 465  
 
 466  
     /**
 467  
      * Returns the fully qualified name of the Column to
 468  
      * use as the LastLogin Column for a role
 469  
      *
 470  
      * @return A String containing the column name
 471  
      */
 472  
     public static String getLastLoginColumn()
 473  
     {
 474  0
         return lastLoginColumn;
 475  
     }
 476  
 
 477  
     /**
 478  
      * Returns the fully qualified name of the Column to
 479  
      * use as the objectdata Column for a role
 480  
      *
 481  
      * @return A String containing the column name
 482  
      */
 483  
     public static String getObjectdataColumn()
 484  
     {
 485  0
         return objectdataColumn;
 486  
     }
 487  
 
 488  
     /**
 489  
      * Returns the full name of a column.
 490  
      *
 491  
      * @param name The column to fully qualify
 492  
      *
 493  
      * @return A String with the full name of the column.
 494  
      */
 495  
     public static String getColumnName(String name)
 496  
     {
 497  0
         StringBuffer sb = new StringBuffer();
 498  0
         sb.append(getTableName());
 499  0
         sb.append(".");
 500  0
         sb.append(name);
 501  0
         return sb.toString();
 502  
     }
 503  
 
 504  
     /**
 505  
      * Returns the full name of a column.
 506  
      *
 507  
      * @param name The column to fully qualify
 508  
      *
 509  
      * @return A String with the full name of the column.
 510  
      * @deprecated use getColumnName(String name)
 511  
      */
 512  
     public String getFullColumnName(String name)
 513  
     {
 514  0
         return getColumnName(name);
 515  
     }
 516  
 
 517  
 
 518  
     /**
 519  
      * Returns a new, empty object for the underlying peer.
 520  
      * Used to create a new underlying object
 521  
      *
 522  
      * @return A new object which is compatible to the Peer
 523  
      *         and can be used as a User object
 524  
      *
 525  
      */
 526  
 
 527  
     public static Persistent newPersistentInstance()
 528  
     {
 529  0
         Persistent obj = null;
 530  
 
 531  0
         if (userObject == null)
 532  
         {
 533  
             // This can happen if the Turbine wants to determine the
 534  
             // name of the anonymous user before the security service
 535  
             // has been initialized. In this case, the Peer Manager
 536  
             // has not yet been inited and the userObject is still
 537  
             // null. Return null in this case.
 538  
             //
 539  0
             return obj;
 540  
         }
 541  
 
 542  
         try
 543  
         {
 544  0
             obj = (Persistent) userObject.newInstance();
 545  
         }
 546  0
         catch (Exception e)
 547  
         {
 548  0
             log.error("Could not instantiate a user object", e);
 549  0
             obj = null;
 550  0
         }
 551  0
         return obj;
 552  
     }
 553  
 
 554  
     /**
 555  
      * Checks if a User is defined in the system. The name
 556  
      * is used as query criteria.
 557  
      *
 558  
      * @param user The User to be checked.
 559  
      * @return <code>true</code> if given User exists in the system.
 560  
      * @throws DataBackendException when more than one User with
 561  
      *         the same name exists.
 562  
      * @throws Exception A generic exception.
 563  
      */
 564  
     public static boolean checkExists(User user)
 565  
         throws DataBackendException, Exception
 566  
     {
 567  0
         Criteria criteria = new Criteria();
 568  
 
 569  0
         criteria.addSelectColumn(getIdColumn());
 570  
 
 571  0
         criteria.add(getNameColumn(), user.getName());
 572  
 
 573  0
         List results = BasePeer.doSelect(criteria);
 574  
 
 575  0
         if (results.size() > 1)
 576  
         {
 577  0
             throw new DataBackendException("Multiple users named '" +
 578  
                                            user.getName() + "' exist!");
 579  
         }
 580  0
         return (results.size() == 1);
 581  
     }
 582  
 
 583  
     /**
 584  
      * Returns a List of all User objects.
 585  
      *
 586  
      * @return A List with all users in the system.
 587  
      * @exception Exception A generic exception.
 588  
      */
 589  
     public static List selectAllUsers()
 590  
         throws Exception
 591  
     {
 592  0
         Criteria criteria = new Criteria();
 593  0
         criteria.addAscendingOrderByColumn(getLastNameColumn());
 594  0
         criteria.addAscendingOrderByColumn(getFirstNameColumn());
 595  0
         criteria.setIgnoreCase(true);
 596  0
         return doSelect(criteria);
 597  
     }
 598  
 
 599  
     /**
 600  
      * Returns a List of all confirmed User objects.
 601  
      *
 602  
      * @return A List with all confirmed users in the system.
 603  
      * @exception Exception A generic exception.
 604  
      */
 605  
     public static List selectAllConfirmedUsers()
 606  
         throws Exception
 607  
     {
 608  0
         Criteria criteria = new Criteria();
 609  
 
 610  0
         criteria.add (getConfirmColumn(), User.CONFIRM_DATA);
 611  0
         criteria.addAscendingOrderByColumn(getLastNameColumn());
 612  0
         criteria.addAscendingOrderByColumn(getFirstNameColumn());
 613  0
         criteria.setIgnoreCase(true);
 614  0
         return doSelect(criteria);
 615  
     }
 616  
 
 617  
     /*
 618  
      * ========================================================================
 619  
      *
 620  
      * WARNING! Do not read on if you have a weak stomach. What follows here
 621  
      * are some abominations thanks to the braindead static peers of Torque
 622  
      * and the rigidity of Java....
 623  
      *
 624  
      * ========================================================================
 625  
      *
 626  
      */
 627  
 
 628  
     /**
 629  
      * Calls buildCriteria(User user) in the configured UserPeer. If you get
 630  
      * a ClassCastException in this routine, you put a User object into this
 631  
      * method which can't be cast into an object for the TorqueSecurityService. This is a
 632  
      * configuration error most of the time.
 633  
      *
 634  
      * @param user An object which implements the User interface
 635  
      *
 636  
      * @return A criteria for the supplied user object
 637  
      */
 638  
 
 639  
     public static Criteria buildCriteria(User user)
 640  
     {
 641  
         Criteria crit;
 642  
 
 643  
         try
 644  
         {
 645  0
             Class[] clazz = new Class[] { userObject };
 646  0
             Object[] params =
 647  
                 new Object[] { ((TorqueUser) user).getPersistentObj() };
 648  
 
 649  0
             crit =  (Criteria) userPeerClass
 650  
                 .getMethod("buildCriteria", clazz)
 651  
                 .invoke(null, params);
 652  
         }
 653  0
         catch (Exception e)
 654  
         {
 655  0
             crit = null;
 656  0
         }
 657  
 
 658  0
         return crit;
 659  
     }
 660  
 
 661  
     /**
 662  
      * Invokes doUpdate(Criteria c) on the configured Peer Object
 663  
      *
 664  
      * @param criteria  A Criteria Object
 665  
      *
 666  
      * @exception TorqueException A problem occured.
 667  
      */
 668  
 
 669  
     public static void doUpdate(Criteria criteria)
 670  
         throws TorqueException
 671  
     {
 672  
         try
 673  
         {
 674  0
             Class[] clazz = new Class[] { Criteria.class };
 675  0
             Object[] params = new Object[] { criteria };
 676  
 
 677  0
             userPeerClass
 678  
                 .getMethod("doUpdate", clazz)
 679  
                 .invoke(null, params);
 680  
         }
 681  0
         catch (Exception e)
 682  
         {
 683  0
             throw new TorqueException("doUpdate failed", e);
 684  0
         }
 685  0
     }
 686  
 
 687  
     /**
 688  
      * Invokes doInsert(Criteria c) on the configured Peer Object
 689  
      *
 690  
      * @param criteria  A Criteria Object
 691  
      *
 692  
      * @exception TorqueException A problem occured.
 693  
      */
 694  
 
 695  
     public static void doInsert(Criteria criteria)
 696  
         throws TorqueException
 697  
     {
 698  
         try
 699  
         {
 700  0
             Class[] clazz = new Class[] { Criteria.class };
 701  0
             Object[] params = new Object[] { criteria };
 702  
 
 703  0
             userPeerClass
 704  
                 .getMethod("doInsert", clazz)
 705  
                 .invoke(null, params);
 706  
         }
 707  0
         catch (Exception e)
 708  
         {
 709  0
             throw new TorqueException("doInsert failed", e);
 710  0
         }
 711  0
     }
 712  
 
 713  
     /**
 714  
      * Invokes doSelect(Criteria c) on the configured Peer Object
 715  
      *
 716  
      * @param criteria  A Criteria Object
 717  
      *
 718  
      * @return A List of User Objects selected by the Criteria
 719  
      *
 720  
      * @exception TorqueException A problem occured.
 721  
      */
 722  
     public static List doSelect(Criteria criteria)
 723  
         throws TorqueException
 724  
     {
 725  
         List list;
 726  
 
 727  
         try
 728  
         {
 729  0
             Class[] clazz =
 730  
                 new Class[] { Criteria.class };
 731  0
             Object[] params = new Object[] { criteria };
 732  
 
 733  0
             list = (List) userPeerClass
 734  
                 .getMethod("doSelect", clazz)
 735  
                 .invoke(null, params);
 736  
         }
 737  0
         catch (Exception e)
 738  
         {
 739  0
             throw new TorqueException("doSelect failed", e);
 740  0
         }
 741  0
         List newList = new ArrayList(list.size());
 742  
 
 743  
         //
 744  
         // Wrap the returned Objects into TorqueUsers.
 745  
         //
 746  0
         for (Iterator it = list.iterator(); it.hasNext(); )
 747  
         {
 748  0
             User u = getNewUser((Persistent) it.next());
 749  0
             newList.add(u);
 750  0
         }
 751  
 
 752  0
         return newList;
 753  
     }
 754  
 
 755  
     /**
 756  
      * Invokes doDelete(Criteria c) on the configured Peer Object
 757  
      *
 758  
      * @param criteria  A Criteria Object
 759  
      *
 760  
      * @exception TorqueException A problem occured.
 761  
      */
 762  
     public static void doDelete(Criteria criteria)
 763  
         throws TorqueException
 764  
     {
 765  
         try
 766  
         {
 767  0
             Class[] clazz = new Class[] { Criteria.class };
 768  0
             Object[] params = new Object[] { criteria };
 769  
 
 770  0
             userPeerClass
 771  
                 .getMethod("doDelete", clazz)
 772  
                 .invoke(null, params);
 773  
         }
 774  0
         catch (Exception e)
 775  
         {
 776  0
             throw new TorqueException("doDelete failed", e);
 777  0
         }
 778  0
     }
 779  
 
 780  
     /**
 781  
      * Invokes setName(String s) on the supplied base object
 782  
      *
 783  
      * @param obj The object to use for setting the name
 784  
      * @param name The Name to set
 785  
      */
 786  
     public static void setUserName(Persistent obj, String name)
 787  
     {
 788  0
         if (obj == null)
 789  
         {
 790  0
             return;
 791  
         }
 792  
 
 793  
         try
 794  
         {
 795  0
             Object[] params = new Object[] { name };
 796  0
             namePropDesc.getWriteMethod().invoke(obj, params);
 797  
         }
 798  0
         catch (ClassCastException cce)
 799  
         {
 800  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 801  0
             log.error(msg);
 802  0
             throw new RuntimeException(msg);
 803  
         }
 804  0
         catch (Exception e)
 805  
         {
 806  0
             log.error(e, e);
 807  0
         }
 808  0
     }
 809  
 
 810  
     /**
 811  
      * Invokes getName() on the supplied base object
 812  
      *
 813  
      * @param obj The object to use for getting the name
 814  
      *
 815  
      * @return A string containing the name
 816  
      *
 817  
      * @deprecated use getName(obj)
 818  
      */
 819  
     public static String getUserName(Persistent obj)
 820  
     {
 821  0
         return getName(obj);
 822  
     }
 823  
 
 824  
     /**
 825  
      * Invokes getName() on the supplied base object
 826  
      *
 827  
      * @param obj The object to use for getting the name
 828  
      *
 829  
      * @return A string containing the name
 830  
      */
 831  
     public static String getName(Persistent obj)
 832  
     {
 833  0
         String name = null;
 834  
 
 835  0
         if (obj == null)
 836  
         {
 837  0
             return null;
 838  
         }
 839  
 
 840  
         try
 841  
         {
 842  0
             name = (String) namePropDesc
 843  
                 .getReadMethod()
 844  
                 .invoke(obj, new Object[] {});
 845  
         }
 846  0
         catch (ClassCastException cce)
 847  
         {
 848  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 849  0
             log.error(msg);
 850  0
             throw new RuntimeException(msg);
 851  
         }
 852  0
         catch (Exception e)
 853  
         {
 854  0
             log.error(e, e);
 855  0
         }
 856  0
         return name;
 857  
     }
 858  
 
 859  
     /**
 860  
      * Invokes setPassword(String s) on the supplied base object
 861  
      *
 862  
      * @param obj The object to use for setting the password
 863  
      * @param password The Password to set
 864  
      */
 865  
     public static void setUserPassword(Persistent obj, String password)
 866  
     {
 867  0
         if (obj == null)
 868  
         {
 869  0
             return;
 870  
         }
 871  
 
 872  
         try
 873  
         {
 874  0
             Object[] params = new Object[] { password };
 875  0
             passwordPropDesc.getWriteMethod().invoke(obj, params);
 876  
         }
 877  0
         catch (ClassCastException cce)
 878  
         {
 879  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 880  0
             log.error(msg);
 881  0
             throw new RuntimeException(msg);
 882  
         }
 883  0
         catch (Exception e)
 884  
         {
 885  0
             log.error(e, e);
 886  0
         }
 887  0
     }
 888  
 
 889  
     /**
 890  
      * Invokes getPassword() on the supplied base object
 891  
      *
 892  
      * @param obj The object to use for getting the password
 893  
      *
 894  
      * @return A string containing the password
 895  
      */
 896  
     public static String getUserPassword(Persistent obj)
 897  
     {
 898  0
         String password = null;
 899  
 
 900  0
         if (obj == null)
 901  
         {
 902  0
             return null;
 903  
         }
 904  
 
 905  
         try
 906  
         {
 907  0
             password = (String) passwordPropDesc
 908  
                 .getReadMethod()
 909  
                 .invoke(obj, new Object[] {});
 910  
         }
 911  0
         catch (ClassCastException cce)
 912  
         {
 913  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 914  0
             log.error(msg);
 915  0
             throw new RuntimeException(msg);
 916  
         }
 917  0
         catch (Exception e)
 918  
         {
 919  0
             log.error(e, e);
 920  0
         }
 921  0
         return password;
 922  
     }
 923  
 
 924  
     /**
 925  
      * Invokes setFirstName(String s) on the supplied base object
 926  
      *
 927  
      * @param obj The object to use for setting the first name
 928  
      * @param firstName The first name to set
 929  
      */
 930  
     public static void setUserFirstName(Persistent obj, String firstName)
 931  
     {
 932  0
         if (obj == null)
 933  
         {
 934  0
             return;
 935  
         }
 936  
 
 937  
         try
 938  
         {
 939  0
             Object[] params = new Object[] { firstName };
 940  0
             firstNamePropDesc.getWriteMethod().invoke(obj, params);
 941  
         }
 942  0
         catch (ClassCastException cce)
 943  
         {
 944  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 945  0
             log.error(msg);
 946  0
             throw new RuntimeException(msg);
 947  
         }
 948  0
         catch (Exception e)
 949  
         {
 950  0
             log.error(e, e);
 951  0
         }
 952  0
     }
 953  
 
 954  
     /**
 955  
      * Invokes getFirstName() on the supplied base object
 956  
      *
 957  
      * @param obj The object to use for getting the first name
 958  
      *
 959  
      * @return A string containing the first name
 960  
      */
 961  
     public static String getUserFirstName(Persistent obj)
 962  
     {
 963  0
         String firstName = null;
 964  
 
 965  0
         if (obj == null)
 966  
         {
 967  0
             return null;
 968  
         }
 969  
 
 970  
         try
 971  
         {
 972  0
             firstName = (String) firstNamePropDesc
 973  
                 .getReadMethod()
 974  
                 .invoke(obj, new Object[] {});
 975  
         }
 976  0
         catch (ClassCastException cce)
 977  
         {
 978  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 979  0
             log.error(msg);
 980  0
             throw new RuntimeException(msg);
 981  
         }
 982  0
         catch (Exception e)
 983  
         {
 984  0
             log.error(e, e);
 985  0
         }
 986  0
         return firstName;
 987  
     }
 988  
 
 989  
     /**
 990  
      * Invokes setLastName(String s) on the supplied base object
 991  
      *
 992  
      * @param obj The object to use for setting the last name
 993  
      * @param lastName The Last Name to set
 994  
      */
 995  
     public static void setUserLastName(Persistent obj, String lastName)
 996  
     {
 997  0
         if (obj == null)
 998  
         {
 999  0
             return;
 1000  
         }
 1001  
 
 1002  
         try
 1003  
         {
 1004  0
             Object[] params = new Object[] { lastName };
 1005  0
             lastNamePropDesc.getWriteMethod().invoke(obj, params);
 1006  
         }
 1007  0
         catch (ClassCastException cce)
 1008  
         {
 1009  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1010  0
             log.error(msg);
 1011  0
             throw new RuntimeException(msg);
 1012  
         }
 1013  0
         catch (Exception e)
 1014  
         {
 1015  0
             log.error(e, e);
 1016  0
         }
 1017  0
     }
 1018  
 
 1019  
     /**
 1020  
      * Invokes getLastName() on the supplied base object
 1021  
      *
 1022  
      * @param obj The object to use for getting the last name
 1023  
      *
 1024  
      * @return A string containing the last name
 1025  
      */
 1026  
     public static String getUserLastName(Persistent obj)
 1027  
     {
 1028  0
         String lastName = null;
 1029  
 
 1030  0
         if (obj == null)
 1031  
         {
 1032  0
             return null;
 1033  
         }
 1034  
 
 1035  
         try
 1036  
         {
 1037  0
             lastName = (String) lastNamePropDesc
 1038  
                 .getReadMethod()
 1039  
                 .invoke(obj, new Object[] {});
 1040  
         }
 1041  0
         catch (ClassCastException cce)
 1042  
         {
 1043  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1044  0
             log.error(msg);
 1045  0
             throw new RuntimeException(msg);
 1046  
         }
 1047  0
         catch (Exception e)
 1048  
         {
 1049  0
             log.error(e, e);
 1050  0
         }
 1051  0
         return lastName;
 1052  
     }
 1053  
 
 1054  
     /**
 1055  
      * Invokes setEmail(String s) on the supplied base object
 1056  
      *
 1057  
      * @param obj The object to use for setting the email
 1058  
      * @param email The Email to set
 1059  
      */
 1060  
     public static void setUserEmail(Persistent obj, String email)
 1061  
     {
 1062  0
         if (obj == null)
 1063  
         {
 1064  0
             return;
 1065  
         }
 1066  
 
 1067  
         try
 1068  
         {
 1069  0
             Object[] params = new Object[] { email };
 1070  0
             emailPropDesc.getWriteMethod().invoke(obj, params);
 1071  
         }
 1072  0
         catch (ClassCastException cce)
 1073  
         {
 1074  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1075  0
             log.error(msg);
 1076  0
             throw new RuntimeException(msg);
 1077  
         }
 1078  0
         catch (Exception e)
 1079  
         {
 1080  0
             log.error(e, e);
 1081  0
         }
 1082  0
     }
 1083  
 
 1084  
     /**
 1085  
      * Invokes getEmail() on the supplied base object
 1086  
      *
 1087  
      * @param obj The object to use for getting the email
 1088  
      *
 1089  
      * @return A string containing the email
 1090  
      */
 1091  
     public static String getUserEmail(Persistent obj)
 1092  
     {
 1093  0
         String email = null;
 1094  
 
 1095  0
         if (obj == null)
 1096  
         {
 1097  0
             return null;
 1098  
         }
 1099  
 
 1100  
         try
 1101  
         {
 1102  0
             email = (String) emailPropDesc
 1103  
                 .getReadMethod()
 1104  
                 .invoke(obj, new Object[] {});
 1105  
         }
 1106  0
         catch (ClassCastException cce)
 1107  
         {
 1108  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1109  0
             log.error(msg);
 1110  0
             throw new RuntimeException(msg);
 1111  
         }
 1112  0
         catch (Exception e)
 1113  
         {
 1114  0
             log.error(e, e);
 1115  0
         }
 1116  0
         return email;
 1117  
     }
 1118  
 
 1119  
     /**
 1120  
      * Invokes setConfirmed(String s) on the supplied base object
 1121  
      *
 1122  
      * @param obj The object to use for setting the confirm value
 1123  
      * @param confirm The confirm value to set
 1124  
      */
 1125  
     public static void setUserConfirmed(Persistent obj, String confirm)
 1126  
     {
 1127  0
         if (obj == null)
 1128  
         {
 1129  0
             return;
 1130  
         }
 1131  
 
 1132  
         try
 1133  
         {
 1134  0
             Object[] params = new Object[] { confirm };
 1135  0
             confirmPropDesc.getWriteMethod().invoke(obj, params);
 1136  
         }
 1137  0
         catch (ClassCastException cce)
 1138  
         {
 1139  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1140  0
             log.error(msg);
 1141  0
             throw new RuntimeException(msg);
 1142  
         }
 1143  0
         catch (Exception e)
 1144  
         {
 1145  0
             log.error(e, e);
 1146  0
         }
 1147  0
     }
 1148  
 
 1149  
     /**
 1150  
      * Invokes getConfirmed() on the supplied base object
 1151  
      *
 1152  
      * @param obj The object to use for getting the confirm value
 1153  
      *
 1154  
      * @return A string containing the confirm value
 1155  
      */
 1156  
     public static String getUserConfirmed(Persistent obj)
 1157  
     {
 1158  0
         String confirm = null;
 1159  
 
 1160  0
         if (obj == null)
 1161  
         {
 1162  0
             return null;
 1163  
         }
 1164  
 
 1165  
         try
 1166  
         {
 1167  0
             confirm = (String) confirmPropDesc
 1168  
                 .getReadMethod()
 1169  
                 .invoke(obj, new Object[] {});
 1170  
         }
 1171  0
         catch (ClassCastException cce)
 1172  
         {
 1173  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1174  0
             log.error(msg);
 1175  0
             throw new RuntimeException(msg);
 1176  
         }
 1177  0
         catch (Exception e)
 1178  
         {
 1179  0
             log.error(e, e);
 1180  0
         }
 1181  0
         return confirm;
 1182  
     }
 1183  
 
 1184  
     /**
 1185  
      * Invokes setCreateDate(java.util.Date date) on the supplied base object
 1186  
      *
 1187  
      * @param obj The object to use for setting the create date
 1188  
      * @param createDate The create date to set
 1189  
      */
 1190  
     public static void setUserCreateDate(Persistent obj, java.util.Date createDate)
 1191  
     {
 1192  0
         if (obj == null)
 1193  
         {
 1194  0
             return;
 1195  
         }
 1196  
 
 1197  
         try
 1198  
         {
 1199  0
             Object[] params = new Object[] { createDate };
 1200  0
             createDatePropDesc.getWriteMethod().invoke(obj, params);
 1201  
         }
 1202  0
         catch (ClassCastException cce)
 1203  
         {
 1204  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1205  0
             log.error(msg);
 1206  0
             throw new RuntimeException(msg);
 1207  
         }
 1208  0
         catch (Exception e)
 1209  
         {
 1210  0
             log.error(e, e);
 1211  0
         }
 1212  0
     }
 1213  
 
 1214  
     /**
 1215  
      * Invokes getCreateDate() on the supplied base object
 1216  
      *
 1217  
      * @param obj The object to use for getting the create date
 1218  
      *
 1219  
      * @return A string containing the create date
 1220  
      */
 1221  
     public static java.util.Date getUserCreateDate(Persistent obj)
 1222  
     {
 1223  0
         java.util.Date createDate = null;
 1224  
 
 1225  0
         if (obj == null)
 1226  
         {
 1227  0
             return null;
 1228  
         }
 1229  
 
 1230  
         try
 1231  
         {
 1232  0
             createDate = (java.util.Date) createDatePropDesc
 1233  
                 .getReadMethod()
 1234  
                 .invoke(obj, new Object[] {});
 1235  
         }
 1236  0
         catch (ClassCastException cce)
 1237  
         {
 1238  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1239  0
             log.error(msg);
 1240  0
             throw new RuntimeException(msg);
 1241  
         }
 1242  0
         catch (Exception e)
 1243  
         {
 1244  0
             log.error(e, e);
 1245  0
         }
 1246  0
         return createDate;
 1247  
     }
 1248  
 
 1249  
     /**
 1250  
      * Invokes setLastLogin(java.util.Date date) on the supplied base object
 1251  
      *
 1252  
      * @param obj The object to use for setting the last login daet
 1253  
      * @param lastLogin The last login date to set
 1254  
      */
 1255  
     public static void setUserLastLogin(Persistent obj, java.util.Date lastLogin)
 1256  
     {
 1257  0
         if (obj == null)
 1258  
         {
 1259  0
             return;
 1260  
         }
 1261  
 
 1262  
         try
 1263  
         {
 1264  0
             Object[] params = new Object[] { lastLogin };
 1265  0
             lastLoginPropDesc.getWriteMethod().invoke(obj, params);
 1266  
         }
 1267  0
         catch (ClassCastException cce)
 1268  
         {
 1269  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1270  0
             log.error(msg);
 1271  0
             throw new RuntimeException(msg);
 1272  
         }
 1273  0
         catch (Exception e)
 1274  
         {
 1275  0
             log.error(e, e);
 1276  0
         }
 1277  0
     }
 1278  
 
 1279  
     /**
 1280  
      * Invokes getLastLogin() on the supplied base object
 1281  
      *
 1282  
      * @param obj The object to use for getting the last login date
 1283  
      *
 1284  
      * @return A string containing the last login date
 1285  
      */
 1286  
     public static java.util.Date getUserLastLogin(Persistent obj)
 1287  
     {
 1288  0
         java.util.Date lastLogin = null;
 1289  
 
 1290  0
         if (obj == null)
 1291  
         {
 1292  0
             return null;
 1293  
         }
 1294  
 
 1295  
         try
 1296  
         {
 1297  0
             lastLogin = (java.util.Date) lastLoginPropDesc
 1298  
                 .getReadMethod()
 1299  
                 .invoke(obj, new Object[] {});
 1300  
         }
 1301  0
         catch (ClassCastException cce)
 1302  
         {
 1303  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1304  0
             log.error(msg);
 1305  0
             throw new RuntimeException(msg);
 1306  
         }
 1307  0
         catch (Exception e)
 1308  
         {
 1309  0
             log.error(e, e);
 1310  0
         }
 1311  0
         return lastLogin;
 1312  
     }
 1313  
 
 1314  
     /**
 1315  
      * Invokes setObjectdata(byte [] date) on the supplied base object
 1316  
      *
 1317  
      * @param obj The object to use for setting the last login daet
 1318  
      * @param objectdata The objectdata to use
 1319  
      */
 1320  
     public static void setUserObjectdata(Persistent obj, byte [] objectdata)
 1321  
     {
 1322  0
         if (obj == null)
 1323  
         {
 1324  0
             return;
 1325  
         }
 1326  
 
 1327  
         try
 1328  
         {
 1329  0
             Object[] params = new Object[] { objectdata };
 1330  0
             objectdataPropDesc.getWriteMethod().invoke(obj, params);
 1331  
         }
 1332  0
         catch (ClassCastException cce)
 1333  
         {
 1334  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1335  0
             log.error(msg);
 1336  0
             throw new RuntimeException(msg);
 1337  
         }
 1338  0
         catch (Exception e)
 1339  
         {
 1340  0
             log.error(e, e);
 1341  0
         }
 1342  0
     }
 1343  
 
 1344  
     /**
 1345  
      * Invokes getObjectdata() on the supplied base object
 1346  
      *
 1347  
      * @param obj The object to use for getting the last login date
 1348  
      *
 1349  
      * @return A string containing the last login date
 1350  
      */
 1351  
     public static byte [] getUserObjectdata(Persistent obj)
 1352  
     {
 1353  0
         byte [] objectdata = null;
 1354  
 
 1355  0
         if (obj == null)
 1356  
         {
 1357  0
             return null;
 1358  
         }
 1359  
 
 1360  
         try
 1361  
         {
 1362  0
             objectdata = (byte []) objectdataPropDesc
 1363  
                 .getReadMethod()
 1364  
                 .invoke(obj, new Object[] {});
 1365  
         }
 1366  0
         catch (ClassCastException cce)
 1367  
         {
 1368  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1369  0
             log.error(msg);
 1370  0
             throw new RuntimeException(msg);
 1371  
         }
 1372  0
         catch (Exception e)
 1373  
         {
 1374  0
             log.error(e, e);
 1375  0
         }
 1376  0
         return objectdata;
 1377  
     }
 1378  
 
 1379  
     /**
 1380  
      * Invokes setId(int n) on the supplied base object
 1381  
      *
 1382  
      * @param obj The object to use for setting the name
 1383  
      * @param id The new Id
 1384  
      */
 1385  
     public static void setId(Persistent obj, int id)
 1386  
     {
 1387  0
         if (obj == null)
 1388  
         {
 1389  0
             return;
 1390  
         }
 1391  
 
 1392  
         try
 1393  
         {
 1394  0
             Object[] params = new Object[] { Integer.TYPE };
 1395  0
             idPropDesc.getWriteMethod().invoke(obj, params);
 1396  
         }
 1397  0
         catch (ClassCastException cce)
 1398  
         {
 1399  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1400  0
             log.error(msg);
 1401  0
             throw new RuntimeException(msg);
 1402  
         }
 1403  0
         catch (Exception e)
 1404  
         {
 1405  0
             log.error(e, e);
 1406  0
         }
 1407  0
     }
 1408  
 
 1409  
     /**
 1410  
      * Invokes getId() on the supplied base object
 1411  
      *
 1412  
      * @param obj The object to use for getting the id
 1413  
      *
 1414  
      * @return The Id of this object
 1415  
      */
 1416  
     public static Integer getIdAsObj(Persistent obj)
 1417  
     {
 1418  0
         Integer id = null;
 1419  
 
 1420  0
         if (obj == null)
 1421  
         {
 1422  0
             return new Integer(0);
 1423  
         }
 1424  
 
 1425  
         try
 1426  
         {
 1427  0
             id = (Integer) idPropDesc
 1428  
                 .getReadMethod()
 1429  
                 .invoke(obj, new Object[] {});
 1430  
         }
 1431  0
         catch (ClassCastException cce)
 1432  
         {
 1433  0
             String msg = obj.getClass().getName() + " does not seem to be an User Object!";
 1434  0
             log.error(msg);
 1435  0
             throw new RuntimeException(msg);
 1436  
         }
 1437  0
         catch (Exception e)
 1438  
         {
 1439  0
             log.error(e, e);
 1440  0
         }
 1441  0
         return id;
 1442  
     }
 1443  
 
 1444  
     /**
 1445  
      * Returns the Class of the configured Object class
 1446  
      * from the peer
 1447  
      *
 1448  
      * @return The class of the objects returned by the configured peer
 1449  
      *
 1450  
      */
 1451  
 
 1452  
     private static Class getPersistenceClass()
 1453  
     {
 1454  0
         Class persistenceClass = null;
 1455  
 
 1456  
         try
 1457  
         {
 1458  0
             Object[] params = new Object[0];
 1459  
 
 1460  0
             persistenceClass =  (Class) userPeerClass
 1461  
                 .getMethod("getOMClass", (Class[])null)
 1462  
                 .invoke(null, params);
 1463  
         }
 1464  0
         catch (Exception e)
 1465  
         {
 1466  0
             persistenceClass = null;
 1467  0
         }
 1468  
 
 1469  0
         return persistenceClass;
 1470  
     }
 1471  
 
 1472  
     /**
 1473  
      * Returns a new, configured User Object with
 1474  
      * a supplied Persistent object at its core
 1475  
      *
 1476  
      * @param p The persistent object
 1477  
      *
 1478  
      * @return a new, configured User Object
 1479  
      *
 1480  
      * @exception Exception Could not create a new Object
 1481  
      *
 1482  
      */
 1483  
 
 1484  
     public static User getNewUser(Persistent p)
 1485  
     {
 1486  0
         User u = null;
 1487  
         try
 1488  
         {
 1489  0
             Class userWrapperClass = TurbineSecurity.getUserClass();
 1490  
 
 1491  0
             Class [] clazz = new Class [] { Persistent.class };
 1492  0
             Object [] params = new Object [] { p };
 1493  
 
 1494  0
             u = (User) userWrapperClass
 1495  
                 .getConstructor(clazz)
 1496  
                 .newInstance(params);
 1497  
         }
 1498  0
         catch (Exception e)
 1499  
         {
 1500  0
             log.error("Could not instantiate a new user from supplied persistent: ", e);
 1501  0
         }
 1502  
 
 1503  0
         return u;
 1504  
     }
 1505  
 }
 1506  
 
 1507