public EntityValueEncoderFactory(SessionFactory sessionFactory, Configuration rdfBeanConfiguration, Class<T> cl) { this.sessionFactory = sessionFactory; this.cl = cl; this.idProperty = rdfBeanConfiguration.getMappedClass(cl).getIdProperty(); }
private List<ID> findMappedTypes(ID subject, UID context, Multimap<UID, STMT> properties) { List<ID> types = new ArrayList<ID>(); if (properties.containsKey(RDF.type)) { for (STMT stmt : properties.get(RDF.type)) { NODE type = stmt.getObject(); if (type instanceof UID && configuration.getMappedClasses((UID) type) != null) { types.add((UID) type); } } } return types; }
private boolean isPolymorphic(MappedClass mappedClass) { return configuration.isPolymorphic(mappedClass.getJavaClass()); }
Class<? extends T> actualType = matchType(mappedTypes, requiredType); if (actualType != null) { if (!configuration.allowCreate(actualType)) { instance = null; } else { try { MappedClass mappedClass = configuration.getMappedClass(actualType); MappedConstructor mappedConstructor = mappedClass.getConstructor(); if (mappedConstructor == null) {
MappedClass mappedClass = configuration.getMappedClass(clazz); ID subject = resourceCache.get(instance); if (subject == null) { if (subject.isURI() && configuration.isRestricted((UID) subject)) { return subject;
} else if (last.getContext() != null) { pathToContext.put(path, context = last.getContext()); } else if (configuration.isMapped(path.getType())) { MappedClass mappedClass = configuration.getMappedClass(path.getType()); if (mappedClass.getClass() != null) { pathToContext.put(path, mappedClass.getContext());
boolean matched = false; for (STMT typeStmt : typeStmts) { for (MappedClass cl : configuration.getMappedClasses(typeStmt.getObject().asURI())) { if (componentType.isAssignableFrom(cl.getJavaClass())) { matched = true; UID dataType = configuration.getConverterRegistry().getDatatype(componentType); if (dataType == null || !stmt.getObject().asLiteral().getDatatype().equals(dataType)) { continue;
else if (configuration.isMapped(targetClass) || mappedProperty.isInjection()) { convertedValue = convertMappedClass(value, targetClass, propertyPath, mappedProperty); convertedValue = configuration.getConverterRegistry().fromString(value.getValue(), targetClass);
private LIT toRDFLiteral(Object o) { if (o instanceof LIT) { return (LIT) o; } UID dataType = configuration.getConverterRegistry().getDatatype(o.getClass()); return new LIT(configuration.getConverterRegistry().toString(o), dataType); }
private <T> T assertMapped(T instance) { if (!configuration.isMapped(instance.getClass())) { throw new IllegalArgumentException(instance.getClass().getName() + " is not mapped"); } return instance; }
private ID createResource(@Nullable UID type, BeanMap instance) { ID id = configuration.createURI(instance.getBean()); if (id == null) { // String base = type != null ? type.getLocalName() : "Resource"; // String local = UUID.randomUUID().toString().replace("-", ""); // id = new UID("resource://" + base + "/" + local); id = connection.createBNode(); } return id; }
private Set<NODE> getPathValue(MappedPath path, ID subject, PropertiesMap properties, UID context) { if (configuration.allowRead(path)) { Set<NODE> values; MappedProperty<?> property = path.getMappedProperty(); if (property.isMixin()) { values = Collections.<NODE> singleton(subject); } else if (path.size() > 0) { values = findPathValues(subject, path, 0, properties, context); } else { values = new LinkedHashSet<NODE>(); } if (values.isEmpty()) { for (UID uri : property.getDefaults()) { values.add(uri); } } return values; } return Collections.emptySet(); }
public BeanQueryImpl(Session session, Ontology ontology, RDFConnection connection) { super(new QueryMixin<BeanQueryImpl>()); queryMixin.setSelf(this); this.session = session; this.ontology = ontology; this.converterRegistry = session.getConfiguration().getConverterRegistry(); this.connection = connection; }
private Type createType(Class<?> clazz) { Type type = classToType.get(clazz); if (type == null) { if (configuration.isMapped(clazz) && !clazz.isEnum()) { type = createEntityType(clazz); } else { type = typeFactory.get(clazz); } classToType.put(clazz, type); } return type; }
private UID getContext(Class<?> clazz, @Nullable ID subject, @Nullable UID defaultContext) { UID contextUID = configuration.getMappedClass(clazz).getContext(); if (contextUID != null) { return contextUID; } else { return defaultContext; } }
@Nullable private Class<?> convertClassReference(UID uid, Class<?> targetClass) { List<MappedClass> mappedClasses = configuration.getMappedClasses(uid); boolean foundMatch = false; for (MappedClass mappedClass : mappedClasses) { Class<?> clazz = mappedClass.getJavaClass(); if (targetClass.isAssignableFrom(clazz)) { targetClass = clazz; foundMatch = true; } } if (foundMatch) { return targetClass; } else { return null; } }
private boolean isPolymorphic(MappedProperty<?> mappedProperty) { if (mappedProperty.isCollection() || mappedProperty.isMap()) { return configuration.isPolymorphic(mappedProperty.getComponentType()); } else { return configuration.isPolymorphic(mappedProperty.getType()); } }
private Object convertValue(NODE node, Class<?> targetClass) { UID targetType = configuration.getConverterRegistry().getDatatype(targetClass); if (targetClass.isAssignableFrom(node.getClass())) { return node; } else if (targetType != null && node.isLiteral()) { // TODO : make sure this works also with untyped literals etc if (((LIT) node).getDatatype().equals(targetType)) { return configuration.getConverterRegistry().fromString(node.getValue(), targetClass); } else { throw new IllegalArgumentException("Literal " + node + " is not of type " + targetType); } } else if (targetType == null && node.isURI()) { return get(targetClass, node.asURI()); } else { throw new IllegalArgumentException("Node " + node + " could not be converted to " + targetClass.getName()); } }
private NODE toRDFValue(Object o, @Nullable UID context) { if (o instanceof NODE) { return (NODE) o; } Class<?> type = getClass(o); if (configuration.isMapped(type)) { return toRDF(o, context); } else if (o instanceof UID) { return (UID) o; } else { return toRDFLiteral(o); } }
private <T> T assertHasIdProperty(T instance) { MappedClass mappedClass = configuration.getMappedClass(instance.getClass()); if (mappedClass.getIdProperty() == null) { throw new IllegalArgumentException(instance.getClass().getName() + " has no id property"); } return instance; }