![JAR search and dependency download from the Maven repository](/logo.png)
org.loom.simpleds.SimpledsKeyConverterFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of loom-appengine Show documentation
Show all versions of loom-appengine Show documentation
Uploads all artifacts belonging to configuration ':archives'.
The newest version!
package org.loom.simpleds;
import javax.inject.Singleton;
import org.loom.appengine.annotations.RootKey;
import org.loom.appengine.annotations.RootKey.RootKeyType;
import org.loom.appengine.converter.KeyConverter;
import org.loom.appengine.converter.KeyIdConverter;
import org.loom.appengine.converter.KeyNameConverter;
import org.loom.binding.AnnotationContainer;
import org.loom.binding.PropertyWrapper;
import org.loom.converter.AnnotationDrivenConverterFactory;
import org.simpleds.annotations.Entity;
import org.simpleds.annotations.Id;
import org.simpleds.converter.Converter;
import com.google.appengine.api.datastore.Key;
/**
* Create {@link Converter} for {@link Key} properties
* @author Nacho
*
*/
@Singleton
public class SimpledsKeyConverterFactory implements AnnotationDrivenConverterFactory {
/** KeyConverter can be used as a singleton */
private KeyConverter singleton = new KeyConverter();
@SuppressWarnings("deprecation")
public org.loom.converter.Converter getConverter(AnnotationContainer propertyWrapper, Id annotation) {
if (propertyWrapper.getPropertyClass() != Key.class) {
return null;
}
Class> containerClass = ((PropertyWrapper)propertyWrapper).getContainerClass();
Entity entity = containerClass.getAnnotation(Entity.class);
if (entity != null && entity.parent().length == 0 && annotation.parent().length == 0) {
// root entity, create specific converter
RootKey rootKey = propertyWrapper.getAnnotation(RootKey.class);
return rootKey != null && rootKey.type() == RootKeyType.NAME? new KeyNameConverter(containerClass) : new KeyIdConverter(containerClass);
}
return singleton;
}
public Class getAnnotationClass() {
return Id.class;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy