1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package com.unitesk.atp.dynattrs;
33
34 import java.util.Set;
35
36 /***
37 * The implementation of {@link Attributed} interface that accesses attributes
38 * through <I>getter</I> and <I>setter</I> methods according to JavaBeans
39 * naming conventions.
40 *
41 * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
42 * @version $Id: BeanWrapper.java,v 1.1 2004/10/09 06:19:04 all-x Exp $
43 */
44 public class BeanWrapper extends IndexedAttributedImpl
45 {
46 /***
47 * Constructs wrapper of specified object.
48 * @param obj Object to wrap.
49 * @throws NullPointerException
50 * If <code>obj</code> is <code>null</code>.
51 */
52 public BeanWrapper( Object obj )
53 {
54 if( obj == null )
55 {
56 throw new NullPointerException();
57 }
58
59 this.obj = obj;
60 }
61
62 /***
63 * {@inheritDoc}
64 */
65 public boolean hasAttribute( String name )
66 {
67 return Accessor.hasBeanProperty( obj, name );
68 }
69
70 /***
71 * Bean wrapper doesn't allow creation of attributes.
72 */
73 public boolean isAttrCreatable()
74 {
75 return false;
76 }
77
78 /***
79 * Bean wrapper doesn't allow removal of attributes.
80 */
81 public boolean isRemovable( String name )
82 {
83 if( !hasAttribute( name ) )
84 {
85 throw new AttributeException( this, name );
86 }
87 return false;
88 }
89
90 /***
91 * {@inheritDoc}
92 */
93 public boolean isWritable( String name )
94 {
95 if( !hasAttribute( name ) )
96 {
97 throw new AttributeException( this, name );
98 }
99 return Accessor.isBeanPropertyWritable( obj, name );
100 }
101
102
103
104 /***
105 * Unsupported operation.
106 */
107 public void addAttribute( String name, Object value )
108 {
109 throw new UnsupportedOperationException();
110 }
111
112 /***
113 * Unsupported operation.
114 */
115 public void removeAttribute( String name )
116 {
117 throw new UnsupportedOperationException();
118 }
119
120
121
122 /***
123 * {@inheritDoc}
124 */
125 public Object getAttribute( String name )
126 {
127 return Accessor.getBeanProperty( obj, name );
128 }
129
130 /***
131 * {@inheritDoc}
132 */
133 public void setAttribute( String name, Object value )
134 {
135 Accessor.setBeanProperty( obj, name, value );
136 }
137
138
139
140 /***
141 * {@inheritDoc}
142 */
143 public Set
144 {
145 return Accessor.getBeanPropertyNames( obj );
146 }
147
148
149
150
151 private Object obj;
152 }