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.api.core.security;
17  
18  import static de.smartics.properties.api.core.app.LibraryCodeNumbers.SECURITY_CODE_START;
19  import de.smartics.exceptions.code.NumberCodeInfo;
20  import de.smartics.exceptions.i18n.message.MessageParamsDescriptor;
21  import de.smartics.properties.api.core.app.PropertiesCode;
22  import de.smartics.properties.api.core.domain.PropertyDescriptorMessageBean;
23  
24  /**
25   * Codes dealing with property problems.
26   */
27  public enum SecurityCode implements PropertiesCode
28  {
29    // ***************************** Enumeration ******************************
30  
31    /**
32     * The {@code security.properties} file cannot be loaded.
33     */
34    @MessageParamsDescriptor(SecurityMessageBean.class)
35    LOADING_SECURITY_PROPERTIES_FAILED(0),
36  
37    /**
38     * Key generation failed.
39     */
40    @MessageParamsDescriptor(SecurityMessageBean.class)
41    INIT_KEY_GENERATION_FAILED(1),
42  
43    /**
44     * Cipher generation failed.
45     */
46    @MessageParamsDescriptor(PropertyDescriptorMessageBean.class)
47    INIT_CIPHER_GENERATION_FAILED(2),
48  
49    /**
50     * Key generation failed in the context of a given property.
51     */
52    @MessageParamsDescriptor(PropertyDescriptorMessageBean.class)
53    KEY_GENERATION_FAILED(10),
54  
55    /**
56     * Cipher generation failed in the context of a given property.
57     */
58    @MessageParamsDescriptor(PropertyDescriptorMessageBean.class)
59    CIPHER_GENERATION_FAILED(11),
60  
61    /**
62     * Decryption of a property value failed.
63     */
64    @MessageParamsDescriptor(PropertyDescriptorMessageBean.class)
65    DECRYPTION_FAILED(12),
66  
67    /**
68     * Encryption of a property value failed.
69     */
70    @MessageParamsDescriptor(PropertyDescriptorMessageBean.class)
71    ENCRYPTION_FAILED(13);
72  
73    // ******************************** Fields ********************************
74  
75    // --- constants ----------------------------------------------------------
76  
77    // --- members ------------------------------------------------------------
78  
79    /**
80     * The code information.
81     */
82    private final NumberCodeInfo info;
83  
84    // ***************************** Constructors *****************************
85  
86    /**
87     * Default constructor.
88     *
89     * @param minorNumber the minor part of the error code.
90     */
91    private SecurityCode(final Integer minorNumber)
92    {
93      this.info =
94          new NumberCodeInfo("Security", SECURITY_CODE_START, minorNumber);
95    }
96  
97    // ******************************** Methods *******************************
98  
99    // --- init ---------------------------------------------------------------
100 
101   // --- get&set ------------------------------------------------------------
102 
103   @Override
104   public String getCode()
105   {
106     return info.getCode();
107   }
108 
109   @Override
110   public String getComponentId()
111   {
112     return info.getComponentId();
113   }
114 
115   @Override
116   public String getDisplayId()
117   {
118     return info.toString();
119   }
120 
121   @Override
122   public Integer getMajorNumber()
123   {
124     return info.getMajorNumber();
125   }
126 
127   @Override
128   public Integer getMinorNumber()
129   {
130     return info.getMinorNumber();
131   }
132 
133   // --- business -----------------------------------------------------------
134 
135   // --- object basics ------------------------------------------------------
136 
137   /**
138    * Returns the string representation of the object.
139    *
140    * @return the string representation of the object.
141    */
142   @Override
143   public String toString()
144   {
145     return getDisplayId();
146   }
147 }