THRIFT-303. java: Changes to __isset interface
authorBryan Duxbury <bryanduxbury@apache.org>
Sat, 7 Feb 2009 01:08:58 +0000 (01:08 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Sat, 7 Feb 2009 01:08:58 +0000 (01:08 +0000)
This patch makes __isset always private and adds a method per field to set the __isset state when not using the bean-style generator.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@741805 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_java_generator.cc
lib/java/src/org/apache/thrift/TBase.java

index 347a014..cee43ad 100644 (file)
@@ -628,8 +628,8 @@ void t_java_generator::generate_java_struct_definition(ofstream &out,
   if (members.size() > 0) {
     out <<
       endl <<
-      indent() << "public final Isset __isset = new Isset();" << endl <<
-      indent() << "public static final class Isset implements java.io.Serializable {" << endl;
+      indent() << "private final Isset __isset = new Isset();" << endl <<
+      indent() << "private static final class Isset implements java.io.Serializable {" << endl;
     indent_up();
       for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
         indent(out) <<
@@ -1441,6 +1441,14 @@ void t_java_generator::generate_java_bean_boilerplate(ofstream& out,
     indent(out) << "return this.__isset." << field_name << ";" << endl;
     indent_down();
     indent(out) << "}" << endl << endl;
+    
+    if(!bean_style_) {
+      indent(out) << "public void set" << cap_name << get_cap_name("isSet") << "(boolean value) {" << endl;
+      indent_up();
+      indent(out) << "this.__isset." << field_name << " = value;" << endl;
+      indent_down();
+      indent(out) << "}"; 
+    }
   }
 }
 
index ef4e323..bf1dc38 100644 (file)
@@ -28,14 +28,14 @@ public interface TBase extends Cloneable {
    * @param oprot Output protocol
    */
   public void write(TProtocol oprot) throws TException;
-  
+
   /**
    * Check if a field is currently set or unset.
    *
    * @param fieldId The field's id tag as found in the IDL.
    */
   public boolean isSet(int fieldId);
-  
+
   /**
    * Get a field's value by id. Primitive types will be wrapped in the 
    * appropriate "boxed" types.
@@ -43,7 +43,7 @@ public interface TBase extends Cloneable {
    * @param fieldId The field's id tag as found in the IDL.
    */
   public Object getFieldValue(int fieldId);
-  
+
   /**
    * Set a field's value by id. Primitive types must be "boxed" in the 
    * appropriate object wrapper type.