C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/run/xml/XmlValue.hpp

00001 /*
00002  * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
00003  *
00004  * Licensed under the Universal Permissive License v 1.0 as shown at
00005  * http://oss.oracle.com/licenses/upl.
00006  */
00007 #ifndef COH_XML_VALUE_HPP
00008 #define COH_XML_VALUE_HPP
00009 
00010 #include "coherence/lang.ns"
00011 
00012 #include <ostream>
00013 
00014 COH_OPEN_NAMESPACE3(coherence,run,xml)
00015 
00016 class XmlElement;
00017 
00018 
00019 /**
00020 * An interface for XML element content and element attribute values.
00021 *
00022 * @author tb  2007.12.12
00023 */
00024 class COH_EXPORT XmlValue
00025     : public interface_spec<XmlValue>
00026     {
00027     // ----- XmlValue interface ---------------------------------------------
00028 
00029     public:
00030         /**
00031         * Get the value as a bool.  If the internal value cannot be
00032         * translated into a bool, the supplied default value is
00033         * returned.
00034         *
00035         * @param fDefault  the default return value
00036         *
00037         * @return the value as a bool or the default value
00038         */
00039         virtual bool getBoolean(bool fDefault = false) const = 0;
00040 
00041         /**
00042         * Set the value as a bool.
00043         *
00044         * @param fValue  a new value of type bool
00045         */
00046         virtual void setBoolean(bool fValue) = 0;
00047 
00048         /**
00049         * Get the value as an integer.  If the internal value cannot be
00050         * translated into int32_t, the supplied default value is
00051         * returned.
00052         *
00053         * @param nDefault  the default return value
00054         *
00055         * @return the value as int32_t or the default value
00056         */
00057         virtual int32_t getInt32(int32_t nDefault = 0) const = 0;
00058 
00059         /**
00060         * Set the integer value.
00061         *
00062         * @param nValue  a new value of type int32_t
00063         */
00064         virtual void setInt32(int32_t nValue) = 0;
00065 
00066         /**
00067         * Get the value as a String.  If the internal value cannot be
00068         * translated into a String, the supplied default value is
00069         * returned.
00070         *
00071         * @param vsDefault  the default return value
00072         *
00073         * @return the value as a String or the default value
00074         */
00075         virtual String::View getString(String::View vsDefault = "") const = 0;
00076 
00077         /**
00078         * Set the String value.
00079         *
00080         * @param vsValue  a new value of type String
00081         */
00082         virtual void setString(String::View vsValue) = 0;
00083 
00084         /**
00085         * Get the value as an Object.  The following types are
00086         * supported:
00087         *
00088         * <ul>
00089         * <li>{@link coherence::lang::Boolean}</li>
00090         * <li>{@link coherence::lang::Integer32}</li>
00091         * <li>{@link coherence::lang::String}</li>
00092         * </ul>
00093         *
00094         * It is always legal for an implementation to return the value as a
00095         * String.
00096         *
00097         * @return the value as an Object or NULL if the XmlValue does
00098         *         not have a value; attributes never have a NULL value
00099         */
00100         virtual Object::View getValue() const = 0;
00101 
00102         /**
00103         * Get the parent element of this value.
00104         *
00105         * @return the parent element, or NULL if this value
00106         *         has no parent
00107         */
00108         virtual TypedHandle<XmlElement> getParent() = 0;
00109 
00110         /**
00111         * Get the parent element of this value as a view.
00112         *
00113         * @return the parent element, or NULL if this value
00114         *         has no parent
00115         */
00116         virtual TypedHandle<const XmlElement> getParent() const = 0;
00117 
00118         /**
00119         * Set the parent element of this value. Once set, the parent
00120         * cannot be reset.
00121         *
00122         * @param hElement  the parent element
00123         *
00124         * @throws coherence::lang::IllegalArgumentException
00125         *         if the specified parent is NULL
00126         * @throws coherence::lang::IllegalStateException
00127         *         if the parent is already set
00128         */
00129         virtual void setParent(TypedHandle<XmlElement> hElement) = 0;
00130 
00131         /**
00132         * Determine if the value is empty.
00133         *
00134         * @return true if the value is empty, false otherwise
00135         */
00136         virtual bool isEmpty() const = 0;
00137 
00138         /**
00139         * Determine if this value is an element attribute.
00140         *
00141         * @return true if this value is an element attribute, false
00142         *         otherwise
00143         */
00144         virtual bool isAttribute() const = 0;
00145 
00146         /**
00147         * Determine if this value is an element's content.
00148         *
00149         * @return true if this value is an element's content, false
00150         *         otherwise
00151         */
00152         virtual bool isContent() const = 0;
00153 
00154         /**
00155         * Format the value as XML.
00156         *
00157         * @return the XML formatted string
00158         */
00159         virtual String::View formatValue() const = 0;
00160 
00161         /**
00162         * Write the value as XML.
00163         *
00164         * @param out  an std::ostream to write to
00165         */
00166         COH_INLINE void writeValue(std::ostream& out) const
00167             {
00168             out << formatValue();
00169             }
00170 
00171     // ----- enumerated types useful for implementating this interface ------
00172 
00173     public:
00174         static const int32_t type_boolean    = 1;
00175         static const int32_t type_int        = 2;
00176         static const int32_t type_long       = 3;
00177         static const int32_t type_double     = 4;
00178         static const int32_t type_decimal    = 5;
00179         static const int32_t type_string     = 6;
00180         static const int32_t type_binary     = 7;
00181         static const int32_t type_date       = 8;
00182         static const int32_t type_time       = 9;
00183         static const int32_t type_datetime   = 10;
00184     };
00185 
00186 COH_CLOSE_NAMESPACE3
00187 
00188 #endif // COH_XML_VALUE_HPP
Copyright © 2000, 2025, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.