| 1 | /* |
| 2 | * Copyright 2005-2006 The RbUtils Project |
| 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 | */ |
| 17 | |
| 18 | // $Id: AbstractFileProcessor.java,v 1.3 2006/09/16 14:44:14 redfish Exp $ |
| 19 | |
| 20 | package org.ktc.rbutils.api.audit; |
| 21 | |
| 22 | import java.util.Iterator; |
| 23 | import java.util.Locale; |
| 24 | import org.ktc.rbutils.api.audit.event.ProcessEvent; |
| 25 | import org.ktc.rbutils.api.audit.event.ProcessFileEndEvent; |
| 26 | import org.ktc.rbutils.api.audit.event.ProcessFileStartEvent; |
| 27 | import org.ktc.rbutils.api.i18n.Message; |
| 28 | |
| 29 | /** |
| 30 | * Abstract base class for File Processing. Adds the root directory fonctionnality. |
| 31 | * @since RbUtils 0.9.3.3 |
| 32 | * @version $Revision: 1.3 $ |
| 33 | * @author moishi |
| 34 | */ |
| 35 | public abstract class AbstractFileProcessor extends AbstractProcessor implements FileProcessor { |
| 36 | /** Name of the processed file. */ |
| 37 | protected String fileName; |
| 38 | |
| 39 | /** Name of the class corresponding to the processed file. */ |
| 40 | protected String className; |
| 41 | |
| 42 | /** Locale of the processed file. */ |
| 43 | protected Locale fileLocale; |
| 44 | |
| 45 | /** |
| 46 | * {@inheritDoc} |
| 47 | */ |
| 48 | public void fireProcessFileStarted() { |
| 49 | final ProcessFileStartEvent event = new ProcessFileStartEvent(this, fileName, fileLocale, |
| 50 | className); |
| 51 | for (final Iterator it = loggers.iterator(); it.hasNext();) { |
| 52 | final Logger logger = (Logger) it.next(); |
| 53 | logger.processFileStarted(event); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritDoc} |
| 59 | */ |
| 60 | public void fireProcessFileEnded() { |
| 61 | final ProcessFileEndEvent event = new ProcessFileEndEvent(this, fileName, fileLocale, |
| 62 | className); |
| 63 | for (final Iterator it = loggers.iterator(); it.hasNext();) { |
| 64 | final Logger logger = (Logger) it.next(); |
| 65 | logger.processFileEnded(event); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * {@inheritDoc} |
| 71 | */ |
| 72 | public void fireError(final Message message, final String detailledMessage) { |
| 73 | final ProcessEvent event = new ProcessEvent(this, MessageType.ERROR, message, |
| 74 | detailledMessage); |
| 75 | for (final Iterator it = loggers.iterator(); it.hasNext();) { |
| 76 | final Logger logger = (Logger) it.next(); |
| 77 | logger.addError(event); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * {@inheritDoc} |
| 83 | */ |
| 84 | public void fireInformation(final Message message, final String detailledMessage) { |
| 85 | final ProcessEvent event = new ProcessEvent(this, MessageType.INFO, message, |
| 86 | detailledMessage); |
| 87 | for (final Iterator it = loggers.iterator(); it.hasNext();) { |
| 88 | final Logger logger = (Logger) it.next(); |
| 89 | logger.addError(event); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | } |