Salome HOME
0023299: [CEA] Finalize multi-study removal
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.cxx
index fc2591d58b3ca8101c4c318cdc4b7097aca26a05..5c1337f1851906c3194881007a903f585a933227 100644 (file)
-//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 //  File   : SALOMEDS_Study_i.cxx
-//  Author : Yves FRICAUD
+//  Author : Sergey RUIN
 //  Module : SALOME
-//  $Header$
-
+//
 #include "utilities.h"
+#include <sstream>
 #include "SALOMEDS_Study_i.hxx"
-
-#include "SALOMEDS_DataMapIteratorOfDataMapStringLabel.hxx"
-#include <TColStd_SequenceOfExtendedString.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TDataStd_ChildNodeIterator.hxx>
-#include <TDocStd_Application.hxx>
-#include <TDocStd_Owner.hxx>
-#include <CDM_Document.hxx>
-#include <CDM_Application.hxx>
-#include <TDF_ChildIDIterator.hxx>
-#include <SALOME_GenericObj_i.hh>
-#include "SALOMEDS_LocalIDAttribute.hxx"
-#include "SALOMEDS_PersRefAttribute.hxx"
 #include "SALOMEDS_UseCaseIterator_i.hxx"
-using namespace std;
+#include "SALOMEDS_GenericAttribute_i.hxx"
+#include "SALOMEDS_AttributeStudyProperties_i.hxx"
+#include "SALOMEDS_AttributeParameter_i.hxx"
+#include "SALOMEDS_ChildIterator_i.hxx"
+#include "SALOMEDS_Driver_i.hxx"
+#include "SALOMEDS.hxx"
+
+#include "SALOMEDSImpl_SObject.hxx"
+#include "SALOMEDSImpl_SComponent.hxx"
+#include "SALOMEDSImpl_UseCaseBuilder.hxx"
+#include "SALOMEDSImpl_AttributeStudyProperties.hxx"
+#include "SALOMEDSImpl_AttributeParameter.hxx"
+#include "SALOMEDSImpl_ChildIterator.hxx"
+#include "SALOMEDSImpl_IParameters.hxx"
+#include "SALOMEDSImpl_Callback.hxx"
+
+#include "DF_Label.hxx"
+#include "DF_Attribute.hxx"
+
+#include "Utils_ExceptHandlers.hxx"
+
+#include "Basics_Utils.hxx"
+#include "SALOME_KernelServices.hxx"
+
+#ifdef WIN32
+#include <process.h>
+#else
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
+UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
+
+static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
+
+namespace SALOMEDS
+{
+  class Notifier: public SALOMEDSImpl_AbstractCallback
+  {
+  public:
+    Notifier(CORBA::ORB_ptr orb)
+    {
+      _orb = CORBA::ORB::_duplicate(orb);
+    }
+
+    //============================================================================
+    /*! Function : addSO_Notification
+     *  Purpose  : This function tells all the observers that a SO has been added
+     */
+    //============================================================================
+
+    virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
+    {
+      std::string anID=theSObject.GetID();
+      const char* cID=anID.c_str();
+      for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+      {
+        it->first->notifyObserverID(cID,1);
+      }
+      return true; // NGE return always true but can be modified if needed
+    }
+
+    //============================================================================
+    /*! Function : removeSO_Notification
+     *  Purpose  : This function tells all the observers that a SO has been removed
+     */
+    //============================================================================
+
+    virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
+    {
+      std::string anID=theSObject.GetID();
+      const char* cID=anID.c_str();
+      for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+      {
+        it->first->notifyObserverID(cID,2);
+      }
+      return true; // NGE return always true but can be modified if needed
+    }
+
+    //============================================================================
+    /*! Function : modifySO_Notification
+     *  Purpose  : This function tells all the observers that a SO has been modified
+     */
+    //============================================================================
+
+    virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
+    {
+      for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+      {
+        if(it->second)
+        {
+          std::string anID=theSObject.GetID();
+          const char* cID=anID.c_str();
+          it->first->notifyObserverID(cID,reason);
+        }
+      }
+      return true; // NGE return always true but can be modified if needed
+    }
+
+    //============================================================================
+    /*! Function : modifyNB_Notification
+     *  Purpose  : This function tells all the observers that 
+     *             a NoteBook variable has been added/modified/removed.
+     */
+    //============================================================================
+    
+    virtual bool modifyNB_Notification(const char* theVarName)
+    {
+      for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+        {
+          it->first->notifyObserverID(theVarName,6);
+        }
+      return true; // NGE return always true but can be modified if needed
+    }
+
+    //============================================================================
+    /*! Function : attach
+     *  Purpose  : register an Observer
+     */
+    //============================================================================
 
+    virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
+    {
+      myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
+    }
+
+    //============================================================================
+    /*! Function : detach
+     *  Purpose  : unregister an Observer
+     */
+    //============================================================================
+
+    virtual void detach(SALOMEDS::Observer_ptr theObs)
+    {
+      for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+      {
+       if ( it->first->_is_equivalent(theObs) ) {
+         myObservers.erase( it );
+         break;
+       }
+      }
+    }
+
+  private:
+    typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
+    typedef ObsList::iterator ObsListIter;
+    ObsList myObservers;
+    CORBA::ORB_var                    _orb;
+  };
+
+  class GenObjRegister: public SALOMEDSImpl_AbstractCallback
+  {
+  public:
+    GenObjRegister(CORBA::ORB_ptr orb)
+    {
+      _orb = CORBA::ORB::_duplicate(orb);
+    }
+    virtual void RegisterGenObj  (const std::string& theIOR)
+    {
+      try
+      {
+        CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
+        if ( obj->_non_existent() ) return;
+        SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
+        if(! CORBA::is_nil(gobj) )
+        {
+          gobj->Register();
+        }
+      }
+      catch(const CORBA::Exception& e)
+      {
+      }
+    }
+    virtual void UnRegisterGenObj(const std::string& theIOR)
+    {
+      try
+      {
+        CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
+        if ( obj->_non_existent() ) return;
+        SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
+        if(! CORBA::is_nil(gobj) )
+        {
+          gobj->UnRegister();
+        }
+      }
+      catch(const CORBA::Exception& e)
+      {
+      }
+    }
+
+  private:
+    CORBA::ORB_var _orb;
+  };
 
-#define DIRECTORYID 16661
-#define FILEID "FILE: "
-#define FILELOCALID 26662 
+} // namespace SALOMEDS
 
 //============================================================================
 /*! Function : SALOMEDS_Study_i
  *  Purpose  : SALOMEDS_Study_i constructor
  */
 //============================================================================
-SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(TDocStd_Document) doc,
-                                  CORBA::ORB_ptr                 orb,
-                                  const char* study_name)
+SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
 {
-  _orb = CORBA::ORB::_duplicate(orb);
-  _doc = doc;
-  _name = new char[strlen(study_name) +1];
-  strcpy(_name,study_name);
-  _isSaved = false ;
-  _URL = NULL;
-  _StudyId = -1;
-  _autoFill = true;
-  myNbPostponed.Append(0);
-  myNbUndos = 0;
+  _orb     = CORBA::ORB::_duplicate(orb);
+  _impl    = new SALOMEDSImpl_Study();
+  _factory = new SALOMEDS_DriverFactory_i(_orb);
+
+  Init();
 }
