00001 /* 00002 * Codecs.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_CODECS_HPP 00017 #define COH_CODECS_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/pof/PofReader.hpp" 00022 #include "coherence/io/pof/PofWriter.hpp" 00023 #include "coherence/io/pof/reflect/Codec.hpp" 00024 00025 COH_OPEN_NAMESPACE4(coherence,io,pof,reflect) 00026 00027 using coherence::io::pof::PofReader; 00028 using coherence::io::pof::PofWriter; 00029 00030 /** 00031 * Codecs is a container for accessing default Codec implementations. 00032 * 00033 * @author hr 2011.06.29 00034 * 00035 * @since 3.7.1 00036 */ 00037 class COH_EXPORT Codecs 00038 : public extends<Object> 00039 { 00040 // ----- factory methods ------------------------------------------------ 00041 00042 public: 00043 /** 00044 * Based on the Class::View provided either instantiate if it 00045 * is unknown or use a default codec. 00046 * 00047 * @param vClz the class defining the codec to use or the type the 00048 * codec should handle 00049 * 00050 * @return codec that supports encoding and decoding of objects 00051 * of the specified type 00052 */ 00053 static Codec::View getCodec(Class::View vClz); 00054 00055 // ----- inner class: AbstractCodec ------------------------------------- 00056 00057 public: 00058 /** 00059 * Abstract Codec implementations that encodes objects by simply 00060 * delegating to PofWriter::writeObject. Generally the default 00061 * writeObject implementation does not need to be modified as the 00062 * current accommodation of types and conversion to POF is generally 00063 * accepted, with the deserialization being more likely to be 00064 * specific. 00065 * 00066 * @author hr 2011.06.29 00067 * 00068 * @since 3.7.1 00069 */ 00070 class COH_EXPORT AbstractCodec 00071 : public abstract_spec<AbstractCodec, 00072 extends<Object>, 00073 implements<Codec> > 00074 { 00075 // ----- Codec interface ---------------------------------------- 00076 00077 public: 00078 /** 00079 * {@inheritDoc} 00080 */ 00081 virtual void encode(PofWriter::Handle hOut, int32_t nIndex, Object::View v) const; 00082 }; 00083 00084 // ----- inner class: DefaultCodec -------------------------------------- 00085 00086 public: 00087 /** 00088 * Implementation of Codec that simply delegates to 00089 * PofReader::readObject and PofWriter::writeObject to deserialize and 00090 * serialize an object. 00091 * 00092 * @author hr 2011.06.29 00093 * 00094 * @since 3.7.1 00095 */ 00096 class COH_EXPORT DefaultCodec 00097 : public class_spec<DefaultCodec, 00098 extends<AbstractCodec> > 00099 { 00100 friend class factory<DefaultCodec>; 00101 00102 // ----- Codec interface ---------------------------------------- 00103 00104 public: 00105 /** 00106 * {@inheritDoc} 00107 */ 00108 virtual Object::Holder decode(PofReader::Handle hIn, int32_t nIndex) const; 00109 }; 00110 00111 // ----- constants ------------------------------------------------------ 00112 00113 public: 00114 /** 00115 * Returns a singleton instance of a Codecs::DefaultCodec. 00116 * 00117 * @return Codecs::DefaultCodec 00118 */ 00119 static Codec::View getDefault(); 00120 }; 00121 00122 COH_CLOSE_NAMESPACE4 00123 00124 #endif /* COH_CODECS_HPP */