public abstract class AbstractFactory extends java.lang.Object implements Factory
The strongly-typed create() method calls the main createObject() factory method. This first checks whether the supplied type is generic; if so, it dispatches to the appropriate method to create a List, Set, Map or Pair object. Otherwise, it expects to create a simple object. If the type is not a predefined type, creates an instance of an external type.
Normally the value and type are supplied as String values, either using the model language syntax, or Java syntax. The type String is checked for correct generic syntax. If the value is null or empty, will create a default instance of the given type. For List, Set and Map types, this is an empty instance. For other types, this is the usual Java default instance (zero, false, etc). The methods for creating List, Set and Map types expect the value to be the usual printable representation of that collection type; however, if a single element value is provided, a singleton collection will be created. The wildcard "?" represents the default singleton value.
Constructor and Description |
---|
AbstractFactory() |
Modifier and Type | Method and Description |
---|---|
<T> T |
create(java.lang.String value,
java.lang.String type)
Creates a strongly-typed instance of any kind of Java Object with the
given printed representation and Java type.
|
protected java.lang.Object |
createDefaultObject(java.lang.String type)
Creates a default object of a simple type.
|
protected abstract java.lang.Object |
createExternalObject(java.lang.String value,
java.lang.String type)
Creates an instance of an uninterpreted external type, with the given
value.
|
protected java.util.List<java.lang.Object> |
createListObject(java.lang.String value,
java.util.List<java.lang.String> params)
Creates a generic List of the given element type, having the given
value.
|
protected java.util.Map<java.lang.Object,java.lang.Object> |
createMapObject(java.lang.String value,
java.util.List<java.lang.String> params)
Creates a generic Map object of the given parametric type, with the
given value.
|
protected java.util.Map.Entry<java.lang.Object,java.lang.Object> |
createPairObject(java.lang.String value,
java.util.List<java.lang.String> params)
Creates a generic Pair object of the given parametric type, with the
given value.
|
protected java.util.Set<java.lang.Object> |
createSetObject(java.lang.String value,
java.util.List<java.lang.String> params)
Creates a generic Set of the given element type, having the given
value.
|
protected java.lang.Object |
createSimpleObject(java.lang.String value,
java.lang.String type)
Creates an object of a simple type, having the given value.
|
protected void |
error(java.lang.String message)
Reports an IllegalArgumentException during object creation.
|
protected java.lang.String |
makeEntityId(java.lang.String type)
Try to synthesise an Entity ID in cases where these are manufactured.
|
protected int |
safeIndexOf(java.lang.String string,
char separator,
int startIndex)
Finds the first index of a separator in a String, starting from a
given index, while respecting bracketed structures.
|
protected java.util.List<java.lang.String> |
safeSplit(java.lang.String string,
java.lang.String regex)
Safe search routine to split a value-string containing recursively
embedded value-strings.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createObject
protected void error(java.lang.String message) throws java.lang.IllegalArgumentException
message
- the error message.java.lang.IllegalArgumentException
- always.protected int safeIndexOf(java.lang.String string, char separator, int startIndex)
string
- the String to search.separator
- the separator character.startIndex
- the index at which to start searching.protected java.util.List<java.lang.String> safeSplit(java.lang.String string, java.lang.String regex)
string
- the multi-part value, as a String, not bracketed.regex
- the separator pattern.protected java.lang.String makeEntityId(java.lang.String type)
type
- the type name of the Entity.public <T> T create(java.lang.String value, java.lang.String type)
protected java.lang.Object createDefaultObject(java.lang.String type)
type
- the type as a String.protected java.lang.Object createSimpleObject(java.lang.String value, java.lang.String type)
value
- the value, as a String.type
- the type, as a String.protected abstract java.lang.Object createExternalObject(java.lang.String value, java.lang.String type)
value
- an identifier String.type
- an external type, as a String.protected java.util.List<java.lang.Object> createListObject(java.lang.String value, java.util.List<java.lang.String> params)
value
- the list-value, as a String.params
- the generic List type parameters.protected java.util.Set<java.lang.Object> createSetObject(java.lang.String value, java.util.List<java.lang.String> params)
value
- the set-value, as a String.params
- the generic Set type parameters.protected java.util.Map<java.lang.Object,java.lang.Object> createMapObject(java.lang.String value, java.util.List<java.lang.String> params)
value
- the map-value, as a String.params
- the generic Map type parameters.protected java.util.Map.Entry<java.lang.Object,java.lang.Object> createPairObject(java.lang.String value, java.util.List<java.lang.String> params)
value
- the pair-value, as a String.params
- the generic Entry type parameters.