Java tutorial
/* * Copyright (c) 2014 Kaiserpfalz EDV-Service, Roland Lichti * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.kaiserpfalzEdv.iam.core.role; import de.kaiserpfalzEdv.commons.NameableReadable; import de.kaiserpfalzEdv.iam.commons.naming.IdDO; import de.kaiserpfalzEdv.iam.role.Permission; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Set; import java.util.UUID; /** * @author klenkes * @since 2014Q */ public abstract class AttachedPermission implements Permission { private static final Logger LOG = LoggerFactory.getLogger(AttachedPermission.class); private IdDO id = new IdDO(); protected RoleDO role; protected PermissionDO permission; @SuppressWarnings({ "UnusedDeclaration", "deprecation" }) @Deprecated // Only for JPA, JAXB, builders and so on ... protected AttachedPermission() { } protected AttachedPermission(final RoleDO role, final Permission permission) { this.role = role; this.permission = convertToPermissionDO(permission); } private PermissionDO convertToPermissionDO(final Permission permission) { try { return (PermissionDO) permission; } catch (ClassCastException e) { return new PermissionBuilder().withPermission(permission).build(); } } public abstract void filter(Set<Permission> permissions); protected void clearPermission(Set<Permission> permissions) { while (permissions.contains(this)) { permissions.remove(this); } } @Override public int hashCode() { return permission.hashCode(); } @Override public boolean equals(Object other) { return permission.equals(other); } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("tenant", getTenantId()) .append("id", getId()).append("name", getNameable()).build(); } @Override public NameableReadable getNameable() { return permission.getNameable(); } @Override public UUID getId() { return permission.getId(); } @Override public UUID getTenantId() { return permission.getTenantId(); } @Override public String getName() { return permission.getName(); } @Override public String getShortName() { return permission.getShortName(); } @Override public String getCanonicalName() { return permission.getCanonicalName(); } @Override public String getDisplayName() { return permission.getDisplayName(); } }