-  
+
 //============================================================================
 /*! Function : ~SALOMEDS_Study_i
  *  Purpose  : SALOMEDS_Study_i destructor
@@ -78,9 +246,265 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(TDocStd_Document) doc,
 //============================================================================
 SALOMEDS_Study_i::~SALOMEDS_Study_i()
 {
-  delete [] _name ;
-  delete [] _URL ;
-}  
+  Clear();
+  delete _factory;
+  delete _impl;
+}
+
+//============================================================================
+/*! Function : Init
+ *  Purpose  : Initialize study components
+ */
+//============================================================================
+void SALOMEDS_Study_i::Init()
+{
+  _builder        = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);  
+  _notifier       = new SALOMEDS::Notifier(_orb);
+  _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
+  _closed         = false;
+
+  _impl->setNotifier(_notifier);
+  _impl->setGenObjRegister( _genObjRegister );
+
+  // Notify GUI that study was created
+  SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+  CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
+  SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
+  if ( !CORBA::is_nil(aSession) ) {
+    std::stringstream ss;
+    ss << "studyCreated";
+    std::string str = ss.str();
+    SALOMEDS::unlock();
+    aSession->emitMessageOneWay(str.c_str());
+    SALOMEDS::lock();
+  }
+}
+
+//============================================================================
+/*! Function : Clear
+ *  Purpose  : Clear study components
+ */
+//============================================================================
+void SALOMEDS_Study_i::Clear()
+{
+  //delete the builder servant
+  PortableServer::POA_var poa=_builder->_default_POA();
+  PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
+  poa->deactivate_object(anObjectId.in());
+  _builder->_remove_ref();
+  
+  _impl->Clear();
+  _impl->setNotifier(0);
+  delete _notifier;
+  delete _genObjRegister;
+
+  SALOMEDS::Locker lock;
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
+
+  RemovePostponed(-1);
+
+  SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
+  for (; itcomponent->More(); itcomponent->Next()) {
+    SALOMEDS::SComponent_var sco = itcomponent->Value();
+    CORBA::String_var compodatatype=sco->ComponentDataType();
+    MESSAGE ( "Look for an engine for data type :"<< compodatatype);
+    // if there is an associated Engine call its method for closing
+    CORBA::String_var IOREngine;
+    if (sco->ComponentIOR(IOREngine)) {
+      // we have found the associated engine to write the data
+      MESSAGE ( "We have found an engine for data type :"<< compodatatype);
+      //_narrow can throw a corba exception
+      try {
+           CORBA::Object_var obj = _orb->string_to_object(IOREngine);
+           if (!CORBA::is_nil(obj)) {
+             SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
+             if (!anEngine->_is_nil())  {
+               SALOMEDS::unlock();
+               anEngine->Close(sco);
+               SALOMEDS::lock();
+             }
+           }
+      }
+      catch (CORBA::Exception&) {
+      }
+    }
+    sco->UnRegister();
+  }
+
+  //Does not need any more this iterator
+  itcomponent->UnRegister();
+
+  // Notify GUI that study is cleared
+  SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+  CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
+  SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
+  if ( !CORBA::is_nil(aSession) ) {
+    std::stringstream ss;
+    ss << "studyCleared";
+    std::string str = ss.str();
+    SALOMEDS::unlock();
+    aSession->emitMessageOneWay(str.c_str());
+    SALOMEDS::lock();
+  }
+
+  _closed = true;
+}
+
+//============================================================================
+/*! Function : Open
+ *  Purpose  : Open a Study from it's persistent reference
+ */
+//============================================================================
+bool SALOMEDS_Study_i::Open(const char* aUrl)
+  throw(SALOME::SALOME_Exception)
+{
+  SALOMEDS::Locker lock;
+
+  Unexpect aCatch(SalomeException);
+  MESSAGE("Begin of SALOMEDS_Study_i::Open");
+
+  bool res = _impl->Open(std::string(aUrl));
+
+  if ( !res )
+    THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
+  return res;
+}
+
+//============================================================================
+/*! Function : Save
+ *  Purpose  : Save a Study to it's persistent reference
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile)
+{
+  SALOMEDS::Locker lock;
+  return _impl->Save(_factory, theMultiFile);
+}
+
+CORBA::Boolean SALOMEDS_Study_i::SaveASCII(CORBA::Boolean theMultiFile)
+{
+  SALOMEDS::Locker lock;
+  return _impl->SaveASCII(_factory, theMultiFile);
+}
+
+//=============================================================================
+/*! Function : SaveAs
+ *  Purpose  : Save a study to the persistent reference aUrl
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile)
+{
+  SALOMEDS::Locker lock;
+  return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile);
+}
+
+CORBA::Boolean SALOMEDS_Study_i::SaveAsASCII(const char* aUrl, CORBA::Boolean theMultiFile)
+{
+  SALOMEDS::Locker lock;
+  return _impl->SaveAsASCII(std::string(aUrl), _factory, theMultiFile);
+}
+
+//============================================================================
+/*! Function : CanCopy
+ *  Purpose  :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
+{
+  SALOMEDS::Locker lock;
+
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
+
+  SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
+  bool ret = _impl->CanCopy(anObject, aDriver);
+  delete aDriver;
+  return ret;
+}
+
+//============================================================================
+/*! Function : Copy
+ *  Purpose  :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
+{
+  SALOMEDS::Locker lock;
+
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
+
+  SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
+  bool ret = _impl->Copy(anObject, aDriver);
+  delete aDriver;
+  return ret;
+}
+
+//============================================================================
+/*! Function : CanPaste
+ *  Purpose  :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
+{
+  SALOMEDS::Locker lock;
+
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
+
+  SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
+  bool ret = _impl->CanPaste(anObject, aDriver);
+  delete aDriver;
+  return ret;
+}
+
+//============================================================================
+/*! Function : Paste
+ *  Purpose  :
+ */
+//============================================================================
+SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
+     throw(SALOMEDS::StudyBuilder::LockProtection)
+{
+  SALOMEDS::Locker lock;
+
+  Unexpect aCatch(LockProtection);
+
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
+  SALOMEDSImpl_SObject aNewSO;
+
+  try {
+    SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
+    aNewSO =  _impl->Paste(anObject, aDriver);
+    delete aDriver;
+  }
+  catch (...) {
+    throw SALOMEDS::StudyBuilder::LockProtection();
+  }
+
+  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
+  return so._retn();
+}
+
+SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
+{
+  SALOMEDS_Driver_i* driver = NULL;
+
+  SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
+  if(!aSCO.IsNull()) {
+    std::string IOREngine = aSCO.GetIOR();
+    if(!IOREngine.empty()) {
+      CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
+      Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
+      driver = new SALOMEDS_Driver_i(Engine, orb);
+    }
+  }
+
+  return driver;
+}
 
 //============================================================================
 /*! Function : GetPersistentReference
@@ -89,7 +513,10 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i()
 //============================================================================
 char* SALOMEDS_Study_i::GetPersistentReference()
 {
-  return URL();
+  SALOMEDS::Locker lock; 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+  return CORBA::string_dup(_impl->GetPersistentReference().c_str());
 }
 //============================================================================
 /*! Function : GetTransientReference
@@ -98,18 +525,10 @@ char* SALOMEDS_Study_i::GetPersistentReference()
 //============================================================================
 char* SALOMEDS_Study_i::GetTransientReference()
 {
-  CORBA::String_var IOR;
-
-  Handle(SALOMEDS_IORAttribute) Att;
-  TDF_Label _lab = _doc->GetData()->Root();
-  if (!_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
-
-    TCollection_AsciiString ch(Att->Get());
-    IOR = CORBA::string_dup(ch.ToCString());
-  }
-  else IOR = CORBA::string_dup(""); // NULL ?
-
-  return CORBA::string_dup(IOR); 
+  SALOMEDS::Locker lock; 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+  return CORBA::string_dup(_impl->GetTransientReference().c_str());
 }
 
 //============================================================================
@@ -119,8 +538,10 @@ char* SALOMEDS_Study_i::GetTransientReference()
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
 {
-  if (_doc.IsNull()) return true;
-  return _doc->IsEmpty();
+  SALOMEDS::Locker lock; 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+  return _impl->IsEmpty();
 }
 
 //============================================================================
@@ -130,25 +551,18 @@ CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
 //============================================================================
 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
 {
-  bool _find = false;
-  Standard_CString name;
-  SALOMEDS::SComponentIterator_var itcomp = NewComponentIterator();
-  SALOMEDS::SComponent_var compo;
-
-  for (; itcomp->More(); itcomp->Next()) {
-    SALOMEDS::SComponent_var SC = itcomp->Value();
-    name = SC->ComponentDataType();
-    //ED if ( TCollection_AsciiString(name).IsEqual(TCollection_AsciiString(strdup(aComponentName))) ) {
-    if(strcmp(aComponentName,name) == 0){
-      _find = true;
-      return SALOMEDS::SComponent::_narrow(SC); 
-    }
-  }
-  if(!_find)
-    {
-      return SALOMEDS::SComponent::_nil();
-    }
-  return compo;
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SComponent_var sco;
+
+  SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
+  if (!aCompImpl.IsNull())
+    sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
+
+  return sco._retn();
 }
 
 //============================================================================
@@ -158,28 +572,18 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponent
 //============================================================================
 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
 {
-  // Iterate on each components defined in the study
-  // Get the component ID and compare with aComponentID 
-  bool _find = false;
-  char *ID;
-  SALOMEDS::SComponent_ptr compo;
-
-  SALOMEDS::SComponentIterator_var itcomp = NewComponentIterator();
-  for (; itcomp->More(); itcomp->Next()) {
-    SALOMEDS::SComponent_var SC = itcomp->Value();
-    ID = SC->GetID();
-    if(strcmp(aComponentID,ID)==0)
-      {
-       // ComponentID found
-       _find = true;
-        compo = SALOMEDS::SComponent::_narrow(SC);
-      }
-  }
-  if(!_find)
-    {
-      compo = SALOMEDS::SComponent::_nil();
-    }
-  return compo;
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SComponent_var sco;
+
+  SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
+  if (!aCompImpl.IsNull())
+    sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
+
+  return sco._retn();
 }
 
 //============================================================================
@@ -189,32 +593,25 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
 {
-  // Iterate to all components defined in the study
-  // After testing the component name, iterate in all objects defined under
-  // components (function _FindObject)
-  bool _find = false;
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
+  SALOMEDS::Locker lock; 
 
-  SALOMEDS::SComponentIterator_var it = NewComponentIterator();
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SComponent_var SC = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (SC->FindAttribute(anAttr,"AttributeName")) 
-       {
-         SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
-         CORBA::String_var Val = Name->Value();
-         if (strcmp(Val, anObjectName) == 0)
-           {
-             _find = true;
-             RefSO = SALOMEDS::SObject::_narrow(SC);
-           }
-       }
-       if (!_find) RefSO =  _FindObject(SC,anObjectName, _find);
-      }
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
+  SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
+  if (!aSO.IsNull()) {
+    if (aSO.IsComponent()) {
+      SALOMEDSImpl_SComponent aSCO = aSO;
+      so = SALOMEDS_SComponent_i::New(aSCO, _orb);
+    }
+    else {
+      so = SALOMEDS_SObject_i::New(aSO, _orb);
+    }
   }
-  return RefSO;
+
+  return so._retn();
 }
 
 //============================================================================
@@ -224,15 +621,41 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
 {
-  // Convert aSO->GetID in TDF_Label.
-  TDF_Label Lab;
-  TDF_Tool::Label(_doc->GetData(), strdup(anObjectID), Lab);
-  
-  if (Lab.IsNull()) return SALOMEDS::SObject::_nil();
-  SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (Lab,_orb);
-  SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); 
-  return so;
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New(aSO, _orb);
+
+  return so._retn();
+}
+
+//============================================================================
+/*! Function : CreateObjectID
+ *  Purpose  : Creates an Object with ID = anObjectID
+ */
+//============================================================================
+SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
+  if (anObjectID && strlen(anObjectID) > 0) {
+    SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
+    if (!aSO.IsNull())
+      so = SALOMEDS_SObject_i::New(aSO, _orb);
+  }
 
