KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > impl > hibernate > Category


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: Category.java,v 1.5 2003/09/28 21:41:57 niko_schmuck Exp $
28

29 package de.nava.informa.impl.hibernate;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33
34 import de.nava.informa.core.CategoryIF;
35
36 /**
37  * Hibernate implementation of the CategoryIF interface.
38  *
39  * @author Niko Schmuck (niko@nava.de)
40  *
41  * @hibernate.class
42  * table="CATEGORIES"
43  */

44 public class Category implements CategoryIF, java.io.Serializable JavaDoc {
45
46   private int id;
47   private String JavaDoc title;
48   private CategoryIF parent;
49   private Collection JavaDoc children;
50
51   public Category() {
52     this("Unnamed category");
53   }
54
55   public Category(String JavaDoc title) {
56     setTitle(title);
57     this.children = new ArrayList JavaDoc();
58   }
59   
60   // --------------------------------------------------------------
61
// implementation of CategoryIF interface
62
// --------------------------------------------------------------
63

64   /**
65    * @hibernate.id
66    * generator-class="native"
67    * column="CATEGORY_ID"
68    * type="integer"
69    */

70   public int getIntId() {
71     return id;
72   }
73
74   public void setIntId(int id) {
75     this.id = id;
76   }
77
78   public long getId() {
79     return id;
80   }
81
82   public void setId(long longid) {
83     this.id = (int) longid;
84   }
85
86   /**
87    * @hibernate.property
88    * column="TITLE"
89    * not-null="true"
90    */

91   public String JavaDoc getTitle() {
92     return title;
93   }
94
95   public void setTitle(String JavaDoc title) {
96     this.title = title;
97   }
98
99   /**
100    * @hibernate.many-to-one
101    * class="de.nava.informa.impl.hibernate.Category"
102    * column="PARENT_ID"
103    */

104   public CategoryIF getParent() {
105     return parent;
106   }
107
108   public void setParent(CategoryIF parent) {
109     this.parent = parent;
110   }
111
112   /**
113    * @hibernate.bag
114    * lazy="true"
115    * order-by="CATEGORY_ID"
116    * @hibernate.collection-key
117    * column="PARENT_ID"
118    * @hibernate.collection-one-to-many
119    * class="de.nava.informa.impl.hibernate.Category"
120    */

121   public Collection JavaDoc getChildren() {
122     return children;
123   }
124   
125   public void setChildren(Collection JavaDoc children) {
126     this.children = children;
127   }
128   
129   public void addChild(CategoryIF child) {
130     children.add(child);
131     child.setParent(this);
132   }
133   
134   public void removeChild(CategoryIF child) {
135     children.remove(child);
136   }
137   
138   // --------------------------------------------------------------
139
// overwrite default method implementation from Object
140
// --------------------------------------------------------------
141

142   public String JavaDoc toString() {
143     return "[Category (" + id + "): " + title + "]";
144   }
145   
146 }
147
Popular Tags