public String toString()

in guacamole/src/main/java/org/apache/guacamole/event/AffectedObject.java [54:127]


    public String toString() {

        Object object = event.getObject();
        String identifier = event.getObjectIdentifier();
        String dataSource = event.getAuthenticationProvider().getIdentifier();

        String objectType;
        String name = null; // Not all objects have names

        // Obtain name of object (if applicable and available)
        if (object instanceof Nameable) {
            try {
                name = ((Nameable) object).getName();
            }
            catch (RuntimeException | Error e) {
                logger.debug("Name of object \"{}\" could not be retrieved.", identifier, e);
            }
        }

        // Determine type of object
        switch (event.getDirectoryType()) {

            // Active connections
            case ACTIVE_CONNECTION:
                objectType = "active connection";
                break;

            // Connections
            case CONNECTION:
                objectType = "connection";
                break;

            // Connection groups
            case CONNECTION_GROUP:
                objectType = "connection group";
                break;

            // Sharing profiles
            case SHARING_PROFILE:
                objectType = "sharing profile";
                break;

            // Users
            case USER:

                if (identifier != null && identifier.equals(event.getAuthenticatedUser().getIdentifier()))
                    return "their own user account within \"" + dataSource + "\"";

                objectType = "user";
                break;

            // User groups
            case USER_GROUP:
                objectType = "user group";
                break;

            // Unknown
            default:
                objectType = (object != null) ? object.getClass().toString() : "an unknown object";
                
        }

        // Describe at least the type of the object and its identifier,
        // including the name of the object, as well, if available
        if (identifier != null) {
            if (name != null)
                return objectType + " \"" + identifier + "\" within \"" + dataSource + "\" (currently named \"" + name + "\")";
            else
                return objectType + " \"" + identifier + "\" within \"" + dataSource + "\"";
        }
        else
            return objectType + " within \"" + dataSource + "\"";

    }