+  return so._retn();
 }
 
 //============================================================================
@@ -242,57 +665,27 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
  */
 //============================================================================
 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
-                                                                   const char* aComponentName )
+                                                                    const char* aComponentName )
 {
-  SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
-  listSO->length(0);
-  
-  SALOMEDS::SComponent_ptr compo = FindComponent(aComponentName) ;
-  if ( compo->_is_nil() ) {
-    MESSAGE ("In FindObjectByName() :  Component named " << aComponentName << " not found ");
-    return listSO._retn();
-  }
+  SALOMEDS::Locker lock; 
 
-  // Iterate on each object and subobject of the component
-  // If objectName is found add it to the list of SObjects 
-  char *name;
-  char *childName ;
-  SALOMEDS::SObject_ptr addSO = SALOMEDS::SObject::_nil();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  CORBA::String_var compoId = compo->GetID();
-  SALOMEDS::ChildIterator_var it = NewChildIterator(compo);
-  int length = 0 ;
-  for ( ; it->More();it->Next() ) {
-    
-    SALOMEDS::SObject_var CSO = it->Value();
-    SALOMEDS::GenericAttribute_var anAttr;
-    SALOMEDS::AttributeName_var    aName;
-    if ( CSO->FindAttribute(anAttr, "AttributeName") ) {
-      aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      name = aName->Value();
-      if ( strcmp( name, anObjectName ) == 0) {
-       addSO = SALOMEDS::SObject::_narrow(CSO);
-       /* add to list */
-       length++ ;
-       listSO->length(length);
-       listSO[length-1] = addSO ;
-      }
-      
-      /* looks also for eventual children */
-      bool found = false ;
-      addSO = _FindObject( CSO, anObjectName, found ) ;
-      if( found) {
-       length++ ;
-       listSO->length(length);
-       listSO[length-1] = addSO ;
-      }
-    }
+  std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
+                                                                  std::string((char*)aComponentName));
+
+  SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
+  int aLength = aSeq.size();
+  listSO->length(aLength);
+  for (int i = 0; i < aLength; i++) {
+    SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
+    listSO[i] = so;
   }
-  return listSO._retn() ;
+  
+  return listSO._retn();
 }
 
