You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2020/09/10 14:38:19 UTC

[myfaces-tobago] 01/02: chore: slight internal refactoring

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 6c3102514cd9fbec6b0ff144f49a49d40a729dfa
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Sep 10 07:54:56 2020 +0200

    chore: slight internal refactoring
---
 .../apache/myfaces/tobago/context/ThemeImpl.java   | 31 ++++++++++----------
 .../tobago/internal/config/TobagoConfigImpl.java   | 34 +++++++++++-----------
 2 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
index 92aa282..1cb786b 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
@@ -40,24 +40,23 @@ public class ThemeImpl implements Theme, Serializable {
   private ThemeImpl fallback;
   private String fallbackName;
   private List<Theme> fallbackList;
-  private ThemeResources productionResources;
-  private ThemeResources resources;
+  private final ThemeResources productionResources;
+  private final ThemeResources resources;
   private ThemeScript[] productionScripts;
   private ThemeStyle[] productionStyles;
   private ThemeScript[] scripts;
   private ThemeStyle[] styles;
-  private boolean versioned;
   private String version;
 
-  private boolean unmodifiable = false;
+  private boolean locked = false;
 
   public ThemeImpl() {
     resources = new ThemeResources(false);
     productionResources = new ThemeResources(true);
   }
 
-  private void checkLocked() throws IllegalStateException {
-    if (unmodifiable) {
+  private void checkUnlocked() throws IllegalStateException {
+    if (locked) {
       throw new IllegalStateException("The configuration must not be changed after initialization!");
     }
   }
@@ -66,7 +65,7 @@ public class ThemeImpl implements Theme, Serializable {
    * Lock the configuration, so it cannot be modified any more.
    */
   public void lock() {
-    unmodifiable = true;
+    locked = true;
   }
 
   @Override
@@ -75,7 +74,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void setName(final String name) {
-    checkLocked();
+    checkUnlocked();
     this.name = name;
   }
 
@@ -85,7 +84,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void setDisplayName(final String displayName) {
-    checkLocked();
+    checkUnlocked();
     this.displayName = displayName;
   }
 
@@ -94,7 +93,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void setFallback(final ThemeImpl fallback) {
-    checkLocked();
+    checkUnlocked();
     this.fallback = fallback;
   }
 
@@ -103,7 +102,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void setFallbackName(final String fallbackName) {
-    checkLocked();
+    checkUnlocked();
     this.fallbackName = fallbackName;
   }
 
@@ -113,7 +112,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void resolveFallbacks() {
-    checkLocked();
+    checkUnlocked();
     fallbackList = new ArrayList<>();
     ThemeImpl actual = this;
     while (actual != null) {
@@ -131,7 +130,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void resolveResources() {
-    checkLocked();
+    checkUnlocked();
     final ThemeImpl fallbackTheme = getFallback();
     if (fallbackTheme != null) {
       fallbackTheme.resolveResources();
@@ -149,7 +148,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   private void addResources(final ThemeResources themeResources) {
-    checkLocked();
+    checkUnlocked();
 
     if (themeResources.isProduction()) {
       productionResources.merge(themeResources);
@@ -159,7 +158,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void init() {
-    checkLocked();
+    checkUnlocked();
     productionScripts = sortScripts(productionResources.getScriptList());
     productionStyles = sortStyles(productionResources.getStyleList());
     scripts = sortScripts(resources.getScriptList());
@@ -202,7 +201,7 @@ public class ThemeImpl implements Theme, Serializable {
   }
 
   public void setVersion(final String version) {
-    checkLocked();
+    checkUnlocked();
     this.version = version;
   }
 
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java
index a205cb4..f40d5b9 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java
@@ -60,7 +60,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   private boolean createSessionSecret;
   private boolean checkSessionSecret;
   private boolean preventFrameAttacks;
-  private ContentSecurityPolicy contentSecurityPolicy;
+  private final ContentSecurityPolicy contentSecurityPolicy;
   private SecurityAnnotation securityAnnotation;
   private boolean setNosniffHeader;
   private Map<String, String> defaultValidatorInfo;
@@ -68,7 +68,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   private boolean decodeLineFeed;
   private Map<String, String> mimeTypes;
 
-  private boolean unmodifiable = false;
+  private boolean locked = false;
 
   protected TobagoConfigImpl(String fixme) { // CDI workaround fixme
     supportedThemeNames = new ArrayList<>();
@@ -88,7 +88,7 @@ public class TobagoConfigImpl extends TobagoConfig {
    * Lock the configuration, so it cannot be modified any more.
    */
   protected void lock() {
-    unmodifiable = true;
+    locked = true;
     supportedThemes = Collections.unmodifiableList(supportedThemes);
     for (final Theme theme : supportedThemes) {
       ((ThemeImpl) theme).lock();
@@ -101,20 +101,20 @@ public class TobagoConfigImpl extends TobagoConfig {
     mimeTypes = Collections.unmodifiableMap(mimeTypes);
   }
 
-  private void checkLocked() throws IllegalStateException {
-    if (unmodifiable) {
+  private void checkUnlocked() throws IllegalStateException {
+    if (locked) {
       throw new TobagoConfigurationException("The configuration must not be changed after initialization!");
     }
   }
 
   protected void addSupportedThemeName(final String name) {
-    checkLocked();
+    checkUnlocked();
     supportedThemeNames.add(name);
   }
 
   // TODO one init method
   protected void resolveThemes() {
-    checkLocked();
+    checkUnlocked();
 
     if (defaultThemeName != null) {
       defaultTheme = availableThemes.get(defaultThemeName);
@@ -186,7 +186,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void setDefaultThemeName(final String defaultThemeName) {
-    checkLocked();
+    checkUnlocked();
     this.defaultThemeName = defaultThemeName;
   }
 
@@ -201,7 +201,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void addAvailableTheme(final ThemeImpl availableTheme) {
-    checkLocked();
+    checkUnlocked();
     availableThemes.put(availableTheme.getName(), availableTheme);
   }
 
@@ -211,7 +211,7 @@ public class TobagoConfigImpl extends TobagoConfig {
 
   protected synchronized void initDefaultValidatorInfo() {
     if (defaultValidatorInfo != null) {
-      checkLocked();
+      checkUnlocked();
     }
     final FacesContext facesContext = FacesContext.getCurrentInstance();
     if (facesContext != null) {
@@ -236,7 +236,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void setCreateSessionSecret(final boolean createSessionSecret) {
-    checkLocked();
+    checkUnlocked();
     this.createSessionSecret = createSessionSecret;
   }
 
@@ -246,7 +246,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void setCheckSessionSecret(final boolean checkSessionSecret) {
-    checkLocked();
+    checkUnlocked();
     this.checkSessionSecret = checkSessionSecret;
   }
 
@@ -257,7 +257,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void setPreventFrameAttacks(final boolean preventFrameAttacks) {
-    checkLocked();
+    checkUnlocked();
     this.preventFrameAttacks = preventFrameAttacks;
   }
 
@@ -272,7 +272,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void setSetNosniffHeader(final boolean setNosniffHeader) {
-    checkLocked();
+    checkUnlocked();
     this.setNosniffHeader = setNosniffHeader;
   }
 
@@ -282,7 +282,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   public void setSecurityAnnotation(final SecurityAnnotation securityAnnotation) {
-    checkLocked();
+    checkUnlocked();
     this.securityAnnotation = securityAnnotation;
   }
 
@@ -300,7 +300,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   protected void setSanitizer(final Sanitizer sanitizer) {
-    checkLocked();
+    checkUnlocked();
     this.sanitizer = sanitizer;
   }
 
@@ -310,7 +310,7 @@ public class TobagoConfigImpl extends TobagoConfig {
   }
 
   public void setDecodeLineFeed(final boolean decodeLineFeed) {
-    checkLocked();
+    checkUnlocked();
     this.decodeLineFeed = decodeLineFeed;
   }