java_ts_generator Namespace Reference


Functions

void generate (UTL_ScopedName *name)
 called directly by dds_visitor::visit_structure() if -Wb,java


Function Documentation

void java_ts_generator::generate ( UTL_ScopedName *  name  ) 

called directly by dds_visitor::visit_structure() if -Wb,java

Definition at line 172 of file ts_generator.cpp.

References BE_GlobalData::add_include(), be_global, BE_GlobalData::impl_, BE_GlobalData::impl_name_, BE_GlobalData::java_arg(), scoped(), and BE_GlobalData::STREAM_CPP.

Referenced by dds_visitor::visit_structure().

00172                                       {
00173     if (idl_global->is_dcps_type(name) == 0) {
00174       // no #pragma DCPS_DATA_TYPE, so nothing to generate
00175       return;
00176     }
00177 
00178     ACE_CString output_file = be_global->java_arg();
00179     if (output_file.length()) {
00180       be_global->impl_name_ = output_file;
00181     }
00182     be_global->add_include("idl2jni_jni.h", BE_GlobalData::STREAM_CPP);
00183 
00184     std::string type = scoped(name);
00185 
00186     std::string file, jniclass, jpackage;
00187     for (UTL_ScopedName* sn = name; sn;
00188         sn = static_cast<UTL_ScopedName*>(sn->tail())) {
00189       std::string tmp = sn->head()->get_string();
00190       if (tmp != "" && sn->tail()) {
00191         jpackage += tmp;
00192         file += tmp;
00193         ACE_OS::mkdir(file.c_str());
00194       }
00195       for (size_t i = tmp.find('_'); i < tmp.length();
00196           i = tmp.find('_', i + 1)) {
00197         tmp.insert(++i, 1, '1');
00198       }
00199       jniclass += tmp;
00200       if (jniclass != "" && sn->tail()) {
00201         jniclass += '_';
00202         jpackage += '.';
00203         file += '/';
00204       }
00205     }
00206 
00207     if (jpackage[jpackage.size() - 1] == '.') {
00208       jpackage.resize(jpackage.size() - 1);
00209     }
00210 
00211     std::string clazz = name->last_component()->get_string();
00212     file += clazz + "TypeSupportImpl.java";
00213 
00214     std::ofstream java(file.c_str());
00215     java << (jpackage.size() ? "package " : "") << jpackage
00216       << (jpackage.size() ? ";\n" :"") <<
00217       "public class " << clazz << "TypeSupportImpl extends _" << clazz
00218       << "TypeSupportTAOPeer {\n"
00219       "    public " << clazz << "TypeSupportImpl() {\n"
00220       "        super(_jni_init());\n"
00221       "    }\n"
00222       "    private static native long _jni_init();\n"
00223       "}\n";
00224     be_global->impl_ <<
00225       "extern \"C\" JNIEXPORT jlong JNICALL\n"
00226       "Java_" << jniclass << "TypeSupportImpl__1jni_1init(JNIEnv*, jclass) {\n"
00227       "  return reinterpret_cast<jlong>(static_cast<CORBA::Object_ptr>(new "
00228       << type << "TypeSupportImpl));\n"
00229       "}\n\n";
00230   }


Generated on Fri Feb 12 20:06:10 2016 for OpenDDS by  doxygen 1.4.7