Salome HOME
- Deleted Study as an input parameter and class field.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.cxx
index 1f8e0aa75067bc52597819a1a6e0a3bb702dd13a..cd586ec2f80023d78afc04392e2afcadf5bd4b98 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_UseCaseIterator_i.hxx"
+#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 <TDataStd_ChildNodeIterator.hxx>
-#include <TDocStd_Application.hxx>
-#include <TDocStd_Owner.hxx>
-#include <CDM_Document.hxx>
-#include <CDM_Application.hxx>
-#include <TDF_ChildIDIterator.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 <TColStd_SequenceOfExtendedString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TCollection_AsciiString.hxx>
+#include "DF_Label.hxx"
+#include "DF_Attribute.hxx"
 
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_ListOfInteger.hxx>
+#include "Utils_ExceptHandlers.hxx"
 
-#include "SALOMEDS_Study_i.hxx"
+#include "Basics_Utils.hxx"
+#include "SALOME_KernelServices.hxx"
 
-#include "SALOMEDS_StudyManager_i.hxx"
-#include "SALOMEDS_Callback_i.hxx"
+#ifdef WIN32
+#include <process.h>
+#else
+#include <sys/types.h>
+#include <unistd.h>
+#endif
 
-#include "SALOMEDS_SComponent_i.hxx"
-#include "SALOMEDS_SObject_i.hxx"
+UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
+UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
 
-#include "SALOMEDS_StudyBuilder_i.hxx"
-#include "SALOMEDS_ChildIterator_i.hxx"
+static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
 
-#include "SALOMEDS_UseCaseBuilder_i.hxx"
-#include "SALOMEDS_SComponentIterator_i.hxx"
+namespace SALOMEDS
+{
+  class Notifier: public SALOMEDSImpl_AbstractCallback
+  {
+  public:
+    Notifier(CORBA::ORB_ptr orb)
+    {
+      _orb = CORBA::ORB::_duplicate(orb);
+    }
 
-#include "SALOME_GenericObj_i.hh"
-#include "SALOMEDS_LocalIDAttribute.hxx"
-#include "SALOMEDS_PersRefAttribute.hxx"
+    //============================================================================
+    /*! Function : addSO_Notification
+     *  Purpose  : This function tells all the observers that a SO has been added
+     */
+    //============================================================================
 
-#include "SALOMEDS_StudyPropertiesAttribute.hxx"
-#include "SALOMEDS_DataMapIteratorOfDataMapStringLabel.hxx"
+    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
+    }
 
-#include "utilities.h"
+    //============================================================================
+    /*! Function : removeSO_Notification
+     *  Purpose  : This function tells all the observers that a SO has been removed
+     */
+    //============================================================================
 
-#define DIRECTORYID 16661
-#define FILEID "FILE: "
-#define FILELOCALID 26662 
+    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
+    }
 
-using namespace std;
+    //============================================================================
+    /*! Function : modifySO_Notification
+     *  Purpose  : This function tells all the observers that a SO has been modified
+     */
+    //============================================================================
 
-bool operator<(const TDF_Label& theLeft, const TDF_Label& theRight)
-{
-  TColStd_ListOfInteger aTagLeftList;
-  TDF_Tool::TagList(theLeft,aTagLeftList);
-  TColStd_ListIteratorOfListOfInteger anLeftIter(aTagLeftList);
-  
-  TColStd_ListOfInteger aTagRightList;
-  TDF_Tool::TagList(theRight,aTagRightList);
-  TColStd_ListIteratorOfListOfInteger anRightIter(aTagRightList);
-  
-  for(;;){
-    Standard_Boolean aLeftMore = anLeftIter.More();
-    Standard_Boolean aRightMore = anRightIter.More();
-    
-    if(!aLeftMore && !aRightMore)
-      return Standard_False;
-    
-    if(!aLeftMore)
-      return Standard_True;
-    
-    if(!aRightMore)
-      return Standard_False;
-    
-    Standard_Integer aLeftTag = anLeftIter.Value();
-    anLeftIter.Next();
-    
-    Standard_Integer aRightTag = anRightIter.Value();
-    anRightIter.Next();
-    
-    if(aLeftTag == aRightTag)
-      continue;
+    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.
+     */
+    //============================================================================
     
-    return aLeftTag < aRightTag;
-  }
-  
-  return Standard_False;
-}
+    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;
+  };
+
+} // namespace SALOMEDS
 
-  
 //============================================================================
 /*! Function : SALOMEDS_Study_i
  *  Purpose  : SALOMEDS_Study_i constructor
  */
 //============================================================================
-SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDS_StudyManager_i* theStudyManager,
-                                  const Handle(TDocStd_Document)& theDoc,
-                                  const char* theStudyName):
-  _StudyManager(theStudyManager),
-  _doc(theDoc),
-  _isSaved(false),
-  _URL(NULL),
-  _StudyId(-1),
-  _autoFill(true),
-  myNbUndos(0)
+SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
 {
-  _UseCaseBuilder = new SALOMEDS_UseCaseBuilder_i(this,_doc);
-  SALOMEDS::UseCaseBuilder_var aUseCaseBuilder = _UseCaseBuilder->_this();
+  _orb     = CORBA::ORB::_duplicate(orb);
+  _impl    = new SALOMEDSImpl_Study();
+  _factory = new SALOMEDS_DriverFactory_i(_orb);
+  _closed  = true;
 
-  _Builder = new SALOMEDS_StudyBuilder_i(this,_doc);
-  SALOMEDS::StudyBuilder_var aStudyBuilder = _Builder->_this(); 
-
-  SALOMEDS_Callback_i* aCallBackServant = new SALOMEDS_Callback_i(aUseCaseBuilder);
-  _callbackOnAdd = aCallBackServant->_this();
-  _callbackOnRemove = _callbackOnAdd;
-
-  _name = new char[strlen(theStudyName) +1];
-  strcpy(_name,theStudyName);
-  myNbPostponed.Append(0);
+  Init();
 }
-  
+
 //============================================================================
 /*! Function : ~SALOMEDS_Study_i
  *  Purpose  : SALOMEDS_Study_i destructor
@@ -146,128 +247,291 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDS_StudyManager_i* theStudyManager,
 //============================================================================
 SALOMEDS_Study_i::~SALOMEDS_Study_i()
 {
-  delete [] _name ;
-  delete [] _URL ;
-}  
+  Clear();
+  delete _factory;
+  delete _impl;
+}
 
 //============================================================================
-CORBA::ORB_var SALOMEDS_Study_i::GetORB() const
+/*! Function : Init
+ *  Purpose  : Initialize study components
+ */
+//============================================================================
+void SALOMEDS_Study_i::Init()
 {
-  return _StudyManager->GetORB();
+  if ( !_impl->GetDocument() )
+    _impl->Init();
+
+  if (!_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
+
+  _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 );
+
+  // update desktop title with new study name
+  NameChanged();
+
+  // 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();
+  }
 }
 
 //============================================================================
-PortableServer::POA_var SALOMEDS_Study_i::GetPOA() const
+/*! Function : Clear
+ *  Purpose  : Clear study components
+ */
+//============================================================================
+void SALOMEDS_Study_i::Clear()
 {
-  return _StudyManager->GetPOA();
-}
+  SALOMEDS::Locker lock;
+  if (_closed)
+    return;
+  //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();
+
+  RemovePostponed(-1);
+
+  if (_impl->GetDocument()) {
+    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();
+  }
 
-SALOMEDS_SObject_i* 
-SALOMEDS_Study_i::DownCast(SALOMEDS::SObject_ptr theSObject) const
-{
-  if(!CORBA::is_nil(theSObject)){
-    PortableServer::POA_var aPOA = GetPOA();
-    PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theSObject,aPOA);
-    if(aServant.in())
-      return dynamic_cast<SALOMEDS_SObject_i*>(aServant.in());
+  // 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();
   }
-  return NULL;
+
+  _impl->Clear();
+  _impl->setNotifier(0);
+  delete _notifier;
+  delete _genObjRegister;
+  _notifier = NULL;
+
+  _closed = true;
 }
 
 //============================================================================
-/*! Function : SetOnAddSObject
- *  Purpose  : 
+/*! Function : Open
+ *  Purpose  : Open a Study from it's persistent reference
  */
 //============================================================================
-SALOMEDS::Callback_ptr SALOMEDS_Study_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
+bool SALOMEDS_Study_i::Open(const char* aUrl)
+  throw(SALOME::SALOME_Exception)
 {
-  SALOMEDS::Callback_var aRet = _callbackOnAdd;
-  _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback);
-  return aRet._retn();
+  if (!_closed)
+    Clear();
+  Init();
+  SALOMEDS::Locker lock;
+
+  Unexpect aCatch(SalomeException);
+  MESSAGE("Begin of SALOMEDS_Study_i::Open");
+
+  bool res = _impl->Open(std::string(aUrl));
+
+  // update desktop title with new study name
+  NameChanged();
+
+  if ( !res )
+    THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
+  return res;
 }
 
 //============================================================================
-/*! Function : SetOnNewSObject
- *  Purpose  : 
+/*! Function : Save
+ *  Purpose  : Save a Study to it's persistent reference
  */
 //============================================================================
-SALOMEDS::Callback_ptr SALOMEDS_Study_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
+CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
 {
-  SALOMEDS::Callback_var aRet = _callbackOnRemove;
-  _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback);
-  return aRet._retn();
+  SALOMEDS::Locker lock;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
+  return _impl->Save(_factory, theMultiFile, theASCII);
 }
 
+//=============================================================================
+/*! Function : SaveAs
+ *  Purpose  : Save a study to the persistent reference aUrl
+ */
 //============================================================================
-void SALOMEDS_Study_i::OnAddSObject(SALOMEDS::SObject_ptr theObject)
+CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
 {
-  if(!CORBA::is_nil(_callbackOnAdd.in()))
-    _callbackOnAdd->OnAddSObject(theObject);
+  SALOMEDS::Locker lock;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
+  return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
 }
 
 //============================================================================
