1 /*
2 * Copyright (c) 2005 Regents of the University of California (Regents). Created
3 * by TELS, Graduate School of Education, University of California at Berkeley.
4 *
5 * This software is distributed under the GNU Lesser General Public License, v2.
6 *
7 * Permission is hereby granted, without written agreement and without license
8 * or royalty fees, to use, copy, modify, and distribute this software and its
9 * documentation for any purpose, provided that the above copyright notice and
10 * the following two paragraphs appear in all copies of this software.
11 *
12 * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14 * PURPOSE. THE SOFTWAREAND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
15 * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
16 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 *
18 * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
19 * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
20 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
21 * REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23 package net.sf.sail.core.entity;
24
25 import java.beans.beancontext.BeanContext;
26 import java.beans.beancontext.BeanContextChildSupport;
27
28 import net.sf.sail.core.beans.Pod;
29 import net.sf.sail.core.uuid.PodUuid;
30
31 import org.doomdark.uuid.UUID;
32
33 /**
34 * Identifies the shape and context of the data to be written by the <b>IAgent</b>
35 * into the ISock.
36 *
37 * @author turadg
38 */
39 public class Rim<T> extends BeanContextChildSupport {
40
41 /**
42 *
43 */
44 private static final long serialVersionUID = 4637021392257551556L;
45
46 transient static int rimCount = 0;
47
48 transient int rimSerial = ++rimCount;
49
50 String name = "undefined" + rimSerial;
51
52 // XMLEncoder only marshals Class properties if their value
53 // is null in an uninitialized object.
54 Class<T> shape = null;
55
56 /**
57 * Construct new Rim with a default shape and name. The default shape is
58 * Object.class. The default name is a serialial counter appended to
59 * "undefined", e.g. "undefined0".
60 */
61 public Rim() {
62 // default constructor
63 }
64
65 public Class<T> getShape() {
66 return shape;
67 }
68
69 public void setShape(Class<T> shape) {
70 if (shape == null)
71 throw new IllegalArgumentException("null shape set on rim");
72 this.shape = shape;
73 }
74
75 public String getName() {
76 return name;
77 }
78
79 public void setName(String name) {
80 if (name == null)
81 throw new IllegalArgumentException("null name set on rim");
82 this.name = name;
83 }
84
85 public UUID getContainerId() {
86 BeanContext bc = getBeanContext();
87 if (bc == null)
88 throw new NullPointerException("Rim without a BeanContext");
89 if (!(bc instanceof Pod))
90 throw new RuntimeException("Rim's BeanContext not a Pod");
91 Pod pod = (Pod) bc;
92 PodUuid podId = pod.getPodId();
93 if (podId == null)
94 throw new NullPointerException("pod has no id: " + pod);
95 return podId;
96 }
97
98 @Override
99 public String toString() {
100 return "Rim@" + rimSerial + "[" + name + ":" + shape + "]";
101 }
102 }