View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.spi.core.context;
17  
18  import org.apache.commons.lang.builder.ToStringBuilder;
19  
20  import de.smartics.properties.api.core.domain.PropertiesContext;
21  import de.smartics.properties.api.core.domain.PropertyContext;
22  import de.smartics.properties.api.core.domain.PropertyDescriptor;
23  
24  /**
25   * A proxy to provide property context instances.
26   */
27  public final class PropertyContextProxy implements PropertyContextProvider
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    /**
34     * The class version identifier.
35     */
36    private static final long serialVersionUID = 1L;
37  
38    // --- members --------------------------------------------------------------
39  
40    /**
41     * The properties context to fetch information from the META-INF folder.
42     *
43     * @serial
44     */
45    private final PropertiesContext context;
46  
47    // ****************************** Initializer *******************************
48  
49    // ****************************** Constructors ******************************
50  
51    /**
52     * Default constructor.
53     *
54     * @param context the properties context to fetch information from the
55     *          META-INF folder. May be <code>null</code>.
56     */
57    public PropertyContextProxy(final PropertiesContext context)
58    {
59      this.context =
60          (context != null ? context : new PropertiesContext.Builder().build());
61    }
62  
63    // ****************************** Inner Classes *****************************
64  
65    // ********************************* Methods ********************************
66  
67    // --- init -----------------------------------------------------------------
68  
69    // --- get&set --------------------------------------------------------------
70  
71    // --- business -------------------------------------------------------------
72  
73    @Override
74    public PropertyContext getPropertyContext(
75        final PropertyDescriptor propertyDescriptor) throws NullPointerException
76    {
77      return new MandatoryPropertyContext(context, propertyDescriptor);
78    }
79  
80    // --- object basics --------------------------------------------------------
81  
82    /**
83     * Returns the string representation of the object.
84     *
85     * @return the string representation of the object.
86     */
87    @Override
88    public String toString()
89    {
90      return ToStringBuilder.reflectionToString(this);
91    }
92  }