KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tutorial1 > Product


1 package org.apache.ojb.tutorial1;
2
3 /* Copyright 2002-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /**
19  * Represents product objects in the tutorial system
20  *
21  * @ojb.class
22  */

23 public class Product implements java.io.Serializable JavaDoc
24 {
25     /**
26      * Artificial primary key atribute
27      *
28      * @ojb.field primarykey="true"
29      * autoincrement="ojb"
30      */

31     private Integer JavaDoc id;
32
33     /**
34      * Product name
35      *
36      * @ojb.field length="100"
37      */

38     protected String JavaDoc name;
39
40     /**
41      * Price per item
42      *
43      * @ojb.field
44      */

45     protected double price;
46
47     /**
48      * Stock of currently available items
49      *
50      * @ojb.field
51      */

52     protected int stock;
53
54     /**
55      * Returns the id
56      *
57      * @return The id
58      */

59     public int getId()
60     {
61         return id.intValue();
62     }
63
64     /**
65      * Returns the name of the product.
66      *
67      * @return The name
68      */

69     public String JavaDoc getName()
70     {
71         return name;
72     }
73
74     /**
75      * Returns the price of the product.
76      *
77      * @return The price
78      */

79     public double getPrice()
80     {
81         return price;
82     }
83
84     /**
85      * Returns the number of available items of this product.
86      *
87      * @return The number of items in stock
88      */

89     public int getStock()
90     {
91         return stock;
92     }
93
94     /**
95      * Sets the id of the product.
96      *
97      * @param newId The new id
98      */

99     public void setId(int newId)
100     {
101         id = new Integer JavaDoc(newId);
102     }
103
104     /**
105      * Sets the name of the product.
106      *
107      * @param newName The new name
108      */

109     public void setName(String JavaDoc newName)
110     {
111         name = newName;
112     }
113
114     /**
115      * Sets the price of the product
116      *
117      * @param newPrice The new price
118      */

119     public void setPrice(double newPrice)
120     {
121         price = newPrice;
122     }
123
124     /**
125      * Sets the number of available items of this product.
126      *
127      * @param newStock The number of available items
128      */

129     public void setStock(int newStock)
130     {
131         stock = newStock;
132     }
133
134     /**
135      * Returns a string representation of the product.
136      *
137      * @return The string representation
138      */

139     public String JavaDoc toString()
140     {
141         return "[" + id + "] " + name + "\t\t\t price: " + price + "\t\t stock: " + stock;
142     }
143 }
144
Popular Tags