public SimpleConfiguration( ConverterRegistry converterRegistry, Set<MappedClass> mappedClasses) { this.converterRegistry = converterRegistry; this.mappedClasses = mappedClasses; for (MappedClass mappedClass : mappedClasses) { uidToMappedClass.put(mappedClass.getUID(), mappedClass); classToMappedClass.put(mappedClass.getJavaClass(), mappedClass); for (MappedClass superClass : mappedClass.getMappedSuperClasses()) { polymorphicClasses.add(superClass.getJavaClass()); } } }
Type resolveTypeVariable(String typeVariableName, MappedClass declaringClass) { int i = 0; for (TypeVariable<?> typeParameter : declaringClass.clazz.getTypeParameters()) { if (typeParameter.getName().equals(typeVariableName)) { break; } else { i++; } } int j = 0; boolean found = false; for (MappedClass superClass : getMappedSuperClasses()) { if (declaringClass.equals(superClass)) { found = true; break; } else { j++; } } if (!found) { throw new SessionException("Super class declaration for " + declaringClass + " not found from " + this); } Type type = (j == 0 ? clazz.getGenericSuperclass() : clazz.getGenericInterfaces()[j - 1]); if (type instanceof ParameterizedType) { return ((ParameterizedType) type).getActualTypeArguments()[i]; } else { throw new SessionException("Generic parameters not supplied from " + this + " to " + declaringClass); } }
public Configuration build() { if (converterRegistry == null) { converterRegistry = new ConverterRegistryImpl(); } // populate mappedSuperClasses for (MappedClass mappedClass : mappedClasses.values()) { if (!mappedClass.getJavaClass().getSuperclass().equals(Object.class)) { MappedClass mappedSuperClass = mappedClasses.get(mappedClass.getJavaClass().getSuperclass()); if (mappedSuperClass != null) { mappedClass.getMappedSuperClasses().add(mappedSuperClass); } } } // merge data for (MappedClass mappedClass : mappedClasses.values()) { Deque<MappedClass> supers = new ArrayDeque<MappedClass>(mappedClass.getMappedSuperClasses()); while (!supers.isEmpty()) { MappedClass mappedSuperClass = supers.pop(); supers.addAll(mappedSuperClass.getMappedSuperClasses()); for (MappedPath path : mappedSuperClass.getProperties()) { MappedProperty<?> property = (MappedProperty<?>) path.getMappedProperty().clone(); property.resolve(mappedClass); mappedClass.addMappedPath(new MappedPath(property, path.getPredicatePath(), !mappedClass.equals(property.getDeclaringClass()))); } } } return new SimpleConfiguration(converterRegistry, new HashSet<MappedClass>(mappedClasses.values())); }
public final void addClasses(Class<?>... classes) { for (Class<?> clazz : classes) { if (clazz.getAnnotation(ClassMapping.class) != null) { MappedClass mappedClass = mappedClassFactory.getMappedClass(clazz); if (mappedClass.getUID() != null) { ClassMapping classMapping = clazz.getAnnotation(ClassMapping.class); if (clazz.isEnum() && !classMapping.parent().equals(Object.class)) { MappedClass parentClass = mappedClassFactory.getMappedClass(classMapping .parent()); for (Object constant : clazz.getEnumConstants()) { UID instance = new UID(mappedClass.getClassNs(), ((Enum) constant).name()); addClass(instance, parentClass); } } addClass(mappedClass.getUID(), mappedClass); } for (MappedClass superClass : mappedClass.getMappedSuperClasses()) { polymorphicClasses.add(superClass.getJavaClass()); } mappedClasses.add(mappedClass); } else { throw new IllegalArgumentException("No @ClassMapping annotation for " + clazz.getName()); } } }
public ConfigurationOntology(Configuration configuration) { Set<UID> types = new HashSet<UID>(); Multimap<UID, UID> directSubtypes = MultimapFactory.<UID, UID> createWithSet(); Multimap<UID, UID> directSupertypes = MultimapFactory.<UID, UID> createWithSet(); for (MappedClass mappedClass : configuration.getMappedClasses()) { types.add(mappedClass.getUID()); for (MappedClass superClass : mappedClass.getMappedSuperClasses()) { directSupertypes.put(mappedClass.getUID(), superClass.getUID()); directSubtypes.put(superClass.getUID(), mappedClass.getUID()); } // ClassMapping classMapping = // mappedClass.getJavaClass().getAnnotation(ClassMapping.class); // if (!classMapping.parent().equals("")) { // UID parent = new UID(classMapping.parent()); // directSupertypes.put(mappedClass.getUID(), parent); // directSubtypes.put(parent, mappedClass.getUID()); // } } initializeTypeHierarchy(types, directSubtypes, directSupertypes); }
mappedClass = new MappedClass(clazz, uid, context != null ? new UID(context.value()) : null, superclasses); if (!clazz.isEnum()) { for (MappedClass mappedSuperClass : mappedClass.getMappedSuperClasses()) { if (mappedSuperClass != null) { for (MappedPath path : mappedSuperClass.getProperties()) {