Commit e816d246301a7ac7fac175df808afb737fe909d7
1 parent
b36156d7
Exists in
master
Exclusão de mais uma classe desnecessária: CoreBundle
Showing
8 changed files
with
74 additions
and
39 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/CoreBundle.java
| @@ -1,28 +0,0 @@ | @@ -1,28 +0,0 @@ | ||
| 1 | -package br.gov.frameworkdemoiselle.internal.implementation; | ||
| 2 | - | ||
| 3 | -import javax.inject.Inject; | ||
| 4 | - | ||
| 5 | -import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 6 | -import br.gov.frameworkdemoiselle.util.Beans; | ||
| 7 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 8 | - | ||
| 9 | -public class CoreBundle { | ||
| 10 | - | ||
| 11 | - @Inject | ||
| 12 | - @Name("demoiselle-core-bundle") | ||
| 13 | - private ResourceBundle bundle; | ||
| 14 | - | ||
| 15 | - private static CoreBundle instance; | ||
| 16 | - | ||
| 17 | - private static synchronized CoreBundle getInstance() { | ||
| 18 | - if (instance == null) { | ||
| 19 | - instance = Beans.getReference(CoreBundle.class); | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - return instance; | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - public static ResourceBundle get() { | ||
| 26 | - return getInstance().bundle; | ||
| 27 | - } | ||
| 28 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java
| @@ -37,9 +37,11 @@ | @@ -37,9 +37,11 @@ | ||
| 37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | ||
| 39 | import br.gov.frameworkdemoiselle.DemoiselleException; | 39 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 40 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
| 40 | import br.gov.frameworkdemoiselle.security.Authenticator; | 41 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 41 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 42 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 42 | import br.gov.frameworkdemoiselle.security.User; | 43 | import br.gov.frameworkdemoiselle.security.User; |
| 44 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 43 | 45 | ||
| 44 | /** | 46 | /** |
| 45 | * Authenticator that actually does nothing but raise exceptions. | 47 | * Authenticator that actually does nothing but raise exceptions. |
| @@ -51,6 +53,8 @@ public class DefaultAuthenticator implements Authenticator { | @@ -51,6 +53,8 @@ public class DefaultAuthenticator implements Authenticator { | ||
| 51 | 53 | ||
| 52 | private static final long serialVersionUID = 1L; | 54 | private static final long serialVersionUID = 1L; |
| 53 | 55 | ||
| 56 | + private static ResourceBundle bundle; | ||
| 57 | + | ||
| 54 | /** | 58 | /** |
| 55 | * @see br.gov.frameworkdemoiselle.security.Authenticator#authenticate() | 59 | * @see br.gov.frameworkdemoiselle.security.Authenticator#authenticate() |
| 56 | */ | 60 | */ |
| @@ -76,8 +80,15 @@ public class DefaultAuthenticator implements Authenticator { | @@ -76,8 +80,15 @@ public class DefaultAuthenticator implements Authenticator { | ||
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | private DemoiselleException getException() { | 82 | private DemoiselleException getException() { |
| 79 | - return new DemoiselleException(CoreBundle.get().getString("authenticator-not-defined", | 83 | + return new DemoiselleException(getBundle().getString("authenticator-not-defined", |
| 80 | SecurityContext.class.getSimpleName())); | 84 | SecurityContext.class.getSimpleName())); |
| 81 | } | 85 | } |
| 82 | 86 | ||
| 87 | + private static ResourceBundle getBundle() { | ||
| 88 | + if (bundle == null) { | ||
| 89 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + return bundle; | ||
| 93 | + } | ||
| 83 | } | 94 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizer.java
| @@ -37,9 +37,11 @@ | @@ -37,9 +37,11 @@ | ||
| 37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | ||
| 39 | import br.gov.frameworkdemoiselle.DemoiselleException; | 39 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 40 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
| 40 | import br.gov.frameworkdemoiselle.security.Authorizer; | 41 | import br.gov.frameworkdemoiselle.security.Authorizer; |
| 41 | import br.gov.frameworkdemoiselle.security.RequiredPermission; | 42 | import br.gov.frameworkdemoiselle.security.RequiredPermission; |
| 42 | import br.gov.frameworkdemoiselle.security.RequiredRole; | 43 | import br.gov.frameworkdemoiselle.security.RequiredRole; |
| 44 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 43 | 45 | ||
| 44 | /** | 46 | /** |
| 45 | * Authorizator that actually does nothing but raise exceptions. | 47 | * Authorizator that actually does nothing but raise exceptions. |
| @@ -51,16 +53,25 @@ public class DefaultAuthorizer implements Authorizer { | @@ -51,16 +53,25 @@ public class DefaultAuthorizer implements Authorizer { | ||
| 51 | 53 | ||
| 52 | private static final long serialVersionUID = 1L; | 54 | private static final long serialVersionUID = 1L; |
| 53 | 55 | ||
| 56 | + private static ResourceBundle bundle; | ||
| 57 | + | ||
| 54 | @Override | 58 | @Override |
| 55 | public boolean hasRole(String role) { | 59 | public boolean hasRole(String role) { |
| 56 | - throw new DemoiselleException(CoreBundle.get().getString("authorizer-not-defined", | 60 | + throw new DemoiselleException(getBundle().getString("authorizer-not-defined", |
| 57 | RequiredRole.class.getSimpleName())); | 61 | RequiredRole.class.getSimpleName())); |
| 58 | } | 62 | } |
| 59 | 63 | ||
| 60 | @Override | 64 | @Override |
| 61 | public boolean hasPermission(String resource, String operation) { | 65 | public boolean hasPermission(String resource, String operation) { |
| 62 | - throw new DemoiselleException(CoreBundle.get().getString("authorizer-not-defined", | 66 | + throw new DemoiselleException(getBundle().getString("authorizer-not-defined", |
| 63 | RequiredPermission.class.getSimpleName())); | 67 | RequiredPermission.class.getSimpleName())); |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 70 | + private static ResourceBundle getBundle() { | ||
| 71 | + if (bundle == null) { | ||
| 72 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + return bundle; | ||
| 76 | + } | ||
| 66 | } | 77 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java
| @@ -37,8 +37,10 @@ | @@ -37,8 +37,10 @@ | ||
| 37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | ||
| 39 | import br.gov.frameworkdemoiselle.DemoiselleException; | 39 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 40 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
| 40 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 41 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 41 | import br.gov.frameworkdemoiselle.transaction.Transactional; | 42 | import br.gov.frameworkdemoiselle.transaction.Transactional; |
| 43 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 42 | 44 | ||
| 43 | /** | 45 | /** |
| 44 | * Transaction strategy that actually does nothing but raise exceptions. | 46 | * Transaction strategy that actually does nothing but raise exceptions. |
| @@ -50,6 +52,8 @@ public class DefaultTransaction implements Transaction { | @@ -50,6 +52,8 @@ public class DefaultTransaction implements Transaction { | ||
| 50 | 52 | ||
| 51 | private static final long serialVersionUID = 1L; | 53 | private static final long serialVersionUID = 1L; |
| 52 | 54 | ||
| 55 | + private static ResourceBundle bundle; | ||
| 56 | + | ||
| 53 | @Override | 57 | @Override |
| 54 | public void begin() { | 58 | public void begin() { |
| 55 | throw getException(); | 59 | throw getException(); |
| @@ -81,7 +85,15 @@ public class DefaultTransaction implements Transaction { | @@ -81,7 +85,15 @@ public class DefaultTransaction implements Transaction { | ||
| 81 | } | 85 | } |
| 82 | 86 | ||
| 83 | private DemoiselleException getException() { | 87 | private DemoiselleException getException() { |
| 84 | - return new DemoiselleException(CoreBundle.get().getString("transaction-not-defined", | 88 | + return new DemoiselleException(getBundle().getString("transaction-not-defined", |
| 85 | Transactional.class.getSimpleName())); | 89 | Transactional.class.getSimpleName())); |
| 86 | } | 90 | } |
| 91 | + | ||
| 92 | + private static ResourceBundle getBundle() { | ||
| 93 | + if (bundle == null) { | ||
| 94 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + return bundle; | ||
| 98 | + } | ||
| 87 | } | 99 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
| @@ -45,10 +45,12 @@ import javax.inject.Inject; | @@ -45,10 +45,12 @@ import javax.inject.Inject; | ||
| 45 | 45 | ||
| 46 | import org.slf4j.Logger; | 46 | import org.slf4j.Logger; |
| 47 | 47 | ||
| 48 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
| 48 | import br.gov.frameworkdemoiselle.message.DefaultMessage; | 49 | import br.gov.frameworkdemoiselle.message.DefaultMessage; |
| 49 | import br.gov.frameworkdemoiselle.message.Message; | 50 | import br.gov.frameworkdemoiselle.message.Message; |
| 50 | import br.gov.frameworkdemoiselle.message.MessageContext; | 51 | import br.gov.frameworkdemoiselle.message.MessageContext; |
| 51 | import br.gov.frameworkdemoiselle.message.SeverityType; | 52 | import br.gov.frameworkdemoiselle.message.SeverityType; |
| 53 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 52 | 54 | ||
| 53 | /** | 55 | /** |
| 54 | * The message store is designed to provide access to messages. It is shared by every application layer. | 56 | * The message store is designed to provide access to messages. It is shared by every application layer. |
| @@ -65,6 +67,8 @@ public class MessageContextImpl implements Serializable, MessageContext { | @@ -65,6 +67,8 @@ public class MessageContextImpl implements Serializable, MessageContext { | ||
| 65 | 67 | ||
| 66 | private final List<Message> messages = new ArrayList<Message>(); | 68 | private final List<Message> messages = new ArrayList<Message>(); |
| 67 | 69 | ||
| 70 | + private static ResourceBundle bundle; | ||
| 71 | + | ||
| 68 | @Override | 72 | @Override |
| 69 | public void add(final Message message, Object... params) { | 73 | public void add(final Message message, Object... params) { |
| 70 | Message aux; | 74 | Message aux; |
| @@ -75,7 +79,7 @@ public class MessageContextImpl implements Serializable, MessageContext { | @@ -75,7 +79,7 @@ public class MessageContextImpl implements Serializable, MessageContext { | ||
| 75 | aux = message; | 79 | aux = message; |
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | - logger.debug(CoreBundle.get().getString("adding-message-to-context", message.toString())); | 82 | + logger.debug(getBundle().getString("adding-message-to-context", message.toString())); |
| 79 | messages.add(aux); | 83 | messages.add(aux); |
| 80 | } | 84 | } |
| 81 | 85 | ||
| @@ -96,7 +100,15 @@ public class MessageContextImpl implements Serializable, MessageContext { | @@ -96,7 +100,15 @@ public class MessageContextImpl implements Serializable, MessageContext { | ||
| 96 | 100 | ||
| 97 | @Override | 101 | @Override |
| 98 | public void clear() { | 102 | public void clear() { |
| 99 | - logger.debug(CoreBundle.get().getString("cleaning-message-context")); | 103 | + logger.debug(getBundle().getString("cleaning-message-context")); |
| 100 | messages.clear(); | 104 | messages.clear(); |
| 101 | } | 105 | } |
| 106 | + | ||
| 107 | + private static ResourceBundle getBundle() { | ||
| 108 | + if (bundle == null) { | ||
| 109 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + return bundle; | ||
| 113 | + } | ||
| 102 | } | 114 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java
| @@ -64,6 +64,16 @@ public class ResourceBundleProducer implements Serializable { | @@ -64,6 +64,16 @@ public class ResourceBundleProducer implements Serializable { | ||
| 64 | * @param String | 64 | * @param String |
| 65 | * baseName | 65 | * baseName |
| 66 | */ | 66 | */ |
| 67 | + public static ResourceBundle create(String baseName) { | ||
| 68 | + return create(baseName, Beans.getReference(Locale.class)); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * This method should be used by classes that can not inject ResourceBundle, to create the ResourceBundle. | ||
| 73 | + * | ||
| 74 | + * @param String | ||
| 75 | + * baseName | ||
| 76 | + */ | ||
| 67 | public static ResourceBundle create(String baseName, Locale locale) { | 77 | public static ResourceBundle create(String baseName, Locale locale) { |
| 68 | ResourceBundle bundle = null; | 78 | ResourceBundle bundle = null; |
| 69 | 79 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/AuthorizationException.java
| @@ -36,7 +36,8 @@ | @@ -36,7 +36,8 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.security; | 37 | package br.gov.frameworkdemoiselle.security; |
| 38 | 38 | ||
| 39 | -import br.gov.frameworkdemoiselle.internal.implementation.CoreBundle; | 39 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
| 40 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * Thrown when trying to access some resource and/or execute an operation without the proper authorization. | 43 | * Thrown when trying to access some resource and/or execute an operation without the proper authorization. |
| @@ -47,6 +48,8 @@ public class AuthorizationException extends SecurityException { | @@ -47,6 +48,8 @@ public class AuthorizationException extends SecurityException { | ||
| 47 | 48 | ||
| 48 | private static final long serialVersionUID = 1L; | 49 | private static final long serialVersionUID = 1L; |
| 49 | 50 | ||
| 51 | + private static ResourceBundle bundle; | ||
| 52 | + | ||
| 50 | /** | 53 | /** |
| 51 | * Constructor with message. | 54 | * Constructor with message. |
| 52 | * | 55 | * |
| @@ -58,8 +61,14 @@ public class AuthorizationException extends SecurityException { | @@ -58,8 +61,14 @@ public class AuthorizationException extends SecurityException { | ||
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | public AuthorizationException(String resource, String operation) { | 63 | public AuthorizationException(String resource, String operation) { |
| 61 | - // TODO: remove the CoreBundle call | ||
| 62 | - super(CoreBundle.get().getString("access-denied-ui", resource, operation)); | 64 | + super(getBundle().getString("access-denied-ui", resource, operation)); |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 67 | + private static ResourceBundle getBundle() { | ||
| 68 | + if (bundle == null) { | ||
| 69 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + return bundle; | ||
| 73 | + } | ||
| 65 | } | 74 | } |
impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java
| @@ -36,14 +36,12 @@ | @@ -36,14 +36,12 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.transaction; | 37 | package br.gov.frameworkdemoiselle.transaction; |
| 38 | 38 | ||
| 39 | -import javax.enterprise.context.RequestScoped; | ||
| 40 | import javax.transaction.Status; | 39 | import javax.transaction.Status; |
| 41 | import javax.transaction.SystemException; | 40 | import javax.transaction.SystemException; |
| 42 | import javax.transaction.UserTransaction; | 41 | import javax.transaction.UserTransaction; |
| 43 | 42 | ||
| 44 | import br.gov.frameworkdemoiselle.util.Beans; | 43 | import br.gov.frameworkdemoiselle.util.Beans; |
| 45 | 44 | ||
| 46 | -@RequestScoped | ||
| 47 | public class JTATransaction implements Transaction { | 45 | public class JTATransaction implements Transaction { |
| 48 | 46 | ||
| 49 | private static final long serialVersionUID = 1L; | 47 | private static final long serialVersionUID = 1L; |