public abstract class AbstractBaseComponent extends Object implements IDDMSComponent
In DDMS | 2.0 | 3.0 | 3.1 | 4.0.1/4.1 | 5.0 |
Extensions of this class are generally expected to be immutable, and the underlying XOM element MUST be set before the component is used. It is assumed that after the constructor on a component has been called, the component will be well-formed and valid.
History |
---|
None. |
Nested Elements | |||
---|---|---|---|
|
Attributes | |||
---|---|---|---|
|
Validation Rules | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Modifier and Type | Field and Description |
---|---|
static Map<OutputFormat,String> |
OUTPUT_TEMPLATES |
Modifier | Constructor and Description |
---|---|
protected |
AbstractBaseComponent()
Empty constructor
|
protected |
AbstractBaseComponent(nu.xom.Element element)
Base constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
addDdms40Warning(String component)
Adds a warning about a component which is used in a valid manner, but may cause issues with systems that only
process an earlier DDMS version with the same namespace.
|
protected static void |
addJson(com.google.gson.JsonObject object,
AbstractAttributeGroup value)
Adds an attribute group's JSON object to a JSON object, but only if it is not empty.
|
protected static void |
addJson(com.google.gson.JsonObject object,
AbstractBaseComponent value)
Adds a DMMS component's JSON object to a JSON object.
|
protected static void |
addJson(com.google.gson.JsonObject object,
String name,
List<?> value)
Adds a list of values to a JSON object, but only if it is not empty and not null.
|
protected static void |
addJson(com.google.gson.JsonObject object,
String name,
Object value)
Adds a value to a JSON object, but only if it is not empty and not null.
|
protected void |
addWarning(String text)
Convenience method to create a warning and add it to the list of validation warnings.
|
protected void |
addWarnings(List<ValidationMessage> warnings,
boolean forAttributes)
Convenience method to add multiple warnings to the list of validation warnings.
|
protected String |
buildHTMLTextOutput(OutputFormat format,
String prefix,
List<?> contents)
Convenience method to build a meta tag for HTML output or a text line for Text output for a list of multiple DDMS
components.
|
static String |
buildHTMLTextOutput(OutputFormat format,
String name,
String content)
Convenience method to build a meta tag for HTML output or a text line for Text output.
|
protected String |
buildIndex(int index,
int total)
Constructs a braced 1-based index to differentiate multiples in HTML/Text output, based on the 0-based list index
of the item, and the
output.indexLevel configurable property. |
protected String |
buildPrefix(String prefix,
String token,
String suffix)
Convenience method to construct a naming prefix for use in HTML/Text output
|
boolean |
equals(Object obj)
Test for logical equality.
|
protected String |
getAttributeValue(String name)
Convenience method to look up an attribute which is in the same namespace as the enclosing element
|
protected String |
getAttributeValue(String name,
String namespaceURI)
Convenience method to look up an attribute
|
protected nu.xom.Element |
getChild(String name)
Convenience method to get the first child element with a given name in the same namespace as the parent element
|
protected static Double |
getChildTextAsDouble(nu.xom.Element element,
String name)
Convenience method to convert one of the lat/lon fields into a Double.
|
protected DDMSVersion |
getDDMSVersion()
Returns the most recent compatible DDMSVersion for this component, based on the XML Namespace.
|
abstract String |
getHTMLTextOutput(OutputFormat format,
String prefix,
String suffix)
Renders this component as HTML or Text, with an optional prefix to nest it.
|
abstract com.google.gson.JsonObject |
getJSONObject()
Renders this component as a JSON object, which can either be converted to a JSON string or inserted into the
parent JSON object.
|
protected String |
getLocatorSuffix()
Can be overridden to change the locator string used in warnings and errors.
|
String |
getName()
Will return an empty string if the element is not set, but this cannot occur after instantiation.
|
String |
getNamespace()
Will return an empty string if the element is not set, but this cannot occur after instantiation.
|
protected List<IDDMSComponent> |
getNestedComponents()
Accessor for a collection of nested components.
|
String |
getPrefix()
Will return an empty string if the element is not set, but this cannot occur after instantiation.
|
String |
getQualifiedName()
Will return an empty string if the element is not set, but this cannot occur after instantiation.
|
SecurityAttributes |
getSecurityAttributes()
The base implementation of a DDMS component assumes that there are no security attributes.
|
List<ValidationMessage> |
getValidationWarnings()
Returns a list of any warning messages that occurred during validation.
|
protected nu.xom.Element |
getXOMElement()
Accessor for the XOM element representing this component
|
nu.xom.Element |
getXOMElementCopy()
Accessor for a copy of the underlying XOM element
|
int |
hashCode()
Returns a hashcode for the component.
|
protected void |
requireAtLeastVersion(String version)
Helper method to validate that a specific version of DDMS (or higher) is being used.
|
protected void |
requireAtMostVersion(String version)
Helper method to validate that a specific version of DDMS (or lower) is being used.
|
protected void |
setXOMElement(nu.xom.Element element,
boolean validateNow)
Accessor for the XOM element representing this component.
|
String |
toHTML()
Renders this component as HTML.
|
String |
toJSON()
Renders this component as JSON.
|
String |
toString()
Returns the XML representation of the component
|
String |
toText()
Renders this component as Text.
|
String |
toXML()
Will return an empty string if the name is not set, but this cannot occur after instantiation.
|
protected void |
validate()
Base case for validation.
|
protected void |
validateWarnings()
Base case for warnings.
|
public static final Map<OutputFormat,String> OUTPUT_TEMPLATES
protected AbstractBaseComponent() throws InvalidDDMSException
InvalidDDMSException
protected AbstractBaseComponent(nu.xom.Element element) throws InvalidDDMSException
element
- the XOM element representing this componentInvalidDDMSException
public String getPrefix()
getPrefix
in interface IDDMSComponent
IDDMSComponent.getPrefix()
public String getName()
getName
in interface IDDMSComponent
IDDMSComponent.getName()
public String getNamespace()
getNamespace
in interface IDDMSComponent
IDDMSComponent.getNamespace()
public String getQualifiedName()
getQualifiedName
in interface IDDMSComponent
IDDMSComponent.getQualifiedName()
public SecurityAttributes getSecurityAttributes()
getSecurityAttributes
in interface IDDMSComponent
public List<ValidationMessage> getValidationWarnings()
IDDMSComponent
getValidationWarnings
in interface IDDMSComponent
IDDMSComponent.getValidationWarnings()
protected void validate() throws InvalidDDMSException
InvalidDDMSException
protected void validateWarnings()
protected void addDdms40Warning(String component)
DDMS 4.0 and 4.1 share the same XML namespace, so it is impossible to tell which DDMS version is employed from the XML namespace alone. If an XML instance of a metacard employs a new DDMS 4.1 construct (like the new ntk:Access element in a ddms:metacardInfo element), that XML instance will fail to work in a DDMS 4.0 system.
component
- a text description of the component that is being warned aboutpublic String toHTML()
IDDMSComponent
toHTML
in interface IDDMSComponent
IDDMSComponent.toHTML()
public String toJSON()
IDDMSComponent
output.json.prettyPrint
property to control pretty printing of the
output.toJSON
in interface IDDMSComponent
IDDMSComponent.toJSON()
public String toText()
IDDMSComponent
output.indexLevel
property to add indices to the output.toText
in interface IDDMSComponent
IDDMSComponent.toText()
public abstract com.google.gson.JsonObject getJSONObject()
protected static void addJson(com.google.gson.JsonObject object, String name, Object value)
object
- the object to add toname
- the name of the array, if addedvalue
- the value to addprotected static void addJson(com.google.gson.JsonObject object, String name, List<?> value)
object
- the object to add toname
- the name of the array, if addedvalue
- the value to add, converted into a JSON arrayprotected static void addJson(com.google.gson.JsonObject object, AbstractAttributeGroup value)
object
- the object to add tovalue
- the value to addprotected static void addJson(com.google.gson.JsonObject object, AbstractBaseComponent value)
object
- the object to add tovalue
- the value to addpublic abstract String getHTMLTextOutput(OutputFormat format, String prefix, String suffix)
I consider this to be an internal method, that unfortunately must be marked as public to allow cross-package access when generating output. Use toHTML() and toText() as the formal, public methods to generate output.
format
- the desired format of this outputprefix
- an optional prefix to put on each name.suffix
- an optional suffix to append to each name, such as an index.protected List<IDDMSComponent> getNestedComponents()
public static String buildHTMLTextOutput(OutputFormat format, String name, String content)
format
- the desired format of this outputname
- the name of the name-value pairing (will be escaped in HTML)content
- the value of the name-value pairing (will be escaped in HTML)UnsupportedOperationException
- if the format is not HTML or Text.protected String buildHTMLTextOutput(OutputFormat format, String prefix, List<?> contents)
format
- the desired format of this outputprefix
- the first part of the name in the name-value pairing (will be escaped in HTML)contents
- a list of the values (will be escaped in HTML)UnsupportedOperationException
- if the format is not HTML or Text.protected String buildPrefix(String prefix, String token, String suffix)
prefix
- an optional first part to the prefixtoken
- an optional second part to the prefixsuffix
- an optional third part to the prefixprotected String buildIndex(int index, int total)
output.indexLevel
configurable property. When this property is 0, indices are
never shown. At 1, indices are shown when needed, but hidden when there is only 1 item to display. At 2, indices
are always shown. If the property is set to something else, it defaults to 0.index
- the 0-based index of an item in a listtotal
- the total number of items in that listpublic String toXML()
toXML
in interface IDDMSComponent
IDDMSComponent.toXML()
protected String getAttributeValue(String name)
name
- the local name of the attributeprotected String getAttributeValue(String name, String namespaceURI)
name
- the local name of the attributenamespaceURI
- the namespace of the attributeprotected nu.xom.Element getChild(String name)
name
- the local name to search forprotected static Double getChildTextAsDouble(nu.xom.Element element, String name)
element
- the parent elementname
- the local name of the childprotected void requireAtLeastVersion(String version) throws InvalidDDMSException
version
- the inclusive threshold versionInvalidDDMSException
- if the version is not high enoughprotected void requireAtMostVersion(String version) throws InvalidDDMSException
version
- the inclusive threshold versionInvalidDDMSException
- if the version is too high enoughprotected DDMSVersion getDDMSVersion()
UnsupportedVersionException
- if the XML namespace is not one of the supported DDMS namespaces.public boolean equals(Object obj)
The base case tests against the name value and namespaceURI, as well as any child components classified as "nested components" and any security attributes. Extending classes may require additional rules for equality. This case automatically includes any nested components or security attributes.
equals
in class Object
Object.equals(Object)
public int hashCode()
This automatically includes any nested components or security attributes.
hashCode
in class Object
Object.hashCode()
public String toString()
toString
in class Object
Object.toString()
protected String getLocatorSuffix()
For components such as Format, there are wrapper elements that are not implemented as Java objects. These elements should be included in the XPath string used to identify the source of the error.
For example, if a ddms:extent element has a warning and the ddms:format element reports it, the locator information should be "/ddms:format/ddms:Media/ddms:extent" and not the default of "/ddms:format/ddms:extent"
protected void addWarning(String text)
text
- the description textprotected void addWarnings(List<ValidationMessage> warnings, boolean forAttributes)
Child locator information will be prefixed with the parent (this) locator information. This does not overwrite the original warning -- it creates a new copy.
warnings
- the list of validation messages to addforAttributes
- if true, the locator suffix is not used, because the attributes will be for the topmost
element (for example, warnings for gml:Polygon's security attributes should not end up with a locator of
/gml:Polygon/gml:exterior/gml:LinearRing).protected nu.xom.Element getXOMElement()
public nu.xom.Element getXOMElementCopy()
getXOMElementCopy
in interface IDDMSComponent
protected void setXOMElement(nu.xom.Element element, boolean validateNow) throws InvalidDDMSException
validate
.element
- the XOM element to usevalidateNow
- whether to validate the component immediately after settingInvalidDDMSException
Copyright 2010 - 2019 by Brian Uri!
Generated on 09/15/2016 12:36 PM
https://ddmsence.urizone.net/