-void SALOMEDS_Study_i::OnRemoveSObject(SALOMEDS::SObject_ptr theObject)
-{
-  if(!CORBA::is_nil(_callbackOnRemove.in()))
-    _callbackOnRemove->OnRemoveSObject(theObject);
-}
-
+/*! Function : CanCopy
+ *  Purpose  :
+ */
 //============================================================================
-void SALOMEDS_Study_i::CheckLocked()
+CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
 {
-  if(_doc->HasOpenCommand()) 
-    return;
+  SALOMEDS::Locker lock;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
 
-  Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
-  if(_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(),anAttr))
-    if(anAttr->IsLocked())
-      throw SALOMEDS::StudyBuilder::LockProtection();
-}
+  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;
+}
 
 //============================================================================
-char* SALOMEDS_Study_i::ConvertObjectToIOR(CORBA::Object_ptr theObject)
+/*! Function : Copy
+ *  Purpose  :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
 {
-  return GetORB()->object_to_string(theObject); 
-}
+  SALOMEDS::Locker lock;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
 
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
 
-//============================================================================
-CORBA::Object_ptr SALOMEDS_Study_i::ConvertIORToObject(const char* theIOR) 
-{ 
-  return GetORB()->string_to_object(theIOR); 
+  SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
+  bool ret = _impl->Copy(anObject, aDriver);
+  delete aDriver;
+  return ret;
 }
 
-
 //============================================================================
-/*! Function : GetPersistentReference
- *  Purpose  : Get persistent reference of study (idem URL())
+/*! Function : CanPaste
+ *  Purpose  :
  */
 //============================================================================
-char* SALOMEDS_Study_i::GetPersistentReference()
+CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
 {
-  return URL();
+  SALOMEDS::Locker lock;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();
+
+  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 : GetTransientReference
- *  Purpose  : Get IOR of the Study (registred in OCAF document in doc->Root)
+/*! Function : Paste
+ *  Purpose  :
  */
 //============================================================================
-char* SALOMEDS_Study_i::GetTransientReference()
+SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
+     throw(SALOMEDS::StudyBuilder::LockProtection)
 {
-  CORBA::String_var IOR;
+  SALOMEDS::Locker lock;
 
-  Handle(SALOMEDS_IORAttribute) Att;
-  TDF_Label _lab = _doc->GetData()->Root();
-  if (!_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
+  Unexpect aCatch(LockProtection);
 
-    TCollection_AsciiString ch(Att->Get());
-    IOR = CORBA::string_dup(ch.ToCString());
+  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);
+    }
   }
-  else IOR = CORBA::string_dup(""); // NULL ?
 
-  return CORBA::string_dup(IOR); 
+  return driver;
+}
+
+//============================================================================
+/*! Function : GetPersistentReference
+ *  Purpose  : Get persistent reference of study (idem URL())
+ */
+//============================================================================
+char* SALOMEDS_Study_i::GetPersistentReference()
+{
+  SALOMEDS::Locker lock; 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+  return CORBA::string_dup(_impl->GetPersistentReference().c_str());
 }
 
 //============================================================================
@@ -277,8 +541,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();
 }
 
 //============================================================================
@@ -286,21 +552,20 @@ CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
  *  Purpose  : Find a Component with ComponentDataType = aComponentName
  */
 //============================================================================
-SALOMEDS::SComponent_ptr 
-SALOMEDS_Study_i::FindComponent(const char* theComponentName)
+SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
 {
-  bool anIsFound = false;
-  SALOMEDS::SComponent_var aSComponent;
-  SALOMEDS_SComponentIterator_i aComponentIter(this,_doc);
-  for(; aComponentIter.More() && !anIsFound; aComponentIter.Next()){
-    SALOMEDS::SComponent_var aSComp = aComponentIter.Value();
-    CORBA::String_var aName = aSComp->ComponentDataType();
-    if(strcmp(theComponentName,aName.in()) == 0){
-      aSComponent = aSComp;
-      anIsFound = true;
-    }
-  }
-  return aSComponent._retn();
+  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();
 }
 
 //============================================================================
@@ -310,28 +575,18 @@ SALOMEDS_Study_i::FindComponent(const char* theComponentName)
 //============================================================================
 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_i itcomp(this,_doc);
-  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();
 }
 
 //============================================================================
@@ -339,29 +594,27 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen
  *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
  */
 //============================================================================
-SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* theObjectName)
-{
-  // Iterate to all components defined in the study
-  // After testing the component name, iterate in all objects defined under
-  // components (function _FindObject)
-  bool aIsFound = false;
-  SALOMEDS::SObject_var aRefSO;
-  SALOMEDS_SComponentIterator_i aComponentIter(this,_doc);
-  for(; aComponentIter.More() && !aIsFound; aComponentIter.Next()){
-    TDF_Label aLab = aComponentIter.GetValue();
-    Handle(TDataStd_Name) anAttr;
-    if(aLab.FindAttribute(TDataStd_Name::GetID(),anAttr)){
-      TCollection_AsciiString aString(anAttr->Get());
-      if(strcmp(aString.ToCString(),theObjectName) == 0){
-       aRefSO = SALOMEDS_SComponent_i::NewRef(this,aLab)._retn();
-       aIsFound = true;
-      }
+SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
+{
+  SALOMEDS::Locker lock; 
+
+  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);
     }
-    if(!aIsFound) 
-      aRefSO = _FindObject(aLab,theObjectName,aIsFound);
   }
 
-  return aRefSO._retn();
+  return so._retn();
 }
 
 //============================================================================
