org.picketlink.idm.jpa.internal.mappers.EntityMapping Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* 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 org.picketlink.idm.jpa.internal.mappers;
import org.picketlink.common.properties.Property;
import org.picketlink.common.properties.query.AnnotatedPropertyCriteria;
import org.picketlink.common.properties.query.NamedPropertyCriteria;
import org.picketlink.common.properties.query.PropertyQueries;
import org.picketlink.common.properties.query.TypedPropertyCriteria;
import org.picketlink.idm.jpa.annotations.OwnerReference;
import org.picketlink.idm.jpa.annotations.entity.IdentityManaged;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author pedroigor
*/
public class EntityMapping {
private final Map properties;
private final Class> supportedType;
private Property typeProperty;
public EntityMapping(Class> managedType) {
this.supportedType = managedType;
this.properties = new HashMap();
}
public void addProperty(Property property, Property mappedProperty) {
if (mappedProperty != null) {
this.properties.put(property, mappedProperty);
}
}
public void addTypeProperty(Property property) {
if (property != null) {
addProperty(new PropertyMapping() {
@Override
public Object getValue(Object instance) {
return instance.getClass().getName();
}
@Override
public void setValue(Object instance, Object value) {
//TODO: Implement setValue
}
}, property);
this.typeProperty = property;
}
}
public Map getProperties() {
return Collections.unmodifiableMap(this.properties);
}
public Property getTypeProperty() {
return this.typeProperty;
}
public Class> getOwnerType() {
for (Property property : getProperties().values()) {
if (property.getAnnotatedElement().isAnnotationPresent(OwnerReference.class)) {
return property.getJavaClass();
}
}
return null;
}
public void addOwnerProperty(Class> entityType) {
final Property