protected void generateFile(PrintWriter out) throws Exception {
ArrayList<JProperty> properties = new ArrayList<JProperty>();
jclass.getDeclaredProperties();
for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
JProperty p = jclass.getDeclaredProperties()[i];
if (isValidProperty(p)) {
properties.add(p);
}
}
String name = jclass.getSimpleName();
String type = ("ow_" + name).toUpperCase() + "_TYPE";
String baseName = "DataStructure";
JClass superclass = jclass.getSuperclass();
while (superclass.getSuperclass() != null) {
if (sortedClasses.contains(superclass)) {
baseName = superclass.getSimpleName();
break;
} else {
superclass = superclass.getSuperclass();
}
}
out.println("ow_boolean ow_is_a_" + name + "(ow_DataStructure *object) {");
out.println(" if( object == 0 )");
out.println(" return 0;");
out.println(" ");
out.println(" switch(object->structType) {");
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
JClass sub = (JClass)iterator.next();
String subtype = "OW_" + sub.getSimpleName().toUpperCase() + "_TYPE";
if (jclass.isAssignableFrom(sub) && !isAbstract(sub)) {
out.println("");
out.println(" case " + subtype + ":");
}
}
out.println("");
out.println(" return 1;");
out.println(" }");
out.println(" return 0;");
out.println("}");
if (!isAbstract(jclass)) {
out.println("");
out.println("");
out.println("ow_" + name + " *ow_" + name + "_create(apr_pool_t *pool) ");
out.println("{");
out.println(" ow_" + name + " *value = apr_pcalloc(pool,sizeof(ow_" + name + "));");
out.println(" if( value!=0 ) {");
out.println(" ((ow_DataStructure*)value)->structType = " + type + ";");
out.println(" }");
out.println(" return value;");
out.println("}");
}
out.println("");
out.println("");
out.println("apr_status_t ow_marshal1_" + name + "(ow_bit_buffer *buffer, ow_" + name + " *object)");
out.println("{");
out.println(" ow_marshal1_" + baseName + "(buffer, (ow_" + baseName + "*)object);");
for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
JProperty property = iter.next();
String propname = toPropertyCase(property.getSimpleName());
boolean cached = isCachedProperty(property);
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
JAnnotationValue size = annotation.getValue("size");
type = property.getType().getQualifiedName();
if (type.equals("boolean")) {
out.println(" ow_bit_buffer_append(buffer, object->" + propname + ");");
} else if (type.equals("byte")) {
} else if (type.equals("char")) {
} else if (type.equals("short")) {
} else if (type.equals("int")) {
} else if (type.equals("long")) {
out.println(" ow_marshal1_long(buffer, object->" + propname + ");");
} else if (type.equals("byte[]")) {
if (size == null) {
out.println(" ow_bit_buffer_append(buffer, object->" + propname + "!=0 );");
}
} else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
if (size == null) {
out.println(" ow_bit_buffer_append(buffer, object->" + propname + "!=0 );");
}
} else if (type.equals("java.lang.String")) {
out.println(" ow_marshal1_string(buffer, object->" + propname + ");");
} else {
if (property.getType().isArrayType()) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
} else {
out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->" + propname + "));");
}
} else if (isThrowable(property.getType())) {
out.println(" SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->" + propname + "));");
} else {
if (cached) {
out.println(" SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->" + propname + "));");
} else {
out.println(" SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->" + propname + "));");
}
}
}
out.println("");
}
out.println(" ");
out.println(" return APR_SUCCESS;");
out.println("}");
out.println("apr_status_t ow_marshal2_" + name + "(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_" + name + " *object)");
out.println("{");
out.println(" ow_marshal2_" + baseName + "(buffer, bitbuffer, (ow_" + baseName + "*)object); ");
for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
JProperty property = iter.next();
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
JAnnotationValue size = annotation.getValue("size");
Object propname = toPropertyCase(property.getSimpleName());
boolean cached = isCachedProperty(property);
type = property.getType().getQualifiedName();
if (type.equals("boolean")) {
out.println(" ow_bit_buffer_read(bitbuffer);");
} else if (type.equals("byte")) {
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
} else if (type.equals("char")) {
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
} else if (type.equals("short")) {
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
} else if (type.equals("int")) {
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
} else if (type.equals("long")) {
out.println(" SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->" + propname + "));");
} else if (type.equals("byte[]")) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
} else {
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->" + propname + "));");
}
} else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
} else {
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->" + propname + "));");
}
} else if (type.equals("java.lang.String")) {
out.println(" SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->" + propname + "));");
} else {
if (property.getType().isArrayType()) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->" + propname + ", " + size.asInt() + "));");
} else {
out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->" + propname + "));");
}
} else if (isThrowable(property.getType())) {
out.println(" SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->" + propname + "));");
} else {
if (cached) {
out.println(" SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->" + propname + "));");
} else {
out.println(" SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->" + propname + "));");
}
}
}
out.println("");
}
out.println(" ");
out.println(" return APR_SUCCESS;");
out.println("}");
out.println("");
out.println("apr_status_t ow_unmarshal_" + name + "(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_" + name + " *object, apr_pool_t *pool)");
out.println("{");
out.println(" ow_unmarshal_" + baseName + "(buffer, bitbuffer, (ow_" + baseName + "*)object, pool); ");
for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
JProperty property = iter.next();
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
JAnnotationValue size = annotation.getValue("size");
String propname = toPropertyCase(property.getSimpleName());
boolean cached = isCachedProperty(property);
type = property.getType().getQualifiedName();
if (type.equals("boolean")) {
out.println(" object->" + propname + " = ow_bit_buffer_read(bitbuffer);");
} else if (type.equals("byte")) {
out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
} else if (type.equals("char")) {
out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
} else if (type.equals("short")) {
out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
} else if (type.equals("int")) {
out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
} else if (type.equals("long")) {
out.println(" SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->" + propname + ", pool));");
} else if (type.equals("byte[]")) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->" + propname + ", " + size.asInt() + ", pool));");
} else {
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->" + propname + ", pool));");
}
} else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->" + propname + ", " + size.asInt() + ", pool));");
} else {
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->" + propname + ", pool));");
}
} else if (type.equals("java.lang.String")) {
out.println(" SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->" + propname + ", pool));");
} else {
if (property.getType().isArrayType()) {
if (size != null) {
out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->" + propname + ", " + size.asInt() + ", pool));");
} else {
out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->" + propname + ", pool));");
}
} else if (isThrowable(property.getType())) {
out.println(" SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->" + propname + ", pool));");
} else {
if (cached) {
out.println(" SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->" + propname + ", pool));");
} else {