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