anchor.diff:  ENDCLASS.                    "lcl_object_dtel DEFINITION
   
   *----------------------------------------------------------------------*
  -*       CLASS lcl_object_dtel IMPLEMENTATION
  +*       CLASS lcl_object_tabl IMPLEMENTATION
   *----------------------------------------------------------------------*
   *
   *----------------------------------------------------------------------*
  
positive.code: ENDCLASS.                    "lcl_object_intf DEFINITION
  
  *----------------------------------------------------------------------*
  *       CLASS lcl_object_dtel IMPLEMENTATION
  *----------------------------------------------------------------------*
  *
  *----------------------------------------------------------------------*
  
negative.code: *----------------------------------------------------------------------*
  CLASS lcl_object_w3ht DEFINITION INHERITING FROM lcl_object_w3super FINAL.
  ENDCLASS.                    "lcl_object_W3HT DEFINITION
  
  *----------------------------------------------------------------------*
  *       CLASS lcl_object_shi3 DEFINITION
  *----------------------------------------------------------------------*
  CLASS lcl_object_shi3 DEFINITION INHERITING FROM lcl_objects_super FINAL.
  
    PUBLIC SECTION.
      INTERFACES lif_object.
      ALIASES mo_files FOR lif_object~mo_files.
  
      METHODS constructor
        IMPORTING
          is_item     TYPE ty_item
          iv_language TYPE spras.
  
  
    PRIVATE SECTION.
  
      TYPES: BEGIN OF ty_id_map,
               old TYPE ttree-id,
               new TYPE ttree-id,
             END OF ty_id_map.
      TYPES  tt_id_map TYPE STANDARD TABLE OF ty_id_map.
      TYPES  ts_id_map TYPE SORTED TABLE OF ty_id_map WITH UNIQUE KEY old.
  
      DATA: mv_tree_id TYPE ttree-id,
            mt_map     TYPE ts_id_map. " SORTED !
  
      METHODS jump_se43
        RAISING  lcx_exception.
  
      METHODS strip_stamps
        CHANGING cs_head  TYPE ttree
                 ct_nodes TYPE hier_iface_t.
  
      METHODS regenerate_ids
        CHANGING ct_nodes TYPE hier_iface_t
                 ct_refs  TYPE hier_ref_t
                 ct_texts TYPE hier_texts_t
        RAISING  lcx_exception.
  
      METHODS replace_id
        IMPORTING iv_id            TYPE clike
        RETURNING VALUE(rv_new_id) TYPE ttree-id
        RAISING  lcx_exception.
  
  ENDCLASS.                    "lcl_object_shi3 DEFINITION
  
  *----------------------------------------------------------------------*
  *       CLASS lcl_object_shi3 IMPLEMENTATION
  *----------------------------------------------------------------------*
  CLASS lcl_object_shi3 IMPLEMENTATION.
  
    METHOD constructor.
      super->constructor( is_item = is_item iv_language = iv_language ).
      mv_tree_id = ms_item-obj_name.
    ENDMETHOD.                    "constructor
  
    METHOD lif_object~get_metadata.
      rs_metadata = get_metadata( ).
    ENDMETHOD.                    "lif_object~get_metadata
  
    METHOD jump_se43.
  
      DATA: lt_bdcdata TYPE TABLE OF bdcdata.
  
      FIELD-SYMBOLS: <ls_bdcdata> LIKE LINE OF lt_bdcdata.
  
      APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
      <ls_bdcdata>-program  = 'SAPLBMEN'.
      <ls_bdcdata>-dynpro   = '0200'.
      <ls_bdcdata>-dynbegin = abap_true.
  
      APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
      <ls_bdcdata>-fnam = 'BDC_OKCODE'.
      <ls_bdcdata>-fval = '=SHOW'.
  
      APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
      <ls_bdcdata>-fnam = 'BMENUNAME-ID'.
      <ls_bdcdata>-fval = ms_item-obj_name.
  
      CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
        STARTING NEW TASK 'GIT'
        EXPORTING
          tcode                 = 'SE43'
          mode_val              = 'E'
        TABLES
          using_tab             = lt_bdcdata
        EXCEPTIONS
          system_failure        = 1
          communication_failure = 2
          resource_failure      = 3
          OTHERS                = 4.
  
      IF sy-subrc <> 0.
         _raise 'error from ABAP4_CALL_TRANSACTION, SHI3'.
      ENDIF.
  
    ENDMETHOD.                    "jump_se43
  
    METHOD lif_object~jump.
      jump_se43( ).
    ENDMETHOD.                    "jump
  
    METHOD lif_object~exists.
  
      DATA: ls_msg    TYPE hier_mess,
            ls_header TYPE ttree,
            ls_tadir  TYPE tadir.
  
      CALL FUNCTION 'STREE_STRUCTURE_EXIST'
        EXPORTING
          structure_id         = mv_tree_id
          do_not_read_devclass = ''
        IMPORTING
          message              = ls_msg
          structure_header     = ls_header
          structure_tadir      = ls_tadir.
  
      rv_bool = boolc( ls_header-id IS NOT INITIAL ).
  
    ENDMETHOD.                    "lif_object~exists
  
    METHOD lif_object~delete.
  
      CALL FUNCTION 'BMENU_DELETE_TREE'
        EXPORTING
          tree_id            = mv_tree_id
        EXCEPTIONS
          trees_do_not_exist = 1
          no_authority       = 2
          canceled           = 3
          OTHERS             = 4.
  
      IF sy-subrc <> 0.
         _raise 'error from BMENU_DELETE_TREE, SHI3'.
      ENDIF.
  
    ENDMETHOD.                    "delete
  
    METHOD lif_object~serialize.
  
      DATA: ls_msg    TYPE hier_mess,
            ls_head   TYPE ttree,
            lt_titles TYPE TABLE OF ttreet,
            lt_nodes  TYPE TABLE OF hier_iface,
            lt_texts  TYPE TABLE OF hier_texts,
            lt_refs   TYPE TABLE OF hier_ref.
  
      CALL FUNCTION 'STREE_STRUCTURE_READ'
        EXPORTING
          structure_id     = mv_tree_id
        IMPORTING
          message          = ls_msg
          structure_header = ls_head
        TABLES
          description      = lt_titles.
  
      IF sy-subrc <> 0.
        _raise 'Error from STREE_STRUCTURE_READ, SHI3'.
      ENDIF.
  
      CALL FUNCTION 'STREE_HIERARCHY_READ'
        EXPORTING
          structure_id       = mv_tree_id
          read_also_texts    = 'X'
          all_languages      = 'X'
        IMPORTING
          message            = ls_msg
        TABLES
          list_of_nodes      = lt_nodes
          list_of_references = lt_refs
          list_of_texts      = lt_texts.
      IF sy-subrc <> 0.
        _raise 'Error from STREE_HIERARCHY_READ, SHI3'.
      ENDIF.
  
      strip_stamps( CHANGING cs_head  = ls_head
                             ct_nodes = lt_nodes ).
  
      io_xml->add( iv_name = 'TREE_HEAD'
                   ig_data = ls_head ).
      io_xml->add( iv_name = 'TREE_TITLES'
                   ig_data = lt_titles ).
      io_xml->add( iv_name = 'TREE_NODES'
                   ig_data = lt_nodes ).
      io_xml->add( iv_name = 'TREE_REFS'
                   ig_data = lt_refs ).
      io_xml->add( iv_name = 'TREE_TEXTS'
                   ig_data = lt_texts ).
  
    ENDMETHOD.                    "serialize
  
    METHOD strip_stamps.
  
      FIELD-SYMBOLS <node> LIKE LINE OF ct_nodes.
  
      CLEAR: cs_head-luser, cs_head-ldate, cs_head-ltime.
      CLEAR: cs_head-fuser, cs_head-fdate, cs_head-ftime.
      CLEAR: cs_head-responsibl.
  
      LOOP AT ct_nodes ASSIGNING <node>.
        CLEAR: <node>-luser, <node>-ldate, <node>-ltime.
        CLEAR: <node>-fuser, <node>-fdate, <node>-ftime.
      ENDLOOP.
  
    ENDMETHOD.                    "strip_stamps
  
    METHOD regenerate_ids.
  
      DATA: l_uid  TYPE sys_uid,
            lt_map TYPE tt_id_map.
  
      FIELD-SYMBOLS: <node> LIKE LINE OF ct_nodes,
                     <ref>  LIKE LINE OF ct_refs,
                     <text> LIKE LINE OF ct_texts,
                     <map>  LIKE LINE OF mt_map.
  
      "Build map
      LOOP AT ct_nodes ASSIGNING <node>.
        APPEND INITIAL LINE TO lt_map ASSIGNING <map>.
        IF <node>-parent_id IS INITIAL.
          <map>-old = <node>-node_id.
          <map>-new = <node>-node_id. "Root node
        ELSE.
          CALL FUNCTION 'STREE_GET_UNIQUE_ID'
            IMPORTING
              unique_id = l_uid.
  
          <map>-old = <node>-node_id.
          <map>-new = l_uid-id.
        ENDIF.
        <node>-node_id = <map>-new. "Replace id
      ENDLOOP.
  
      mt_map = lt_map. "Sort
  
      LOOP AT ct_nodes ASSIGNING <node>.
        <node>-parent_id  = replace_id( <node>-parent_id ).
        <node>-brother_id = replace_id( <node>-brother_id ).
      ENDLOOP.
  
      LOOP AT ct_refs ASSIGNING <ref>.
        <ref>-node_id = replace_id( <ref>-node_id ).
      ENDLOOP.
  
      LOOP AT ct_texts ASSIGNING <text>.
        <text>-node_id = replace_id( <text>-node_id ).
      ENDLOOP.
  
    ENDMETHOD.                    "regenerate_ids
  
    METHOD replace_id.
  
      DATA ls_map LIKE LINE OF mt_map.
  
      IF iv_id IS INITIAL.
        RETURN. "No substitution for empty values
      ENDIF.
  
      READ TABLE mt_map WITH TABLE KEY old = iv_id INTO ls_map.
      IF sy-subrc <> 0.
        _raise 'Cannot replace id, SHI3'.
      ENDIF.
  
      rv_new_id = ls_map-new.
  
    ENDMETHOD.                    "replace_id
  
    METHOD lif_object~deserialize.
  
      DATA: ls_msg    TYPE hier_mess,
            ls_head   TYPE ttree,
            lt_titles TYPE TABLE OF ttreet,
            lt_nodes  TYPE TABLE OF hier_iface,
            lt_texts  TYPE TABLE OF hier_texts,
            lt_refs   TYPE TABLE OF hier_ref.
  
      io_xml->read( EXPORTING iv_name = 'TREE_HEAD'
                    CHANGING  cg_data = ls_head ).
      io_xml->read( EXPORTING iv_name = 'TREE_TITLES'
                    CHANGING  cg_data = lt_titles ).
      io_xml->read( EXPORTING iv_name = 'TREE_NODES'
                    CHANGING  cg_data = lt_nodes ).
      io_xml->read( EXPORTING iv_name = 'TREE_REFS'
                    CHANGING  cg_data = lt_refs ).
      io_xml->read( EXPORTING iv_name = 'TREE_TEXTS'
                    CHANGING  cg_data = lt_texts ).
  
      regenerate_ids( CHANGING ct_nodes = lt_nodes
                               ct_refs  = lt_refs
                               ct_texts = lt_texts ).
  
      IF lif_object~exists( ) = abap_true.
        lif_object~delete( ).
      ENDIF.
  
      call function 'STREE_HIERARCHY_SAVE'
        exporting
          structure_id             = mv_tree_id
          structure_type           = 'BMENU'
          structure_description    = space
          structure_masterlanguage = mv_language
          structure_responsible    = sy-uname
          development_class        = iv_package
        importing
          message                  = ls_msg
        tables
          list_of_nodes            = lt_nodes
          list_of_references       = lt_refs
          list_of_texts            = lt_texts
          structure_descriptions   = lt_titles
        exceptions
          no_nodes_given           = 1
          others                   = 2.
      if sy-subrc <> 0.
        _raise 'Error from STREE_HIERARCHY_SAVE, SHI3'.
      endif.
  
    ENDMETHOD.                    "deserialize
  
  ENDCLASS.                    "lcl_object_shi3 IMPLEMENTATION
  
  CLASS lcl_persistence_db DEFINITION FINAL CREATE PRIVATE FRIENDS lcl_app.
  
  