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 java.util.List;
19  import java.util.Locale;
20  
21  import org.apache.commons.lang.builder.ToStringBuilder;
22  
23  import de.smartics.properties.api.core.domain.PropertiesContext;
24  import de.smartics.properties.api.core.domain.PropertyContext;
25  import de.smartics.properties.api.core.domain.PropertyDescriptor;
26  import de.smartics.util.lang.Arg;
27  import de.smartics.util.lang.NullArgumentException;
28  
29  /**
30   * Provides context information for a given property.
31   * <p>
32   * The implementation guarantees that a context is present.
33   * </p>
34   */
35  public final class MandatoryPropertyContext implements PropertyContext
36  {
37    // ********************************* Fields *********************************
38  
39    // --- constants ------------------------------------------------------------
40  
41    /**
42     * The class version identifier.
43     * <p>
44     * The value of this constant is {@value}.
45     * </p>
46     */
47    private static final long serialVersionUID = 1L;
48  
49    // --- members --------------------------------------------------------------
50  
51    /**
52     * The context of the properties.
53     *
54     * @serial
55     */
56    private final PropertiesContext propertiesContext;
57  
58    /**
59     * The descriptor of the property.
60     *
61     * @serial
62     */
63    private final PropertyDescriptor descriptor;
64  
65    // ****************************** Initializer *******************************
66  
67    // ****************************** Constructors ******************************
68  
69    /**
70     * Default constructor.
71     *
72     * @param propertiesContext the context of the properties.
73     * @param descriptor the descriptor of the property.
74     * @throws NullArgumentException if either {@code propertiesContext} or
75     *           {@code descriptor} is <code>null</code>.
76     */
77    public MandatoryPropertyContext(final PropertiesContext propertiesContext,
78        final PropertyDescriptor descriptor) throws NullArgumentException
79    {
80      this.propertiesContext =
81          Arg.checkNotNull("propertiesContext", propertiesContext);
82      this.descriptor = Arg.checkNotNull("descriptor", descriptor);
83    }
84  
85    // ****************************** Inner Classes *****************************
86  
87    // ********************************* Methods ********************************
88  
89    // --- init -----------------------------------------------------------------
90  
91    // --- get&set --------------------------------------------------------------
92  
93    @Override
94    public PropertiesContext getPropertiesContext()
95    {
96      return propertiesContext;
97    }
98  
99    // --- business -------------------------------------------------------------
100 
101   @Override
102   public String getHomePageUrl()
103   {
104     return propertiesContext.getHomePageUrl();
105   }
106 
107   @Override
108   public String getHomePageUrl(final Locale locale)
109   {
110     // TODO Only supports the default language currently.
111     return getHomePageUrl();
112   }
113 
114   @Override
115   public String getPropertiesReportIndexUrl()
116   {
117     return propertiesContext.getPropertiesReportIndexUrl();
118   }
119 
120   @Override
121   public String getPropertiesReportIndexUrl(final Locale locale)
122   {
123     // TODO Only supports the default language currently.
124     return getPropertiesReportIndexUrl();
125   }
126 
127   @Override
128   public String getPropertiesReportUrl()
129   {
130     return propertiesContext.getPropertiesReportUrl();
131   }
132 
133   @Override
134   public String getPropertiesReportUrl(final Locale locale)
135   {
136     // TODO Only supports the default language currently.
137     return getPropertiesReportUrl();
138   }
139 
140   @Override
141   public String getPropertyReportUrl()
142   {
143     return propertiesContext.createReportUrl(descriptor);
144   }
145 
146   @Override
147   public String getPropertyReportUrl(final Locale locale)
148   {
149     // TODO Only supports the default language currently.
150     return getPropertyReportUrl();
151   }
152 
153   @Override
154   public List<Locale> getSupportedLocales()
155   {
156     return propertiesContext.getLocales();
157   }
158 
159   // --- object basics --------------------------------------------------------
160 
161   /**
162    * Returns the string representation of the object.
163    *
164    * @return the string representation of the object.
165    */
166   @Override
167   public String toString()
168   {
169     return ToStringBuilder.reflectionToString(this);
170   }
171 }