KickJava   Java API By Example, From Geeks To Geeks.

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


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 examples.invoice.persistclass.AddressAccessor;
27 import org.objectweb.jorm.api.PAccessor;
28 import org.objectweb.jorm.api.PBinding;
29 import org.objectweb.jorm.api.PException;
30
31 /**
32  * @author P. Dechamboux
33  */

34 public class Address implements PAccessor, AddressAccessor, AddressIdPNG {
35     private String JavaDoc name;
36     private String JavaDoc street;
37     private String JavaDoc zip;
38     private String JavaDoc town;
39     private String JavaDoc country;
40     private PBinding pBinding;
41
42     public String JavaDoc pnGetAdrname(Object JavaDoc ctx) throws PException {
43         return name;
44     }
45
46     public String JavaDoc pnGetAdrtown(Object JavaDoc ctx) throws PException {
47         return town;
48     }
49
50     public String JavaDoc pnGetAdrstreet(Object JavaDoc ctx) throws PException {
51         return street;
52     }
53
54     public PBinding getPBinding() {
55         return pBinding;
56     }
57
58     /**
59      * Creates a new Address.
60      */

61     public Address(Object JavaDoc conn, PBinding pb, String JavaDoc n, String JavaDoc s, String JavaDoc z, String JavaDoc t, String JavaDoc c) throws PException {
62         pBinding = pb;
63         name = n;
64         street = s;
65         zip = (z == null) ? "38000" : z;
66         town = (t == null) ? "Grenoble" : t;
67         country = (c == null) ? "France" : c;
68         pBinding.export(conn, this);
69         pBinding.write(conn, this);
70     }
71
72     /**
73      * Creates an Address that is already persistent.
74      */

75     public Address(Object JavaDoc conn, PBinding pb) throws PException {
76         pBinding = pb;
77         pb.read(conn, this);
78     }
79
80     /**
81      * Turns this persistent object into a non-persistent one.
82      */

83     public void delete(Object JavaDoc conn) throws PException {
84         pBinding.unexport(conn);
85         pBinding.write(conn, this);
86         pBinding = null;
87     }
88
89     /**
90      * Yields a printable version a the full Address.
91      */

92     public String JavaDoc toPrintable() throws PException {
93         return "ID: [" + pBinding.getPName().encodeString() + "] - VALUE: [name: " + name + ", street: " + street + ", zip: " + zip + ", town: " + town + ", country: " + country + "]";
94     }
95
96     // IMPLEMENTATION OF PAccessor INTERFACE
97

98     public Object JavaDoc getMemoryInstance() {
99         return this;
100     }
101
102     // IMPLEMENTATION OF AddressAccessor INTERFACE (generated by JORM)
103

104     // Accessors to the name field
105
public void paSetName(String JavaDoc val) throws PException {
106         name = val;
107     }
108
109     public String JavaDoc paGetName() throws PException {
110         return name;
111     }
112
113     // Accessors to the zip field
114
public void paSetZip(String JavaDoc val) throws PException {
115         zip = val;
116     }
117
118     public String JavaDoc paGetZip() throws PException {
119         return zip;
120     }
121
122     // Accessors to the town field
123
public void paSetTown(String JavaDoc val) throws PException {
124         town = val;
125     }
126
127     public String JavaDoc paGetTown() throws PException {
128         return town;
129     }
130
131     // Accessors to the country field
132
public void paSetCountry(String JavaDoc val) throws PException {
133         country = val;
134     }
135
136     public String JavaDoc paGetCountry() throws PException {
137         return country;
138     }
139
140     // Accessors to the street field
141
public void paSetStreet(String JavaDoc val) throws PException {
142         street = val;
143     }
144
145     public String JavaDoc paGetStreet() throws PException {
146         return street;
147     }
148 }
149
Popular Tags