View Javadoc

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  
32  /***
33   * Identifies the shape and context of the data to be written by the <b>IAgent</b>
34   * into the ISock.
35   * 
36   * @author turadg
37   */
38  public class Rim extends BeanContextChildSupport {
39  
40  	/***
41  	 * 
42  	 */
43  	private static final long serialVersionUID = 4637021392257551556L;
44  
45  	transient static int rimCount = 0;
46  
47  	transient int rimSerial = ++rimCount;
48  
49  	String name = "undefined" + rimSerial;
50  
51  	Class shape = Object.class;
52  
53  	/***
54  	 * Construct new Rim with a default shape and name. The default shape is
55  	 * Object.class. The default name is a serialial counter appended to
56  	 * "undefined", e.g. "undefined0".
57  	 */
58  	public Rim() {
59  		// default constructor
60  	}
61  
62  	public Class getShape() {
63  		return shape;
64  	}
65  
66  	public void setShape(Class shape) {
67  		if (shape == null)
68  			throw new IllegalArgumentException("null shape set on rim");
69  		this.shape = shape;
70  	}
71  
72  	public String getName() {
73  		return name;
74  	}
75  
76  	public void setName(String name) {
77  		if (name == null)
78  			throw new IllegalArgumentException("null name set on rim");
79  		this.name = name;
80  	}
81  
82  	public PodUuid getContainingPodId() {
83  		BeanContext bc = getBeanContext();
84  		if (bc == null) throw new NullPointerException("Rim without a BeanContext");
85  		if (!(bc instanceof Pod))
86  			throw new RuntimeException("Rim's BeanContext not a Pod");
87  		Pod pod = (Pod) bc;
88  		PodUuid podId = pod.getPodId();
89  		if (podId == null) throw new NullPointerException("pod has no id: "+pod);
90  		return podId;
91  	}
92  
93  	@Override
94  	public String toString() {
95  		return "Rim@" + rimSerial + "[" + name + ":" + shape + "]";
96  	}
97  }