Package de.fmui.osb.broker.objects
Class AbstractOpenServiceBrokerObject
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<java.lang.String,java.lang.Object>
-
- de.fmui.osb.broker.internal.json.JSONObjectImpl
-
- de.fmui.osb.broker.objects.AbstractOpenServiceBrokerObject
-
- All Implemented Interfaces:
JSONAware
,JSONObject
,JSONStreamAware
,Validatable
,java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.String,java.lang.Object>
- Direct Known Subclasses:
BindingLastOperationResponseBody
,BindRequestBody
,BindResource
,BindResponseBody
,CatalogResponseBody
,Context
,Credentials
,DashboardClient
,DeprovisionResponseBody
,Device
,FetchBindingResponseBody
,FetchInstanceResponseBody
,InstanceLastOperationResponseBody
,Parameters
,Plan
,PlanMetadata
,PreviousValues
,ProvisionRequestBody
,ProvisionResponseBody
,Schema
,SchemaParameters
,Schemas
,Service
,ServiceBindingSchema
,ServiceInstanceSchema
,ServiceMetadata
,UnbindResponseBody
,UpdateServiceInstanceRequestBody
,UpdateServiceInstanceResponseBody
,VolumeMount
public abstract class AbstractOpenServiceBrokerObject extends de.fmui.osb.broker.internal.json.JSONObjectImpl implements Validatable
Base class for all Open Service Broker objects.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractOpenServiceBrokerObject()
Default constructor.AbstractOpenServiceBrokerObject(java.util.Map<java.lang.String,java.lang.Object> m)
Constructor with initial values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> JSONArray<T>
addToArray(java.lang.String key, java.lang.Class<T> clazz, T[] values)
Adds elements to an array.<T> JSONArray<T>
createArray(java.lang.String key, java.lang.Class<T> clazz)
Creates and adds a new array.<T> JSONArray<T>
createArray(java.lang.String key, java.lang.Class<T> clazz, T[] values)
Creates, fills, and adds a new array.JSONObject
createObject(java.lang.String key)
Creates and adds a new object.<T> T
get(java.lang.String key, java.lang.Class<T> clazz)
Gets and casts a value of a field.<T> JSONArray<T>
getArray(java.lang.String key, java.lang.Class<T> clazz)
Gets an array and check if all elements are of the given class.java.lang.Boolean
getBoolean(java.lang.String key)
Gets and casts a value of a field to a Boolean.JSONObject
getJSONObject(java.lang.String key)
Gets and casts a value of a field to aJSONObject
.java.lang.Long
getNumber(java.lang.String key)
Gets and casts a value of a field to a Long.java.lang.String
getString(java.lang.String key)
Gets and casts a value of a field to a String.boolean
isNullOrEmpty(java.lang.String key)
Checks if a field value exists, isnull
, is empty string, or an empty list.boolean
isValidID(java.lang.String key)
Checks if a field value is valid ID as defined in the OSBAPI specification.boolean
isValidName(java.lang.String key)
Checks if a field value is valid CLI name as defined in the OSBAPI specification.void
load(java.io.Reader in)
Loads a JSON into this object.void
load(java.lang.String json)
Loads a JSON into this object.void
validate()
Check if the object and its subobjects are in valid state.protected void
validateSubobjects()
Walks through all fields in this object and validates their values.-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
-
Methods inherited from class de.fmui.osb.broker.internal.json.JSONObjectImpl
addJSONString, escape, put, toJSONString, toJSONString, toString, toString, writeJSONString, writeJSONString
-
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
-
-
-
-
Constructor Detail
-
AbstractOpenServiceBrokerObject
public AbstractOpenServiceBrokerObject()
Default constructor.
-
AbstractOpenServiceBrokerObject
public AbstractOpenServiceBrokerObject(java.util.Map<java.lang.String,java.lang.Object> m)
Constructor with initial values.- Parameters:
m
- a map containing the initial values of this object- Throws:
java.lang.NullPointerException
- if the specified map isnull
-
-
Method Detail
-
createObject
public JSONObject createObject(java.lang.String key)
Creates and adds a new object.- Parameters:
key
- the key of the new object- Returns:
- the newly created object
-
createArray
public <T> JSONArray<T> createArray(java.lang.String key, java.lang.Class<T> clazz)
Creates and adds a new array.- Type Parameters:
T
- the type of the array elements- Parameters:
key
- the key of the new arrayclazz
- the class of the elements of the array- Returns:
- the newly created array
-
createArray
public <T> JSONArray<T> createArray(java.lang.String key, java.lang.Class<T> clazz, T[] values)
Creates, fills, and adds a new array.- Type Parameters:
T
- the type of the array elements- Parameters:
key
- the key of the new arrayclazz
- the class of the elements of the arrayvalues
- initial values of the array- Returns:
- the newly created array
-
addToArray
public <T> JSONArray<T> addToArray(java.lang.String key, java.lang.Class<T> clazz, T[] values)
Adds elements to an array. If the array doesn't exist, it will be created.- Type Parameters:
T
- the type of the array elements- Parameters:
key
- the key of the new arrayclazz
- the class of the elements of the arrayvalues
- the values to add- Returns:
- the updated or created array
-
get
public <T> T get(java.lang.String key, java.lang.Class<T> clazz)
Gets and casts a value of a field.- Type Parameters:
T
- the type of the value- Parameters:
key
- the field keyclazz
- the expected class of the value- Returns:
- the value
-
getArray
public <T> JSONArray<T> getArray(java.lang.String key, java.lang.Class<T> clazz)
Gets an array and check if all elements are of the given class.- Type Parameters:
T
- the type of the array elements- Parameters:
key
- the field keyclazz
- the expected class of the elements in the array- Returns:
- the array
-
getString
public java.lang.String getString(java.lang.String key)
Gets and casts a value of a field to a String.- Parameters:
key
- the field key- Returns:
- the value
-
getNumber
public java.lang.Long getNumber(java.lang.String key)
Gets and casts a value of a field to a Long.- Parameters:
key
- the field key- Returns:
- the value
-
getBoolean
public java.lang.Boolean getBoolean(java.lang.String key)
Gets and casts a value of a field to a Boolean.- Parameters:
key
- the field key- Returns:
- the value
-
getJSONObject
public JSONObject getJSONObject(java.lang.String key)
Gets and casts a value of a field to aJSONObject
.- Parameters:
key
- the field key- Returns:
- the JSON object
-
isNullOrEmpty
public boolean isNullOrEmpty(java.lang.String key)
Checks if a field value exists, isnull
, is empty string, or an empty list.- Parameters:
key
- the field key- Returns:
true
if the field does not exist, its value isnull
or an empty string or an empty list,false
otherwise
-
isValidName
public boolean isValidName(java.lang.String key)
Checks if a field value is valid CLI name as defined in the OSBAPI specification.- Parameters:
key
- the field key- Returns:
true
if the field exists, its value is string, and the string is a valid CLI name,false
otherwise
-
isValidID
public boolean isValidID(java.lang.String key)
Checks if a field value is valid ID as defined in the OSBAPI specification.- Parameters:
key
- the field key- Returns:
true
if the field exists, its value is string, and the string is a valid ID,false
otherwise
-
validate
public void validate() throws ValidationException
Description copied from interface:Validatable
Check if the object and its subobjects are in valid state.- Specified by:
validate
in interfaceValidatable
- Throws:
ValidationException
- if the object is not in an valid state
-
validateSubobjects
protected void validateSubobjects() throws ValidationException
Walks through all fields in this object and validates their values.- Throws:
ValidationException
- if a validation fails
-
load
public void load(java.io.Reader in) throws java.io.IOException
Loads a JSON into this object.- Parameters:
in
- the reader providing the JSON- Throws:
java.io.IOException
- if reading or parsing fails
-
load
public void load(java.lang.String json) throws java.io.IOException
Loads a JSON into this object.- Parameters:
json
- the JSON string- Throws:
java.io.IOException
- if reading or parsing fails
-
-