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.config.cache; 17 18 import javax.naming.NamingException; 19 20 import de.smartics.exceptions.i18n.message.MessageParam; 21 import de.smartics.properties.api.core.app.AbstractBaseMessageBean; 22 23 /** 24 * Provides context information for problems dealing with caches. 25 */ 26 public class CacheMessageBean extends AbstractBaseMessageBean // NOPMD 27 { 28 // ********************************* Fields ********************************* 29 30 // --- constants ------------------------------------------------------------ 31 32 /** 33 * The class version identifier. 34 * <p> 35 * The value of this constant is {@value}. 36 * </p> 37 */ 38 private static final long serialVersionUID = 1L; 39 40 // --- members -------------------------------------------------------------- 41 42 /** 43 * The location of the cache configuration. 44 */ 45 @MessageParam 46 private final String cacheConfiguration; // NOPMD 47 48 /** 49 * The identifier of the cache. Usually this is the mapped name of the cache. 50 * 51 * @serial 52 */ 53 @MessageParam 54 private final String cacheId; // NOPMD 55 56 /** 57 * The identifier of the missing cache configuration property. 58 * 59 * @serial 60 */ 61 @MessageParam 62 private final String missingProperty; // NOPMD 63 64 // ****************************** Initializer ******************************* 65 66 // ****************************** Constructors ****************************** 67 68 /** 69 * Constructor without cause. 70 * 71 * @param code the error or exception code of the exception. 72 * @param cacheConfiguration the location of the cache configuration. 73 * @param cacheId the identifier of the cache. 74 * @param missingProperty the identifier of the missing cache configuration 75 * property. 76 */ 77 public CacheMessageBean(final CacheCode code, 78 final String cacheConfiguration, final String cacheId, 79 final String missingProperty) 80 { 81 this(code, null, cacheConfiguration, cacheId, missingProperty); 82 } 83 84 /** 85 * Default constructor. 86 * 87 * @param code the error or exception code of the exception. 88 * @param cause the cause to the problem. 89 * @param cacheConfiguration the location of the cache configuration. 90 * @param cacheId the identifier of the cache. 91 * @param missingProperty the identifier of the missing cache configuration 92 * property. 93 */ 94 public CacheMessageBean(final CacheCode code, final Throwable cause, 95 final String cacheConfiguration, final String cacheId, 96 final String missingProperty) 97 { 98 super(code, cause); 99 this.cacheConfiguration = cacheConfiguration; 100 this.cacheId = cacheId; 101 this.missingProperty = missingProperty; 102 } 103 104 // ****************************** Inner Classes ***************************** 105 106 // ********************************* Methods ******************************** 107 108 // --- init ----------------------------------------------------------------- 109 110 // --- factory -------------------------------------------------------------- 111 112 /** 113 * Returns a message bean signaling that the mandatory cache configuration 114 * property is missing in the cache configuration. 115 * 116 * @param cacheConfiguration the descriptor to the cache configuration file. 117 * @param missingProperty the identifier of the missing cache configuration 118 * property. 119 * @return the message bean. 120 */ 121 public static CacheMessageBean missingProperty( 122 final String cacheConfiguration, final String missingProperty) 123 { 124 return new CacheMessageBean(CacheCode.MISSING_MAPPED_NAME, 125 cacheConfiguration, null, missingProperty); 126 } 127 128 /** 129 * Returns a message bean signaling that the cache configuration file cannot 130 * be loaded. 131 * 132 * @param cause the cause to the problem. 133 * @param cacheConfiguration the descriptor to the cache configuration file 134 * that caused the problem. 135 * @return the message bean. 136 */ 137 public static CacheMessageBean configFailure(final Throwable cause, 138 final String cacheConfiguration) 139 { 140 return new CacheMessageBean(CacheCode.CONFIGURATION_FILE_LOAD_FAILURE, 141 cause, cacheConfiguration, null, null); 142 } 143 144 /** 145 * Returns a message bean signaling that accessing the cache via JNDI failed. 146 * 147 * @param cause the cause to the problem. 148 * @param cacheConfiguration the descriptor to the cache configuration file 149 * that caused the problem. 150 * @param cacheId the identifier of the cache. 151 * @return the message bean. 152 */ 153 public static CacheMessageBean jndi(final NamingException cause, 154 final String cacheConfiguration, final String cacheId) 155 { 156 return new CacheMessageBean(CacheCode.JNDI_PROBLEM, cause, 157 cacheConfiguration, cacheId, null); 158 } 159 160 // --- get&set -------------------------------------------------------------- 161 162 // --- business ------------------------------------------------------------- 163 164 // --- object basics -------------------------------------------------------- 165 166 }