// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
// public class BasicKeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
// 		extends BasicPersistentEntity<T, P> implements KeyValuePersistentEntity<T, P> {
// 
// 	private static final SpelExpressionParser PARSER = new SpelExpressionParser();
// 
// 	private static final KeySpaceResolver DEFAULT_FALLBACK_RESOLVER = ClassNameKeySpaceResolver.INSTANCE;
// 
// 	private final @Nullable Expression keyspaceExpression;
// 	private final @Nullable String keyspace;
// 
// 	/**
// 	 * @param information must not be {@literal null}.
// 	 * @param fallbackKeySpaceResolver can be {@literal null}.
// 	 */
// 	public BasicKeyValuePersistentEntity(TypeInformation<T> information,
// 			@Nullable KeySpaceResolver fallbackKeySpaceResolver) {
// 
// 		super(information);
// 
// 		Class<T> type = information.getType();
// 		String keySpace = AnnotationBasedKeySpaceResolver.INSTANCE.resolveKeySpace(type);
// 
// 		if (StringUtils.hasText(keySpace)) {
// 
// 			this.keyspace = keySpace;
// 			this.keyspaceExpression = detectExpression(keySpace);
// 		} else {
// 
// 			this.keyspace = resolveKeyspace(fallbackKeySpaceResolver, type);
// 			this.keyspaceExpression = null;
// 		}
// 	}
// 
// 	/**
// 	 * Returns a SpEL {@link Expression} if the given {@link String} is actually an expression that does not evaluate to a
// 	 * {@link LiteralExpression} (indicating that no subsequent evaluation is necessary).
// 	 *
// 	 * @param potentialExpression must not be {@literal null}
// 	 * @return the parsed {@link Expression} or {@literal null}.
// 	 */
// 	@Nullable
// 	private static Expression detectExpression(String potentialExpression) {
// 
// 		Expression expression = PARSER.parseExpression(potentialExpression, ParserContext.TEMPLATE_EXPRESSION);
// 		return expression instanceof LiteralExpression ? null : expression;
// 	}
// 
// 	@Nullable
// 	private static String resolveKeyspace(@Nullable KeySpaceResolver fallbackKeySpaceResolver, Class<?> type) {
// 		return (fallbackKeySpaceResolver == null ? DEFAULT_FALLBACK_RESOLVER : fallbackKeySpaceResolver)
// 				.resolveKeySpace(type);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * @see org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity#getKeySpace()
// 	 */
// 	@Override
// 	public String getKeySpace() {
// 		return keyspaceExpression == null //
// 				? keyspace //
// 				: keyspaceExpression.getValue(getEvaluationContext(null), String.class);
// 	}
// }
// 
// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/KeySpaceResolver.java
// public interface KeySpaceResolver {
// 
// 	/**
// 	 * Determine the {@literal keySpace} to use for a given type.
// 	 *
// 	 * @param type must not be {@literal null}.
// 	 * @return
// 	 */
// 	@Nullable
// 	String resolveKeySpace(Class<?> type);
// }
// 
// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentEntity.java
// public interface KeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
// 		extends MutablePersistentEntity<T, P> {
// 
// 	/**
// 	 * Get the {@literal keySpace} a given entity assigns to.
// 	 *
// 	 * @return can be {@literal null}.
// 	 */
// 	@Nullable
// 	String getKeySpace();
// }
// 
// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentProperty.java
// public class KeyValuePersistentProperty<P extends KeyValuePersistentProperty<P>>
// 		extends AnnotationBasedPersistentProperty<P> {
// 
// 	public KeyValuePersistentProperty(Property property, PersistentEntity<?, P> owner,
// 			SimpleTypeHolder simpleTypeHolder) {
// 		super(property, owner, simpleTypeHolder);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()
// 	 */
// 	@Override
// 	@SuppressWarnings("unchecked")
// 	protected Association<P> createAssociation() {
// 		return new Association<>((P) this, null);
// 	}
// }


import java.util.Collections;
import org.springframework.data.keyvalue.core.mapping.BasicKeyValuePersistentEntity;
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
/*
 * Copyright 2014-2022 the original author or authors.
 *
 * 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
 *
 *      https://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.keyvalue.core.mapping.context;



/**
 * Default implementation of a {@link MappingContext} using {@link KeyValuePersistentEntity} and
 * {@link KeyValuePersistentProperty} as primary abstractions.
 *
 * @author Christoph Strobl
 * @author Oliver Gierke
 * @author Mark Paluch
 */
