OpenDDS  Snapshot(2023/04/28-20:55)
Functions
java_ts_generator Namespace Reference

Functions

void generate (AST_Structure *node)
 called directly by dds_visitor::visit_structure() if -Wb,java More...
 

Function Documentation

◆ generate()

void java_ts_generator::generate ( AST_Structure *  node)

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

Definition at line 508 of file ts_generator.cpp.

References ACE_ERROR, ACE_TEXT(), be_global, ACE_String_Base< char >::length(), LM_ERROR, ACE_OS::mkdir(), name, and scoped().

Referenced by typeobject_generator::gen_enum(), typeobject_generator::gen_struct(), typeobject_generator::gen_typedef(), typeobject_generator::gen_union(), and dds_visitor::visit_structure().

508  {
509  UTL_ScopedName* name = node->name();
510 
511  if (!(idl_global->is_dcps_type(name) || be_global->is_topic_type(node))) {
512  return;
513  }
514 
515  ACE_CString output_file = be_global->java_arg();
516  if (output_file.length()) {
517  be_global->impl_name_ = output_file;
518  }
519  be_global->add_include("idl2jni_jni.h", BE_GlobalData::STREAM_CPP);
520 
521  std::string type = scoped(name);
522 
523  std::string file, jniclass, jpackage;
524  for (UTL_ScopedName* sn = name; sn;
525  sn = static_cast<UTL_ScopedName*>(sn->tail())) {
526  std::string tmp = sn->head()->get_string();
527  if (!tmp.empty() && sn->tail()) {
528  jpackage += tmp;
529  file += tmp;
530  if (ACE_OS::mkdir(file.c_str()) != 0 && errno != EEXIST) {
531  ACE_ERROR((LM_ERROR, ACE_TEXT("ERROR: java_ts_generator::generate - ")
532  ACE_TEXT("unable to create specified directory: %C"), file.c_str()));
533  }
534  }
535  for (size_t i = tmp.find('_'); i < tmp.length();
536  i = tmp.find('_', i + 1)) {
537  tmp.insert(++i, 1, '1');
538  }
539  jniclass += tmp;
540  if (!jniclass.empty() && sn->tail()) {
541  jniclass += '_';
542  jpackage += '.';
543  file += '/';
544  }
545  }
546 
547  if (jpackage.size() && jpackage[jpackage.size() - 1] == '.') {
548  jpackage.resize(jpackage.size() - 1);
549  }
550 
551  std::string clazz = name->last_component()->get_string();
552  file += clazz + "TypeSupportImpl.java";
553 
554  std::ofstream java(file.c_str());
555  java << (jpackage.size() ? "package " : "") << jpackage
556  << (jpackage.size() ? ";\n" :"") <<
557  "public class " << clazz << "TypeSupportImpl extends _" << clazz
558  << "TypeSupportTAOPeer {\n"
559  " public " << clazz << "TypeSupportImpl() {\n"
560  " super(_jni_init());\n"
561  " }\n"
562  " private static native long _jni_init();\n"
563  "}\n";
564  be_global->impl_ <<
565  "extern \"C\" JNIEXPORT jlong JNICALL\n"
566  "Java_" << jniclass << "TypeSupportImpl__1jni_1init(JNIEnv*, jclass) {\n"
567  " return reinterpret_cast<jlong>(static_cast<CORBA::Object_ptr>(new "
568  << type << "TypeSupportImpl));\n"
569  "}\n\n";
570  }
#define ACE_ERROR(X)
int mkdir(const char *path, mode_t mode=ACE_DEFAULT_DIR_PERMS)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
BE_GlobalData * be_global
Definition: be_global.cpp:44
size_type length(void) const