Skip to content

Commit

Permalink
DELTASPIKE-1456 add default methods to ConfigSource
Browse files Browse the repository at this point in the history
* isScannable() is now a default method which returns true
* getOrdinal() is now a default method which checks "deltaspike_ordinal"
or returns 100.
  • Loading branch information
struberg committed Jul 29, 2022
1 parent 0c1c940 commit 6312294
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public interface ConfigSource
* in {@link #getOrdinal()}.
*/
String DELTASPIKE_ORDINAL = "deltaspike_ordinal";

/**
* The default value if no special ordinal is defined for this ConfigSource.
*/
int DELTASPIKE_DEFAULT_ORDINAL = 100;

/**
* Lookup order:
Expand Down Expand Up @@ -78,9 +83,19 @@ public interface ConfigSource
* /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
* config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
*
* <p>This method will only get evaluated once at startup and whenever a new ConfigSource is added.</p>
*
* @return the 'importance' aka ordinal of the configured values. The higher, the more important.
*/
int getOrdinal();
default int getOrdinal()
{
String ordinal = getPropertyValue(DELTASPIKE_ORDINAL);
if (ordinal != null && ordinal.length() > 0)
{
return Integer.valueOf(ordinal);
}
return DELTASPIKE_DEFAULT_ORDINAL;
}

/**
* Return properties contained in this config source.
Expand All @@ -107,7 +122,10 @@ public interface ConfigSource
* @return true if this ConfigSource should be scanned for its list of properties,
* false if it should not be scanned.
*/
boolean isScannable();
default boolean isScannable()
{
return true;
}

/**
* This callback should get invoked if an attribute change got detected inside the ConfigSource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ public List<ConfigSource> getConfigSources()

private static class TestConfigSource1 implements ConfigSource
{
@Override
public int getOrdinal()
{
return 1;
}

@Override
public String getPropertyValue(String key)
{
if ("test".equals(key))
{
return "test1";
}
if (ConfigSource.DELTASPIKE_ORDINAL.equals(key))
{
return "1";
}
return null;
}

Expand All @@ -69,10 +67,6 @@ public String getConfigName()
return TestConfigSourceProvider.class.getName();
}

@Override
public boolean isScannable() {
return true;
}
}

private static class TestConfigSource2 implements ConfigSource
Expand Down

0 comments on commit 6312294

Please sign in to comment.