View Javadoc

1   /* $Id: Book.java 1102402 2011-05-12 18:03:26Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.digester3.annotations.catalog;
19  
20  import org.apache.commons.digester3.annotations.rules.BeanPropertySetter;
21  import org.apache.commons.digester3.annotations.rules.FactoryCreate;
22  
23  /**
24   * @since 2.1
25   */
26  @FactoryCreate( pattern = "catalog/book", factoryClass = BookFactory.class )
27  public final class Book
28      implements Item
29  {
30  
31      private final String isbn;
32  
33      @BeanPropertySetter( pattern = "catalog/book/title" )
34      private String title;
35  
36      @BeanPropertySetter( pattern = "catalog/book/author" )
37      private String author;
38  
39      @BeanPropertySetter( pattern = "catalog/book/desc" )
40      private String desc;
41  
42      public Book( String isbn )
43      {
44          this.isbn = isbn;
45      }
46  
47      public String getTitle()
48      {
49          return this.title;
50      }
51  
52      public void setTitle( String title )
53      {
54          this.title = title;
55      }
56  
57      public String getAuthor()
58      {
59          return this.author;
60      }
61  
62      public void setAuthor( String author )
63      {
64          this.author = author;
65      }
66  
67      public String getDesc()
68      {
69          return this.desc;
70      }
71  
72      public void setDesc( String desc )
73      {
74          this.desc = desc;
75      }
76  
77      public String getIsbn()
78      {
79          return this.isbn;
80      }
81  
82      @Override
83      public boolean equals( Object obj )
84      {
85          if ( this == obj )
86              return true;
87          if ( obj == null )
88              return false;
89          if ( getClass() != obj.getClass() )
90              return false;
91          Book other = (Book) obj;
92          if ( this.author == null )
93          {
94              if ( other.getAuthor() != null )
95                  return false;
96          }
97          else if ( !this.author.equals( other.getAuthor() ) )
98              return false;
99          if ( this.desc == null )
100         {
101             if ( other.getDesc() != null )
102                 return false;
103         }
104         else if ( !this.desc.equals( other.getDesc() ) )
105             return false;
106         if ( this.isbn == null )
107         {
108             if ( other.getIsbn() != null )
109                 return false;
110         }
111         else if ( !this.isbn.equals( other.getIsbn() ) )
112             return false;
113         if ( this.title == null )
114         {
115             if ( other.getTitle() != null )
116                 return false;
117         }
118         else if ( !this.title.equals( other.getTitle() ) )
119             return false;
120         return true;
121     }
122 
123     @Override
124     public String toString()
125     {
126         return "Book [author=" + author + ", desc=" + desc + ", isbn=" + isbn + ", title=" + title + "]";
127     }
128 
129     public void print()
130     {
131         System.out.println( this.toString() );
132     }
133 
134 }