Commit b069c8edb608acb98ce623d96f8da411c2a48505
1 parent
32f550d1
Exists in
master
Inclusão de lançamento de exceção caso o arquivo buscado não exista no
projeto e inclusão de log caso a key buscada não exista no arquivo informado.
Showing
2 changed files
with
65 additions
and
19 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
| 1 | 1 | /* |
| 2 | +/* | |
| 2 | 3 | * Demoiselle Framework |
| 3 | 4 | * Copyright (C) 2010 SERPRO |
| 4 | 5 | * ---------------------------------------------------------------------------- |
| ... | ... | @@ -63,8 +64,10 @@ import br.gov.frameworkdemoiselle.annotation.Name; |
| 63 | 64 | import br.gov.frameworkdemoiselle.configuration.ConfigType; |
| 64 | 65 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
| 65 | 66 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; |
| 67 | +import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | |
| 66 | 68 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 67 | 69 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
| 70 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 68 | 71 | import br.gov.frameworkdemoiselle.util.Reflections; |
| 69 | 72 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 70 | 73 | import br.gov.frameworkdemoiselle.util.Strings; |
| ... | ... | @@ -83,6 +86,8 @@ public class ConfigurationLoader implements Serializable { |
| 83 | 86 | |
| 84 | 87 | private Logger logger; |
| 85 | 88 | |
| 89 | + private CoreBootstrap bootstrap; | |
| 90 | + | |
| 86 | 91 | /** |
| 87 | 92 | * Loads a config class filling it with the corresponding values. |
| 88 | 93 | * |
| ... | ... | @@ -93,9 +98,14 @@ public class ConfigurationLoader implements Serializable { |
| 93 | 98 | public void load(Object object) throws ConfigurationException { |
| 94 | 99 | Class<?> config = object.getClass(); |
| 95 | 100 | |
| 101 | + if (!getBootstrap().isAnnotatedType(config)) { | |
| 102 | + config = config.getSuperclass(); | |
| 103 | + getLogger().debug(getBundle().getString("proxy-detected", config, config.getClass().getSuperclass())); | |
| 104 | + } | |
| 105 | + | |
| 96 | 106 | getLogger().debug(getBundle().getString("loading-configuration-class", config.getName())); |
| 97 | 107 | |
| 98 | - for (Field field : Reflections.getNonStaticFields(config)) { | |
| 108 | + for (Field field : Reflections.getNonStaticDeclaredFields(config)) { | |
| 99 | 109 | loadField(field, object, config); |
| 100 | 110 | } |
| 101 | 111 | } |
| ... | ... | @@ -108,10 +118,11 @@ public class ConfigurationLoader implements Serializable { |
| 108 | 118 | |
| 109 | 119 | if (config != null) { |
| 110 | 120 | Key key = new Key(field, clazz, config); |
| 111 | - Object value = getValue(key, field, config); | |
| 112 | - | |
| 113 | - validate(field, key, value, resource); | |
| 114 | - setValue(field, key, object, value); | |
| 121 | + if(validateKey(resource, key, type, config)){ | |
| 122 | + Object value = getValue(key, field, config); | |
| 123 | + validate(field, key, value, resource); | |
| 124 | + setValue(field, key, object, value); | |
| 125 | + } | |
| 115 | 126 | } |
| 116 | 127 | } |
| 117 | 128 | } |
| ... | ... | @@ -131,6 +142,24 @@ public class ConfigurationLoader implements Serializable { |
| 131 | 142 | } |
| 132 | 143 | } |
| 133 | 144 | |
| 145 | + private boolean validateKey(String resource, Key key, ConfigType type, org.apache.commons.configuration.Configuration config){ | |
| 146 | + if(!config.containsKey(key.toString())){ | |
| 147 | + if(type.toString().equals("PROPERTIES")){ | |
| 148 | + getLogger().info(getBundle().getString("key-not-found-in-file", key, resource + ".properties")); | |
| 149 | + }else{ | |
| 150 | + if(type.toString().equals("XML")){ | |
| 151 | + getLogger().info(getBundle().getString("key-not-found-in-file", key, resource + ".xml")); | |
| 152 | + }else{ | |
| 153 | + if(type.toString().equals("SYSTEM")){ | |
| 154 | + getLogger().info(getBundle().getString("key-not-found-in-system", key)); | |
| 155 | + } | |
| 156 | + } | |
| 157 | + } | |
| 158 | + return false; | |
| 159 | + } | |
| 160 | + return true; | |
| 161 | + } | |
| 162 | + | |
| 134 | 163 | /** |
| 135 | 164 | * Returns the configuration class according to specified resource name and configuration type. |
| 136 | 165 | * |
| ... | ... | @@ -154,6 +183,9 @@ public class ConfigurationLoader implements Serializable { |
| 154 | 183 | |
| 155 | 184 | if (url != null) { |
| 156 | 185 | result = new DataConfiguration(new PropertiesConfiguration(url)); |
| 186 | + }else{ | |
| 187 | + throw new ConfigurationException( | |
| 188 | + getBundle().getString("resource-not-found", resource + ".properties")); | |
| 157 | 189 | } |
| 158 | 190 | |
| 159 | 191 | break; |
| ... | ... | @@ -163,6 +195,9 @@ public class ConfigurationLoader implements Serializable { |
| 163 | 195 | |
| 164 | 196 | if (url != null) { |
| 165 | 197 | result = new DataConfiguration(new XMLConfiguration(url)); |
| 198 | + }else{ | |
| 199 | + throw new ConfigurationException( | |
| 200 | + getBundle().getString("resource-not-found", resource + ".xml")); | |
| 166 | 201 | } |
| 167 | 202 | |
| 168 | 203 | break; |
| ... | ... | @@ -405,6 +440,14 @@ public class ConfigurationLoader implements Serializable { |
| 405 | 440 | return logger; |
| 406 | 441 | } |
| 407 | 442 | |
| 443 | + private CoreBootstrap getBootstrap() { | |
| 444 | + if (bootstrap == null) { | |
| 445 | + bootstrap = Beans.getReference(CoreBootstrap.class); | |
| 446 | + } | |
| 447 | + | |
| 448 | + return bootstrap; | |
| 449 | + } | |
| 450 | + | |
| 408 | 451 | private class Key { |
| 409 | 452 | |
| 410 | 453 | private String prefix; |
| ... | ... | @@ -459,4 +502,4 @@ public class ConfigurationLoader implements Serializable { |
| 459 | 502 | return this.key; |
| 460 | 503 | } |
| 461 | 504 | } |
| 462 | 505 | -} |
| 506 | +} | |
| 463 | 507 | \ No newline at end of file | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| ... | ... | @@ -34,12 +34,15 @@ |
| 34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | 35 | |
| 36 | 36 | engine-on=Ligando os motores do Demoiselle ${project.version} |
| 37 | -ambiguous-strategy-resolution=Foi detectada ambiguidade da interface "{0}" com as seguintes implementa\u00E7\u00F5es\: "{1}". Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. | |
| 38 | -bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) | |
| 37 | +resource-not-found=Arquivo {0} n\u00E3o foi encontrado | |
| 38 | +key-not-found-in-file=A chave {0} n\u00E3o foi encontrada no arquivo {1} | |
| 39 | +key-not-found-in-system=A vari\u00E1vel de ambiente {0} n\u00E3o foi encontrada no sistema | |
| 40 | +ambiguous-strategy-resolution=Foi detectada ambiguidade da interface "{0}" com as seguintes implementa\u00E7\u00F5es\: "{1}". Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. | |
| 41 | +bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) | |
| 39 | 42 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} |
| 40 | 43 | handling-exception=Tratando a exce\u00E7\u00E3o {0} |
| 41 | 44 | proxy-detected=Detectado o proxy {0} da classe {1} |
| 42 | -ambiguous-key=Existe mais de uma chave declarada no arquivo de configura\u00E7\u00E3o para o campo {0} da classe {1}. Indique qual a chave correta utilizando a anota\u00E7\u00E3o Name | |
| 45 | +ambiguous-key=Existe mais de uma chave declarada no arquivo de configura\u00E7\u00E3o para o campo {0} da classe {1}. Indique qual a chave correta utilizando a anota\u00E7\u00E3o Name | |
| 43 | 46 | taking-off=O Demoiselle ${project.version} decolou |
| 44 | 47 | engine-off=Desligando os motores do Demoiselle ${project.version} |
| 45 | 48 | setting-up-bean-manager=BeanManager dispon\u00EDvel atrav\u00E9s do utilit\u00E1rio {0} |
| ... | ... | @@ -61,14 +64,14 @@ configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pod |
| 61 | 64 | configuration-key-not-found=Chave de configura\u00E7\u00E3o "{0}" n\u00E3o encontrada. Conven\u00E7\u00F5es verificadas\: "{1}" |
| 62 | 65 | |
| 63 | 66 | transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.transaction.class com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties |
| 64 | -executing-all=Executando todos os \: {0} | |
| 67 | +executing-all=Executando todos os \: {0} | |
| 65 | 68 | custom-context-was-registered=O contexto {0} foi registrado |
| 66 | 69 | custom-context-was-unregistered=O contexto {0} foi removido |
| 67 | - | |
| 70 | + | |
| 68 | 71 | error-creating-configuration-from-resource=Error creating configuration from resource named "{0}" |
| 69 | -configuration-type-not-implemented-yet=Configuration type "{0}" is not implemented yet | |
| 70 | -error-converting-to-type=Error converting to type "{0}" | |
| 71 | -error-creating-new-instance-for=Error creating a new instance for "{0}" | |
| 72 | +configuration-type-not-implemented-yet=Configuration type "{0}" is not implemented yet | |
| 73 | +error-converting-to-type=Error converting to type "{0}" | |
| 74 | +error-creating-new-instance-for=Error creating a new instance for "{0}" | |
| 72 | 75 | executed-successfully=\ {0} execultado com sucesso |
| 73 | 76 | must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0} |
| 74 | 77 | loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0} |
| ... | ... | @@ -77,8 +80,8 @@ page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}] |
| 77 | 80 | page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}] |
| 78 | 81 | processing=Processando\: {0} |
| 79 | 82 | processing-fail=Falha no processamento devido a uma exce\u00E7\u00E3o lan\u00E7ada pela aplica\u00E7\u00E3o |
| 80 | -for= \ para\: | |
| 81 | -file-not-found=O arquivo {0} n\u00E3o foi encontrado | |
| 83 | +for= \ para\: | |
| 84 | +file-not-found=O arquivo {0} n\u00E3o foi encontrado | |
| 82 | 85 | |
| 83 | 86 | adding-message-to-context=Adicionando uma mensagem no contexto: [{0}] |
| 84 | 87 | cleaning-message-context=Limpando o contexto de mensagens |
| ... | ... | @@ -87,10 +90,10 @@ access-allowed=O usu\u00E1rio "{0}" acessou o recurso "{2}" com a a\u00E7\u00E3o |
| 87 | 90 | access-denied=O usu\u00E1rio "{0}" n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o "{1}" no recurso "{2}" |
| 88 | 91 | access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0} |
| 89 | 92 | authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authorizer.class como regra de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo demoiselle.properties. |
| 90 | -user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado | |
| 93 | +user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado | |
| 91 | 94 | has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1} |
| 92 | 95 | does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1} |
| 93 | -does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} | |
| 96 | +does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} | |
| 94 | 97 | user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1} |
| 95 | 98 | |
| 96 | 99 | -authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties. |
| 100 | +authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties. | |
| 97 | 101 | \ No newline at end of file | ... | ... |