@@ -371,15 +624,18 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* theObjectName)
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
 {
-  // Convert aSO->GetID in TDF_Label.
-  TDF_Label Lab;
-  TDF_Tool::Label(_doc->GetData(), (char*)anObjectID, Lab);
-  
-  if (Lab.IsNull()) 
-    return SALOMEDS::SObject::_nil();
+  SALOMEDS::Locker lock; 
 
-  return SALOMEDS_SObject_i::NewRef(this,Lab)._retn();
+  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();
 }
 
 //============================================================================
@@ -389,14 +645,20 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
 {
-  // Convert aSO->GetID in TDF_Label.
-  TDF_Label Lab;
-  TDF_Tool::Label(_doc->GetData(), (char*)anObjectID, Lab, Standard_True);
-  
-  if (Lab.IsNull()) 
-    return SALOMEDS::SObject::_nil();
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  return SALOMEDS_SObject_i::NewRef(this,Lab)._retn();
+  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();
 }
 
 //============================================================================
@@ -405,95 +667,47 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
  *           : with ComponentDataType = aComponentName
  */
 //============================================================================
-SALOMEDS::Study::ListOfSObject* 
-SALOMEDS_Study_i::FindObjectByName(const char* theObjectName,
-                                  const char* theComponentName)
+SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
+                                                                    const char* aComponentName )
 {
-  SALOMEDS::Study::ListOfSObject_var aListOfSObj = new SALOMEDS::Study::ListOfSObject ;
-  aListOfSObj->length(0);
+  SALOMEDS::Locker lock; 
 
-  SALOMEDS::SComponent_ptr aSComponent = FindComponent(theComponentName) ;
-  if(aSComponent->_is_nil()){
-    MESSAGE ("In FindObjectByName() :  Component named " << theComponentName << " not found ");
-    return aListOfSObj._retn();
-  }
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  // Iterate on each object and subobject of the component
-  // If objectName is found add it to the list of SObjects 
-  TDF_Label aLabel;
-  CORBA::String_var anEntry = aSComponent->GetID();
-  TDF_Tool::Label(_doc->GetData(),const_cast<char*>(anEntry.in()),aLabel);
-  
-  int aLength = 0 ;
-  SALOMEDS::SObject_var aRefSO;
-  TDF_ChildIterator aChildIter(aLabel,true);
-  for(; aChildIter.More(); aChildIter.Next()){
-    TDF_Label aLab = aChildIter.Value();
-    Handle(TDataStd_Name) anAttr;
-    if(aLab.FindAttribute(TDataStd_Name::GetID(),anAttr)){
-      TCollection_AsciiString aString(anAttr->Get());
-      if(strcmp(aString.ToCString(),theObjectName) == 0){
-       aRefSO = SALOMEDS_SObject_i::NewRef(this,aLab)._retn();
-       /* add to list */
-       aLength++ ;
-       aListOfSObj->length(aLength);
-       aListOfSObj[aLength-1] = aRefSO;
-      }
-    }
-  }
+  std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
+                                                                  std::string((char*)aComponentName));
 
-  return aListOfSObj._retn() ;
+  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();
 }
 
-
-
 //============================================================================
 /*! Function : FindObjectIOR
  *  Purpose  : Find an Object with IOR = anObjectIOR
  */
 //============================================================================
-SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* theObjectIOR)
-{
-  // firstly searching in the datamap for optimization
-  char* anIOR = const_cast<char*>(theObjectIOR);
-  if(myIORLabels.IsBound(anIOR)){
-    TDF_Label aLabel = myIORLabels.Find(anIOR);
-    TSObjectHolder aSObjectHolder = SALOMEDS_SObject_i::New(this,aLabel);
-    SALOMEDS_SObject_i* aSObjectPtr = aSObjectHolder.first;
-    SALOMEDS::SObject_var aSObject = aSObjectHolder.second;
-    // 11 oct 2002: forbidden attributes must be checked here
-    SALOMEDS::GenericAttribute_var anAttr;
-    if(!aSObjectPtr->FindAttribute(anAttr,"AttributeIOR")){
-      myIORLabels.UnBind(anIOR);
-    }else{
-      return aSObject._retn();
-    }
-  }
+SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
+{
+  SALOMEDS::Locker lock; 
 
-  // Iterate to all components defined in the study
-  // After testing the component name, iterate in all objects defined under
-  // components (function _FindObject)
-  bool aIsFound = false;
-  SALOMEDS::SObject_var aRefSO;
-  SALOMEDS_SComponentIterator_i aComponentIter(this,_doc);
-  for(; aComponentIter.More() && !aIsFound; aComponentIter.Next()){
-    TDF_Label aLab = aComponentIter.GetValue();
-    Handle(SALOMEDS_IORAttribute) anAttr;
-    if(aLab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
-      TCollection_AsciiString aString(anAttr->Get());
-      if(strcmp(aString.ToCString(),theObjectIOR) == 0){
-       aRefSO = SALOMEDS_SComponent_i::NewRef(this,aLab);
-       aIsFound = true;
-      }
-    }
-    if(!aIsFound) 
-      aRefSO = _FindObjectIOR(aLab,theObjectIOR,aIsFound);
-  }
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  if(!aRefSO->_is_nil()) 
-    MESSAGE("SALOMEDS_Study_i::FindObjectIOR: found label with old methods");
+  SALOMEDS::SObject_var so;
 
-  return aRefSO._retn();
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New(aSO, _orb);
+
+  return so._retn();
 }
 
 //============================================================================
@@ -503,337 +717,280 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* theObjectIOR)
 //============================================================================
 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