-
-
 //============================================================================
 /*! Function : FindObjectIOR
  *  Purpose  : Find an Object with IOR = anObjectIOR
@@ -300,45 +693,18 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char*
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
 {
-  // firstly searching in the datamap for optimization
-  CORBA::String_var anIOR = CORBA::string_dup(anObjectIOR);
-  if (myIORLabels.IsBound(TCollection_ExtendedString(anIOR))) {
-    SALOMEDS_SObject_i* aResult = new SALOMEDS_SObject_i(myIORLabels.Find(TCollection_ExtendedString(anIOR)),_orb);
-    // 11 oct 2002: forbidden attributes must be checked here
-    SALOMEDS::GenericAttribute_var anAttr;
-    if (!aResult->FindAttribute(anAttr,"AttributeIOR")) {
-      myIORLabels.UnBind(TCollection_ExtendedString(anIOR));
-    } else return aResult->_this();
-  }
-  // Iterate to all components defined in the study
-  // After testing the component name, iterate in all objects defined under
-  // components (function _FindObject)
-  bool _find = false;
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
-
-  SALOMEDS::SComponentIterator_var it = NewComponentIterator();
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SComponent_var SC = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (SC->FindAttribute(anAttr,"AttributeIOR")) 
-       {
-         SALOMEDS::AttributeIOR_var IOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-          CORBA::String_var Val = IOR->Value();
-         if (strcmp(Val, anObjectIOR) == 0)
-           {
-             _find = true;
-             RefSO = SALOMEDS::SObject::_narrow(SC);
-           }
-       }
-       if (!_find) 
-         RefSO =  _FindObjectIOR(SC,anObjectIOR, _find);
-      }
-  }
-  if (!RefSO->_is_nil()) INFOS("SALOMEDS_Study_i::FindObjectIOR: found label with old methods");
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New(aSO, _orb);
 
-  return RefSO;
+  return so._retn();
 }
 
 //============================================================================
@@ -348,767 +714,1057 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
 {
-  TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aToken;
-  SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_nil();
-  int i = 1, aLength = aPath.Length();
-  bool isRelative = false;
+  SALOMEDS::Locker lock; 
 
-  if(aLength == 0) {  //Empty path - return the current context
-    SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (_current, _orb);
-    aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); 
-    return aSO._retn();
-  }
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  if(aPath.Value(1) != '/')  //Relative path 
-    isRelative = true;
+  SALOMEDS::SObject_var so;
 
-  TDF_ChildIterator anIterator;
-  TDF_Label aLabel;
-  Handle(TDataStd_Name) anAttr;
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New (aSO, _orb);
 
-  if(isRelative) {
-    if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); 
-    anIterator.Initialize(_current, Standard_False);
-  }
-  else {
-    if(aPath.Length() == 1 && aPath.Value(1) == '/') {    //Root
-      SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb);
-      aSO = SALOMEDS::SObject::_narrow(so_servant->_this());
-      return aSO._retn();
-    }
-    anIterator.Initialize(_doc->Main(), Standard_False);
-  }
+  return so._retn();
+}
+
+//============================================================================
+/*! Function : GetObjectPath
+ *  Purpose  : 
+ */
+//============================================================================
+char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
+{
+  SALOMEDS::Locker lock; 
 
-  while(i <= aLength) {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-    aToken = aPath.Token("/", i);
-    if(aToken.Length() == 0) break;
+  std::string aPath = "";
 
-    for ( ; anIterator.More(); anIterator.Next() ) {
-      aLabel = anIterator.Value();
-      if(aLabel.FindAttribute(TDataStd_Name::GetID(), anAttr)) {
-       if(anAttr->Get() == aToken) {
-         aToken = aPath.Token("/", i+1); //Check if it was the last part of the path
-         if(aToken.Length() == 0) {  //The searched label is found (no part of the path is left)
-             SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (aLabel, _orb);
-             aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); 
-             return aSO._retn();
-         }
+  if (!CORBA::is_nil(theObject)) {
+    SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
+    SALOMEDSImpl_SObject aSO;
 
-         anIterator.Initialize(aLabel, Standard_False);
-         break;
-       }
-      }
+    if (!CORBA::is_nil(aSObj)) {
+      aSO = _impl->FindObjectID(aSObj->GetID());
+    }
+    else {
+      aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
+    }
+    
+    if (!aSO.IsNull()) {    
+      aPath = _impl->GetObjectPath(aSO);
     }
-
-    i++;
   }
 
-  return aSO._retn();
+  return CORBA::string_dup(aPath.c_str());
+}
+
+
+//============================================================================
+/*! Function : SetContext
+ *  Purpose  : Sets the current context
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetContext(const char* thePath) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetContext(std::string((char*)thePath));
+  if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
+    throw SALOMEDS::Study::StudyInvalidContext();  
+}
+
+//============================================================================
+/*! Function : GetContext
+ *  Purpose  : Gets the current context
+ */
+//============================================================================
+char* SALOMEDS_Study_i::GetContext() 
+{
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
+
+  return CORBA::string_dup(_impl->GetContext().c_str());
+}
+
+//============================================================================
+/*! Function : GetObjectNames
+ *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+
+  if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
+    throw SALOMEDS::Study::StudyInvalidContext();
+  
+  std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
+  if (_impl->GetErrorCode() == "InvalidContext")
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  int aLength = aSeq.size();
+  aResult->length(aLength);
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
+  }
+
+  return aResult._retn();
+}
+
+//============================================================================
+/*! Function : GetDirectoryNames
+ *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+
+  if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
+    throw SALOMEDS::Study::StudyInvalidContext();
+  
+  std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
+  if (_impl->GetErrorCode() == "InvalidContext")
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  int aLength = aSeq.size();
+  aResult->length(aLength);
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
+  }
+  
+  return aResult._retn();
+}
+
+//============================================================================
+/*! Function : GetFileNames
+ *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+
+  if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
+    throw SALOMEDS::Study::StudyInvalidContext();
+  
+  std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
+  if (_impl->GetErrorCode() == "InvalidContext")
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  int aLength = aSeq.size();
+  aResult->length(aLength);
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
+  }
+
+  return aResult._retn();
+}
+
+//============================================================================
+/*! Function : GetComponentNames
+ *  Purpose  : method to get all components names
+ *  SRN:       Note, theContext can be any, it doesn't matter
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+
+  std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
+
+  int aLength = aSeq.size();
+  aResult->length(aLength);
+  for(int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
+  }
+
+  return aResult._retn();
+}
+
+//============================================================================
+/*! Function : NewChildIterator
+ *  Purpose  : Create a ChildIterator from an SObject
+ */
+//============================================================================
+SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  CORBA::String_var anID = theSO->GetID();
+  SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
+  SALOMEDSImpl_ChildIterator anItr(aSO);
+  SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
+  SALOMEDS::ChildIterator_var it = it_servant->_this();
+
+  return it._retn();
+}
+
+
+//============================================================================
+/*! Function : NewComponentIterator
+ *  Purpose  : Create a SComponentIterator
+ */
+//============================================================================
+SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
+  it_servant->Init();
+  SALOMEDS::SComponentIterator_var it = it_servant->_this();
+
+  return it._retn();
+}
+
+
+//============================================================================
+/*! Function : NewBuilder
+ *  Purpose  : Create a StudyBuilder
+ */
+//============================================================================
+SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
+
+  return sb._retn();
+}
+//============================================================================
+/*! Function : Name
+ *  Purpose  : get study name
+ */
+//============================================================================
+char* SALOMEDS_Study_i::Name()
+{
+  SALOMEDS::Locker lock; 
+  // Name is specified as IDL attribute: user exception cannot be raised
+  return CORBA::string_dup(_impl->Name().c_str());
+}
+
+//============================================================================
+/*! Function : IsSaved
+ *  Purpose  : get if study has been saved
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsSaved()
+{
+  SALOMEDS::Locker lock; 
+  // IsSaved is specified as IDL attribute: user exception cannot be raised
+  return (!_closed) ? _impl->IsSaved() : false;
+}
+
+//============================================================================
+/*! Function : IsSaved
+ *  Purpose  : set if study has been saved
+ */
+//============================================================================
+void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
+{
+  SALOMEDS::Locker lock; 
+  // IsSaved is specified as IDL attribute: user exception cannot be raised
+  if (!_closed)
+    _impl->IsSaved(save);
+}
+
+//============================================================================
+/*! Function : IsModified
+ *  Purpose  : Detect if a Study has been modified since it has been saved
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsModified()
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsModified();
+}
+
+//============================================================================
+/*! Function : Modified
+ *  Purpose  : Sets a Modified flag of a Study to True
+ */
+//============================================================================
+void SALOMEDS_Study_i::Modified()
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->Modify();
+}
+
+//============================================================================
+/*! Function : URL
+ *  Purpose  : get URL of the study (persistent reference of the study)
+ */
+//============================================================================
+char* SALOMEDS_Study_i::URL()
+{
+  SALOMEDS::Locker lock; 
+  // URL is specified as IDL attribute: user exception cannot be raised
+  return CORBA::string_dup(_impl->URL().c_str());
+}
+
+//============================================================================
+/*! Function : URL
+ *  Purpose  : set URL of the study (persistent reference of the study)
+ */
+//============================================================================
+void SALOMEDS_Study_i::URL(const char* url)
+{
+  SALOMEDS::Locker lock; 
+  // URL is specified as IDL attribute: user exception cannot be raised
+  _impl->URL(std::string((char*)url));
+}
+
+void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
+}
+
+SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
+{
+  SALOMEDS::Locker lock;
+
+  SALOMEDSImpl_AttributeIOR* Att = NULL;
+  if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
+    char* IOR = CORBA::string_dup(Att->Value().c_str());
+    CORBA::Object_var obj = orb->string_to_object(IOR);
+    SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
+    ASSERT(!CORBA::is_nil(aStudy));
+    return SALOMEDS::Study::_duplicate(aStudy);
+  } else {
+    MESSAGE("GetStudy: Problem to get study");
+  }
+  return SALOMEDS::Study::_nil();
+}
+
+void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) 
+{
+  SALOMEDS::Locker lock; 
+  SALOMEDSImpl_Study::IORUpdated(theAttribute);
+}
+
+SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::GenericAttribute_ptr aTarget;
+  if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
+    return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
+  }
+  SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
+  aList->length(0);
+  return aList;
+}
+
+
+SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() 
+{
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
+  SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
+  SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
+  return aProp._retn();
+}
+
+char* SALOMEDS_Study_i::GetLastModificationDate() 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
+}
+
+SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() 
+{
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
+
+  std::vector<std::string> aSeq = _impl->GetModificationsDate();
+
+  int aLength = aSeq.size();
+  aDates->length(aLength);
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
+  }
+
+  return aDates._retn();
+}
+
+//============================================================================
+/*! Function : GetUseCaseBuilder
+ *  Purpose  : Returns a UseCase builder
+ */
+//============================================================================
+SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
+  SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
+  return uc._retn();
+}
+
+//============================================================================
+/*! Function : AddPostponed
+ *  Purpose  : 
+ */
+ //============================================================================
+void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
+{
+  SALOMEDS::Locker lock; 
+  //Not implemented
+}
+
+void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
+{
+  SALOMEDS::Locker lock; 
+  //Not implemented
+}
+
+//============================================================================
+/*! Function : RemovePostponed
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) 
+{  
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  std::vector<std::string> anIORs = _impl->GetIORs();
+  int i, aSize = (int)anIORs.size();
+  
+  for (i = 0; i < aSize; i++) {
+    try {
+      CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
+      SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
+      //rnv: To avoid double deletion of the Salome Generic Objects:
+      //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
+      //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
+      //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
+    } catch (...) {}
+  }
+
+  //Not implemented
+}
+
+//============================================================================
+/*! Function : UndoPostponed
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
+{
+  SALOMEDS::Locker lock; 
+  //Not implemented
+}
+
+
+//============================================================================
+/*! Function : DumpStudy
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
+                                           const char* theBaseName, 
+                                           CORBA::Boolean isPublished,
+                                           CORBA::Boolean isMultiFile)
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
+  SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
+  bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
+  delete factory;
+
+  return ret;
+}
+
+//============================================================================
+/*! Function : GetCommonParameters
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
+{
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
+  SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
+  SALOMEDS::AttributeParameter_var aParam = SP->_this();
+
+  return aParam._retn();
+}
+//============================================================================
+/*! Function : GetCommonModuleParameters
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID, 
+                                                                       const char* theModuleName, 
+                                                                       CORBA::Long theSavePoint)
+{
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
+  SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
+  SALOMEDS::AttributeParameter_var aParam = SP->_this();
+
+  return aParam._retn();
 }
 
 //============================================================================
-/*! Function : GetObjectPath
+/*! Function : SetStudyLock
  *  Purpose  : 
  */
 //============================================================================
