Package adams.core
Class NewInstance
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.NewInstance
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Serializable
public class NewInstance extends LoggingObject
For instantiating objects, with or without custom constructor.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
FILENAME
the filename.protected Set<Class>
m_Classes
the classes that have a custom constructor.protected Set<String>
m_Classnames
the classnames that have a custom constructor.protected Map<Class,Constructor>
m_Constructors
the constructors.protected Map<Class,Object[]>
m_DefaultValues
the constructor default values.protected Properties
m_Properties
the placeholders.protected static NewInstance
m_Singleton
the singleton.static String
SUFFIX_TYPE
the suffix for the type.static String
SUFFIX_VALUE
the suffix for the type.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
configure(Class cls)
Configures constructor and default values.static NewInstance
getSingleton()
Returns the singleton instance of the NewInstance.boolean
hasCustomInstantiation(Class cls)
Checks whether the class is registered with a custom instantiation.boolean
hasCustomInstantiation(String classname)
Checks whether the classname is registered with a custom instantiation.protected void
initialize()
loads the props file and interpretes it.static Object
newInstance(Class cls)
Returns a new object instance.static Object
newInstance(Class cls, boolean quiet)
Returns a new object instance.static Object
newInstance(String classname)
Returns a new object instance.static Object
newInstance(String classname, boolean quiet)
Returns a new object instance.Object
newObject(Class cls)
Returns a new object instance.Object
newObject(Class cls, boolean quiet)
Returns a new object instance.Object
newObject(String classname)
Returns a new object instance.Object
newObject(String classname, boolean quiet)
Returns a new object instance.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the filename.- See Also:
- Constant Field Values
-
SUFFIX_TYPE
public static final String SUFFIX_TYPE
the suffix for the type.- See Also:
- Constant Field Values
-
SUFFIX_VALUE
public static final String SUFFIX_VALUE
the suffix for the type.- See Also:
- Constant Field Values
-
m_Singleton
protected static NewInstance m_Singleton
the singleton.
-
m_Properties
protected Properties m_Properties
the placeholders.
-
m_Constructors
protected Map<Class,Constructor> m_Constructors
the constructors.
-
-
Method Detail
-
initialize
protected void initialize()
loads the props file and interpretes it.
-
hasCustomInstantiation
public boolean hasCustomInstantiation(String classname)
Checks whether the classname is registered with a custom instantiation.- Parameters:
classname
- the classname to check- Returns:
- true if custom instantiation
-
hasCustomInstantiation
public boolean hasCustomInstantiation(Class cls)
Checks whether the class is registered with a custom instantiation.- Parameters:
cls
- the class to check- Returns:
- true if custom instantiation
-
newObject
public Object newObject(String classname)
Returns a new object instance.- Parameters:
classname
- the class to instantiate- Returns:
- the instance, null if failed to instantiate
-
newObject
public Object newObject(String classname, boolean quiet)
Returns a new object instance.- Parameters:
classname
- the class to instantiatequiet
- whether to suppress error messages- Returns:
- the instance, null if failed to instantiate
-
configure
protected boolean configure(Class cls) throws Exception
Configures constructor and default values.- Parameters:
cls
- the class to configure- Returns:
- true if successfully configured (or already present)
- Throws:
Exception
- if configuration fails (eg instantiating a custom class)
-
newObject
public Object newObject(Class cls)
Returns a new object instance.- Parameters:
cls
- the class to instantiate- Returns:
- the instance, null if failed to instantiate
-
newObject
public Object newObject(Class cls, boolean quiet)
Returns a new object instance.- Parameters:
cls
- the class to instantiatequiet
- whether to suppress error messages- Returns:
- the instance, null if failed to instantiate
-
getSingleton
public static NewInstance getSingleton()
Returns the singleton instance of the NewInstance.- Returns:
- the singleton
-
newInstance
public static Object newInstance(String classname)
Returns a new object instance.- Parameters:
classname
- the class to instantiate- Returns:
- the instance, null if failed to instantiate
-
newInstance
public static Object newInstance(String classname, boolean quiet)
Returns a new object instance.- Parameters:
classname
- the class to instantiatequiet
- whether to suppress error messages- Returns:
- the instance, null if failed to instantiate
-
newInstance
public static Object newInstance(Class cls)
Returns a new object instance.- Parameters:
cls
- the class to instantiate- Returns:
- the instance, null if failed to instantiate
-
-