From dcbea17ff8fe031f7ff96edb8923c2b8643fc597 Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Sun, 26 Aug 2012 10:30:23 +0000 Subject: [PATCH] Removed deprecated package 'configuration'. --- .../macaco/configuration/MConfiguration.java | 109 ------------------ .../MConfigurationException.java | 31 ----- .../MFileParsingConfigurationException.java | 30 ----- .../MValueNotFoundConfigurationException.java | 30 ----- 4 files changed, 200 deletions(-) delete mode 100644 src/java/com/marcozanon/macaco/configuration/MConfiguration.java delete mode 100644 src/java/com/marcozanon/macaco/configuration/MConfigurationException.java delete mode 100644 src/java/com/marcozanon/macaco/configuration/MFileParsingConfigurationException.java delete mode 100644 src/java/com/marcozanon/macaco/configuration/MValueNotFoundConfigurationException.java diff --git a/src/java/com/marcozanon/macaco/configuration/MConfiguration.java b/src/java/com/marcozanon/macaco/configuration/MConfiguration.java deleted file mode 100644 index f012ea7..0000000 --- a/src/java/com/marcozanon/macaco/configuration/MConfiguration.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * Released under MIT license (see LICENSE for details). - */ - -package com.marcozanon.macaco.configuration; - -import com.marcozanon.macaco.MInformation; -import com.marcozanon.macaco.MObject; -import com.marcozanon.macaco.text.MText; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.IOException; -import java.io.LineNumberReader; -import java.io.UnsupportedEncodingException; -import java.util.LinkedHashMap; - -public class MConfiguration extends MObject { - - protected LinkedHashMap parameters = new LinkedHashMap(); - - /* */ - - public MConfiguration(String file) throws MFileParsingConfigurationException { - super(); - // - this.parseFile(file); - } - - /* Parameters */ - - protected LinkedHashMap getParametersReference() { - return this.parameters; - } - - /* Strings management */ - - public void parseFile(String file) throws MFileParsingConfigurationException { - if (MText.isBlank(file)) { - throw new IllegalArgumentException("Invalid 'file': null or empty."); - } - // - LineNumberReader buffer = null; - try { - buffer = new LineNumberReader(new InputStreamReader(new FileInputStream(file), MInformation.TEXT_ENCODING)); - } - catch (FileNotFoundException exception) { - throw new MFileParsingConfigurationException("Could not open file.", exception); - } - catch (UnsupportedEncodingException exception) { // cannot happen - } - String line = null; - synchronized (this.getParametersReference()) { - while (true) { - try { - line = buffer.readLine(); - } - catch (IOException exception) { - throw new MFileParsingConfigurationException("Could not read file.", exception); - } - if (null == line) { - break; - } - line = line.trim(); - if ((line.startsWith("#")) || (line.startsWith(";")) || (MText.isEmpty(line))) { - continue; - } - else { - int a = line.indexOf("="); - if (-1 == a) { - throw new MFileParsingConfigurationException(String.format("Invalid line: %s: string malformed.", buffer.getLineNumber())); - } - String key = line.substring(0, a).trim(); - String value = line.substring(a + 1).trim(); - if (this.getParametersReference().containsKey(key)) { - throw new MFileParsingConfigurationException(String.format("Invalid line: %s: duplicated key: %s.", buffer.getLineNumber(), key)); - } - this.getParametersReference().put(key, value); - } - } - } - try { - buffer.close(); - } - catch (IOException exception) { - throw new MFileParsingConfigurationException("Could not close file.", exception); - } - } - - public void clear() { - synchronized (this.getParametersReference()) { - this.getParametersReference().clear(); - } - } - - public String getValue(String key) throws MValueNotFoundConfigurationException { - if (MText.isBlank(key)) { - throw new IllegalArgumentException("Invalid 'key': null or empty."); - } - // - if (!this.getParametersReference().containsKey(key)) { - throw new MValueNotFoundConfigurationException(String.format("Invalid 'key': %s: not available.", key)); - } - return this.getParametersReference().get(key); - } - -} diff --git a/src/java/com/marcozanon/macaco/configuration/MConfigurationException.java b/src/java/com/marcozanon/macaco/configuration/MConfigurationException.java deleted file mode 100644 index 2335d50..0000000 --- a/src/java/com/marcozanon/macaco/configuration/MConfigurationException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * Released under MIT license (see LICENSE for details). - */ - -package com.marcozanon.macaco.configuration; - -import com.marcozanon.macaco.MException; - -public abstract class MConfigurationException extends MException { - - /* */ - - public MConfigurationException() { - super(); - } - - public MConfigurationException(String message) { - super(message); - } - - public MConfigurationException(Throwable error) { - super(error); - } - - public MConfigurationException(String message, Throwable error) { - super(message, error); - } - -} diff --git a/src/java/com/marcozanon/macaco/configuration/MFileParsingConfigurationException.java b/src/java/com/marcozanon/macaco/configuration/MFileParsingConfigurationException.java deleted file mode 100644 index b464314..0000000 --- a/src/java/com/marcozanon/macaco/configuration/MFileParsingConfigurationException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * Released under MIT license (see LICENSE for details). - */ - -package com.marcozanon.macaco.configuration; - -@SuppressWarnings("serial") -public class MFileParsingConfigurationException extends MConfigurationException { - - /* */ - - public MFileParsingConfigurationException() { - super(); - } - - public MFileParsingConfigurationException(String message) { - super(message); - } - - public MFileParsingConfigurationException(Throwable error) { - super(error); - } - - public MFileParsingConfigurationException(String message, Throwable error) { - super(message, error); - } - -} diff --git a/src/java/com/marcozanon/macaco/configuration/MValueNotFoundConfigurationException.java b/src/java/com/marcozanon/macaco/configuration/MValueNotFoundConfigurationException.java deleted file mode 100644 index 05a13cd..0000000 --- a/src/java/com/marcozanon/macaco/configuration/MValueNotFoundConfigurationException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * Released under MIT license (see LICENSE for details). - */ - -package com.marcozanon.macaco.configuration; - -@SuppressWarnings("serial") -public class MValueNotFoundConfigurationException extends MConfigurationException { - - /* */ - - public MValueNotFoundConfigurationException() { - super(); - } - - public MValueNotFoundConfigurationException(String message) { - super(message); - } - - public MValueNotFoundConfigurationException(Throwable error) { - super(error); - } - - public MValueNotFoundConfigurationException(String message, Throwable error) { - super(message, error); - } - -} -- 2.30.2