-char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
+void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
 {
-  TCollection_AsciiString aPath("");
-  if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.ToCString());
-
-  SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(theObject);
-  if(anObject->_is_nil()) {
-    anObject = FindObjectIOR(_orb->object_to_string(theObject));
-    if(anObject->_is_nil()) return CORBA::string_dup(aPath.ToCString());
-  }
+  SALOMEDS::Locker lock; 
 
-  SALOMEDS::GenericAttribute_var anAttr;
-  if(anObject->FindAttribute(anAttr, "AttributeName")) {
-    SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
-    if(anAttr->_is_nil()) return CORBA::string_dup(aPath.ToCString());
-    TCollection_AsciiString aValue(aName->Value());
-    aValue.Prepend("/");
-    aValue += aPath;
-    aPath = aValue;
-    SALOMEDS::SObject_ptr aFather = anObject->GetFather();
-    if(!aFather->_is_nil()) {
-      TDF_Label aLabel;
-      Handle(TDataStd_Name) aNameAttrib;
-      TDF_Tool::Label(_doc->GetData(), aFather->GetID(), aLabel);
-      if(aLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttrib)) {
-         aValue = GetObjectPath(aFather);
-         aPath = aValue + aPath;
-      }
-    }
-  }
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  return  CORBA::string_dup(aPath.ToCString());
+  _impl->SetStudyLock(theLockerID);
 }
 
-
 //============================================================================
-/*! Function : SetContext
- *  Purpose  : Sets the current context
+/*! Function : IsStudyLocked
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::SetContext(const char* thePath) 
+bool SALOMEDS_Study_i::IsStudyLocked()
 {
-  if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
-  TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext("");
-  bool isInvalid = false, isFound = false;
-  SALOMEDS::SObject_var aSO;
-  
-  if(aPath.Value(1) != '/') { //Relative path 
-    aContext = TCollection_AsciiString(GetContext());
-    aContext += '/';
-    aContext += aPath;
-  }
-  else
-    aContext = aPath;
-  
-  try {
-    aSO = FindObjectByPath(aContext.ToCString());
-  }
-  catch( ... ) {
-    isInvalid = true;
-  }
+  SALOMEDS::Locker lock; 
 
-  if(isInvalid || aSO->_is_nil()) throw SALOMEDS::Study::StudyInvalidContext();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  TDF_Label aLabel;
-  TDF_Tool::Label(_doc->GetData(), aSO->GetID(), aLabel);
-  if(aLabel.IsNull()) throw SALOMEDS::Study::StudyInvalidContext();
-  else
-    _current = aLabel;  //Set the current context
-  
+  return _impl->IsStudyLocked();
 }
 
 //============================================================================
-/*! Function : GetContext
- *  Purpose  : Gets the current context
+/*! Function : UnLockStudy
+ *  Purpose  : 
  */
 //============================================================================
-char* SALOMEDS_Study_i::GetContext() 
+void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
 {
-  if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext();   
-  SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (_current, _orb);
-  SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); 
-  return GetObjectPath(aSO._retn());
-}
+  SALOMEDS::Locker lock; 
 
-//============================================================================
-/*! Function : GetObjectNames
- *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
- */
-//============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) {
-  TColStd_SequenceOfExtendedString aResultSeq;
-  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  TDF_Label aLabel;
-  if (strlen(theContext) == 0) {
-    if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext();   
-    aLabel = _current;
-  } else {
-    TDF_Label aTmp = _current;
-    SetContext(theContext);
-    aLabel = _current;
-    _current = aTmp;
-  }
-  TDF_ChildIterator anIter(aLabel, Standard_False); // iterate all subchildren at all sublevels
-  for(; anIter.More(); anIter.Next()) {
-    TDF_Label aLabel = anIter.Value();
-//      Handle(TDF_Attribute) anAttribute;
-//      if (aLabel.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttribute) ||
-//     aLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anAttribute)) {
-    Handle(TDataStd_Name) aName;
-    if (aLabel.FindAttribute(TDataStd_Name::GetID(), aName)) aResultSeq.Append(aName->Get());
-//    }
-  }
-  // fill the result table
-  int anIndex, aLength = aResultSeq.Length();
-  aResult->length(aLength);
-  for(anIndex = 0; anIndex < aLength; anIndex++) {
-    aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString());
-  }
-  return aResult._retn();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->UnLockStudy(theLockerID);
 }
 
 //============================================================================
