String expression = ((GroupAvailability) functionality.getAvailabilityPolicy()).getExpression();
String expression = ((ExpressionGroupAvailability) functionality.getAvailabilityPolicy()).getExpression();
    private Element generateElement(Functionality functionality) {        Element element = new Element("functionality");                element.setAttribute("type", functionality.getClass().getName());        element.setAttribute("uuid", functionality.getUuid().toString());                Element name = new Element("name");        generateMultiLanguageStringElement(name, functionality.getName());                Element title = new Element("title");        generateMultiLanguageStringElement(title, functionality.getTitle());                Element description = new Element("description");        generateMultiLanguageStringElement(description, functionality.getDescription());                element.addContent(name);        element.addContent(title);        element.addContent(description);                if (functionality.getPath() != null) {            element.setAttribute("path", functionality.getPath());        }                if (functionality.getParameters() != null) {            element.setAttribute("parameters", functionality.getParameters());        }                if (functionality.getOrderInModule() != null) {            element.setAttribute("order", String.valueOf(functionality.getOrderInModule()));        }        element.setAttribute("principal", String.valueOf(functionality.isPrincipal()));        element.setAttribute("enabled", String.valueOf(functionality.isEnabled()));        element.setAttribute("relative", String.valueOf(functionality.isRelative()));        element.setAttribute("visible", String.valueOf(functionality.isVisible()));        if (functionality.getAvailabilityPolicy() != null) {            String expression = ((GroupAvailability) functionality.getAvailabilityPolicy()).getExpression();            element.addContent(new Element("availability").addContent(new Text(expression)));        }                if (functionality instanceof Module) {            Module module = (Module) functionality;                        element.setAttribute("prefix", module.getPrefix());            element.setAttribute("maximized", String.valueOf(module.isMaximized()));                        Element children = new Element("children");            for (Functionality child : module.getOrderedFunctionalities()) {                children.addContent(generateElement(child));            }                        element.addContent(children);        }                return element;    }