-    return SALOMEDS_SObject_i::NewRef(this,_current)._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
-      return SALOMEDS_SObject_i::NewRef(this,_doc->Main())._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)
-           return SALOMEDS_SObject_i::NewRef(this,aLabel)._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 : GetObjectPath
- *  Purpose  : 
+/*! Function : NewChildIterator
+ *  Purpose  : Create a ChildIterator from an SObject
  */
 //============================================================================
-char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
+SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
 {
-  TCollection_AsciiString aPath("");
-  if(CORBA::is_nil(theObject)) 
-    return CORBA::string_dup(aPath.ToCString());
+  SALOMEDS::Locker lock; 
 
-  SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(theObject);
-  if(anObject->_is_nil()) {
-    CORBA::String_var anIOR = GetORB()->object_to_string(theObject);
-    anObject = FindObjectIOR(anIOR);
-    if(anObject->_is_nil()) 
-      return CORBA::string_dup(aPath.ToCString());
-  }
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  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;
-      }
-    }
-  }
+  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  CORBA::string_dup(aPath.ToCString());
+  return it._retn();
 }
 
 
 //============================================================================
-/*! Function : SetContext
- *  Purpose  : Sets the current context
+/*! Function : NewComponentIterator
+ *  Purpose  : Create a SComponentIterator
  */
 //============================================================================
-void SALOMEDS_Study_i::SetContext(const char* thePath) 
+SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
 {
-  if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
-  TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext("");
-  bool isInvalid = 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
-  
+  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 : GetContext
- *  Purpose  : Gets the current context
+/*! Function : NewBuilder
+ *  Purpose  : Create a StudyBuilder
  */
 //============================================================================
-char* SALOMEDS_Study_i::GetContext() 
+SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
 {
-  if(_current.IsNull()) 
-    throw SALOMEDS::Study::StudyInvalidContext();   
+  SALOMEDS::Locker lock; 
 
-  SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(this,_current);
-  return GetObjectPath(aSObject);
-}
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
 
+  return sb._retn();
+}
 //============================================================================
-/*! Function : GetObjectNames
- *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
+/*! Function : Name
+ *  Purpose  : get study name
  */
 //============================================================================
-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();
+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 : GetDirectoryNames
- *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
+/*! Function : IsSaved
+ *  Purpose  : get if study has been saved
  */
 //============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(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 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();
-  aResult->length(aLength);
-  for(anIndex = 0; anIndex < aLength; anIndex++) {
-    aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString());
-  }
-  return aResult._retn();
+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 : GetFileNames
- *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
+/*! Function : IsSaved
+ *  Purpose  : set if study has been saved
  */
 //============================================================================
-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::IsSaved(CORBA::Boolean save)
+{
+  SALOMEDS::Locker lock; 
+  // IsSaved is specified as IDL attribute: user exception cannot be raised
+  if (!_closed)
+    _impl->IsSaved(save);
 }
 
 //============================================================================
-/*! Function : GetComponentNames
- *  Purpose  : method to get all components names
+/*! Function : IsModified
+ *  Purpose  : Detect if a Study has been modified since it has been saved
  */
 //============================================================================
-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();
+CORBA::Boolean SALOMEDS_Study_i::IsModified()
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsModified();
 }
 
 //============================================================================
-/*! Function : NewChildIterator
- *  Purpose  : Create a ChildIterator from an SObject
+/*! Function : Modified
+ *  Purpose  : Sets a Modified flag of a Study to True
  */
 //============================================================================
-SALOMEDS::ChildIterator_ptr 
-SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSObject)
+void SALOMEDS_Study_i::Modified()
 {
-  SALOMEDS_ChildIterator_i* aServant = 
-    new SALOMEDS_ChildIterator_i(GetChildIterator(theSObject));
+  SALOMEDS::Locker lock; 
 
-  return aServant->_this();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->Modify();
 }
 