-/*! Function : GetDirectoryNames
- *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
+/*! Function : GetLockerID
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) {
-  TColStd_SequenceOfExtendedString aResultSeq;
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  TDF_Label aLabel;
-  if (strlen(theContext) == 0) {
-    if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext();   
-    aLabel = _current;
-  } else {
-    TDF_Label aTmp = _current;
-    SetContext(theContext);
-    aLabel = _current;
-    _current = aTmp;
-  }
-  TDF_ChildIterator anIter(aLabel, Standard_False); // iterate first-level children at all sublevels
-  for(; anIter.More(); anIter.Next()) {
-    TDF_Label aLabel = anIter.Value();
-    Handle(SALOMEDS_LocalIDAttribute) anID;
-    if (aLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID)) {
-      if (anID->Get() == DIRECTORYID) {
-       Handle(TDataStd_Name) aName;
-       if (aLabel.FindAttribute(TDataStd_Name::GetID(), aName)) {
-         aResultSeq.Append(aName->Get());
-       }
-      }
-    }
-  }
-  // fill the result table
-  int anIndex, aLength = aResultSeq.Length();
+
+  std::vector<std::string> aSeq = _impl->GetLockerID();
+
+  int aLength = aSeq.size();
   aResult->length(aLength);
-  for(anIndex = 0; anIndex < aLength; anIndex++) {
-    aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString());
+  for(int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aResult._retn();
 }
-
 //============================================================================
-/*! Function : GetFileNames
- *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
+/*! Function : SetReal
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) {
-  TColStd_SequenceOfExtendedString aResultSeq;
-  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  TDF_Label aLabel;
-  if (strlen(theContext) == 0) {
-    if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext();   
-    aLabel = _current;
-  } else {
-    TDF_Label aTmp = _current;
-    SetContext(theContext);
-    aLabel = _current;
-    _current = aTmp;
-  }
-  TDF_ChildIterator anIter(aLabel, Standard_False); // iterate all subchildren at all sublevels
-  for(; anIter.More(); anIter.Next()) {
-    TDF_Label aLabel = anIter.Value();
-    Handle(SALOMEDS_LocalIDAttribute) anID;
-    if (aLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID)) {
-      if (anID->Get() == FILELOCALID) {
-       Handle(SALOMEDS_PersRefAttribute) aName;
-       if(aLabel.FindAttribute(SALOMEDS_PersRefAttribute::GetID(), aName)) {
-         TCollection_ExtendedString aFileName = aName->Get();
-         if(aFileName.Length() > 0)
-           aResultSeq.Append(aFileName.Split(strlen(FILEID)));
-       }
-      }
-    }
-//      }
-  }
-  // fill the result table
-  int anIndex, aLength = aResultSeq.Length();
-  aResult->length(aLength);
-  for(anIndex = 0; anIndex < aLength; anIndex++) {
-    aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString());
-  }
-  return aResult._retn();
+void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+
+  _impl->SetVariable(std::string(theVarName), 
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::REAL_VAR);
+  if (_notifier)
+    _notifier->modifyNB_Notification(theVarName);
 }
 
 //============================================================================
-/*! Function : GetComponentNames
- *  Purpose  : method to get all components names
+/*! Function : SetInteger
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) {
-  TColStd_SequenceOfExtendedString aResultSeq;
-  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  TDF_ChildIterator anIter(_doc->Main(), Standard_False); // iterate all subchildren at first level
-  for(; anIter.More(); anIter.Next()) {
-    TDF_Label aLabel = anIter.Value();
-    Handle(TDataStd_Name) aName;
-    if (aLabel.FindAttribute(TDataStd_Name::GetID(), aName)) aResultSeq.Append(aName->Get());
-  }
-  // fill the result table
-  int anIndex, aLength = aResultSeq.Length();
-  aResult->length(aLength);
-  for(anIndex = 0; anIndex < aLength; anIndex++) {
-    aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString());
-  }
-  return aResult._retn();
+void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetVariable(std::string(theVarName), 
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+  if (_notifier)
+    _notifier->modifyNB_Notification(theVarName);
 }
 
 //============================================================================
-/*! Function : NewChildIterator
- *  Purpose  : Create a ChildIterator from an SObject
+/*! Function : SetBoolean
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr aSO)
+void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
 {
-  //Convert aSO->GetID in TDF_Label.
-  TDF_Label Lab;
-  TDF_Tool::Label(_doc->GetData(), strdup(aSO->GetID()), Lab);
-
-  //Create iterator
-  SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(Lab,_orb);
-  SALOMEDS::ChildIterator_var it = SALOMEDS::ChildIterator::_narrow(it_servant->_this()); 
-
-  return it;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetVariable(std::string(theVarName), 
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  if (_notifier)
+    _notifier->modifyNB_Notification(theVarName);
 }
 
-
 //============================================================================
-/*! Function : NewComponentIterator
- *  Purpose  : Create a SComponentIterator
+/*! Function : SetString
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
+void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
 {
-  SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_doc,_orb);
-  SALOMEDS::SComponentIterator_var it = SALOMEDS::SComponentIterator::_narrow(it_servant->_this()); 
-  return it;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetStringVariable(std::string(theVarName), 
+                          theValue,
+                          SALOMEDSImpl_GenericVariable::STRING_VAR);
+  if (_notifier)
+    _notifier->modifyNB_Notification(theVarName);
 }
 
-
 //============================================================================
-/*! Function : NewBuilder
- *  Purpose  : Create a StudyBuilder
+/*! Function : SetStringAsDouble
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
+void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
 {
-  SALOMEDS_StudyBuilder_i* it_servant = new SALOMEDS_StudyBuilder_i(_doc,_orb);
-  SALOMEDS::StudyBuilder_var it = SALOMEDS::StudyBuilder::_narrow(it_servant->_this()); 
-
-  if(_autoFill) {
-    SALOMEDS_Callback_i* callback = new SALOMEDS_Callback_i(GetUseCaseBuilder(), _orb);
-    SALOMEDS::Callback_var cb = SALOMEDS::Callback::_narrow(callback->_this()); 
-
-    it->SetOnAddSObject(cb);
-    it->SetOnRemoveSObject(cb);
-  }
-
-  return it;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
+  _impl->SetStringVariableAsDouble(std::string(theVarName), 
+                                  theValue,
+                                  SALOMEDSImpl_GenericVariable::STRING_VAR);
 }
+
 //============================================================================
-/*! Function : Name
- *  Purpose  : get study name
+/*! Function : GetReal
+ *  Purpose  : 
  */
 //============================================================================
-char* SALOMEDS_Study_i::Name()
+CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
 {
-  return CORBA::string_dup(_name);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->GetVariableValue(std::string(theVarName));
 }
 
 //============================================================================
-/*! Function : Name
- *  Purpose  : set study name
+/*! Function : GetInteger
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::Name(const char* name)
+CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
 {
-  _name = new char[strlen(name) +1];
-  strcpy(_name,name);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return (long)_impl->GetVariableValue(std::string(theVarName));
 }
 
 //============================================================================
-/*! Function : IsSaved
- *  Purpose  : get if study has been saved
+/*! Function : GetBoolean
+ *  Purpose  : 
  */
 //============================================================================
-CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
+CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
 {
-  return _isSaved;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return (bool)_impl->GetVariableValue(std::string(theVarName));
 }
 
 //============================================================================
-/*! Function : IsSaved
- *  Purpose  : set if study has been saved
+/*! Function : GetString
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
+char* SALOMEDS_Study_i::GetString(const char* theVarName)
 {
-  _isSaved = save;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
 }
 
 //============================================================================
-/*! Function : IsModified
- *  Purpose  : Detect if a Study has been modified since it has been saved
+/*! Function : IsReal
+ *  Purpose  : 
  */
 //============================================================================
-CORBA::Boolean  SALOMEDS_Study_i::IsModified()
+CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
 {
-  // True if is modified and not saved
-  if (_doc->IsModified())
-    if (!_isSaved) return true;
-    else return false;
-  else return false;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::REAL_VAR);
 }
 
 //============================================================================
-/*! Function : URL
- *  Purpose  : get URL of the study (persistent reference of the study)
+/*! Function : IsInteger
+ *  Purpose  : 
  */
 //============================================================================
-char* SALOMEDS_Study_i::URL()
+CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
 {
-  if(!_URL) {
-    _URL = new char[1];
-    _URL[0] = (char)0;
-  }
-  return CORBA::string_dup(_URL);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::INTEGER_VAR);
 }
 
 //============================================================================
