| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons; |
| 34 | | | |
| 35 | | | import java.text.MessageFormat; |
| 36 | | | import java.util.ArrayList; |
| 37 | | | import java.util.Arrays; |
| 38 | | | import java.util.Collections; |
| 39 | | | import java.util.Iterator; |
| 40 | | | import java.util.List; |
| 41 | | | import java.util.Map; |
| 42 | | | import java.util.logging.Level; |
| 43 | | | |
| 44 | | | |
| 45 | | | |
| 46 | | | |
| 47 | | | {@link } |
| 48 | | | <p> |
| 49 | | | |
| 50 | | | |
| 51 | | | |
| 52 | | | |
| 53 | | | @author |
| 54 | | | |
| 55 | | | public abstract class LogMessageInfoImpl |
| 56 | | | implements LogMessageInfo |
| 57 | | | { |
| 58 | | | |
| 59 | | | static final long serialVersionUID = 1L; |
| 60 | | | |
| 61 | | | private final String mErrorSymbol; |
| 62 | | | private final int mErrorId; |
| 63 | | | private final Level mLogLevel; |
| 64 | | | private final String mMessagePattern; |
| 65 | | | private final String mSolution; |
| 66 | | | private final List mParameters; |
| 67 | | | private final BusinessImpact mBusinessImpact; |
| 68 | | | private final Category mCategory; |
| 69 | | | private final String mApplicationName; |
| 70 | | | private final String mApplicationNameAbbreviation; |
| 71 | | | private final String mGroupName; |
| 72 | | | private final String mGroupNameAbbreviation; |
| 73 | | | |
| 74 | | (1) | protected LogMessageInfoImpl (String symbol, int id, Level level, |
| 75 | | | String text, String solution, BusinessImpact businessImpact, |
| 76 | | | Category category, String[] params, String appName, |
| 77 | | | String appNameAbbr, String groupName, String groupNameAbbr) |
| 78 | 100 | | { |
| 79 | 100 | | mErrorSymbol = symbol; |
| 80 | 100 | | mErrorId = id; |
| 81 | 100 | | mLogLevel = level; |
| 82 | 100 | | mMessagePattern = text; |
| 83 | 100 | | mSolution = solution; |
| 84 | 100 | | mBusinessImpact = businessImpact; |
| 85 | 100 | | mCategory = category; |
| 86 | 100 | | mParameters = Collections.unmodifiableList(Arrays.asList(params)); |
| 87 | 100 | | mApplicationName = appName; |
| 88 | 100 | | mApplicationNameAbbreviation = appNameAbbr; |
| 89 | 100 | | mGroupName = groupName; |
| 90 | 100 | | mGroupNameAbbreviation = groupNameAbbr; |
| 91 | 100 | | } |
| 92 | | | |
| 93 | | | |
| 94 | | | |
| 95 | | | <b></b> |
| 96 | | | |
| 97 | | | <pre> |
| 98 | | | |
| 99 | | | |
| 100 | | | |
| 101 | | | |
| 102 | | | |
| 103 | | | |
| 104 | | | |
| 105 | | | </pre> |
| 106 | | | <b></b> |
| 107 | | | |
| 108 | | | <i></i> |
| 109 | | | |
| 110 | | | @return |
| 111 | | | |
| 112 | | | public final int toInt () |
| 113 | | | { |
| 114 | 100 | | return mErrorId; |
| 115 | | | } |
| 116 | | | |
| 117 | | | |
| 118 | | | |
| 119 | | | |
| 120 | | | <code></code> |
| 121 | | | @see |
| 122 | | | @return |
| 123 | | | |
| 124 | | | public final String toString () |
| 125 | | | { |
| 126 | 100 | | return mErrorSymbol; |
| 127 | | | } |
| 128 | | | |
| 129 | | | |
| 130 | | | |
| 131 | | | {@inheritDoc} |
| 132 | | | public final String getSymbol () |
| 133 | | | { |
| 134 | 100 | | return mErrorSymbol; |
| 135 | | | } |
| 136 | | | |
| 137 | | | {@inheritDoc} |
| 138 | | | public final Level getLogLevel () |
| 139 | | | { |
| 140 | 100 | | return mLogLevel; |
| 141 | | | } |
| 142 | | | |
| 143 | | | {@inheritDoc} |
| 144 | | | public final String getMessagePattern () |
| 145 | | | { |
| 146 | 100 | | return mMessagePattern; |
| 147 | | | } |
| 148 | | | |
| 149 | | | {@inheritDoc} |
| 150 | | | public final StringBuffer formatMessage (Map parameters, StringBuffer buffer) |
| 151 | | | { |
| 152 | 100 | | final StringBuffer result |
| 153 | | | = buffer != null ? buffer : new StringBuffer(); |
| 154 | | | try |
| 155 | | | { |
| 156 | 100 | (2) | final MessageFormat formatter = new MessageFormat(getMessagePattern()); |
| 157 | | | |
| 158 | 100 | | final List parameter = new ArrayList(); |
| 159 | | | |
| 160 | 100 | | if (parameters != null && !getParameterList().isEmpty()) |
| 161 | | | { |
| 162 | 100 | | final Iterator i = getParameterList().iterator(); |
| 163 | 100 | | while (i.hasNext()) |
| 164 | | | { |
| 165 | 100 | | final String parameterName = (String) i.next(); |
| 166 | 100 | (3) | final List parameterValues = (List) parameters.get(parameterName); |
| 167 | 100 | | if (parameterValues == null || parameterValues.isEmpty()) |
| 168 | | | { |
| 169 | 100 | | parameter.add(null); |
| 170 | | | } |
| 171 | | | else |
| 172 | | | { |
| 173 | 100 | | parameter.add(parameterValues.get(0)); |
| 174 | | | } |
| 175 | 100 | | } |
| 176 | | | } |
| 177 | 100 | | formatter.format(parameter.toArray(), result, null); |
| 178 | | | } |
| 179 | | | |
| 180 | 0 | | catch (Exception ex) |
| 181 | | | { |
| 182 | 0 | | result.append(parameters); |
| 183 | 0 | | result.append(' '); |
| 184 | 0 | | result.append(getMessagePattern()); |
| 185 | 100 | | } |
| 186 | 100 | | return result; |
| 187 | | | } |
| 188 | | | |
| 189 | | | {@inheritDoc} |
| 190 | | | public final String getSolution () |
| 191 | | | { |
| 192 | 100 | | return mSolution; |
| 193 | | | } |
| 194 | | | |
| 195 | | | {@inheritDoc} |
| 196 | | | public final BusinessImpact getBusinessImpact () |
| 197 | | | { |
| 198 | 100 | | return mBusinessImpact; |
| 199 | | | } |
| 200 | | | |
| 201 | | | {@inheritDoc} |
| 202 | | | public final Category getCategory () |
| 203 | | | { |
| 204 | 100 | | return mCategory; |
| 205 | | | } |
| 206 | | | |
| 207 | | | {@inheritDoc} |
| 208 | | | public final List getParameterList () |
| 209 | | | { |
| 210 | 100 | | return mParameters; |
| 211 | | | } |
| 212 | | | |
| 213 | | | {@inheritDoc} |
| 214 | | | public String getAppName () |
| 215 | | | { |
| 216 | 100 | | return mApplicationName; |
| 217 | | | } |
| 218 | | | |
| 219 | | | {@inheritDoc} |
| 220 | | | public String getAppNameAbbreviation () |
| 221 | | | { |
| 222 | 0 | | return mApplicationNameAbbreviation; |
| 223 | | | } |
| 224 | | | |
| 225 | | | {@inheritDoc} |
| 226 | | | public String getGroupName () |
| 227 | | | { |
| 228 | 100 | | return mGroupName; |
| 229 | | | } |
| 230 | | | |
| 231 | | | {@inheritDoc} |
| 232 | | | public String getGroupNameAbbreviation () |
| 233 | | | { |
| 234 | 0 | | return mGroupNameAbbreviation; |
| 235 | | | } |
| 236 | | | } |