-SALOMEDS_ChildIterator_i 
-SALOMEDS_Study_i::GetChildIterator(SALOMEDS::SObject_ptr theSObject)
+//============================================================================
+/*! Function : URL
+ *  Purpose  : get URL of the study (persistent reference of the study)
+ */
+//============================================================================
+char* SALOMEDS_Study_i::URL()
 {
-  TDF_Label aLab;
-  TDF_Tool::Label(_doc->GetData(),theSObject->GetID(),aLab);
-  return SALOMEDS_ChildIterator_i(this,aLab);
+  SALOMEDS::Locker lock; 
+  // URL is specified as IDL attribute: user exception cannot be raised
+  return CORBA::string_dup(_impl->URL().c_str());
 }
 
 //============================================================================
-/*! Function : NewComponentIterator
- *  Purpose  : Create a SComponentIterator
+/*! Function : URL
+ *  Purpose  : set URL of the study (persistent reference of the study)
  */
 //============================================================================
-SALOMEDS::SComponentIterator_ptr 
-SALOMEDS_Study_i::NewComponentIterator()
+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));
+
+  // update desktop title with new study name
+  NameChanged();
+}
+
+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));
+}
+
+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_SComponentIterator_i* aServant = 
-    new SALOMEDS_SComponentIterator_i(GetComponentIterator());
+  SALOMEDS::Locker lock; 
+  
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  return aServant->_this();
+  SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
+  SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
+  SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
+  return aProp._retn();
 }
 
-SALOMEDS_SComponentIterator_i 
-SALOMEDS_Study_i::GetComponentIterator()
+char* SALOMEDS_Study_i::GetLastModificationDate() 
 {
-  return SALOMEDS_SComponentIterator_i(this,_doc);
+  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();
 }
 
 //============================================================================
@@ -843,402 +1000,625 @@ SALOMEDS_Study_i::GetComponentIterator()
 //============================================================================
 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
 {
-  return _UseCaseBuilder->_this();
+  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 : NewBuilder
- *  Purpose  : Create a StudyBuilder
+/*! Function : AddPostponed
+ *  Purpose  : 
  */
-//============================================================================
-SALOMEDS_StudyBuilder_i* SALOMEDS_Study_i::GetBuilder()
+ //============================================================================
+void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
 {
-  return _Builder;
+  SALOMEDS::Locker lock; 
+  //Not implemented
 }
-SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
+
+void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
 {
-  return GetBuilder()->_this();
+  SALOMEDS::Locker lock; 
+  //Not implemented
 }
+
 //============================================================================
-/*! Function : Name
- *  Purpose  : get study name
+/*! Function : RemovePostponed
+ *  Purpose  : 
  */
 //============================================================================
-char* SALOMEDS_Study_i::Name()
+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) 
 {
-  return CORBA::string_dup(_name);
+  SALOMEDS::Locker lock; 
+  //Not implemented
 }
 
+
 //============================================================================
-/*! Function : Name
- *  Purpose  : set study name
+/*! Function : DumpStudy
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::Name(const char* name)
+CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
+                                           const char* theBaseName, 
+                                           CORBA::Boolean isPublished,
+                                           CORBA::Boolean isMultiFile)
 {
-  _name = new char[strlen(name) +1];
-  strcpy(_name,name);
+  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 : IsSaved
- *  Purpose  : get if study has been saved
+/*! Function : GetCommonParameters
+ *  Purpose  : 
  */
 //============================================================================
-CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
+SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
 {
-  return _isSaved;
+  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 : IsSaved
- *  Purpose  : set if study has been saved
+/*! Function : SetStudyLock
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
+void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
 {
-  _isSaved = save;
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetStudyLock(theLockerID);
 }
 
 //============================================================================
-/*! Function : IsModified
- *  Purpose  : Detect if a Study has been modified since it has been saved
+/*! Function : IsStudyLocked
+ *  Purpose  : 
  */
 //============================================================================
-CORBA::Boolean  SALOMEDS_Study_i::IsModified()
+bool SALOMEDS_Study_i::IsStudyLocked()
 {
-  // True if is modified and not saved
-  if (_doc->IsModified())
-    if (!_isSaved) return true;
-    else return false;
-  else return false;
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsStudyLocked();
 }
 
 //============================================================================
-/*! Function : URL
- *  Purpose  : get URL of the study (persistent reference of the study)
+/*! Function : UnLockStudy
+ *  Purpose  : 
  */
 //============================================================================
-char* SALOMEDS_Study_i::URL()
+void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
 {
-  if(!_URL) {
-    _URL = new char[1];
-    _URL[0] = (char)0;
-  }
-  return CORBA::string_dup(_URL);
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->UnLockStudy(theLockerID);
 }
 
 //============================================================================
-/*! Function : URL
- *  Purpose  : set URL of the study (persistent reference of the study)
+/*! Function : GetLockerID
+ *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::URL(const char* url)
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
 {
-  if (_URL) delete [] _URL;
-  _URL = new char[strlen(url) +1];
-  strcpy(_URL,url);
-  SCRUTE(_URL);
+  SALOMEDS::Locker lock; 
 
-  char *aName = _URL;
-  char *adr = strtok(aName, "/");
-  while (adr)
-    {
-      aName = adr;
-      adr = strtok(NULL, "/");
-    }
-  strcpy(_URL,url);
-  Name(aName);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+
+  std::vector<std::string> aSeq = _impl->GetLockerID();
+
+  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 : SetReal
+ *  Purpose  : 
+ */
+//============================================================================
+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 : _FindObject
- *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
+/*! Function : SetInteger
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::SObject_ptr 
-SALOMEDS_Study_i::_FindObject(TDF_Label theLabel,
-                             const char* theObjectName, 
-                             bool& theIsFound)
-{
-  theIsFound = false;
-  // Iterate on each objects and subobjects of the component
-  // If objectName find, stop the loop and get the object reference
-  SALOMEDS::SObject_var aRefSO;
-  TDF_ChildIterator aChildIter(theLabel,true);
-  for(; aChildIter.More() && !theIsFound; aChildIter.Next()){
-    TDF_Label aLab = aChildIter.Value();
-    Handle(TDataStd_Name) anAttr;
-    if(aLab.FindAttribute(TDataStd_Name::GetID(),anAttr)){
-      TCollection_AsciiString aString(anAttr->Get());
-      if(strcmp(aString.ToCString(),theObjectName) == 0){
-       aRefSO = SALOMEDS_SObject_i::NewRef(this,aLab);
-       theIsFound = true;
-      }
-    }
-  }
-  return aRefSO._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 : _FindObject
- *  Purpose  : Find an Object with SALOMEDS::IOR = anObjectIOR
+/*! Function : SetBoolean
+ *  Purpose  : 
  */
 //============================================================================
-SALOMEDS::SObject_ptr 
-SALOMEDS_Study_i::_FindObjectIOR(TDF_Label theLabel,
-                                const char* theObjectIOR, 
-                                bool& theIsFound)
+void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
 {
-  // Iterate on each objects and subobjects of the component
-  // If objectName find, stop the loop and get the object reference
-  SALOMEDS::SObject_var aRefSO;
-  TDF_ChildIterator aChildIter(theLabel,true);
-  for(; aChildIter.More() && !theIsFound; aChildIter.Next()){
-    TDF_Label aLab = aChildIter.Value();
-    Handle(SALOMEDS_IORAttribute) anAttr;
-    if(aLab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
-      TCollection_AsciiString aString(anAttr->Get());
-      if(strcmp(aString.ToCString(),theObjectIOR) == 0){
-       aRefSO = SALOMEDS_SObject_i::NewRef(this,aLab);
-       theIsFound = true;
-      }
-    }
-  }
-  return aRefSO._retn();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetVariable(std::string(theVarName), 
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  if (_notifier)
+    _notifier->modifyNB_Notification(theVarName);
+}
+
+//============================================================================
+/*! Function : SetString
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetStringVariable(std::string(theVarName), 
+                          theValue,
+                          SALOMEDSImpl_GenericVariable::STRING_VAR);
+  if (_notifier)
+    _notifier->modifyNB_Notification(theVarName);
 }
 
-CORBA::Short SALOMEDS_Study_i::StudyId()
+//============================================================================
+/*! Function : SetStringAsDouble
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
 {
-  return _StudyId;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->SetStringVariableAsDouble(std::string(theVarName), 
+                                  theValue,
+                                  SALOMEDSImpl_GenericVariable::STRING_VAR);
 }
 
-void SALOMEDS_Study_i::StudyId(CORBA::Short id)
+//============================================================================
+/*! Function : GetReal
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
 {
-  _StudyId = id;
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->GetVariableValue(std::string(theVarName));
 }
 
-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);
+//============================================================================
+/*! Function : GetInteger
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return (long)_impl->GetVariableValue(std::string(theVarName));
 }
 
-void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute) {
-  TCollection_AsciiString aString;
-  TDF_Tool::Entry(theAttribute->Label(),aString);
-  TCollection_AsciiString aValue(theAttribute->Get());
-  UpdateIORLabelMap(aValue.ToCString(),aString.ToCString());
+//============================================================================
+/*! Function : GetBoolean
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return (bool)_impl->GetVariableValue(std::string(theVarName));
 }
 
-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;
+//============================================================================
+/*! Function : GetString
+ *  Purpose  : 
+ */
+//============================================================================
+char* SALOMEDS_Study_i::GetString(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
 }
 
+//============================================================================
+/*! Function : IsReal
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties(){
-  SALOMEDS::SObject_var aSObject = FindObjectID("0:1");
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::REAL_VAR);
+}
 
-  SALOMEDS::GenericAttribute_var anAttr =  
-    GetBuilder()->FindOrCreateAttribute(aSObject,"AttributeStudyProperties");
+//============================================================================
+/*! Function : IsInteger
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  return SALOMEDS::AttributeStudyProperties::_narrow(anAttr);
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::INTEGER_VAR);
 }
 
-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();
+//============================================================================
+/*! Function : IsBoolean
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
 }
 
-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 : IsString
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  int anIndex, aLength = aNames->length();
-  SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
-  aDates->length(aLength);
+  return _impl->IsTypeOf(std::string(theVarName),
+                        SALOMEDSImpl_GenericVariable::STRING_VAR);
+}
 
-  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();
+//============================================================================
+/*! Function : IsVariable
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsVariable(std::string(theVarName));
 }
 
+//============================================================================
+/*! Function : GetVariableNames
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
+  std::vector<std::string> aVarNames = _impl->GetVariableNames();
+
+  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 : Close
+/*! Function : RemoveVariable
  *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::Close()
-{
-  SALOMEDS_SComponentIterator_i itcomponent(this,_doc);
-
-  const CORBA::ORB_var& anORB = GetORB();
-  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 = anORB->string_to_object(IOREngine);
-      if (!CORBA::is_nil(obj)) {
-       SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
-       
-       if (!anEngine->_is_nil())  
-         anEngine->Close(sco);
-      }
-    }
-  }
+CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  bool res = _impl->RemoveVariable(std::string(theVarName));
+  if (res && _notifier)
+    _notifier->modifyNB_Notification(theVarName);
 
-  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 res;
 }
 
 //============================================================================
-/*! Function : AddPostponed
+/*! Function : RenameVariable
  *  Purpose  : 
  */
- //============================================================================
-void SALOMEDS_Study_i::AddPostponed(const char* theIOR) {
-  if (!GetBuilder()->HasOpenCommand()) return;
-  try {
-    CORBA::Object_var obj = GetORB()->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(const_cast<char*>(theIOR));
-       anIOR.Prepend("d");
-       myPostponedIORs.Append(anIOR); // add prefix: deleted
-       myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1);
-      }
-    }
-  } catch(...) {}
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
+  if (res && _notifier)
+    _notifier->modifyNB_Notification(theVarName);
+
+  return res;
 }
 
