+namespace {
+ static std::string studyName( const std::string& name )
+ {
+ std::string fullName = "/Hello/";
+ fullName += name;
+ return fullName;
+ }
+}
+/*!
+ \brief Constructor
+
+ Creates an instance of the HELLO component engine
+
+ \param orb reference to the ORB
+ \param poa reference to the POA
+ \param contId CORBA object ID, pointing to the owner SALOME container
+ \param instanceName SALOME component instance name
+ \param interfaceName SALOME component interface name
+*/
+HELLO_Abstract::HELLO_Abstract( CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ PortableServer::ObjectId* contId,
+ const char* instanceName,
+ const char* interfaceName,
+ bool withRegistry)
+ : Engines_Component_i( orb, poa, contId, instanceName, interfaceName, false, withRegistry)
+{
+ _thisObj = this;
+ _id = _poa->activate_object( _thisObj ); // register and activate this servant object
+}
+
+/*!
+ \brief Destructor
+
+ Clean up allocated resources
+*/
+HELLO_Abstract::~HELLO_Abstract()
+{
+ // nothing to do
+}
+
+/*!
+ \brief Say hello to \a name
+ \param name person's name
+ \return operation status
+*/
+HELLO_ORB::status HELLO_Abstract::hello( const char* name )
+{
+ // set exception handler to catch unexpected CORBA exceptions
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // set result status to error initially
+ HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN;
+
+ SALOMEDS::Study_var aStudy = this->getStudyServant();
+ // check if reference to study is valid
+ if ( !CORBA::is_nil( aStudy ) ) {
+ // get full object path
+ std::string fullName = studyName( name );
+ // check if the object with the same name is already registered in the study
+ SALOMEDS::SObject_var sobj = aStudy->FindObjectByPath( fullName.c_str() );
+ if ( !CORBA::is_nil( sobj ) ) {
+ // person is already registered in the study -> ERROR
+ result = HELLO_ORB::OP_ERR_ALREADY_MET;
+ }
+ else {
+ // person is not registered yet -> register
+ SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder(); // study builder
+ SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder(); // use case builder
+
+ // find HELLO component; create it if not found
+ SALOMEDS::SComponent_var father = aStudy->FindComponent( "HELLO" );
+ if ( CORBA::is_nil( father ) ) {
+ // create component
+ father = studyBuilder->NewComponent( "HELLO" );
+ // set name attribute
+ father->SetAttrString( "AttributeName", "Hello" );
+ // set icon attribute
+ father->SetAttrString( "AttributePixMap", "ICON_HELLO" );
+ // register component in the study
+ studyBuilder->DefineComponentInstance( father, HELLO_Gen::_this() );
+ // add component to the use case tree
+ // (to support tree representation customization and drag-n-drop)
+ useCaseBuilder->SetRootCurrent();
+ useCaseBuilder->Append( father ); // component object is added as the top level item
+ }
+
+ // create new sub-object, as a child of the component object
+ sobj = studyBuilder->NewObject( father );
+ sobj->SetAttrString( "AttributeName", name );
+ // add object to the use case tree
+ // (to support tree representation customization and drag-n-drop)
+ useCaseBuilder->AppendTo( father, sobj );
+
+ // cleanup
+ father->UnRegister();
+ sobj->UnRegister();
+
+ // set operation status
+ result = HELLO_ORB::OP_OK;
+ }
+ }
+
+ // return result of the operation
+ return result;
+}