KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > invoice > persistclass > Product


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package examples.invoice.persistclass;
25
26 import org.objectweb.jorm.api.PAccessor;
27 import org.objectweb.jorm.api.PBinding;
28 import org.objectweb.jorm.api.PException;
29
30 import java.io.Serializable JavaDoc;
31
32 /**
33  * @author P. Dechamboux
34  */

35 public class Product implements PAccessor, ProductAccessor {
36     private String JavaDoc name;
37     private char size;
38     private String JavaDoc color;
39     private float weight;
40     private float price;
41     private String JavaDoc picture; // stored as a serialized object
42
private PBinding pBinding;
43
44     public PBinding getPBinding() {
45         return pBinding;
46     }
47
48     /**
49      * Creates a new Address.
50      */

51     public Product(Object JavaDoc conn, PBinding pb, String JavaDoc n, char s, String JavaDoc c, float w, float p) throws PException {
52         pBinding = pb;
53         name = n;
54         size = s;
55         color = (c == null) ? "black" : c;
56         weight = w;
57         price = p;
58         picture = "My Picture";
59         pBinding.export(conn);
60         pBinding.write(conn, this);
61     }
62
63     /**
64      * Creates a Product that is already persistent.
65      */

66     public Product(Object JavaDoc conn, PBinding pb) throws PException {
67         pBinding = pb;
68         pb.read(conn, this);
69     }
70
71     /**
72      * Turns this persistent object into a non-persistent one.
73      */

74     public void delete(Object JavaDoc conn) throws PException {
75         pBinding.unexport(conn);
76         pBinding.write(conn, this);
77         pBinding = null;
78     }
79
80     /**
81      * Yields a printable version a the full Address.
82      */

83     public String JavaDoc toPrintable() throws PException {
84         return "ID: [" + pBinding.getPName().encodeString() + "] - VALUE: [name: " + name + ", size: " + size + ", color: " + color + ", weight: " + weight + "kg, price: " + price + "euros, picture: (" + picture + ")]";
85     }
86
87     // IMPLEMENTATION OF PAccessor INTERFACE
88

89     public Object JavaDoc getMemoryInstance() {
90         return this;
91     }
92
93     // IMPLEMENTATION OF AddressAccessor INTERFACE (generated by JORM)
94

95     // Accessors to the name field
96
public void paSetName(String JavaDoc val) throws PException {
97         name = val;
98     }
99
100     public String JavaDoc paGetName() throws PException {
101         return name;
102     }
103
104     // Accessors to the size field
105
public void paSetSize(char val) throws PException {
106         size = val;
107     }
108
109     public char paGetSize() throws PException {
110         return size;
111     }
112
113     // Accessors to the color field
114
public void paSetColor(String JavaDoc val) throws PException {
115         color = val;
116     }
117
118     public String JavaDoc paGetColor() throws PException {
119         return color;
120     }
121
122     // Accessors to the weight field
123
public void paSetWeight(float val) throws PException {
124         weight = val;
125     }
126
127     public float paGetWeight() throws PException {
128         return weight;
129     }
130
131     // Accessors to the price field
132
public void paSetPrice(float val) throws PException {
133         price = val;
134     }
135
136     public float paGetPrice() throws PException {
137         return price;
138     }
139     // Accessors to the picture field
140
public void paSetPicture(Serializable JavaDoc val) throws PException {
141         picture = (String JavaDoc) val;
142     }
143
144     public Serializable JavaDoc paGetPicture() throws PException {
145         return picture;
146     }
147 }
148
Popular Tags