View Javadoc

1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.domain.impl;
17  
18  import org.acegisecurity.domain.util.ReflectionToStringBuilder;
19  
20  import org.apache.commons.beanutils.BeanUtils;
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  import java.io.Serializable;
25  
26  
27  /***
28   * A business domain object.
29   * 
30   * <p>
31   * Only minimal convenience methods are provided by
32   * <code>BusinessObject</code>. Whilst many other methods could easily be
33   * offered (and overridden on an as-required basis) it is felt the default
34   * behaviour of {@link java.lang.Object} is widely understood and an
35   * appropriate default.
36   * </p>
37   *
38   * @author Carlos Sanchez
39   * @author Ben Alex
40   * @author Matthew Porter
41   * @version $Id: BusinessObject.java,v 1.4 2005/11/17 00:55:49 benalex Exp $
42   */
43  public abstract class BusinessObject implements Serializable, Cloneable {
44      //~ Instance fields ========================================================
45  
46      protected final transient Log logger = LogFactory.getLog(getClass());
47  
48      //~ Methods ================================================================
49  
50      /***
51       * Swallow cloning.
52       * 
53       * <p>
54       * This method delegates to BeanUtils.cloneBean().
55       * </p>
56       *
57       * @return a clone of the current instance
58       *
59       * @throws IllegalStateException if there are any problems with swallow
60       *         cloning
61       *
62       * @see java.lang.Object#clone()
63       * @see BeanUtils#cloneBean(Object)
64       */
65      public Object clone() throws CloneNotSupportedException {
66          try {
67              return BeanUtils.cloneBean(this);
68          } catch (Exception e) {
69              logger.error(e);
70              throw new CloneNotSupportedException(e.getMessage());
71          }
72      }
73  
74      /***
75       * Delegates to {@link CollectionIgnoringReflectionToStringBuilder}.
76       *
77       * @see java.lang.Object#toString()
78       */
79      public String toString() {
80          return new ReflectionToStringBuilder(this).toString();
81      }
82  }