Skip to content

Instantly share code, notes, and snippets.

@gjoseph
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjoseph/6a3f7fbc469e76ac2900 to your computer and use it in GitHub Desktop.
Save gjoseph/6a3f7fbc469e76ac2900 to your computer and use it in GitHub Desktop.
diff --git a/magnolia-configuration/src/main/java/info/magnolia/config/registry/Registry.java b/magnolia-configuration/src/main/java/info/magnolia/config/registry/Registry.java
index 99b54eb..cff3bcf 100644
--- a/magnolia-configuration/src/main/java/info/magnolia/config/registry/Registry.java
+++ b/magnolia-configuration/src/main/java/info/magnolia/config/registry/Registry.java
@@ -60,6 +60,7 @@ public interface Registry<T> {
* TODO: do we need this method ? Is it usable ? Isn't query() more useful ?
* TODO: if we need it, can it throw a NoSuchDefinitionException? (if you have a metadata instance, it's an IllegalState if it doesn't point to a provider anymore)
*/
DefinitionProvider<T> getProvider(DefinitionMetadata<T> id);
+ * @throws NoSuchDefinitionException (which is a RuntimeException) if the given reference is not known.
*/
+ DefinitionProvider<T> getProvider(String referenceId) throws NoSuchDefinitionException;
* Implementations are expected to return a subtype of DefinitionQuery that's able to callback its registry to perform the search.
* TODO do we want this on registries or just RegistryFacade ?
*/
DefinitionQuery<T> query();
public static class NoSuchDefinitionException extends RuntimeException {
public NoSuchDefinitionException(String nonExistingId) {
super(nonExistingId);
}
}
public static class InvalidDefinitionException extends RuntimeException {
protected InvalidDefinitionException(String definitionId) {
super(definitionId);
}
}
diff --git a/magnolia-configuration/src/main/java/info/magnolia/config/registry/DefinitionProvider.java b/magnolia-configuration/src/main/java/info/magnolia/config/registry/DefinitionProvider.java
index 34646ff..5a783669 100644
--- a/magnolia-configuration/src/main/java/info/magnolia/config/registry/DefinitionProvider.java
+++ b/magnolia-configuration/src/main/java/info/magnolia/config/registry/DefinitionProvider.java
@@ -49,18 +49,17 @@ public interface DefinitionProvider<T> {
DefinitionMetadata<T> getMetadata();
/**
* Returns the underlying bean if and only if it is successfully resolved, is valid, and is enabled.
*
* @throws Registry.InvalidDefinitionException (which is a RuntimeException) if the underlying bean is not successfully resolved, not valid, or not enabled.
*/
T get() throws Registry.InvalidDefinitionException;
/**
* Returns a {@link info.magnolia.config.registry.DefinitionRawView} representation the underlying bean; it might be
* invalid, partially resolved and/or disabled.
*/
DefinitionRawView getRaw();
// TBD
ValidationInfo getValidationInfo();
}
/**
* Returns a single provider matching the criteria or throws an exception if not unique.
* @throws Registry.NoSuchDefinitionException (which is a RuntimeException) if the query doesn't match any definition.
*/
public abstract DefinitionProvider<T> findSingle() throws Registry.NoSuchDefinitionException;
/**
* Returns all providers matching the given criteria or an empty collection if there are no matches.
*/
public abstract Collection<DefinitionProvider<T>> findMultiple();
public interface DefinitionRawView {
// Some methods copied from Map -- read-only view
// TODO further we can enforce that all keys are Strings, and values are either other DefinitionRawView or Strings or a Value type (String and 'type' to give hints to UI if its a number or sthg else ?)
// TODO what about collections
boolean containsKey(String key);
V get(Object key);
Set<String> keySet();
Set<Map.Entry<String, V>> entrySet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment