Example usage for javax.xml.bind UnmarshalException UnmarshalException

List of usage examples for javax.xml.bind UnmarshalException UnmarshalException

Introduction

In this page you can find the example usage for javax.xml.bind UnmarshalException UnmarshalException.

Prototype

public UnmarshalException(Throwable exception) 

Source Link

Document

Construct an UnmarshalException with a linkedException.

Usage

From source file:org.kuali.rice.kim.impl.jaxb.RoleXmlUtil.java

/**
 * Validates a role permission's role and permission identification information, and assigns its role ID if needed.
 *///from  www .  ja  v  a  2  s .  co m
private static void validateAndPrepareRolePermission(RolePermissionXmlDTO newRolePermission)
        throws UnmarshalException {

    // If this is a standalone role permission, derive and validate its role information accordingly.
    if (newRolePermission instanceof RolePermissionXmlDTO.OutsideOfRole) {
        RolePermissionXmlDTO.OutsideOfRole standaloneRolePerm = (RolePermissionXmlDTO.OutsideOfRole) newRolePermission;
        if (standaloneRolePerm.getRoleNameAndNamespace() != null) {
            // If a role name + namespace is given, assign or validate the role ID accordingly.
            String tempRoleId = KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(
                    standaloneRolePerm.getRoleNamespaceCode(), standaloneRolePerm.getRoleName());
            if (StringUtils.isBlank(tempRoleId)) {
                throw new UnmarshalException("Cannot assign permission to role with namespace \""
                        + standaloneRolePerm.getRoleNamespaceCode() + "\" and name \""
                        + standaloneRolePerm.getRoleName() + "\" because that role does not exist");
            } else if (StringUtils.isBlank(standaloneRolePerm.getRoleId())) {
                // If no role ID was given, assign one from the retrieved role.
                standaloneRolePerm.setRoleId(standaloneRolePerm.getRoleId());
            } else if (!standaloneRolePerm.getRoleId().equals(tempRoleId)) {
                throw new UnmarshalException(
                        "Cannot assign permission to role with ID \"" + standaloneRolePerm.getRoleId()
                                + "\", namespace \"" + standaloneRolePerm.getRoleNamespaceCode()
                                + "\", and name \"" + standaloneRolePerm.getRoleName()
                                + "\" because the existing role with that name and namespace has an ID of \""
                                + tempRoleId + "\" instead");
            }
        } else if (StringUtils.isBlank(standaloneRolePerm.getRoleId())) {
            throw new UnmarshalException(
                    "Cannot assign permission to role without providing the role ID or role name + namespace that the permission is assigned to");
        } else if (KimApiServiceLocator.getRoleService().getRole(standaloneRolePerm.getRoleId()) == null) {
            throw new UnmarshalException("Cannot assign permission to role with ID \""
                    + standaloneRolePerm.getRoleId() + "\" because that role does not exist");
        }
    }

    // Ensure that a role ID was explicitly defined or was derived from a name + namespace combo.
    if (StringUtils.isBlank(newRolePermission.getRoleId())) {
        throw new UnmarshalException(
                "Cannot assign permission to role without providing the role ID or role name + namespace that the permission is assigned to");
    }

    // If the permission is being identified by name and namespace, derive or validate its permission ID accordingly.
    if (newRolePermission.getPermissionNameAndNamespace() != null) {
        PermissionContract permission = KimApiServiceLocator.getPermissionService()
                .findPermByNamespaceCodeAndName(newRolePermission.getPermissionNamespaceCode(),
                        newRolePermission.getPermissionName());
        if (permission == null) {
            throw new UnmarshalException("Cannot get role assigned to permission with namespace \""
                    + newRolePermission.getPermissionNamespaceCode() + "\" and name \""
                    + newRolePermission.getPermissionName() + "\" because that permission does not exist");
        } else if (StringUtils.isBlank(newRolePermission.getPermissionId())) {
            // If no permission ID was given, assign one from the retrieved permission.
            newRolePermission.setPermissionId(permission.getId());
        } else if (!newRolePermission.getPermissionId().equals(permission.getId())) {
            throw new UnmarshalException(
                    "Cannot get role assigned to permission with ID \"" + newRolePermission.getPermissionId()
                            + "\", namespace \"" + newRolePermission.getPermissionNamespaceCode()
                            + "\", and name \"" + newRolePermission.getPermissionName()
                            + "\" because the existing permission with that name and namespace has an ID of \""
                            + permission.getId() + "\" instead");
        }
    } else if (StringUtils.isBlank(newRolePermission.getPermissionId())) {
        throw new UnmarshalException(
                "Cannot assign permission to role without specifying the ID or name and namespace of the permission to assign");
    } else if (KimApiServiceLocator.getPermissionService()
            .getPermission(newRolePermission.getPermissionId()) == null) {
        throw new UnmarshalException("Cannot get role assigned to permission with ID \""
                + newRolePermission.getPermissionId() + "\" because that permission does not exist");
    }
}