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.impl.config.jndi;
17  
18  import javax.annotation.concurrent.ThreadSafe;
19  import javax.naming.NamingException;
20  
21  import de.smartics.properties.api.config.domain.ConfigurationException;
22  import de.smartics.properties.api.config.domain.key.ConfigurationKey;
23  import de.smartics.properties.spi.config.support.AbstractConfigurationPropertiesFactory;
24  
25  /**
26   * Factory to create instances of {@link JndiConfigurationProperties}.
27   */
28  @ThreadSafe
29  public final class JndiConfigurationPropertiesFactory extends
30      AbstractConfigurationPropertiesFactory<JndiConfigurationProperties>
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The class version identifier.
38     */
39    private static final long serialVersionUID = 1L;
40  
41    // --- members --------------------------------------------------------------
42  
43    // ****************************** Initializer *******************************
44  
45    // ****************************** Constructors ******************************
46  
47    /**
48     * Default constructor.
49     */
50    public JndiConfigurationPropertiesFactory()
51    {
52    }
53  
54    // ****************************** Inner Classes *****************************
55  
56    // ********************************* Methods ********************************
57  
58    // --- init -----------------------------------------------------------------
59  
60    // --- get&set --------------------------------------------------------------
61  
62    // --- business -------------------------------------------------------------
63  
64    /**
65     * Creates an empty instance of the configuration properties instance. Where
66     * the public create methods may consult a cache, this method is required to
67     * create a new instance.
68     *
69     * @param key the key to the instance.
70     * @return the instance. Never <code>null</code>.
71     * @throws NullPointerException if {@code key} is <code>null</code>.
72     * @throws ConfigurationException if the configuration cannot be created.
73     */
74    protected JndiConfigurationProperties createNewConfiguration(
75        final ConfigurationKey<?> key) throws NullPointerException,
76      ConfigurationException
77    {
78      try
79      {
80        final JndiConfigurationProperties config =
81            new JndiConfigurationProperties(key, getRegistry(),
82                getFactoryConfiguration().getDecrypter());
83        return config;
84      }
85      catch (final NamingException e)
86      {
87        throw new IllegalStateException("Cannot fetch configuration for key '"
88                                        + key + "' from JNDI.", e); // TODO
89                                                                    // smartics-exception
90      }
91    }
92  
93    // --- object basics --------------------------------------------------------
94  
95  }