-void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) {
-  if (!GetBuilder()->HasOpenCommand()) return;
-  try {
-    CORBA::Object_var obj = GetORB()->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(const_cast<char*>(theIOR));
-       anIOR.Prepend("c");
-       myPostponedIORs.Append(anIOR); // add prefix: created
-       myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1);
-      }
-    }
-  } catch(...) {}
+//============================================================================
+/*! Function : IsVariableUsed
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return _impl->IsVariableUsed(std::string(theVarName));
 }
 
+
 //============================================================================
-/*! Function : RemovePostponed
+/*! Function : ParseVariables
  *  Purpose  : 
  */
 //============================================================================
-void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit) {
-  int anIndex;
-  int anOld;
+SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
+{
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  int aUndoLimit = theUndoLimit;
-  if (theUndoLimit < 0) aUndoLimit = 0;
+  SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
 
-  const CORBA::ORB_var& anORB = GetORB();
-  if (myNbUndos > 0) { // remove undone
-    anOld = 0;
-    for(anIndex = 1; anIndex < myNbPostponed.Length() - myNbUndos; anIndex++)
-      anOld += myNbPostponed(anIndex);
-    int aNew = myPostponedIORs.Length() - myNbPostponed.Last();
+  std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
 
-    for(anIndex = anOld + 1; anIndex <= aNew; anIndex++) {
-      TCollection_AsciiString anIOR = myPostponedIORs(anIndex);
-      if (anIOR.Value(1) == 'c') {
-       CORBA::Object_var obj = anORB->string_to_object(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);
+  int aSectionsLen = aSections.size();
+  aResult->length(aSectionsLen);
 
-    myNbUndos = 0;
+  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;
   }
 
-  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 = anORB->string_to_object(anIOR.Split(1).ToCString());
-       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-      }
+  return aResult._retn();
+}
+
+//============================================================================
+/*! Function : GetDefaultScript
+ *  Purpose  : 
+ */
+//============================================================================
+char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
+{
+  SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
+  return CORBA::string_dup(script.c_str());
+}
+
+//============================================================================
+/*! Function : EnableUseCaseAutoFilling
+ *  Purpose  : 
+ */
+//============================================================================
+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 (anOld > 0) myPostponedIORs.Remove(1, anOld);
-    myNbPostponed.Remove(1, myNbPostponed.Length() - aUndoLimit);
   }
+}
 
-  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 = CORBA::string_dup(TCollection_AsciiString(anAttr->Get()).ToCString());
-      try {
-       CORBA::Object_var obj = anORB->string_to_object(anIOR);
-       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-      } catch (...) {}
-    }
-  } else myNbPostponed.Append(0);
+
+CORBA::Long SALOMEDS_Study_i::getPID()
+{
+#ifdef WIN32
+  return (CORBA::Long)_getpid();
+#else
+  return (CORBA::Long)getpid();
+#endif
+}
+
+void SALOMEDS_Study_i::ShutdownWithExit()
+{
+  exit( EXIT_SUCCESS );
+}
+
+void SALOMEDS_Study_i::Shutdown()
+{
+  if(!CORBA::is_nil(_orb))
+    _orb->shutdown(0);
 }
 
 //============================================================================
-/*! Function : UndoPostponed
- *  Purpose  : 
+/*! 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 : 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);
+}
+
+void SALOMEDS_Study_i::NameChanged()
+{
+  // Notify GUI that the name of study was changed
+  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 << "studyNameChanged";
+    std::string str = ss.str();
+    SALOMEDS::unlock();
+    aSession->emitMessageOneWay(str.c_str());
+    SALOMEDS::lock();
+  }
 }