@SuppressWarnings("unchecked") private Class<?> getGenericClass(MappedClass owner, int typeVariableIndex, TypeVariable<?> type) { Type upperBound = null; if (owner == null || declaringClass.equals(owner)) { typeVariables[typeVariableIndex] = type; upperBound = typeVariables[typeVariableIndex].getBounds()[0]; } else if (typeVariables[typeVariableIndex] != null) { Type genericType = owner.resolveTypeVariable(typeVariables[typeVariableIndex].getName(), declaringClass); if (genericType instanceof TypeVariable) { // Nested TypeVariable in a sub class typeVariables[typeVariableIndex] = (TypeVariable<?>) genericType; upperBound = typeVariables[typeVariableIndex].getBounds()[0]; } else { typeVariables[typeVariableIndex] = null; upperBound = genericType; } declaringClass = owner; } return getGenericClass(upperBound, -1, owner, -1); }
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); } }
private MappedClass resolveMappedClass(MappedClass mappedClass, PropertiesMap properties) { for (STMT stmt : properties.getDirect().get(RDF.type)) { if (stmt.getObject().isURI()) { List<MappedClass> mappedClasses = configuration.getMappedClasses(stmt.getObject().asURI()); for (MappedClass mc : mappedClasses) { if (!mc.equals(mappedClass) && mappedClass.getJavaClass().isAssignableFrom(mc.getJavaClass())) { return mc; } } } } return mappedClass; }
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())); }
property.resolve(mappedClass); mappedClass.addMappedPath(new MappedPath(property, path.getPredicatePath(), !mappedClass.equals(property.getDeclaringClass())));