Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionado processo para criação de instâncias únicas dos resources bundles #470

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import br.gov.frameworkdemoiselle.behave.internal.util.PropertiesLoaderUtil;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
* Gerecia das configurações do Demoiselle Behave. Utiliza o arquivo
Expand Down Expand Up @@ -312,7 +313,7 @@ public static boolean getRunner_ShowExecutionStatistics() {
*/
public static void logValueProperties() {
if (log.isDebugEnabled()) {
BehaveMessage bm = new BehaveMessage(MESSAGEBUNDLE);
BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(MESSAGEBUNDLE);
ArrayList<String> propertieList = new ArrayList<String>();
log.debug("------- " + bm.getString("properties") + " ----------");
Enumeration<Object> keys = properties.keys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import br.gov.frameworkdemoiselle.behave.internal.parser.StoryFileConverter;
import br.gov.frameworkdemoiselle.behave.internal.spi.InjectionManager;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;
import br.gov.frameworkdemoiselle.behave.parser.Parser;
import br.gov.frameworkdemoiselle.behave.parser.Step;

Expand Down Expand Up @@ -103,7 +104,7 @@ public class BehaveContext {
private BehaveMessage bm;

private BehaveContext() {
bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);
}

private void checkClassScopeManagerExtension(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

public class ClassScopeManager {

Expand All @@ -14,7 +15,7 @@ public class ClassScopeManager {

@AfterClass
public static void clearClassLists() {
BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);
if (!BehaveConfig.getRunner_LegacyRunner()){
behaveContext.getStepsClass().clear();
behaveContext.getStoriesClass().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
import br.gov.frameworkdemoiselle.behave.dataprovider.DataProvider;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -53,7 +54,7 @@ public class DefaultDataProvider implements DataProvider {

private static Hashtable<String, Object> data;
private static Logger logger = Logger.getLogger(DefaultDataProvider.class);
private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public DefaultDataProvider() {
data = new Hashtable<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.internal.spi.InjectionManager;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -26,7 +27,7 @@ public class DefaultDatasetProvider implements DatasetProvider {

private static Hashtable<String, Dataset> dataSets;

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public DefaultDatasetProvider() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.internal.spi.InjectionManager;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -24,7 +25,7 @@ public class DatabaseDatasetLoader implements DatasetLoader {

private static DatabaseConnector databaseConnector = (DatabaseConnector) InjectionManager.getInstance().getInstanceDependecy(DatabaseConnector.class);

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public Dataset load(String tableName){
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import br.gov.frameworkdemoiselle.behave.dataprovider.XmlLoader;
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

import com.thoughtworks.xstream.XStream;

Expand All @@ -20,7 +21,7 @@
*/
public class XStreamXmlLoader implements XmlLoader {

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

protected XStream xstream = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.internal.util.RegularExpressionUtil;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -57,7 +58,7 @@ public class ScenarioParameter {

private static final String PARAMETER_PATTERN = "(\"([^\"]*)\")";

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

/**
* Substitui os nome de parâmetro por parâmetros vazios, viabilizando a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import br.gov.frameworkdemoiselle.behave.internal.filter.StoryFilter;
import br.gov.frameworkdemoiselle.behave.internal.util.RegularExpressionUtil;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -98,7 +99,7 @@ public class StoryConverter {

private static final String LINE_BREAK_TOKEN = "\n";

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

/*
* Definições: story=arquivo com um ou mais cenários ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.internal.util.FileUtil;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -54,7 +55,7 @@
*/
public class StoryFileConverter {

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public static List<String> convertReusedScenarios(List<String> originalFolderes, String originalExtension, String convertedExtension, Boolean includeSubFolder) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.internal.ui.UIProxy;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;
import br.gov.frameworkdemoiselle.behave.runner.ui.Element;

/**
Expand All @@ -57,7 +58,7 @@ public class InjectionManager {

private Hashtable<String, Object> singletons = new Hashtable<String, Object>();
private static InjectionManager instance;
private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

void setSingletons(Hashtable<String, Object> singletons) {
this.singletons = singletons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

public class UIProxy implements InvocationHandler {

private Object obj;
Logger log = Logger.getLogger(UIProxy.class);
private BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public static Object newInstance(Object obj) {
return java.lang.reflect.Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new UIProxy(obj));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
import br.gov.frameworkdemoiselle.behave.dataprovider.DataProvider;
import br.gov.frameworkdemoiselle.behave.internal.spi.InjectionManager;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

public class DataProviderUtil {

private static DataProvider dataProvider = (DataProvider) InjectionManager.getInstance().getInstanceDependecy(DataProvider.class);
private static Logger logger = Logger.getLogger(DataProviderUtil.class);
private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public static List<String> replaceDataProvider(List<String> valueList){
List<String> newValueList = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -60,7 +61,7 @@
public class FileUtil {

public static final String FILE_SEPARATOR = System.getProperty("file.separator");
private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public static String loadFile(String pFilePath) throws IOException {
pFilePath = pFilePath.replaceAll("%20", " "); // Correção de problemas com espaços
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -62,7 +63,7 @@ public class PropertiesLoaderUtil implements Serializable {

private static PropertiesLoaderUtil config;
private Properties allProps;
private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE, Locale.getDefault());
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE, Locale.getDefault());

private static Logger log = Logger.getLogger(PropertiesLoaderUtil.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
import br.gov.frameworkdemoiselle.behave.exception.BehaveException;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessage;
import br.gov.frameworkdemoiselle.behave.message.BehaveMessageFactory;

/**
*
Expand All @@ -56,7 +57,7 @@
*/
public class ReflectionUtil {

private static BehaveMessage bm = new BehaveMessage(BehaveConfig.MESSAGEBUNDLE);
private static BehaveMessage bm = BehaveMessageFactory.getInstance().getBehaveMessage(BehaveConfig.MESSAGEBUNDLE);

public static String getLocation(String name) {
Reflections reflections = new Reflections("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,86 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import br.gov.frameworkdemoiselle.behave.config.BehaveConfig;
/**
* Class that manipulates Demoiselle Behave resource bundles.
*
* @author SERPRO
*
*/
public class BehaveMessage {

private ResourceBundle rb = null;
/**
* Messages resource bundle.
*/
private ResourceBundle resourceBundle = null;

/**
* Constroi o BehaveMessage a partir do nome do bundle
* @param baseName
* Creates a BehaveMessage according to passed resource bundle base name and locale.
*
* @param baseName the resource bundle base name
* @param locale the resource bundle locale
*/
public BehaveMessage(String baseName) {
rb = ResourceBundle.getBundle(baseName, new Locale(BehaveConfig.getProperty("behave.message.locale", "pt")));
protected BehaveMessage(String baseName, Locale locale) {
setResourceBundle(baseName, locale);
}

public BehaveMessage(String baseName, Locale locale) {

/**
* Gets the resource bundle.
*
* @return the resource bundle
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}

/**
* Sets the resource bundle base name and locale.
*
* @param baseName the resource bundle base name
* @param locale the resource bundle locale
*/
private void setResourceBundle(String baseName, Locale locale) {

try {
rb = ResourceBundle.getBundle(baseName, locale);
resourceBundle = ResourceBundle.getBundle(baseName, locale);
} catch (MissingResourceException ex) {
rb = ResourceBundle.getBundle(baseName, new Locale("pt","BR"));
resourceBundle = ResourceBundle.getBundle(baseName, new Locale("pt","BR"));
}
}

/**
* Obtem a mensagem no bundle
* @param key chave da mensagem
* @param params parametros da mensagem
* @return
* Gets the resource bundle message based on a key and some parameters.
*
* @param key message key
* @param params message parameteres
*
* @return resource bundle message
*/
public String getString(String key, Object... params) {

if (params == null || params.length == 0) {
return getString(key);
} else {
return MessageFormat.format(getString(key), params);
}

}

/**
* Gets the resource bundle message based on a key.
*
* @param key message key
*
* @return resource bundle message
*/
public String getString(String key) {
if (rb.containsKey(key)) {
return rb.getString(key);

if (resourceBundle.containsKey(key)) {
return resourceBundle.getString(key);
} else {
return "??{" + key + "}??";
}

}

}
Loading