Package ca.uhn.hl7v2.model
Class AbstractPrimitive
java.lang.Object
ca.uhn.hl7v2.model.AbstractType
ca.uhn.hl7v2.model.AbstractPrimitive
- All Implemented Interfaces:
Primitive,Type,Visitable,Serializable
- Direct Known Subclasses:
AbstractTextPrimitive,DT,GenericPrimitive,NULLDT,TM,TSComponentOne
Base class for Primitives. Performs validation in setValue().
- Author:
- Bryan Tripp
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(MessageVisitor visitor, Location location) Callback method for the visitor.voidclear()Clears all data from this typeencode()Encodes this type using HL7 encoding.getValue()Returns a String representation of the value of this field.booleanisEmpty()Returns true if this Visitable has actual contentvoidParses the string into this type and replaces the current contents with the parsed value.voidSets the value of this Primitive, first performing validation as specified bygetMessage().getValidationContext().toString()Returns the value of getValue()Methods inherited from class ca.uhn.hl7v2.model.AbstractType
getExtraComponents, getMessage, getName, provideLocationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ca.uhn.hl7v2.model.Type
getExtraComponents, getMessage, getNameMethods inherited from interface ca.uhn.hl7v2.model.Visitable
provideLocation
-
Constructor Details
-
AbstractPrimitive
- Parameters:
message- message to which this type belongs
-
-
Method Details
-
toString
Returns the value of getValue()- Overrides:
toStringin classAbstractType- See Also:
-
getValue
Description copied from interface:PrimitiveReturns a String representation of the value of this field. -
setValue
Sets the value of this Primitive, first performing validation as specified bygetMessage().getValidationContext(). No validation is performed if getMessage() returns null.Note: as of the next HAPI release, the ValidationContext will be retrieved from getParser().getValidationContext(), which ultimately is the ValidationContext of the active HapiContext.
- Specified by:
setValuein interfacePrimitive- Parameters:
theValue- the value to be set- Throws:
DataTypeException- if the given value is not valid in this context.- See Also:
-
encode
Encodes this type using HL7 encoding.- Specified by:
encodein interfaceType- Overrides:
encodein classAbstractType- Returns:
- the encoded message
- Throws:
HL7Exception- if errors occurred while encoding
-
parse
Parses the string into this type and replaces the current contents with the parsed value. This method accepts HL7 encoded text and treats its input as such.
Note that this method is subtly different from calling
Primitive.setValue(String), but can be quite powerful. For example, using the argument of "milk&cookies" on an ST datatype:-
If you are using
Primitive.setValue(String), the ampersand is treated as an actual ampersand in the text, and the field will be treated as a single field which is encoded as "milk\T\cookies" (\T\ is the escape sequence for the subcomponent delimiter). - If you are using parse(String), the ampersand is treated as a subcomponent delimiter, meaning that the value is set to "milk", and a second component is added with the value of "cookies".
This method makes use of the parser which is stored within the enclosing
Message. At this time, only PipeParsers are supported.- Specified by:
parsein interfaceType- Overrides:
parsein classAbstractType- Parameters:
string- the message to be parsed- Throws:
HL7Exception- if errors occurred while parsing
-
If you are using
-
clear
Clears all data from this type- Specified by:
clearin interfaceType- Overrides:
clearin classAbstractType
-
isEmpty
Description copied from class:AbstractTypeReturns true if this Visitable has actual content- Specified by:
isEmptyin interfaceVisitable- Overrides:
isEmptyin classAbstractType- Returns:
- true if Visitable is empty
- Throws:
HL7Exception- if an error occurred while determining emptiness
-
accept
Description copied from interface:VisitableCallback method for the visitor. This method is supposed to either directly call one of the visitors methods, passingthisas parameter, or traverse through a hierarchical substructure and call accept(MessageVisitor) for each visited element.- Specified by:
acceptin interfaceVisitable- Parameters:
visitor- MessageVisitor instance to be called backlocation- location of this object- Returns:
trueif the visit process shall continue- Throws:
HL7Exception- if a problem occurred during visiting
-