View Javadoc
1   package org.apache.commons.beanutils2;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static java.lang.String.format;
23  
24  import java.beans.IntrospectionException;
25  import java.util.Map;
26  
27  final class NullBeanAccessor<B>
28      implements BeanAccessor<B>
29  {
30  
31      private final String errorMessage;
32  
33      public NullBeanAccessor( String beanTypeName, String methodName )
34      {
35          errorMessage = format( "%s.%s returned null!", beanTypeName, methodName );
36      }
37  
38      /**
39       * {@inheritDoc}
40       */
41      public BeanAccessor<?> get( String propertyName )
42      {
43          throw new NullPointerException( errorMessage );
44      }
45  
46      /**
47       * {@inheritDoc}
48       */
49      public IndexedPropertyGetterAccessor<?> getIndexed( String propertyName )
50      {
51          throw new NullPointerException( errorMessage );
52      }
53  
54      /**
55       * {@inheritDoc}
56       */
57      public MappedPropertyGetterAccessor getMapped( String propertyName )
58      {
59          throw new NullPointerException( errorMessage );
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      public B get()
66      {
67          return null;
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      public <V> V cast()
74      {
75          return null;
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      public BeanPropertySetter<B> set( String propertyName )
82      {
83          throw new NullPointerException( errorMessage );
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      public IndexedPropertySetterAccessor<B> setIndexed( String propertyName )
90      {
91          throw new NullPointerException( errorMessage );
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      public MappedPropertySetterAccessor<B> setMapped( String propertyName )
98      {
99          throw new NullPointerException( errorMessage );
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     public boolean isReadable( String propertyName )
106         throws IntrospectionException
107     {
108         throw new NullPointerException( errorMessage );
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     public boolean isWritable( String propertyName )
115         throws IntrospectionException
116     {
117         throw new NullPointerException( errorMessage );
118     }
119 
120     /**
121      * {@inheritDoc}
122      */
123     public B cloneBean()
124     {
125         return null;
126     }
127 
128     /**
129      * {@inheritDoc}
130      */
131     public <T extends B> void copyPropertiesTo( T target )
132     {
133         throw new NullPointerException( errorMessage );
134     }
135 
136     /**
137      * {@inheritDoc}
138      */
139     public Map<String, Object> describe()
140     {
141         throw new NullPointerException( errorMessage );
142     }
143 
144     /**
145      * {@inheritDoc}
146      */
147     public void populate( Map<String, Object> properties )
148     {
149         throw new NullPointerException( errorMessage );
150     }
151 
152     /**
153      * {@inheritDoc}
154      */
155     public ArgumentsAccessor invoke( String methodName )
156     {
157         throw new NullPointerException( errorMessage );
158     }
159 
160     /**
161      * {@inheritDoc}
162      */
163     public ArgumentsAccessor invokeExact( String methodName )
164     {
165         throw new NullPointerException( errorMessage );
166     }
167 
168 }