public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P extends KeyValuePersistentProperty<P>>
		extends AbstractMappingContext<E, P> {

// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
// public class BasicKeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
// 		extends BasicPersistentEntity<T, P> implements KeyValuePersistentEntity<T, P> {
// 
// 	private static final SpelExpressionParser PARSER = new SpelExpressionParser();
// 
// 	private static final KeySpaceResolver DEFAULT_FALLBACK_RESOLVER = ClassNameKeySpaceResolver.INSTANCE;
// 
// 	private final @Nullable Expression keyspaceExpression;
// 	private final @Nullable String keyspace;
// 
// 	/**
// 	 * @param information must not be {@literal null}.
// 	 * @param fallbackKeySpaceResolver can be {@literal null}.
// 	 */
// 	public BasicKeyValuePersistentEntity(TypeInformation<T> information,
// 			@Nullable KeySpaceResolver fallbackKeySpaceResolver) {
// 
// 		super(information);
// 
// 		Class<T> type = information.getType();
// 		String keySpace = AnnotationBasedKeySpaceResolver.INSTANCE.resolveKeySpace(type);
// 
// 		if (StringUtils.hasText(keySpace)) {
// 
// 			this.keyspace = keySpace;
// 			this.keyspaceExpression = detectExpression(keySpace);
// 		} else {
// 
// 			this.keyspace = resolveKeyspace(fallbackKeySpaceResolver, type);
// 			this.keyspaceExpression = null;
// 		}
// 	}
// 
// 	/**
// 	 * Returns a SpEL {@link Expression} if the given {@link String} is actually an expression that does not evaluate to a
// 	 * {@link LiteralExpression} (indicating that no subsequent evaluation is necessary).
// 	 *
// 	 * @param potentialExpression must not be {@literal null}
// 	 * @return the parsed {@link Expression} or {@literal null}.
// 	 */
// 	@Nullable
// 	private static Expression detectExpression(String potentialExpression) {
// 
// 		Expression expression = PARSER.parseExpression(potentialExpression, ParserContext.TEMPLATE_EXPRESSION);
// 		return expression instanceof LiteralExpression ? null : expression;
// 	}
// 
// 	@Nullable
// 	private static String resolveKeyspace(@Nullable KeySpaceResolver fallbackKeySpaceResolver, Class<?> type) {
// 		return (fallbackKeySpaceResolver == null ? DEFAULT_FALLBACK_RESOLVER : fallbackKeySpaceResolver)
// 				.resolveKeySpace(type);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * @see org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity#getKeySpace()
// 	 */
// 	@Override
// 	public String getKeySpace() {
// 		return keyspaceExpression == null //
// 				? keyspace //
// 				: keyspaceExpression.getValue(getEvaluationContext(null), String.class);
// 	}
// }
// 
// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/KeySpaceResolver.java
// public interface KeySpaceResolver {
// 
// 	/**
// 	 * Determine the {@literal keySpace} to use for a given type.
// 	 *
// 	 * @param type must not be {@literal null}.
// 	 * @return
// 	 */
// 	@Nullable
// 	String resolveKeySpace(Class<?> type);
// }
// 
// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentEntity.java
// public interface KeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
// 		extends MutablePersistentEntity<T, P> {
// 
// 	/**
// 	 * Get the {@literal keySpace} a given entity assigns to.
// 	 *
// 	 * @return can be {@literal null}.
// 	 */
// 	@Nullable
// 	String getKeySpace();
// }
// 
// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentProperty.java
// public class KeyValuePersistentProperty<P extends KeyValuePersistentProperty<P>>
// 		extends AnnotationBasedPersistentProperty<P> {
// 
// 	public KeyValuePersistentProperty(Property property, PersistentEntity<?, P> owner,
// 			SimpleTypeHolder simpleTypeHolder) {
// 		super(property, owner, simpleTypeHolder);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()
// 	 */
// 	@Override
// 	@SuppressWarnings("unchecked")
// 	protected Association<P> createAssociation() {
// 		return new Association<>((P) this, null);
// 	}
// }


// Path: src/main/java/org/springframework/data/keyvalue/core/mapping/context/KeyValueMappingContext.java
import java.util.Collections;
import org.springframework.data.keyvalue.core.mapping.BasicKeyValuePersistentEntity;
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;

/*
 * Copyright 2014-2022 the original author or authors.
 *
 * 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
 *
 *      https://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.keyvalue.core.mapping.context;



/**
 * Default implementation of a {@link MappingContext} using {@link KeyValuePersistentEntity} and
 * {@link KeyValuePersistentProperty} as primary abstractions.
 *
 * @author Christoph Strobl
 * @author Oliver Gierke
 * @author Mark Paluch
 */
public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P extends KeyValuePersistentProperty<P>>
		extends AbstractMappingContext<E, P> {

	private @Nullable KeySpaceResolver fallbackKeySpaceResolver;