-/*! Function : URL
- *  Purpose  : set URL of the study (persistent reference of the study)
+/*! Function : IsBoolean
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::URL(const char* url)
+CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
 {
-  if (_URL) delete [] _URL;
-  _URL = new char[strlen(url) +1];
-  strcpy(_URL,url);
-  SCRUTE(_URL);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  char *aName = _URL;
-  char *adr = strtok(aName, "/");
-  while (adr)
-    {
-      aName = adr;
-      adr = strtok(NULL, "/");
-    }
-  strcpy(_URL,url);
-  Name(aName);
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
 }
 
-
 //============================================================================
-/*! Function : _FindObject
- *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
+/*! Function : IsString
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::SObject_ptr SALOMEDS_Study_i::_FindObject(SALOMEDS::SObject_ptr SO,
-                                                   const char* anObjectName, 
-                                                   bool& _find)
+CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
 {
-  // Iterate on each objects and subobjects of the component
-  // If objectName find, stop the loop and get the object reference
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  CORBA::String_var soid = SO->GetID();
-  SALOMEDS::ChildIterator_var it = NewChildIterator(SO);
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SObject_var CSO = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (CSO->FindAttribute(anAttr,"AttributeName")) 
-       {
-         SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
-          CORBA::String_var Val = Name->Value();
-         if (strcmp(Val, anObjectName) == 0)
-           {
-             RefSO = SALOMEDS::SObject::_narrow(CSO);
-             _find = true;
-           }
-       }
-       if (!_find) RefSO =  _FindObject(CSO, anObjectName, _find);
-      }
-  }
-  return RefSO;
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::STRING_VAR);
 }
 
 //============================================================================
-/*! Function : _FindObject
- *  Purpose  : Find an Object with SALOMEDS::IOR = anObjectIOR
+/*! Function : IsVariable
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::SObject_ptr 
-SALOMEDS_Study_i::_FindObjectIOR(SALOMEDS::SObject_ptr SO,
-                             const char* anObjectIOR, 
-                             bool& _find)
+CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
 {
-  // Iterate on each objects and subobjects of the component
-  // If objectName find, stop the loop and get the object reference
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
-
-  SALOMEDS::ChildIterator_var it = NewChildIterator(SO);
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SObject_var CSO = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (CSO->FindAttribute(anAttr,"AttributeIOR")) 
-       {
-         SALOMEDS::AttributeIOR_var IOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-          CORBA::String_var Val = IOR->Value();
-         if (strcmp(Val, anObjectIOR) == 0)
-           {
-             RefSO = SALOMEDS::SObject::_narrow(CSO);
-             _find = true;
-           }
-       }
-       if (!_find) RefSO =  _FindObjectIOR(CSO, anObjectIOR, _find);
-      }
-  }
-  return RefSO;
-}
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-CORBA::Short SALOMEDS_Study_i::StudyId()
-{
-  return _StudyId;
+  return _impl->IsVariable(std::string(theVarName));
 }
 
-void SALOMEDS_Study_i::StudyId(CORBA::Short id)
+//============================================================================
+/*! Function : GetVariableNames
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
 {
-  _StudyId = id;
-}
-
-void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) {
-  TDF_Label aLabel;
-  CORBA::String_var anEn = CORBA::string_dup(anEntry);
-  CORBA::String_var IOR = CORBA::string_dup(anIOR);
-  TDF_Tool::Label(_doc->GetData(),anEn,aLabel, Standard_True);
-  if (myIORLabels.IsBound(TCollection_ExtendedString(IOR))) myIORLabels.UnBind(TCollection_ExtendedString(IOR));
-  myIORLabels.Bind(TCollection_ExtendedString(IOR), aLabel);
-}
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA::ORB_ptr orb) {
-  Handle(SALOMEDS_IORAttribute) Att;
-  if (theLabel.Root().FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
-    char* IOR = CORBA::string_dup(TCollection_AsciiString(Att->Get()).ToCString());
-    CORBA::Object_var obj = orb->string_to_object(IOR);
-    SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
-    ASSERT(!CORBA::is_nil(aStudy));
-    return SALOMEDS::Study::_duplicate(aStudy);
-  } else {
-    INFOS("GetStudy: Problem to get study");
-  }
-  return SALOMEDS::Study::_nil();
-}
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
-void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute, CORBA::ORB_ptr orb) {
-  TCollection_AsciiString aString;
-  TDF_Tool::Entry(theAttribute->Label(), aString);
-  GetStudy(theAttribute->Label(), orb)->UpdateIORLabelMap(TCollection_AsciiString(theAttribute->Get()).ToCString(),
-                                                         aString.ToCString());
-}
+  std::vector<std::string> aVarNames = _impl->GetVariableNames();
 
-SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) {
-  SALOMEDS::GenericAttribute_ptr aTarget;
-  if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
-    return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
-  }
-  SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
-  aList->length(0);
-  return aList;
+  int aLen = aVarNames.size();
+  aResult->length(aLen);
+  for (int anInd = 0; anInd < aLen; anInd++)
+    aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
+  
+  return aResult._retn();
 }
 
+//============================================================================
+/*! Function : RemoveVariable
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() {
-  SALOMEDS::GenericAttribute_ptr anAttr =  NewBuilder()->FindOrCreateAttribute(FindObjectID("0:1"),
-                                                                              "AttributeStudyProperties");
-  return SALOMEDS::AttributeStudyProperties::_narrow(anAttr);
-}
+  bool res = _impl->RemoveVariable(std::string(theVarName));
+  if (res && _notifier)
+    _notifier->modifyNB_Notification(theVarName);
 
-char* SALOMEDS_Study_i::GetLastModificationDate() {
-  SALOMEDS::AttributeStudyProperties_var aProp = GetProperties();
-  SALOMEDS::StringSeq_var aNames;
-  SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
-  aProp->GetModificationsList(aNames , aMinutes ,aHours, aDays, aMonths, aYears, true);
-  int aLastIndex = aNames->length() - 1;
-  char aResult[20];
-  sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]),
-         (int)(aYears[aLastIndex]), (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
-  CORBA::String_var aResStr = CORBA::string_dup(aResult);
-  return aResStr._retn();
+  return res;
 }
 
-SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() {
-  SALOMEDS::AttributeStudyProperties_var aProp = GetProperties();
-  SALOMEDS::StringSeq_var aNames;
-  SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
-  aProp->GetModificationsList(aNames , aMinutes ,aHours, aDays, aMonths, aYears, false);
+//============================================================================
+/*! Function : RenameVariable
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  int anIndex, aLength = aNames->length();
-  SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
-  aDates->length(aLength);
+  bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
+  if (res && _notifier)
+    _notifier->modifyNB_Notification(theVarName);
 
-  for(anIndex = 0; anIndex < aLength; anIndex++) {
-    char aDate[20];
-    sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays[anIndex]), (int)(aMonths[anIndex]),
-           (int)(aYears[anIndex]), (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
-    aDates[anIndex] = CORBA::string_dup(aDate);
-  }
-  return aDates._retn();
+  return res;
 }
 
-
-
 //============================================================================
-/*! Function : GetUseCaseBuilder
- *  Purpose  : Returns a UseCase builder
+/*! Function : IsVariableUsed
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
+CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
 {
-  SALOMEDS_UseCaseBuilder_i* _caseBuilder = new SALOMEDS_UseCaseBuilder_i(_doc, _orb);
-  SALOMEDS::UseCaseBuilder_var aBuilder = SALOMEDS::UseCaseBuilder::_narrow(_caseBuilder->_this());
-  return aBuilder._retn();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsVariableUsed(std::string(theVarName));
 }
 
 
 //============================================================================
-/*! Function : Close
+/*! Function : ParseVariables
  *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::Close()
+SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
 {
-  SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  for (; itcomponent->More(); itcomponent->Next()) {
-    SALOMEDS::SComponent_var sco = itcomponent->Value();
-         
-    MESSAGE ( "Look for an engine for data type :"<< sco->ComponentDataType());
-    // if there is an associated Engine call its method for closing
-    CORBA::String_var IOREngine;
-    if (sco->ComponentIOR(IOREngine)) {
-      // we have found the associated engine to write the data 
-      MESSAGE ( "We have found an engine for data type :"<< sco->ComponentDataType());
-      CORBA::Object_var obj = _orb->string_to_object(IOREngine);
-      if (!CORBA::is_nil(obj)) {
-       SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
-       
-       if (!anEngine->_is_nil())  
-         anEngine->Close(sco);
-      }
-    }
+  SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
+
+  std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
+
+  int aSectionsLen = aSections.size();
+  aResult->length(aSectionsLen);
+
+  for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
+    std::vector<std::string> aVarNames = aSections[aSectionInd];
+
+    SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
+
+    int aLen = aVarNames.size();
+    aList->length(aLen);
+
+    for (int anInd = 0; anInd < aLen; anInd++)
+      aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
+
+    aResult[aSectionInd] = aList;
   }
 
-  Handle(TDocStd_Application) anApp = Handle(TDocStd_Application)::DownCast(_doc->Application());
-//    Handle(TDocStd_Owner) anOwner;
-//    if (_doc->Main().Root().FindAttribute(TDocStd_Owner::GetID(), anOwner)) {
-//      Handle(TDocStd_Document) anEmptyDoc;
-//      anOwner->SetDocument(anEmptyDoc);
-//    }
-  if(!anApp.IsNull()) anApp->Close(_doc);
-  _doc.Nullify();
+  return aResult._retn();
 }
 
 //============================================================================
-/*! Function : AddPostponed
+/*! Function : GetDefaultScript
  *  Purpose  : 
  */
