Package org.aksw.jenax.reprogen.core
Class MapperProxyUtils
java.lang.Object
org.aksw.jenax.reprogen.core.MapperProxyUtils
Utility methods for generating java proxies that appropriately implement
subclasses of Resource based on annotations.
- Author:
- Claus Stadler, Nov 29, 2018
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic ObjectapplyInModelIfApplicable(Object o, org.apache.jena.rdf.model.Model sourceModel) static Class<?>canActAsCollectionView(Method m, Class<?> iterableClass, boolean expectSubClassOfIterable, Class<?> typeVariableBound) Check if the method signature matches the pattern: IterableClassIterableBaseClass[T] method(Class[T]) IterableClass: A candidate method must return a this class or a super class. static MethodDescriptorstatic StringclassToTag(Class<?> clazz) Convert a class into a 'tag' (or label) to be included into generated identifiers such as by prefixing.static voidcollectReachableResources(org.apache.jena.rdf.model.RDFNode root, HashIdCxt cxt) static BiFunction<org.apache.jena.rdf.model.Resource,HashIdCxt, String> createDefaultStringIdProcessor(String prefix) static BiFunction<org.apache.jena.rdf.model.RDFNode,HashIdCxt, com.google.common.hash.HashCode> createPropertyHashIdProcessor(BiFunction<org.apache.jena.rdf.model.RDFNode, HashIdCxt, com.google.common.hash.HashCode> globalHashProcessor, org.apache.jena.sparql.path.P_Path0 path, Supplier<Collection<? extends org.apache.jena.rdf.model.RDFNode>> valuesSupplier) static <T extends org.apache.jena.rdf.model.Resource>
BiFunction<org.apache.jena.graph.Node,org.apache.jena.enhanced.EnhGraph, T> createProxyFactory(Class<T> clazz, org.apache.jena.shared.PrefixMapping basePm, TypeDecider typeDecider) Method level annotations are processed into property level ones.static ViewBundlecreateViewBundleFromListAndConverter(Class<?> itemType, List<org.apache.jena.rdf.model.RDFNode> list, com.google.common.base.Converter<org.apache.jena.rdf.model.RDFNode, ?> converter) If the converter converts RDFNodes to other RDFNodes (rather than Java types), then the raw view already has the converter applied and thus the java view are the same.static ViewBundlecreateViewBundleFromMapAndConverter(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.Property keyProperty, org.apache.jena.rdf.model.Property valueProperty, Class<?> keyType, Class<?> valueType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider, boolean polymorphicOnly) Return a function that accepts an RDFNode and attempts to convert it to its actual RDFNode subtype w.r.t.static ViewBundlecreateViewBundleFromSetAndConverter(Class<?> itemType, Set<org.apache.jena.rdf.model.RDFNode> set, com.google.common.base.Converter<org.apache.jena.rdf.model.RDFNode, ?> converter, boolean isInjectiveConversion) static StringdefaultToString(Object that, Object[] args) static ClassDescriptorgetClassDescriptor(Class<?> clazz) static ClassDescriptorgetClassDescriptorCached(Class<?> clazz) static HashIdCxtgetHashId(org.apache.jena.rdf.model.RDFNode root) Computes the hash id for a given subclass of RDF node.static com.google.common.hash.HashCodestatic com.google.common.hash.HashCodegetHashIdActual(org.apache.jena.rdf.model.RDFNode root, HashIdCxt cxt) static com.google.common.hash.HashCodegetHashIdCore(org.apache.jena.rdf.model.RDFNode root, HashIdCxt cxt) static Class<?>getStricterType(Class<?> a, Class<?> b) static booleanCheck whether the method is compatible with the signature VoidOrSuperClassOfDeclaringClass myCandidateSetter(Iterable<?>)static booleanmatchesDynamicCollectionViewGetter(Method m, Class<?> expectedReturnType, boolean expectSubClassOfIterable, Class<?> expectedArgType) Check whether the method is compatible with the signature Iterable myMethod(Class); This means the following conditions are satisfied: The method's result is a super (or equal) class of the returnType argument There exists exactly one argument The argument is a super (or equal) class of the given argType argumentstatic <T> TniceInvoke(Method method, Object target, Object... args) static BiFunction<Object,Object[], Object> proxyDefaultMethod(Method method) static org.apache.jena.shared.PrefixMappingreadPrefixesFromClass(Class<?> cls, org.apache.jena.shared.PrefixMapping out) ReadNamespacesandNamespaceannotation from this class and a super classes / interfaces.static org.apache.jena.rdf.model.ResourceConvenience function that runs skolemization on a the given resource and prepends an iri prefix to the generated hashes.static org.apache.jena.rdf.model.Resourceskolemize(String iriPrefix, org.apache.jena.rdf.model.Resource root, Consumer<Map<org.apache.jena.rdf.model.RDFNode, String>> renamesCallback) static StringtoStringDirectProperties(Object that, Object[] args) static StringtoStringTree(Object that, Object[] args) static MethodDescriptorstatic MethodDescriptorstatic MethodDescriptorstatic MethodDescriptorstatic MethodDescriptorIf the method qualifies as a getter, returns a factory function that for a given property yields another function that accesses this property for astatic MethodDescriptorstatic Function<org.apache.jena.rdf.model.Property,BiConsumer<org.apache.jena.rdf.model.Resource, Object>> viewAsCollectionView(Method m, org.apache.jena.datatypes.TypeMapper typeMapper) static Function<Class<?>,BiFunction<org.apache.jena.rdf.model.Property, Boolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>>> viewAsDynamicList(Method m, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) static Function<Class<?>,BiFunction<org.apache.jena.rdf.model.Property, Boolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>>> viewAsDynamicSet(Method m, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) The collection view factory first takes the class that denotes the item type as argument.static BiFunction<org.apache.jena.rdf.model.Property,Boolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>> viewAsList(Method m, boolean isIriType, boolean polymorphicOnly, Class<?> itemType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) static Function<org.apache.jena.rdf.model.Property,Function<org.apache.jena.rdf.model.Resource, ViewBundle>> viewAsMap(Method m, boolean isValueIriType, boolean polymorphicOnly, Class<?> keyType, Class<?> valueType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) static BiFunction<org.apache.jena.rdf.model.Property,Boolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>> viewAsScalarGetter(MethodDescriptor methodDescriptor, Class<?> effectiveType, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) static BiFunction<org.apache.jena.rdf.model.Property,Boolean, Function<org.apache.jena.rdf.model.Resource, Object>> viewAsScalarGetterOldAndUnused(MethodDescriptor methodDescriptor, Class<?> effectiveType, boolean isIriType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) If the method qualifies as a getter, returns a factory function that for a given property yields another function that accesses this property for astatic BiFunction<org.apache.jena.rdf.model.Property,Boolean, BiConsumer<org.apache.jena.rdf.model.Resource, Object>> viewAsScalarSetter(MethodDescriptor methodDescriptor, Class<?> effectiveType, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) static BiFunction<org.apache.jena.rdf.model.Property,Boolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>> viewAsSet(Method m, boolean isIriType, boolean polymorphicOnly, Class<?> itemType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider)
-
Constructor Details
-
MapperProxyUtils
public MapperProxyUtils()
-
-
Method Details
-
viewAsDynamicSet
public static Function<Class<?>,BiFunction<org.apache.jena.rdf.model.Property, viewAsDynamicSetBoolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>>> (Method m, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) The collection view factory first takes the class that denotes the item type as argument. Then, for a given property, it yields a function that for a given subject yields a collection view of the objects TODO We should reuse the code from 'viewAsGetter': This class only differs in the aspect that the item type is dynamic, whereas viewAsGetter attempts to obtain a static item type using reflection.- Parameters:
m-typeMapper-- Returns:
-
viewAsDynamicList
public static Function<Class<?>,BiFunction<org.apache.jena.rdf.model.Property, viewAsDynamicListBoolean, Function<org.apache.jena.rdf.model.Resource, ViewBundle>>> (Method m, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) -
viewAsSet
public static BiFunction<org.apache.jena.rdf.model.Property,Boolean, viewAsSetFunction<org.apache.jena.rdf.model.Resource, ViewBundle>> (Method m, boolean isIriType, boolean polymorphicOnly, Class<?> itemType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) -
viewAsMap
public static Function<org.apache.jena.rdf.model.Property,Function<org.apache.jena.rdf.model.Resource, viewAsMapViewBundle>> (Method m, boolean isValueIriType, boolean polymorphicOnly, Class<?> keyType, Class<?> valueType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) -
viewAsList
public static BiFunction<org.apache.jena.rdf.model.Property,Boolean, viewAsListFunction<org.apache.jena.rdf.model.Resource, ViewBundle>> (Method m, boolean isIriType, boolean polymorphicOnly, Class<?> itemType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) -
createViewBundleFromListAndConverter
public static ViewBundle createViewBundleFromListAndConverter(Class<?> itemType, List<org.apache.jena.rdf.model.RDFNode> list, com.google.common.base.Converter<org.apache.jena.rdf.model.RDFNode, ?> converter) If the converter converts RDFNodes to other RDFNodes (rather than Java types), then the raw view already has the converter applied and thus the java view are the same. The assumption is that this way the RDFNodes have may be converter to sub-types managed in the mapper's meta model.- Parameters:
itemType-list-converter-- Returns:
-
createViewBundleFromMapAndConverter
public static ViewBundle createViewBundleFromMapAndConverter(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.Property keyProperty, org.apache.jena.rdf.model.Property valueProperty, Class<?> keyType, Class<?> valueType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider, boolean polymorphicOnly) Return a function that accepts an RDFNode and attempts to convert it to its actual RDFNode subtype w.r.t. to the type decider. Not for use with literals as input.- Parameters:
valueType-typeMapper-typeDecider-- Returns:
-
createViewBundleFromSetAndConverter
public static ViewBundle createViewBundleFromSetAndConverter(Class<?> itemType, Set<org.apache.jena.rdf.model.RDFNode> set, com.google.common.base.Converter<org.apache.jena.rdf.model.RDFNode, ?> converter, boolean isInjectiveConversion) - Parameters:
itemType- If it is a subclass of RDFNode, the raw view already has the converter appliedset-converter-isInjectiveConversion- Whether the converter is injective. If it is not then additional wrapping is performed to ensure set nature.- Returns:
-
classifyMethod
-
tryClassifyAsScalarGetter
If the method qualifies as a getter, returns a factory function that for a given property yields another function that accesses this property for a- Parameters:
m-typeMapper-- Returns:
-
tryClassifyAsScalarSetter
-
tryClassifyAsCollectionSetter
-
tryClassifyAsMapGetter
-
tryClassifyAsCollectionGetter
-
viewAsScalarGetter
public static BiFunction<org.apache.jena.rdf.model.Property,Boolean, viewAsScalarGetterFunction<org.apache.jena.rdf.model.Resource, ViewBundle>> (MethodDescriptor methodDescriptor, Class<?> effectiveType, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) -
viewAsScalarGetterOldAndUnused
public static BiFunction<org.apache.jena.rdf.model.Property,Boolean, viewAsScalarGetterOldAndUnusedFunction<org.apache.jena.rdf.model.Resource, Object>> (MethodDescriptor methodDescriptor, Class<?> effectiveType, boolean isIriType, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) If the method qualifies as a getter, returns a factory function that for a given property yields another function that accesses this property for a- Parameters:
m-typeMapper-- Returns:
-
matchesCollectionViewSetter
Check whether the method is compatible with the signature VoidOrSuperClassOfDeclaringClass myCandidateSetter(Iterable<?>)- Returns:
-
matchesDynamicCollectionViewGetter
public static boolean matchesDynamicCollectionViewGetter(Method m, Class<?> expectedReturnType, boolean expectSubClassOfIterable, Class<?> expectedArgType) Check whether the method is compatible with the signature Iterable myMethod(Class); This means the following conditions are satisfied:- The method's result is a super (or equal) class of the returnType argument
- There exists exactly one argument
- The argument is a super (or equal) class of the given argType argument
- Parameters:
m-iterableClass-typeVariableBound-- Returns:
-
tryClassifyAsDynamicCollectionGetter
-
canActAsCollectionView
public static Class<?> canActAsCollectionView(Method m, Class<?> iterableClass, boolean expectSubClassOfIterable, Class<?> typeVariableBound) Check if the method signature matches the pattern: IterableClassIterableBaseClass[T] method(Class[T]) IterableClass: A candidate method must return a this class or a super class. Example: If a method with a return type of Set.class is searched, then methods with return type Iterable and Collection are matches, but HashSet and List are not. Returns the itemType if the method is a match - null otherwise. - Parameters:
m-iterableClass-typeVariableBound- The- Returns:
-
viewAsCollectionView
public static Function<org.apache.jena.rdf.model.Property,BiConsumer<org.apache.jena.rdf.model.Resource, viewAsCollectionViewObject>> (Method m, org.apache.jena.datatypes.TypeMapper typeMapper) -
applyInModelIfApplicable
-
viewAsScalarSetter
public static BiFunction<org.apache.jena.rdf.model.Property,Boolean, viewAsScalarSetterBiConsumer<org.apache.jena.rdf.model.Resource, Object>> (MethodDescriptor methodDescriptor, Class<?> effectiveType, boolean isIriType, boolean polymorphicOnly, org.apache.jena.datatypes.TypeMapper typeMapper, TypeDecider typeDecider) -
getStricterType
-
niceInvoke
-
createDefaultStringIdProcessor
public static BiFunction<org.apache.jena.rdf.model.Resource,HashIdCxt, createDefaultStringIdProcessorString> (String prefix) -
proxyDefaultMethod
public static BiFunction<Object,Object[], proxyDefaultMethodObject> (Method method) throws ReflectiveOperationException - Throws:
ReflectiveOperationException
-
defaultToString
-
toStringTree
-
toStringDirectProperties
-
getHashId
Computes the hash id for a given subclass of RDF node.- Type Parameters:
T-- Parameters:
root-viewClazz-cxt- In/out map of visited resources to assigned hash values- Returns:
-
skolemize
public static org.apache.jena.rdf.model.Resource skolemize(String iriPrefix, org.apache.jena.rdf.model.Resource root) Convenience function that runs skolemization on a the given resource and prepends an iri prefix to the generated hashes. This convenience function does not allow for accessing all ocurred renamings. Modifies the model in-place. Example:newResource = skolemize("http://www.example.org/", oldResource;- Parameters:
iriPrefix-root- The 'root' resource from which to start the skolemization process- Returns:
- The resource that is the skolemization of 'root' in the same model as 'root'
-
skolemize
-
getHashId
public static com.google.common.hash.HashCode getHashId(org.apache.jena.rdf.model.RDFNode root, HashIdCxt cxt) -
getHashIdCore
public static com.google.common.hash.HashCode getHashIdCore(org.apache.jena.rdf.model.RDFNode root, HashIdCxt cxt) -
getHashIdActual
public static com.google.common.hash.HashCode getHashIdActual(org.apache.jena.rdf.model.RDFNode root, HashIdCxt cxt) -
collectReachableResources
-
getClassDescriptorCached
-
getClassDescriptor
-
createPropertyHashIdProcessor
public static BiFunction<org.apache.jena.rdf.model.RDFNode,HashIdCxt, createPropertyHashIdProcessorcom.google.common.hash.HashCode> (BiFunction<org.apache.jena.rdf.model.RDFNode, HashIdCxt, com.google.common.hash.HashCode> globalHashProcessor, org.apache.jena.sparql.path.P_Path0 path, Supplier<Collection<? extends org.apache.jena.rdf.model.RDFNode>> valuesSupplier) -
classToTag
Convert a class into a 'tag' (or label) to be included into generated identifiers such as by prefixing.- Parameters:
clazz-
-