From a2dc608ab44426011247a23e84d5ce65a4557874 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 23 Mar 2011 09:45:08 +0100 Subject: [PATCH] Forgot to push deleting MappingConfigurationBuilder and BasicMappingConfigurationBuilder. --- .../BasicMappingConfigurationBuilder.java | 195 ------------------ .../model/MappingConfigurationBuilder.java | 36 ---- 2 files changed, 231 deletions(-) delete mode 100644 spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingConfigurationBuilder.java delete mode 100644 spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationBuilder.java diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingConfigurationBuilder.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingConfigurationBuilder.java deleted file mode 100644 index 697d5079f..000000000 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingConfigurationBuilder.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2011 by the original author(s). - * - * 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.springframework.data.mapping; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.LocalVariableTableParameterNameDiscoverer; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.annotation.Persistent; -import org.springframework.data.annotation.Reference; -import org.springframework.data.annotation.Transient; -import org.springframework.data.mapping.model.Association; -import org.springframework.data.mapping.model.MappingConfigurationBuilder; -import org.springframework.data.mapping.model.MappingConfigurationException; -import org.springframework.data.mapping.model.MappingContext; -import org.springframework.data.mapping.model.MappingException; -import org.springframework.data.mapping.model.PersistentEntity; -import org.springframework.data.mapping.model.PersistentProperty; -import org.springframework.data.mapping.model.PreferredConstructor; -import org.springframework.data.util.TypeInformation; - -/** - * @author Jon Brisbin - */ -public class BasicMappingConfigurationBuilder implements MappingConfigurationBuilder { - - private static final Set UNMAPPED_FIELDS = new HashSet(Arrays.asList("class", "this$0")); - protected static ConcurrentMap, BeanInfo> beanInfo = new ConcurrentHashMap, BeanInfo>(); - protected Logger log = LoggerFactory.getLogger(getClass()); - - public boolean isPersistentEntity(Class type) { - if (type.isAnnotationPresent(Persistent.class)) { - return true; - } else { - for (Annotation annotation : type.getDeclaredAnnotations()) { - if (annotation.annotationType().isAnnotationPresent(Persistent.class)) { - return true; - } - } - for (Field field : type.getDeclaredFields()) { - if (field.isAnnotationPresent(Id.class)) { - return true; - } - } - } - return false; - } - - public PersistentEntity createPersistentEntity(TypeInformation typeInformation, MappingContext mappingContext) throws MappingConfigurationException { - return new BasicPersistentEntity(mappingContext, typeInformation); - } - - public boolean isPersistentProperty(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException { - if (UNMAPPED_FIELDS.contains(field.getName()) || isTransient(field)) { - return false; - } - return true; - } - - public PersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor, TypeInformation information) throws MappingConfigurationException { - return new BasicPersistentProperty(field, descriptor, information); - } - - @SuppressWarnings({"unchecked"}) - public PreferredConstructor getPreferredConstructor(Class type) throws MappingConfigurationException { - // Find the right constructor - PreferredConstructor preferredConstructor = null; - - for (Constructor constructor : type.getConstructors()) { - if (constructor.getParameterTypes().length != 0) { - // Non-no-arg constructor - if (null == preferredConstructor || constructor.isAnnotationPresent(PersistenceConstructor.class)) { - preferredConstructor = new PreferredConstructor((Constructor) constructor); - - String[] paramNames = new LocalVariableTableParameterNameDiscoverer().getParameterNames(constructor); - Type[] paramTypes = constructor.getGenericParameterTypes(); - - for (int i = 0; i < paramTypes.length; i++) { - Class targetType = Object.class; - if (paramTypes[i] instanceof ParameterizedType) { - ParameterizedType ptype = (ParameterizedType) paramTypes[i]; - Type[] types = ptype.getActualTypeArguments(); - if (types.length == 1) { - if (types[0] instanceof TypeVariable) { - // Placeholder type - targetType = Object.class; - } else { - targetType = (Class) types[0]; - } - } else { - targetType = (Class) ptype.getRawType(); - } - } else { - if (paramTypes[i] instanceof TypeVariable) { - @SuppressWarnings("rawtypes") - Type[] bounds = ((TypeVariable) paramTypes[i]).getBounds(); - if (bounds.length > 0) { - targetType = (Class) bounds[0]; - } - } else if (paramTypes[i] instanceof Class) { - targetType = (Class) paramTypes[i]; - } - } - String paramName = (null != paramNames ? paramNames[i] : "param" + i); - preferredConstructor.addParameter(paramName, targetType, targetType.getDeclaredAnnotations()); - } - - if (constructor.isAnnotationPresent(PersistenceConstructor.class)) { - // We're done - break; - } - } - } - } - - return preferredConstructor; - } - - public boolean isAssociation(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException { - if (!isTransient(field)) { - if (field.isAnnotationPresent(Reference.class)) { - return true; - } - for (Annotation annotation : field.getDeclaredAnnotations()) { - if (annotation.annotationType().isAnnotationPresent(Reference.class)) { - return true; - } - } - } - return false; - } - - public Association createAssociation(PersistentProperty property) { - // Only support uni-directional associations in the Basic configuration - Association association = new Association(property, null); - property.setAssociation(association); - - return association; - } - - protected BeanInfo getBeanInfo(Class type) { - BeanInfo info = beanInfo.get(type); - if (null == info) { - try { - info = Introspector.getBeanInfo(type); - } catch (IntrospectionException e) { - throw new MappingException(e.getMessage(), e); - } - beanInfo.put(type, info); - } - return info; - } - - protected boolean isTransient(Field field) { - if (Modifier.isTransient(field.getModifiers()) - || null != field.getAnnotation(Transient.class) - || null != field.getAnnotation(Value.class)) { - return true; - } - return false; - } -} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationBuilder.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationBuilder.java deleted file mode 100644 index b9468e10b..000000000 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationBuilder.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011 by the original author(s). - * - * 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.springframework.data.mapping.model; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; - -/** - * @author Jon Brisbin - */ -public interface MappingConfigurationBuilder { - - boolean isPersistentEntity(Class clazz); - - boolean isPersistentProperty(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException; - - PreferredConstructor getPreferredConstructor(Class clazz) throws MappingConfigurationException; - - boolean isAssociation(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException; - - Association createAssociation(PersistentProperty property); -}