- //============================================================================
-void SALOMEDS_Study_i::AddPostponed(const char* theIOR) {
-  if (!NewBuilder()->HasOpenCommand()) return;
-  try {
-    CORBA::Object_var obj = _orb->string_to_object(theIOR);
-    if (!CORBA::is_nil(obj)) {
-      SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
-      if (!CORBA::is_nil(aGeneric)) {
-       TCollection_AsciiString anIOR(strdup(theIOR));
-       anIOR.Prepend("d");
-       myPostponedIORs.Append(anIOR); // add prefix: deleted
-       myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1);
-      }
-    }
-  } catch(...) {}
-}
+//============================================================================
+char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
+{
+  SALOMEDS::Locker lock; 
 
-void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) {
-  if (!NewBuilder()->HasOpenCommand()) return;
-  try {
-    CORBA::Object_var obj = _orb->string_to_object(theIOR);
-    if (!CORBA::is_nil(obj)) {
-      SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
-      if (!CORBA::is_nil(aGeneric)) {
-       TCollection_AsciiString anIOR(strdup(theIOR));
-       anIOR.Prepend("c");
-       myPostponedIORs.Append(anIOR); // add prefix: created
-       myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1);
-      }
-    }
-  } catch(...) {}
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
+  return CORBA::string_dup(script.c_str());
 }
 
 //============================================================================
-/*! Function : RemovePostponed
+/*! Function : EnableUseCaseAutoFilling
  *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit) {
-  int anIndex;
-  int anOld;
-
-  int aUndoLimit = theUndoLimit;
-  if (theUndoLimit < 0) aUndoLimit = 0;
+void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) 
+{ 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->EnableUseCaseAutoFilling(isEnabled); 
+  SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
+  if (builder) {
+    if (isEnabled) {
+      builder->SetOnAddSObject(_impl->GetCallback());
+      builder->SetOnRemoveSObject(_impl->GetCallback());
+    }
+    else {
+      builder->SetOnAddSObject(NULL);
+      builder->SetOnRemoveSObject(NULL);
+    }
+  }
+}
 
-  if (myNbUndos > 0) { // remove undone
-    anOld = 0;
-    for(anIndex = 1; anIndex < myNbPostponed.Length() - myNbUndos; anIndex++)
-      anOld += myNbPostponed(anIndex);
-    int aNew = myPostponedIORs.Length() - myNbPostponed.Last();
 
-    for(anIndex = anOld + 1; anIndex <= aNew; anIndex++) {
-      TCollection_AsciiString anIOR = myPostponedIORs(anIndex);
-      if (anIOR.Value(1) == 'c') {
-       CORBA::Object_var obj = _orb->string_to_object(strdup(anIOR.Split(1).ToCString()));
-       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-      }
-    }
-    if (anOld < aNew) myPostponedIORs.Remove(anOld + 1, aNew);
-    if (myNbPostponed.Length() > 0) myNbPostponed.Remove(myNbPostponed.Length() - myNbUndos, myNbPostponed.Length() - 1);
+CORBA::Long SALOMEDS_Study_i::getPID()
+{
+#ifdef WIN32
+  return (CORBA::Long)_getpid();
+#else
+  return (CORBA::Long)getpid();
+#endif
+}
 
-    myNbUndos = 0;
-  }
+void SALOMEDS_Study_i::ShutdownWithExit()
+{
+  exit( EXIT_SUCCESS );
+}
 
-  if (myNbPostponed.Length() > aUndoLimit) { // remove objects, that can not be undone
-    anOld = 0;
-    for(anIndex = myNbPostponed.Length() - aUndoLimit; anIndex >= 1; anIndex--)
-      anOld += myNbPostponed(anIndex);
-    for(anIndex = 1; anIndex <= anOld; anIndex++) {
-      TCollection_AsciiString anIOR = myPostponedIORs(anIndex);
-      if (anIOR.Value(1) == 'd') {
-       CORBA::Object_var obj = _orb->string_to_object(strdup(anIOR.Split(1).ToCString()));
-       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-      }
-    }
-    if (anOld > 0) myPostponedIORs.Remove(1, anOld);
-    myNbPostponed.Remove(1, myNbPostponed.Length() - aUndoLimit);
-  }
+void SALOMEDS_Study_i::Shutdown()
+{
+  if(!CORBA::is_nil(_orb))
+    _orb->shutdown(0);
+}
 
-  if (theUndoLimit == -1) { // remove all IORs from the study on the study close
-    TDF_ChildIDIterator anIter(_doc->GetData()->Root(), SALOMEDS_IORAttribute::GetID(), Standard_True);
-    for(; anIter.More(); anIter.Next()) {
-      Handle(SALOMEDS_IORAttribute) anAttr = Handle(SALOMEDS_IORAttribute)::DownCast(anIter.Value());
-      CORBA::String_var anIOR = strdup(TCollection_AsciiString(anAttr->Get()).ToCString());
-      try {
-       CORBA::Object_var obj = _orb->string_to_object(anIOR);
-       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-      } catch (...) {}
-    }
-  } else myNbPostponed.Append(0);
+//============================================================================
+/*! Function : attach
+ *  Purpose  : This function attach an observer to the study
+ */
+//============================================================================
+void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
+{
+  if (_notifier)
+    static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
 }
 
+
 //============================================================================
-/*! Function : UndoPostponed
- *  Purpose  : 
+/*! Function : detach
+ *  Purpose  : This function detaches an observer from the study
  */
 //============================================================================
-void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) {
-  myNbUndos += theWay;
-  // remove current postponed
-  if (myNbPostponed.Last() > 0)
-    myPostponedIORs.Remove(myPostponedIORs.Length() - myNbPostponed.Last() + 1, myPostponedIORs.Length());
-  myNbPostponed(myNbPostponed.Length()) = 0;
+void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
+{
+  if (_notifier)
+    static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
+}
+
+//===========================================================================
+//   PRIVATE FUNCTIONS
+//===========================================================================
+CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
+{
+#ifdef WIN32
+  long pid = (long)_getpid();
+#else
+  long pid = (long)getpid();
+#endif  
+  isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
+  return reinterpret_cast<CORBA::LongLong>(_impl);
 }