To edit some com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element, a session with the com.nomagic.magicdraw.openapi.uml.SessionManager must be created. 

All changes in the UML model will be registered and, on the session closing, will be added into the command history.

    Project project = ...;
    SessionManager.getInstance().createSession(project, "Edit class A");
    if (classA.isEditable())
    {
        classA.setName(newName);
    }
    SessionManager.getInstance().closeSession(project);
It is the programmer responsibility to ensure that the modified element is not read-only by checking element editing permissions.