Package org.bedework.jsforj.impl.values
Class JSValueImpl
- java.lang.Object
-
- org.bedework.jsforj.impl.values.JSValueImpl
-
- All Implemented Interfaces:
JSValue
- Direct Known Subclasses:
JSAbsoluteTriggerImpl,JSAlertImpl,JSArrayImpl,JSBooleanImpl,JSCalendarObjectImpl,JSDurationImpl,JSIntegerImpl,JSLinkImpl,JSListImpl,JSLocalDateTimeImpl,JSLocationImpl,JSMapImpl,JSNullImpl,JSOffsetTriggerImpl,JSParticipantImpl,JSRecurrenceRuleImpl,JSRelationImpl,JSSignedDurationImpl,JSStringImpl,JSTimeZoneImpl,JSTimeZoneRuleImpl,JSTriggerImpl,JSUnknownTriggerImpl,JSUnknownTypeImpl,JSUnsignedIntegerImpl,JSUTCDateTimeImpl,JSVirtualLocationImpl
public abstract class JSValueImpl extends Object implements JSValue
User: mike Date: 10/24/19 Time: 10:35 Provides a view of the current json node and allows updates to that node.When handling overrides we interact with the masterCopy. However the original node is still attached to the parent so will be output when serializing the object.
When we update an override we need to update the original node with the appropriate patches.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJSValueImpl()Only used for proxies.JSValueImpl(String type, com.fasterxml.jackson.databind.JsonNode node)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertArray(String action)protected voidassertBooleanNode()protected voidassertIntNode()protected voidassertObject(String action)protected voidassertStringNode()voidclear()Remove all contained properties and valuesbooleanequals(Object o)booleangetBooleanProperty(String name)Returns value of named boolean property.booleangetBooleanValue()Returns value as a boolean.booleangetChanged()protected JSFactorygetFactory()com.fasterxml.jackson.databind.JsonNodegetNode()StringgetObjectType()booleangetOverrideGenerated()JSValuegetOwner()JSProperty<?>getParentProperty()List<JSProperty<?>>getProperties()Return all contained properties<T extends JSValue>
JSProperty<T>getProperty(com.fasterxml.jackson.core.type.TypeReference<T> type, String name)Return named propertyJSProperty<?>getProperty(String name)Return named propertyJSValuegetPropertyValue(String name)Get the value.StringgetStringProperty(String name)Returns value of named String property.StringgetStringValue()Returns value as a String.StringgetType()JSUnsignedIntegergetUnsignedIntegerProperty(String name)Returns value of named UnsignedInteger property.<T extends JSValue>
TgetValue(com.fasterxml.jackson.core.type.TypeReference<T> type, String pname, boolean create)Returns a value of the desired type and adds as a sub-property of this value.booleanhasChanges()booleanhasProperty(String propertyName)booleanisString()<T extends JSValue>
JSProperty<T>makeProperty(com.fasterxml.jackson.core.type.TypeReference<T> typeRef, String name, String type)Add a property of given type.protected JSProperty<?>makeProperty(String name, com.fasterxml.jackson.databind.JsonNode node)voidmarkOverrideGenerated()Flags this value is being generated for overrides.<T extends JSValue>
JSProperty<T>newProperty(com.fasterxml.jackson.core.type.TypeReference<T> typeRef, String name, String type)Create a property of the given type.voidpreWrite()Called before we output the object.voidremoveProperty(String name)Remove named property throws JsforjException if not an objectprotected voidsetMasterCopy(com.fasterxml.jackson.databind.JsonNode copyNode)voidsetOwner(JSValue val)The owner is the value containing this value.voidsetParentProperty(JSProperty<?> val)The owner is the property containing the value.JSProperty<?>setProperty(String name, boolean val)Set the value for a boolean type propertyJSProperty<?>setProperty(String name, Integer val)Set the value for an UnsignedInteger type propertyJSProperty<JSString>setProperty(String name, String val)Set the value for a string type propertyJSProperty<?>setProperty(String name, JSValue val)Set the value for an JSValue type property<ValType extends JSValue>
JSProperty<ValType>setProperty(JSProperty<ValType> val)Add or replace the named propertyvoidwriteValue(Writer wtr, com.fasterxml.jackson.databind.ObjectMapper mapper)Convert to json with this as rootStringwriteValueAsString(com.fasterxml.jackson.databind.ObjectMapper mapper)Convert to json with this as rootStringwriteValueAsStringFormatted(com.fasterxml.jackson.databind.ObjectMapper mapper)Convert to formatted json with this as root
-
-
-
Constructor Detail
-
JSValueImpl
public JSValueImpl(String type, com.fasterxml.jackson.databind.JsonNode node)
-
JSValueImpl
protected JSValueImpl()
Only used for proxies.
-
-
Method Detail
-
getObjectType
public String getObjectType()
- Specified by:
getObjectTypein interfaceJSValue- Returns:
- type passed to constructor
-
getNode
public com.fasterxml.jackson.databind.JsonNode getNode()
-
preWrite
public void preWrite()
Description copied from interface:JSValueCalled before we output the object. Objects MUST call all children to allow any processing before output - e.g. generate patches.
-
getFactory
protected JSFactory getFactory()
-
setOwner
public void setOwner(JSValue val)
The owner is the value containing this value.- Parameters:
val- the owner of this value
-
getOwner
public JSValue getOwner()
-
setParentProperty
public void setParentProperty(JSProperty<?> val)
The owner is the property containing the value.- Parameters:
val- the property containing the value
-
getParentProperty
public JSProperty<?> getParentProperty()
- Specified by:
getParentPropertyin interfaceJSValue- Returns:
- property containing this value.
-
getChanged
public boolean getChanged()
- Specified by:
getChangedin interfaceJSValue- Returns:
- true if this value was changed - i.e a value was changed or a sub-property added or removed.
-
markOverrideGenerated
public void markOverrideGenerated()
Description copied from interface:JSValueFlags this value is being generated for overrides. Will be skipped when generating patches.- Specified by:
markOverrideGeneratedin interfaceJSValue
-
getOverrideGenerated
public boolean getOverrideGenerated()
- Specified by:
getOverrideGeneratedin interfaceJSValue- Returns:
- true if this is generated for overrides.
-
hasChanges
public boolean hasChanges()
- Specified by:
hasChangesin interfaceJSValue- Returns:
- true if this or any sub-value was changed.
-
setMasterCopy
protected void setMasterCopy(com.fasterxml.jackson.databind.JsonNode copyNode)
-
getType
public String getType()
-
hasProperty
public boolean hasProperty(String propertyName)
- Specified by:
hasPropertyin interfaceJSValue- Parameters:
propertyName- to test for- Returns:
- true if value contains named property
-
getProperties
public List<JSProperty<?>> getProperties()
Description copied from interface:JSValueReturn all contained properties- Specified by:
getPropertiesin interfaceJSValue- Returns:
- properties throws JsforjException if not an object
-
getProperty
public <T extends JSValue> JSProperty<T> getProperty(com.fasterxml.jackson.core.type.TypeReference<T> type, String name)
Description copied from interface:JSValueReturn named property- Specified by:
getPropertyin interfaceJSValue- Parameters:
type- expected typename- of property- Returns:
- property or null throws JsforjException if not an object
-
getProperty
public JSProperty<?> getProperty(String name)
Description copied from interface:JSValueReturn named property- Specified by:
getPropertyin interfaceJSValue- Parameters:
name- of property- Returns:
- property or null throws JsforjException if not an object
-
getPropertyValue
public JSValue getPropertyValue(String name)
Description copied from interface:JSValueGet the value. Return null if absent.- Specified by:
getPropertyValuein interfaceJSValue- Parameters:
name- of property- Returns:
- the value or null
-
getStringProperty
public String getStringProperty(String name)
Description copied from interface:JSValueReturns value of named String property.- Specified by:
getStringPropertyin interfaceJSValue- Parameters:
name- the property name - non null- Returns:
- the value of the property throws JsforjException if not a String property
-
getBooleanProperty
public boolean getBooleanProperty(String name)
Description copied from interface:JSValueReturns value of named boolean property.- Specified by:
getBooleanPropertyin interfaceJSValue- Parameters:
name- the property name - non null- Returns:
- the value of the property - false if absent throws JsforjException if not a boolean property
-
isString
public boolean isString()
-
getUnsignedIntegerProperty
public JSUnsignedInteger getUnsignedIntegerProperty(String name)
Description copied from interface:JSValueReturns value of named UnsignedInteger property.- Specified by:
getUnsignedIntegerPropertyin interfaceJSValue- Parameters:
name- the property name - non null- Returns:
- the value of the property throws JsforjException if not a String property
-
getStringValue
public String getStringValue()
Description copied from interface:JSValueReturns value as a String.- Specified by:
getStringValuein interfaceJSValue- Returns:
- the value of the property throws JsforjException if not a String property
-
getBooleanValue
public boolean getBooleanValue()
Description copied from interface:JSValueReturns value as a boolean.- Specified by:
getBooleanValuein interfaceJSValue- Returns:
- the value of the property throws JsforjException if not a boolean property
-
getValue
public <T extends JSValue> T getValue(com.fasterxml.jackson.core.type.TypeReference<T> type, String pname, boolean create)
Description copied from interface:JSValueReturns a value of the desired type and adds as a sub-property of this value.
-
writeValue
public void writeValue(Writer wtr, com.fasterxml.jackson.databind.ObjectMapper mapper)
Description copied from interface:JSValueConvert to json with this as root- Specified by:
writeValuein interfaceJSValue- Parameters:
wtr- to write tomapper- to convert
-
writeValueAsString
public String writeValueAsString(com.fasterxml.jackson.databind.ObjectMapper mapper)
Description copied from interface:JSValueConvert to json with this as root- Specified by:
writeValueAsStringin interfaceJSValue- Parameters:
mapper- to convert- Returns:
- Json
-
writeValueAsStringFormatted
public String writeValueAsStringFormatted(com.fasterxml.jackson.databind.ObjectMapper mapper)
Description copied from interface:JSValueConvert to formatted json with this as root- Specified by:
writeValueAsStringFormattedin interfaceJSValue- Parameters:
mapper- to convert- Returns:
- Json
-
newProperty
public <T extends JSValue> JSProperty<T> newProperty(com.fasterxml.jackson.core.type.TypeReference<T> typeRef, String name, String type)
Description copied from interface:JSValueCreate a property of the given type. NOT added or set- Specified by:
newPropertyin interfaceJSValuename- the property name - non nulltype- the property type- Returns:
- the property throws JsforjException if property already exists
-
removeProperty
public void removeProperty(String name)
Description copied from interface:JSValueRemove named property throws JsforjException if not an object- Specified by:
removePropertyin interfaceJSValue
-
clear
public void clear()
Description copied from interface:JSValueRemove all contained properties and values
-
setProperty
public <ValType extends JSValue> JSProperty<ValType> setProperty(JSProperty<ValType> val)
Description copied from interface:JSValueAdd or replace the named property- Specified by:
setPropertyin interfaceJSValue- Parameters:
val- the property - non null- Returns:
- the property
-
setProperty
public JSProperty<JSString> setProperty(String name, String val)
Description copied from interface:JSValueSet the value for a string type property- Specified by:
setPropertyin interfaceJSValue- Parameters:
name- the property name - non nullval- the property value - non null- Returns:
- the property
-
setProperty
public JSProperty<?> setProperty(String name, JSValue val)
Description copied from interface:JSValueSet the value for an JSValue type property- Specified by:
setPropertyin interfaceJSValue- Parameters:
name- the property name - non nullval- the property value - non null- Returns:
- the property
-
setProperty
public JSProperty<?> setProperty(String name, Integer val)
Description copied from interface:JSValueSet the value for an UnsignedInteger type property- Specified by:
setPropertyin interfaceJSValue- Parameters:
name- the property name - non nullval- the property value - non null- Returns:
- the property
-
setProperty
public JSProperty<?> setProperty(String name, boolean val)
Description copied from interface:JSValueSet the value for a boolean type property- Specified by:
setPropertyin interfaceJSValue- Parameters:
name- the property name - non nullval- the property value- Returns:
- the property
-
makeProperty
public <T extends JSValue> JSProperty<T> makeProperty(com.fasterxml.jackson.core.type.TypeReference<T> typeRef, String name, String type)
Description copied from interface:JSValueAdd a property of given type.- Specified by:
makePropertyin interfaceJSValuename- the property name - non nulltype- the property type- Returns:
- the property throws JsforjException if property already exists
-
makeProperty
protected JSProperty<?> makeProperty(String name, com.fasterxml.jackson.databind.JsonNode node)
-
assertStringNode
protected void assertStringNode()
-
assertIntNode
protected void assertIntNode()
-
assertBooleanNode
protected void assertBooleanNode()
-
assertObject
protected void assertObject(String action)
-
assertArray
protected void assertArray(String action)
-
-