You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2014/01/08 16:25:27 UTC
[11/51] [abbrv] [partial] MARMOTTA-397: Reorganized and renamed
Marmotta Sesame Tools
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java
new file mode 100644
index 0000000..fb70791
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java
@@ -0,0 +1,809 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.sesame.facading.impl;
+
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFInverse;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFPropertyBuilder;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.api.FacadingPredicateBuilder;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+import org.apache.marmotta.commons.sesame.facading.util.FacadeUtils;
+import org.apache.marmotta.commons.util.DateUtils;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.*;
+
+/**
+ * This class implements an invocation handler to be used for proxy classes that delegate to a
+ * content item and to data in the triple store. It has to be constructed using the triple store
+ * implementation as parameter. Interfaces that make use of this invocation handler need to extend
+ * the {@link Facade} interface.
+ *
+ * @author Sebastian Schaffert <ss...@apache.org>
+ * @author Jakob Frank <ja...@apache.org>
+ */
+class FacadingInvocationHandler implements InvocationHandler {
+
+ public static enum OPERATOR {
+ GET(false, 0, "get"),
+ SET(true, 1, "set"),
+ ADD(true, 1, "add"),
+ DEL(true, 0, "del", "delete", "remove", "rm"),
+ HAS(false, 0, "has", "is");
+
+
+ private static final String[] PX, SPX;
+ static {
+ LinkedList<String> ops = new LinkedList<String>();
+ for (OPERATOR op : OPERATOR.values()) {
+ for (String px : op.prefixes) {
+ ops.add(px);
+ }
+ }
+ PX = ops.toArray(new String[ops.size()]);
+ SPX = ops.toArray(new String[ops.size()]);
+ Arrays.sort(SPX, new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ return o2.length() - o1.length();
+ }
+ });
+ }
+
+ final String[] prefixes;
+ final int numArgs;
+ final boolean writeOp;
+
+ private OPERATOR(boolean isWriteOp, int args, String... strings) {
+ this.writeOp = isWriteOp;
+ this.numArgs = args;
+ this.prefixes = strings;
+ }
+
+ @Override
+ public String toString() {
+ return prefixes[0];
+ }
+
+ public static String[] getOperatorPrefixes() {
+ return PX;
+ }
+
+ public static String[] getLengthSortedOperatorPrefixes() {
+ return SPX;
+ }
+
+ public static OPERATOR getOperator(Method m) {
+ for (OPERATOR op : values()) {
+ for (String px : op.prefixes) {
+ if (m.getName().startsWith(px)) {
+ final int numP = m.getParameterTypes().length;
+ if (numP == op.numArgs || numP == op.numArgs + 1) { return op; }
+ }
+ }
+ }
+ return valueOf(m.getName());
+ }
+ }
+
+ private final RepositoryConnection connection;
+
+ private final Facading facadingService;
+
+ private final Class<? extends Facade> declaredFacade;
+
+ private final FacadingPredicateBuilder propBuilder;
+
+ private final Resource delegate;
+
+ private final URI context;
+
+ private final HashMap<String, Object> fieldCache;
+
+ private final Logger log;
+
+ /**
+ * Indicates if the cache is used, by default is false.
+ */
+ private boolean useCache;
+
+ public FacadingInvocationHandler(Resource item, URI context, Class<? extends Facade> facade, Facading facadingService, RepositoryConnection connection) {
+ this.log = LoggerFactory.getLogger(facade.getName() + "!" + this.getClass().getSimpleName() + "@" + item.stringValue());
+ this.delegate = item;
+ this.facadingService = facadingService;
+ this.declaredFacade = facade;
+ this.connection = connection;
+
+ if (declaredFacade.isAnnotationPresent(RDFPropertyBuilder.class)) {
+ final Class<? extends FacadingPredicateBuilder> bClass = declaredFacade.getAnnotation(RDFPropertyBuilder.class).value();
+ FacadingPredicateBuilder _b = null;
+ try {
+ // Look for a no-arg Constructor
+ _b = bClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException e) {
+ // If there is no no-arg Constructor, try static getInstance()
+ try {
+ for (Method m : bClass.getMethods()) {
+ if (Modifier.isStatic(m.getModifiers()) && "getInstance".equals(m.getName()) && m.getParameterTypes().length == 0) {
+ _b = (FacadingPredicateBuilder) m.invoke(null);
+ break;
+ }
+ }
+ if (_b == null) { throw new IllegalArgumentException("Could not find no-arg Constructor or static no-arg factory-method 'getInstance' for "
+ + bClass.getName()); }
+ } catch (Exception e1) {
+ throw new IllegalArgumentException("Could not load instance of " + bClass.getSimpleName() + " from static factory 'getInstance()': "
+ + e.getMessage(), e);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not create instance of " + bClass.getSimpleName() + ": " + e.getMessage(), e);
+ }
+ this.propBuilder = _b;
+ } else {
+ this.propBuilder = null;
+ }
+
+ if (context != null) {
+ this.context = context;
+ } else {
+ // FIXME
+ this.context = null;
+ }
+
+ fieldCache = new HashMap<String, Object>();
+
+ // disable cache, it does not work well with deleted triples ...
+ useCache = false;
+ }
+
+ /**
+ * Indicates if the cache is allow or not.
+ *
+ * @return the useCache true if the cache is done.
+ */
+ public boolean isUseCache() {
+ return useCache;
+ }
+
+ /**
+ * Used to enable/disable the cache mechanism.
+ *
+ * @param useCache
+ * true foe enable cache, false - no cache.
+ */
+ public void setUseCache(boolean useCache) {
+ this.useCache = useCache;
+ }
+
+ /**
+ * @return the item
+ */
+ public Resource getDelegate() {
+ return delegate;
+ }
+
+ /**
+ * Invoke the invocation handler for the given proxy object, method, and arguments. In order to
+ * execute the passed method, this method does the following: - if the method has a
+ * <code>RDF</code> annotation or if it is a setter and the corresponding getter has a
+ * <code>RDF</code> annotation, we try to retrieve the appropriate value by querying the triple
+ * store and converting the triple store data to the return type of the method; if the return
+ * type is again an interface
+ *
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method,
+ * java.lang.Object[])
+ * @see org.apache.marmotta.commons.sesame.facading.annotations.RDF
+ */
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws InstantiationException, IllegalAccessException, RepositoryException {
+ if (!connection.isOpen()) { throw new IllegalAccessException("the connection is already closed, cannot access proxy methods."); }
+ if (!connection.isActive()) { throw new IllegalAccessException("no active transaction, cannot access triple-store."); }
+
+ // handle default methods:
+ if (FacadingInvocationHelper.checkMethodSig(method, "hashCode")) {
+ return delegate.hashCode();
+ } else if (FacadingInvocationHelper.checkMethodSig(method, "equals", 1)) {
+ final Object other = args[0];
+ return other != null && other.getClass().equals(proxy.getClass()) && other.hashCode() == proxy.hashCode();
+ } else if (FacadingInvocationHelper.checkMethodSig(method, "toString")) {
+ return declaredFacade.getSimpleName() + " with delegate to " + delegate.toString();
+ } else if (FacadingInvocationHelper.checkMethodSig(method, "getDelegate")) { return delegate; }
+
+ // caching
+ final String fieldName = FacadingInvocationHelper.getBaseName(method);
+ if (useCache && method.getName().startsWith("get")) {
+ if (fieldCache.get(fieldName) != null) { return fieldCache.get(fieldName); }
+ }
+
+ final FacadingPredicate fp = getFacadingPredicate(method);
+
+ // distinguish getters and setters and more...
+ switch (OPERATOR.getOperator(method)) {
+ case GET:
+ return handleGet(method, args, fp);
+ case SET:
+ return handleSet(method, args, fp);
+ case ADD:
+ return handleAdd(method, args, fp);
+ case DEL:
+ return handleDel(method, args, fp);
+ case HAS:
+ return handleHas(method, args, fp);
+ default:
+ throw new IllegalArgumentException("Unsupported method: " + method.getName());
+ }
+ }
+
+ private FacadingPredicate getFacadingPredicate(Method method) throws IllegalArgumentException {
+ final String[] rdf_property;
+ final boolean inverse;
+ // look for RDF annotation and extract the property from it; if not on the getter, look
+ // for the corresponding setter and check whether it has a @RDF annotation; if neither has,
+ // throw an IllegalArgumentException
+ RDF rdf = FacadingInvocationHelper.getAnnotation(method, RDF.class);
+ if (rdf != null) {
+ rdf_property = rdf.value();
+ inverse = false;
+ return new FacadingPredicate(inverse, rdf_property);
+ } else {
+ RDFInverse rdfi = FacadingInvocationHelper.getAnnotation(method, RDFInverse.class);
+ if (rdfi != null) {
+ rdf_property = rdfi.value();
+ inverse = true;
+ return new FacadingPredicate(inverse, rdf_property);
+ } else {
+ if (propBuilder != null) {
+ String fName = FacadingInvocationHelper.getBaseName(method);
+ if (fName.length() > 1) {
+ fName = fName.substring(0, 1).toLowerCase(Locale.ENGLISH) + fName.substring(1);
+ }
+ return propBuilder.getFacadingPredicate(fName, declaredFacade, method);
+ } else {
+ throw new IllegalArgumentException("Could not find facading predicate for " + method.getName() + " in " + declaredFacade.getName());
+ }
+ }
+ }
+ }
+
+ private Boolean handleHas(Method method, Object[] args, FacadingPredicate predicate) throws RepositoryException {
+ final Locale loc;
+ if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(Locale.class)) {
+ loc = (Locale) args[0];
+ } else {
+ loc = null;
+ }
+
+ if (predicate.isInverse()) {
+ if (loc != null) { throw new IllegalArgumentException("@RDFInverse not supported for language tagged properties"); }
+ else {
+ for (String p : predicate.getProperties()) {
+ final URI prop = connection.getValueFactory().createURI(p);
+ final RepositoryResult<Statement> result = connection.getStatements(null, prop, delegate, true, context);
+ try {
+ if (result.hasNext()) { return true; }
+ } finally {
+ result.close();
+ }
+ }
+ }
+ } else {
+ for (String p : predicate.getProperties()) {
+ final URI prop = connection.getValueFactory().createURI(p);
+ final RepositoryResult<Statement> result = connection.getStatements(delegate, prop, null, true, context);
+ try {
+ if (loc == null) {
+ if (result.hasNext()) { return true; }
+ } else {
+ while (result.hasNext()) {
+ final Value o = result.next().getObject();
+ if (FacadingInvocationHelper.checkLocale(loc, o)) { return true; }
+ }
+ }
+ } finally {
+ result.close();
+ }
+ }
+ }
+
+
+ return false;
+ }
+
+ private Object handleDel(Method method, Object[] args, FacadingPredicate predicate) throws RepositoryException {
+ final Locale loc;
+ if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(Locale.class)) {
+ loc = (Locale) args[0];
+ } else {
+ loc = null;
+ }
+
+ delProperties(predicate, loc);
+
+ return null;
+ }
+
+ private Object handleAdd(Method method, Object[] args, FacadingPredicate predicate) throws RepositoryException, IllegalArgumentException {
+ final Locale loc;
+ if (method.getParameterTypes().length == 2 && method.getParameterTypes()[1].equals(Locale.class)) {
+ loc = (Locale) args[1];
+ } else {
+ loc = null;
+ }
+
+ final Class<?> paramType = method.getParameterTypes()[0];
+ addProperties(method, args, predicate.getProperties(), predicate.isInverse(), loc, paramType);
+
+ return null;
+ }
+
+ private Object handleSet(Method method, Object[] args, FacadingPredicate predicate)
+ throws RepositoryException, IllegalArgumentException {
+
+ final Locale loc;
+ if (method.getParameterTypes().length == 2 && method.getParameterTypes()[1].equals(Locale.class)) {
+ loc = (Locale) args[1];
+ } else {
+ loc = null;
+ }
+
+ // add to cache
+ if (useCache) {
+ fieldCache.put(FacadingInvocationHelper.getBaseName(method), args[0]);
+ }
+
+ // This is SET, so delete all previous properties
+ delProperties(predicate, loc);
+
+ // *** set the value of a certain RDF property
+ final Class<?> paramType = method.getParameterTypes()[0];
+
+ addProperties(method, args, predicate.getProperties(), predicate.isInverse(), loc, paramType);
+
+
+ return null;
+ }
+
+ private void addProperties(Method method, Object[] args, final String[] rdf_property, final boolean inverse, final Locale loc, final Class<?> paramType)
+ throws RepositoryException, IllegalArgumentException {
+ if (args[0] == null || "".equals(args[0])) {
+ // nop;
+ } else if (FacadeUtils.isBaseType(paramType) && !inverse) {
+ for (String v : rdf_property) {
+ final URI prop = connection.getValueFactory().createURI(v);
+ connection.add(delegate, prop, createLiteral(args[0], loc), context);
+ }
+ } else if (FacadeUtils.isValue(paramType) && !inverse) {
+ for (String v : rdf_property) {
+ final URI prop = connection.getValueFactory().createURI(v);
+ // create a new triple for this property, subject, and object
+ connection.add(delegate, prop, (Value) args[0], context);
+ }
+ } else if (FacadeUtils.isResource(paramType) && inverse) {
+ for (String v : rdf_property) {
+ final URI prop = connection.getValueFactory().createURI(v);
+ // create a new triple for this property, subject, and object
+ connection.add((Resource) args[0], prop, delegate, context);
+ }
+ } else if (FacadeUtils.isFacade(paramType) && !inverse) {
+ for (String v : rdf_property) {
+ final URI prop = connection.getValueFactory().createURI(v);
+ // create a new triple for this property, subject, and object
+ connection.add(delegate, prop, ((Facade) args[0]).getDelegate(), context);
+ }
+ } else if (FacadeUtils.isFacade(paramType) && inverse) {
+ for (String v : rdf_property) {
+ final URI prop = connection.getValueFactory().createURI(v);
+ // create a new triple for this property, subject, and object
+ connection.add(((Facade) args[0]).getDelegate(), prop, delegate, context);
+ }
+ } else if (FacadeUtils.isCollection(paramType)) {
+ for (String v : rdf_property) {
+ final Collection<?> c = (Collection<?>) args[0];
+
+ final URI prop = connection.getValueFactory().createURI(v);
+
+ // add each of the elements in the collection as new triple with prop
+ for (final Object o : c) {
+ if (o == null) {
+ // skip
+ } else if (FacadeUtils.isBaseType(o.getClass()) && !inverse) {
+ connection.add(delegate, prop, createLiteral(o, loc), context);
+ } else if (FacadeUtils.isFacade(o.getClass()) && !inverse) {
+ connection.add(delegate, prop, ((Facade) o).getDelegate(), context);
+ } else if (FacadeUtils.isFacade(o.getClass()) && inverse) {
+ connection.add(((Facade) o).getDelegate(), prop, delegate, context);
+ } else if (FacadeUtils.isValue(o.getClass()) && !inverse) {
+ connection.add(delegate, prop, (Value) o, context);
+ } else if (FacadeUtils.isResource(o.getClass()) && inverse) {
+ connection.add((Resource) o, prop, delegate, context);
+ } else if (inverse) {
+ throw new IllegalArgumentException("method " + method.getName() + ": @RDFInverse not supported for parameter type "
+ + paramType.getName());
+ } else {
+ throw new IllegalArgumentException("the type " + o.getClass().getName() + " is not supported in collections");
+ }
+ }
+ }
+ } else if (inverse) {
+ throw new IllegalArgumentException("method " + method.getName() + ": @RDFInverse not supported for parameter type " + paramType.getName());
+ } else {
+ throw new IllegalArgumentException("method " + method.getName() + ": unsupported parameter type " + paramType.getName());
+ }
+ }
+
+ private void delProperties(final FacadingPredicate predicate, final Locale loc) throws RepositoryException {
+ for (String v : predicate.getProperties()) {
+ final URI prop = connection.getValueFactory().createURI(v);
+
+ if (!predicate.isInverse() && loc == null) {
+ // remove all properties prop that have this subject;
+ connection.remove(delegate, prop, null, context);
+ } else if (predicate.isInverse() && loc == null) {
+ // remove all properties prop that have this object;
+ connection.remove((Resource) null, prop, delegate, context);
+ } else if (!predicate.isInverse() && loc != null) {
+ final RepositoryResult<Statement> statements = connection.getStatements(delegate, prop, null, false, context);
+ try {
+ while (statements.hasNext()) {
+ final Statement s = statements.next();
+ if (FacadingInvocationHelper.checkLocale(loc, s.getObject())) {
+ connection.remove(s);
+ }
+ }
+ } finally {
+ statements.close();
+ }
+ } else if (predicate.isInverse() && loc != null) { throw new IllegalArgumentException("A combination of @RDFInverse and a Literal is not possible");
+ }
+ }
+ }
+
+ private Object handleGet(Method method, Object[] args, FacadingPredicate predicate) throws IllegalAccessException, InstantiationException,
+ RepositoryException {
+ final Locale loc;
+ if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(Locale.class)) {
+ loc = (Locale) args[0];
+ } else {
+ loc = null;
+ }
+
+ // *** get the value of a certain RDF property ***
+
+ final Class<?> returnType = method.getReturnType();
+ final Type typeOfGeneric = method.getGenericReturnType();
+
+ // we believe that the result is universal for each property
+ // and therefore just return the result for the firstly defined property
+ final Object result = transform(returnType, typeOfGeneric, delegate, predicate.getProperties()[0], loc, predicate.isInverse());
+
+ if (useCache) {
+ fieldCache.put(FacadingInvocationHelper.getBaseName(method), result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Helper method to transform the object reachable via rdf_property from r to the given
+ * returnType; if the returnType is a collection, it is also necessary to provide the generic
+ * type. The KiWiEntityManager is used for further querying.<br>
+ * Please note that if the <code>returnType</code>is a collection you <b>must</b> use a concrete
+ * class (e.g. <code>java.util.ArrayList</code>) not an abstract class or interface.
+ *
+ * @param <C>
+ * @param returnType
+ * @param typeOfGeneric
+ * @param rdf_property
+ * @return
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ private <C, D extends Facade> C transform(Class<C> returnType, Type typeOfGeneric, Resource entity, String rdf_property, Locale loc, boolean inverse)
+ throws IllegalAccessException, InstantiationException, RepositoryException {
+ // should not happen actually
+ if (entity == null) { return null; }
+
+ if (FacadeUtils.isBaseType(returnType) && !inverse) {
+ /*
+ * if the return type is string or primitive, get the literal value of the property and
+ * transform it appropriately
+ */
+ final URI property = connection.getValueFactory().createURI(rdf_property);
+ final String value = getProperty(entity, property, loc, context);
+
+ try {
+ // transformation to appropriate primitive type
+ final C result = FacadeUtils.transformToBaseType(value, returnType);
+
+ return result;
+ } catch (final IllegalArgumentException ex) {
+ return null;
+ }
+
+ } else if (FacadeUtils.isValue(returnType) && !inverse) {
+ return queryOutgoingSingle(entity, rdf_property, returnType);
+ } else if (FacadeUtils.isValue(returnType) && inverse) {
+ return queryIncomingSingle(entity, rdf_property, returnType);
+ } else if (FacadeUtils.isFacade(returnType) && !inverse) {
+ /*
+ * for KiWi entities, we retrieve the resource that is targeted by this property (by
+ * using getObject) and create a query on the triple store using createQuery() and the
+ * resource's uri that returns the result in the appropriate type (can e.g. be again a
+ * proxy using this invocation handler!)
+ */
+ Resource object = queryOutgoingSingle(entity, rdf_property, Resource.class);
+
+ if (object != null) {
+ return returnType.cast(facadingService.createFacade(object, returnType.asSubclass(Facade.class), context));
+ } else {
+ return null;
+ }
+ } else if (FacadeUtils.isFacade(returnType) && inverse) {
+ /*
+ * for KiWi entities, we retrieve the resource that is targeted by this property (by
+ * using getObject) and create a query on the triple store using createQuery() and the
+ * resource's uri that returns the result in the appropriate type (can e.g. be again a
+ * proxy using this invocation handler!)
+ */
+ Resource subject = queryIncomingSingle(entity, rdf_property, Resource.class);
+
+ if (subject != null) {
+ return returnType.cast(facadingService.createFacade(subject, returnType.asSubclass(Facade.class), context));
+ } else {
+ return null;
+ }
+ } else if (FacadeUtils.isCollection(returnType)) {
+ /*
+ * if we have a collection, we try to infer the generic type of its contents and use
+ * this to generate values; if the generic type is a kiwi entity, we issue a createQuery
+ * to the tripleStore to retrieve the corresponding values; if the generic type is a
+ * base type, we transform the results to the base type and query for literals
+ */
+ if (typeOfGeneric instanceof ParameterizedType) {
+ final ParameterizedType t = (ParameterizedType) typeOfGeneric;
+ final Class<?> tCls = (Class<?>) t.getActualTypeArguments()[0];
+
+ @SuppressWarnings("rawtypes")
+ final Class<? extends Collection> collectionType = returnType.asSubclass(Collection.class);
+
+ if (FacadeUtils.isFacade(tCls) && !inverse) {
+ return returnType.cast(FacadingInvocationHelper.createCollection(
+ collectionType,
+ facadingService.createFacade(queryOutgoingAll(entity, rdf_property, Resource.class), tCls.asSubclass(Facade.class), context)));
+ } else if (FacadeUtils.isFacade(tCls) && inverse) {
+ return returnType.cast(FacadingInvocationHelper.createCollection(
+ collectionType,
+ facadingService.createFacade(queryIncomingAll(entity, rdf_property, Resource.class), tCls.asSubclass(Facade.class), context)));
+ } else if (FacadeUtils.isValue(tCls) && !inverse) {
+ return returnType.cast(FacadingInvocationHelper.createCollection(
+ collectionType,
+ queryOutgoingAll(entity, rdf_property, tCls.asSubclass(Value.class))));
+ } else if (FacadeUtils.isValue(tCls) && inverse) {
+ return returnType.cast(FacadingInvocationHelper.createCollection(
+ collectionType,
+ queryIncomingAll(entity, rdf_property, tCls.asSubclass(Value.class))));
+ } else if (inverse) {
+ throw new IllegalArgumentException("@RDFInverse not supported for mappings of type " + rdf_property);
+ } else if (FacadeUtils.isBaseType(tCls)) {
+ final Collection<Object> result = FacadingInvocationHelper.createCollection(collectionType, Collections.<Object> emptyList());
+ final URI property = connection.getValueFactory().createURI(rdf_property);
+
+ for (final String s : getProperties(entity, property, loc, context)) {
+ result.add(FacadeUtils.transformToBaseType(s, tCls));
+ }
+
+ return returnType.cast(result);
+ } else {
+ throw new IllegalArgumentException("return type is using generic type " + tCls.getName()
+ + ", which is not supported in RDF-based collections; please use either Java primitive types or KiWi Entities in KiWiFacades");
+ }
+ } else {
+ throw new IllegalArgumentException("return type is unparametrized collection type " + returnType.getName()
+ + ", which is not supported; please use an explicit type parameter in Facades");
+ }
+ } else if (inverse) {
+ throw new IllegalArgumentException("@RDFInverse not supported for mappings of type " + rdf_property);
+ } else {
+ throw new IllegalArgumentException("unsupported return type " + returnType.getName());
+ }
+
+ }
+
+ /**
+ * Return the single object of type C that is reachable from entity by rdf_property. Returns
+ * null if there is no such object or if the type of the object does not match the type passed
+ * as argument.
+ *
+ */
+ private <C> C queryOutgoingSingle(Resource entity, String rdf_property, Class<C> returnType) throws RepositoryException {
+ URI property = connection.getValueFactory().createURI(rdf_property);
+
+ RepositoryResult<Statement> triples = connection.getStatements(entity, property, null, false);
+ try {
+ if (triples.hasNext()) {
+ Statement triple = triples.next();
+
+ Value object = triple.getObject();
+
+ if (returnType.isInstance(object)) {
+ return returnType.cast(object);
+ } else {
+ log.error("cannot cast retrieved object {} for property {} to return type {}", object, rdf_property, returnType);
+ return null;
+ }
+
+ } else {
+ return null;
+ }
+ } finally {
+ triples.close();
+ }
+
+ }
+
+ /**
+ * Return the single subject of type C that can reach entity by rdf_property. Returns null if
+ * there is no such object or if the type of the object does not match the type passed as
+ * argument.
+ *
+ */
+ private <C> C queryIncomingSingle(Resource entity, String rdf_property, Class<C> returnType) throws RepositoryException {
+ URI property = connection.getValueFactory().createURI(rdf_property);
+
+ RepositoryResult<Statement> triples = connection.getStatements(null, property, entity, false);
+ try {
+ if (triples.hasNext()) {
+ Statement triple = triples.next();
+
+ Value subject = triple.getSubject();
+
+ if (returnType.isInstance(subject)) {
+ return returnType.cast(subject);
+ } else {
+ log.error("cannot cast retrieved object {} for property {} to return type {}", subject, rdf_property, returnType);
+ return null;
+ }
+
+ } else {
+ return null;
+ }
+ } finally {
+ triples.close();
+ }
+ }
+
+ /**
+ * Return the all objects of type C that are reachable from entity by rdf_property. Returns
+ * empty set if there is no such object or if the type of the object does not match the type
+ * passed as argument.
+ *
+ */
+ private <C> Set<C> queryOutgoingAll(Resource entity, String rdf_property, Class<C> returnType) throws RepositoryException {
+ final URI property = connection.getValueFactory().createURI(rdf_property);
+
+ final Set<C> dupSet = new LinkedHashSet<C>();
+ final RepositoryResult<Statement> triples = connection.getStatements(entity, property, null, false);
+ try {
+ while (triples.hasNext()) {
+ Statement triple = triples.next();
+ if (returnType.isInstance(triple.getObject())) {
+ dupSet.add(returnType.cast(triple.getObject()));
+ }
+ }
+ } finally {
+ triples.close();
+ }
+
+ return dupSet;
+
+ }
+
+ /**
+ * Return the all objects of type C that are can reach the entity by rdf_property. Returns empty
+ * set if there is no such object or if the type of the object does not match the type passed as
+ * argument.
+ *
+ */
+ private <C> Set<C> queryIncomingAll(Resource entity, String rdf_property, Class<C> returnType) throws RepositoryException {
+ final URI property = connection.getValueFactory().createURI(rdf_property);
+
+ final Set<C> dupSet = new LinkedHashSet<C>();
+ final RepositoryResult<Statement> triples = connection.getStatements(null, property, entity, false);
+ try {
+ while (triples.hasNext()) {
+ Statement triple = triples.next();
+ if (returnType.isInstance(triple.getSubject())) {
+ dupSet.add(returnType.cast(triple.getSubject()));
+ }
+ }
+ } finally {
+ triples.close();
+ }
+
+ return dupSet;
+ }
+
+ private Value createLiteral(Object o, Locale loc) {
+ if (o instanceof Date) {
+ return connection.getValueFactory().createLiteral(DateUtils.getXMLCalendar((Date) o));
+ } else if (Integer.class.isAssignableFrom(o.getClass())) {
+ return connection.getValueFactory().createLiteral((Integer) o);
+ } else if (Long.class.isAssignableFrom(o.getClass())) {
+ return connection.getValueFactory().createLiteral((Long) o);
+ } else if (Double.class.isAssignableFrom(o.getClass())) {
+ return connection.getValueFactory().createLiteral((Double) o);
+ } else if (Float.class.isAssignableFrom(o.getClass())) {
+ return connection.getValueFactory().createLiteral((Float) o);
+ } else if (Boolean.class.isAssignableFrom(o.getClass())) {
+ return connection.getValueFactory().createLiteral((Boolean) o);
+ } else if (loc != null) {
+ return connection.getValueFactory().createLiteral(o.toString(), loc.getLanguage());
+ } else {
+ return connection.getValueFactory().createLiteral(o.toString());
+ }
+ }
+
+ private Set<String> getProperties(Resource entity, URI property, Locale loc, URI context) throws RepositoryException {
+ final String lang = loc == null ? null : loc.getLanguage().toLowerCase();
+
+ final Set<String> values = new HashSet<String>();
+ final RepositoryResult<Statement> candidates = connection.getStatements(entity, property, null, false, context);
+ try {
+ while (candidates.hasNext()) {
+ Statement triple = candidates.next();
+
+ if (triple.getObject() instanceof Literal) {
+ Literal l = (Literal) triple.getObject();
+
+ if (lang == null || lang.equals(l.getLanguage())) {
+ values.add(l.stringValue());
+ }
+ }
+ }
+ } finally {
+ candidates.close();
+ }
+
+ return values;
+ }
+
+ private String getProperty(Resource entity, URI property, Locale loc, URI context) throws RepositoryException {
+ Set<String> values = getProperties(entity, property, loc, context);
+
+ if (values.size() > 0) {
+ return values.iterator().next();
+ } else {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHelper.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHelper.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHelper.java
new file mode 100644
index 0000000..0bf9380
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHelper.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.sesame.facading.impl;
+
+import org.apache.marmotta.commons.sesame.facading.util.FacadeUtils;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Value;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Locale;
+
+class FacadingInvocationHelper {
+ private FacadingInvocationHelper() {
+ // static Non-Instance Util Class
+ }
+
+ static boolean checkMethodSig(Method method, String name, int argNum) {
+ // Check the name
+ if (!method.getName().equals(name)) { return false; }
+
+ // Check # of arguments
+ final Class<?>[] pTypes = method.getParameterTypes();
+ if (pTypes.length != argNum) { return false; }
+
+ return true;
+ }
+
+ static boolean checkMethodSig(Method method, String name, Class<?>... args) {
+ // Do the basic check
+ if (!checkMethodSig(method, name, args.length)) {
+ return false;
+ }
+
+ // Check for the right parameters
+ final Class<?>[] pTypes = method.getParameterTypes();
+ for (int i = 0; i < pTypes.length; i++) {
+ Class<?> p = pTypes[i], a = args[i];
+ if (!p.isAssignableFrom(a)) { return false; }
+ }
+
+ return true;
+ }
+
+ static <A extends Annotation> A getAnnotation(Method method, Class<A> annotation) {
+ if (method.isAnnotationPresent(annotation)) { return method.getAnnotation(annotation); }
+
+ final String field = getBaseName(method);
+ Class<?> clazz = method.getDeclaringClass();
+
+ for (Method m : clazz.getMethods()) {
+ final boolean multiValue = isMultiValue(m);
+ if (m.isAnnotationPresent(annotation)) {
+ for (String op : FacadingInvocationHandler.OPERATOR.getOperatorPrefixes()) {
+ if (m.getName().equals(op + field)) {
+ return m.getAnnotation(annotation);
+ } else if (multiValue && m.getName().equals(op + field + "s")) {
+ return m.getAnnotation(annotation);
+ } else {}
+ }
+ }
+ }
+
+ return null;
+ }
+
+ static String getBaseName(Method method) {
+ final String name = method.getName();
+ final boolean isMultiValue = isMultiValue(method);
+
+ String bName = null;
+ final String[] prefixes = FacadingInvocationHandler.OPERATOR.getLengthSortedOperatorPrefixes();
+ for (String op : prefixes) {
+ if (name.startsWith(op)) {
+ if (isMultiValue && name.endsWith("s")) {
+ bName = name.substring(op.length(), name.length() - 1);
+ break;
+ } else {
+ bName = name.substring(op.length());
+ break;
+ }
+ }
+ }
+ return bName != null ? bName : name;
+ }
+
+ static boolean isMultiValue(Method method) {
+ final FacadingInvocationHandler.OPERATOR oper = FacadingInvocationHandler.OPERATOR.getOperator(method);
+ final boolean isMultiValue = oper.writeOp && method.getParameterTypes().length == 0 ||
+ FacadeUtils.isCollection(oper.writeOp && oper.numArgs > 0 ? method.getParameterTypes()[0] : method.getReturnType());
+ return isMultiValue;
+ }
+
+ static boolean checkLocale(final Locale loc, final Value object) {
+ // Only literals can have a lang-tag
+ if (!(object instanceof Literal)) { return false; }
+
+ // Empty locale always matches
+ if (loc == null) { return true; }
+
+ return loc.getLanguage().equals(((Literal) object).getLanguage());
+ }
+
+ static <C extends Collection<?>, E> Collection<E> createCollection(Class<C> collectionType, Collection<? extends E> elements)
+ throws IllegalAccessException, InstantiationException {
+
+ final Collection<E> result;
+
+ // If the collectionType is Abstract (or an Interface) we try to guess a valid
+ // implementation...
+ if (Modifier.isAbstract(collectionType.getModifiers())) {
+ // FIXME: Maybe we should add some more implementations here?
+ if (collectionType.isAssignableFrom(HashSet.class)) {
+ result = new HashSet<E>();
+ } else if (collectionType.isAssignableFrom(LinkedList.class)) {
+ result = new LinkedList<E>();
+ } else {
+ throw new InstantiationException("Could not find an implementation of " + collectionType.getName());
+ }
+ } else {
+ result = createInstance(collectionType);
+ }
+
+ if (elements != null) {
+ result.addAll(elements);
+ }
+
+ return result;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ static <E, C extends Collection<?>> Collection<E> createInstance(Class<C> collectionType) throws InstantiationException, IllegalAccessException {
+ return (Collection<E>) collectionType.newInstance();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingPredicate.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingPredicate.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingPredicate.java
new file mode 100644
index 0000000..211d370
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingPredicate.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.sesame.facading.impl;
+
+/**
+ * Simple class encapsulating the predicate/property uris.
+ */
+public class FacadingPredicate {
+
+ private final boolean inverse;
+ private final String[] properties;
+
+ public FacadingPredicate(boolean inverse, String... property) {
+ this.inverse = inverse;
+ this.properties = property;
+ }
+
+ public FacadingPredicate(String... property) {
+ this(false, property);
+ }
+
+ public boolean isInverse() {
+ return inverse;
+ }
+
+ public String[] getProperties() {
+ return properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/AbstractNamespacePropBuilder.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/AbstractNamespacePropBuilder.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/AbstractNamespacePropBuilder.java
new file mode 100644
index 0000000..aad0ed4
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/AbstractNamespacePropBuilder.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.sesame.facading.model;
+
+
+import java.lang.reflect.Method;
+
+import org.apache.marmotta.commons.sesame.facading.api.FacadingPredicateBuilder;
+import org.apache.marmotta.commons.sesame.facading.impl.FacadingPredicate;
+
+public abstract class AbstractNamespacePropBuilder implements FacadingPredicateBuilder {
+
+ @Override
+ public FacadingPredicate getFacadingPredicate(String fieldName, Class<? extends Facade> facade, Method method) {
+ return new FacadingPredicate(false, getNamespace() + fieldName);
+ }
+
+ protected abstract String getNamespace();
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/Facade.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/Facade.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/Facade.java
new file mode 100644
index 0000000..2884ee4
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/model/Facade.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.sesame.facading.model;
+
+import org.openrdf.model.Resource;
+
+/**
+ * Interface that must be the base interface of all KiWi facades. It defines no methods but has an underlying KiWiResource
+ * that is used by the KiWi client proxy to resolve the associated data in the triple store.
+ * <p/>
+ * An interface that inherits from this interface indicates that it represents a facade that can delegate getters and
+ * setters to properties in the triple store. All getter methods need to be annotated with appropriate @RDF annotations
+ * that map to a property in the triple store.
+
+ * <p/>
+ * User: Sebastian Schaffert
+ */
+public interface Facade {
+
+ /**
+ * Return the resource that is facaded by this KiWiFacade.
+ *
+ * @return
+ */
+ public Resource getDelegate();
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java
new file mode 100644
index 0000000..3c29da5
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java
@@ -0,0 +1,371 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.sesame.facading.util;
+
+
+import org.apache.commons.lang3.LocaleUtils;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+import org.apache.marmotta.commons.util.DateUtils;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Value;
+
+import java.lang.annotation.Annotation;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * @author Sebastian Schaffert
+ *
+ */
+public class FacadeUtils {
+
+ /**
+ * Check whether a type is a Facade, i.e. inherits from the {@link Facade} interface
+ *
+ * @param <C>
+ * @param clazz
+ * @return
+ */
+ public static <C> boolean isFacade(Class<C> clazz) {
+ return Facade.class.isAssignableFrom(clazz);
+ }
+
+ /**
+ * Check whether a type is a {@link Value}.
+ *
+ * @param <C>
+ * @param clazz
+ * @return
+ */
+ public static <C> boolean isValue(Class<C> clazz) {
+ return Value.class.isAssignableFrom(clazz);
+ }
+
+ /**
+ * Check whether a type is a {@link Resource}.
+ *
+ * @param <C>
+ * @param clazz
+ * @return
+ */
+ public static <C> boolean isResource(Class<C> clazz) {
+ return Resource.class.isAssignableFrom(clazz);
+ }
+
+
+ /**
+ * Check whether a type is a {@link Facade}, i.e. the type or one of its superinterfaces has the
+ * {@link Facade} annotation.
+ *
+ * @param <C>
+ * @param clazz
+ * @return
+ */
+ public static <C> boolean isFacadeAnnotationPresent(Class<C> clazz, Class<? extends Annotation> annotation) {
+ if (clazz.isAnnotationPresent(annotation)) {
+ return true;
+ } else {
+ for(final Class<?> iface : clazz.getInterfaces()) {
+ if(iface.isAnnotationPresent(annotation)) {
+ return true;
+ }
+ }
+ if (clazz.getSuperclass() != null) {
+ return isFacadeAnnotationPresent(clazz.getSuperclass(),annotation);
+ }
+ return false;
+ }
+ }
+
+
+ public static <C extends Annotation,D> C getFacadeAnnotation(Class<D> clazz, Class<C> annotation) {
+ if (clazz.isAnnotationPresent(annotation)) {
+ return clazz.getAnnotation(annotation);
+ } else {
+ for(final Class<?> iface : clazz.getInterfaces()) {
+ if(iface.isAnnotationPresent(annotation)) {
+ return iface.getAnnotation(annotation);
+ }
+ }
+ if (clazz.getSuperclass() != null) {
+ return getFacadeAnnotation(clazz.getSuperclass(),annotation);
+ }
+ return null;
+ }
+
+ }
+
+
+ /**
+ * Returns true if the <code>clazz</code> argument is a {@link Facade}, otherwise it returns
+ * false.
+ *
+ * @param in
+ * the argument to test.
+ * @return true if the <code>clazz</code> argument is a {@link Facade}.
+ */
+ public static boolean isFacade(Object in) {
+
+ if (in == null) {
+ return false;
+ }
+
+ final Class<?> clazz = in.getClass();
+ final boolean result = isFacade(clazz);
+
+ return result;
+ }
+
+ /**
+ * Check whether a type is a collection (List, Set, ...).
+ *
+ * @param <C> the type of the class modeled by the
+ * <code>clazz</code> argument Class object. For
+ * example, the type of String.class is Class
+ * <String>
+ * @param clazz the type to test.
+ * @return true if the type to test is a a type is a
+ * collection (List, Set, ...).
+ */
+ public static <C> boolean isCollection(Class<C> clazz) {
+
+ if (clazz == null) {
+ return false;
+ }
+
+ return Collection.class.isAssignableFrom(clazz);
+ }
+
+
+ /**
+ * Returns true if the <code>clazz</code> argument is a:
+ * <ul>
+ * <li>a primitive
+ * <li>a primitive wrapper
+ * <li>a java.lang.Locale class
+ * <li>a java.lang.Date class
+ * <li>a java.lang.String class
+ * </ul>
+ * otherwise it returns false.
+ *
+ * @param <C>
+ * the type of the class modeled by the <code>clazz</code> argument Class object. For
+ * example, the type of String.class is Class <String>.
+ * @param clazz
+ * the argument to test.
+ * @return true if the <code>clazz</code> argument is a primitive, primitive wrapper, locale,
+ * date or String.
+ */
+ public static <C> boolean isBaseType(Class<C> clazz) {
+
+ if (clazz == null) {
+ return false;
+ }
+
+ final boolean isPrimitive = clazz.isPrimitive();
+ if (isPrimitive) {
+ return true;
+ }
+
+ // if I compare the Locale.class with the clazz argument
+ // I can avoid the infamous case when the clazz is null,
+ // the Locale.class.equals(null) is false, always - at
+ // least this sustains the theory. The same logic for
+ // the other equals realtions.
+ final boolean isLocale = Locale.class.equals(clazz);
+ if (isLocale) {
+ return true;
+ }
+
+ final boolean isDate = Date.class.equals(clazz);
+ if (isDate) {
+ return true;
+ }
+
+ final boolean isString = String.class.equals(clazz);
+ if (isString) {
+ return true;
+ }
+
+ final boolean isBoolean = Boolean.class.equals(clazz);
+ if (isBoolean) {
+ return true;
+ }
+
+ final Class<? super C> superClass = clazz.getSuperclass();
+ final boolean isNumber = Number.class.equals(superClass);
+ if (isNumber) {
+ return true;
+ }
+
+ // even if the char is a primitive is not a number
+ final boolean isCharacter = Character.class.equals(clazz);
+ if (isCharacter) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true if the <code>clazz</code> argument is a:
+ * <ul>
+ * <li>a primitive
+ * <li>a primitive wrapper
+ * </ul>
+ * otherwise it returns false.
+ *
+ * @param <C> the type of the class modeled by the
+ * <code>clazz</code> argument Class object. For
+ * example, the type of String.class is Class
+ * <String>.
+ * @param clazz the argument to test.
+ * @return true if the <code>clazz</code> argument is a
+ * primitive or primitive wrapper.
+ */
+ public static <C> boolean isPrimitive(Class<C> clazz) {
+
+ if (clazz == null) {
+ return false;
+ }
+
+ final boolean isPrimitive = clazz.isPrimitive();
+ if (isPrimitive) {
+ return true;
+ }
+
+ // even if the char is a primitive is not a number
+ final boolean isCharacter = Character.class.equals(clazz);
+ if (isCharacter) {
+ return true;
+ }
+
+ final Class<? super C> superClass = clazz.getSuperclass();
+ final boolean isNumber = Number.class.equals(superClass);
+ if (isNumber) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true if the <code>in</code> argument is a:
+ * <ul>
+ * <li>a primitive
+ * <li>a primitive wrapper
+ * </ul>
+ * otherwise it returns false.
+ *
+ * @param in the argument to test.
+ * @return true if the <code>clazz</code> argument is a
+ * primitive or primitive wrapper.
+ */
+ public static boolean isPrimitive(Object in) {
+ if (in == null) {
+ return false;
+ }
+
+ final Class<?> clazz = in.getClass();
+ return isPrimitive(clazz);
+ }
+
+
+ /**
+ * Transform a value passed as string to the base type (i.e. non-complex type) given as argument
+ *
+ * @param <T>
+ * @param value
+ * @param returnType
+ * @return
+ * @throws IllegalArgumentException
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T transformToBaseType(String value, Class<T> returnType) throws IllegalArgumentException {
+ // transformation to appropriate primitive type
+ /*
+ * README: the "dirty" cast: "(T) x" instead of "returnType.cast(x)" is required since
+ * .cast does not work for primitive types (int, double, float, etc...).
+ * Somehow it results in a ClassCastException
+ */
+ if(Integer.class.equals(returnType) || int.class.equals(returnType)) {
+ if(value == null) {
+ return (T)(Integer)(0);
+ }
+ return (T)(Integer.decode(value));
+ } else if(Long.class.equals(returnType) || long.class.equals(returnType)) {
+ if(value == null) {
+ return (T)(Long)(0L);
+ }
+ return (T)(Long.decode(value));
+ } else if(Double.class.equals(returnType) || double.class.equals(returnType)) {
+ if(value == null) {
+ return (T)(Double)(0.0);
+ }
+ return (T)(Double.valueOf(value));
+ } else if(Float.class.equals(returnType) || float.class.equals(returnType)) {
+ if(value == null) {
+ return (T)(Float)(0.0F);
+ }
+ return (T)(Float.valueOf(value));
+ } else if(Byte.class.equals(returnType) || byte.class.equals(returnType)) {
+ if(value == null) {
+ return (T)(Byte)((byte) 0);
+ }
+ return (T)(Byte.decode(value));
+ } else if(Boolean.class.equals(returnType) || boolean.class.equals(returnType)) {
+ return (T)(Boolean.valueOf(value));
+ } else if(Character.class.equals(returnType) || char.class.equals(returnType)) {
+ if(value == null) {
+ if (Character.class.equals(returnType)){
+ return null;
+ } else {
+ return (T) new Character((char) 0);
+ }
+ } else if(value.length() > 0) {
+ return (T)(Character)(value.charAt(0));
+ } else {
+ return null;
+ }
+ } else if (Locale.class.equals(returnType)) {
+ if(value == null) {
+ return null;
+ } else {
+ return returnType.cast(LocaleUtils.toLocale(value));
+ }
+ } else if (Date.class.equals(returnType)) {
+ if(value == null) {
+ return null;
+ } else {
+ try {
+ return returnType.cast(DateUtils.ISO8601FORMAT.parse(value));
+ } catch (final ParseException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ } else if(String.class.equals(returnType)) {
+ return returnType.cast(value);
+ } else {
+ throw new IllegalArgumentException("primitive type "+returnType.getName()+" not supported by transformation");
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/AbstractFacadingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/AbstractFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/AbstractFacadingTest.java
new file mode 100644
index 0000000..befedc2
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/AbstractFacadingTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.facading;
+
+import java.io.IOException;
+
+import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.junit.After;
+import org.junit.Before;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.rio.RDFParseException;
+
+public abstract class AbstractFacadingTest {
+
+ protected Repository repositoryRDF;
+
+ @Before
+ public void setup() throws RepositoryException, IOException, RDFParseException {
+ // jdbc:h2:mem;MVCC=true;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=10
+ repositoryRDF = new SailRepository(
+ new KiWiStore(
+ "kiwiTest",
+ "jdbc:h2:mem:facading;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=10",
+ "", "", new H2Dialect(),
+ "http://example.com/ctx/default", "http://example.com/ctx/inferred"));
+ repositoryRDF.initialize();
+ }
+
+ @After
+ public void tearDown() throws RepositoryException {
+ repositoryRDF.shutDown();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/FacadingPredicateBuilderTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/FacadingPredicateBuilderTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/FacadingPredicateBuilderTest.java
new file mode 100644
index 0000000..88e043b
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/FacadingPredicateBuilderTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.facading.builder;
+
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.hasItem;
+
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.builder.model.ExampleFacade;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.Literal;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.rio.RDFParseException;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+public class FacadingPredicateBuilderTest extends AbstractFacadingTest {
+
+ private RepositoryConnection connection;
+ private Facading facading;
+
+ @Override
+ @Before
+ public void setup() throws RepositoryException, IOException, RDFParseException {
+ super.setup();
+
+ connection = repositoryRDF.getConnection();
+ connection.begin();
+ facading = FacadingFactory.createFacading(connection);
+ }
+
+ @Test
+ public void testPredicateBuilder() throws RepositoryException {
+ final URI u = connection.getValueFactory().createURI("http://localhost/repository/testResource1");
+ ExampleFacade f = facading.createFacade(u, ExampleFacade.class);
+
+ String title = "Example Title";
+ Set<String> tags = new HashSet<String>();
+ tags.add("Foo");
+ tags.add("Bar");
+
+ f.setTitle(title);
+ f.setTags(tags);
+
+ checkStatement(u, ExampleFacade.NS + "title", title);
+ checkStatement(u, ExampleFacade.NS + "tag", "Foo");
+ checkStatement(u, ExampleFacade.NS + "tag", "Bar");
+
+ Assert.assertEquals(f.getTitle(), title);
+ Assert.assertThat(f.getTags(), allOf(hasItem("Foo"), hasItem("Bar")));
+
+ f.addTag("FooBar");
+ checkStatement(u, ExampleFacade.NS + "tag", "FooBar");
+ Assert.assertThat(f.getTags(), allOf(hasItem("FooBar"), hasItem("Foo"), hasItem("Bar")));
+
+ }
+
+ private void checkStatement(URI s, String prop, String val) throws RepositoryException {
+ final URI propURI = connection.getValueFactory().createURI(prop);
+ final Literal value = connection.getValueFactory().createLiteral(val);
+
+ Assert.assertTrue(String.format("Did not find Statement '<%s> <%s> \"%s\"'", s.stringValue(), prop, val),
+ connection.hasStatement(s, propURI, value, true));
+ }
+
+ @Override
+ @After
+ public void tearDown() throws RepositoryException {
+ if (connection != null) {
+ connection.commit();
+ connection.close();
+ }
+
+ super.tearDown();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExampleFacade.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExampleFacade.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExampleFacade.java
new file mode 100644
index 0000000..632edce
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExampleFacade.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.facading.builder.model;
+
+
+import java.util.Set;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFPropertyBuilder;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+
+@RDFPropertyBuilder(ExamplePropBuilder.class)
+public interface ExampleFacade extends Facade {
+
+ public static final String NS = "http://www.example.com/vocab/test#";
+
+ void setTitle(String title);
+ String getTitle();
+
+ void setTags(Set<String> tags);
+ void addTag(String tag);
+ Set<String> getTags();
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExamplePropBuilder.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExamplePropBuilder.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExamplePropBuilder.java
new file mode 100644
index 0000000..89baca4
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/builder/model/ExamplePropBuilder.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.facading.builder.model;
+
+import org.apache.marmotta.commons.sesame.facading.model.AbstractNamespacePropBuilder;
+
+public class ExamplePropBuilder extends AbstractNamespacePropBuilder {
+
+ @Override
+ protected String getNamespace() {
+ return ExampleFacade.NS;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/CollectionFacadingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/CollectionFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/CollectionFacadingTest.java
new file mode 100644
index 0000000..bebe041
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/CollectionFacadingTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.facading.collections;
+
+import static org.hamcrest.CoreMatchers.hasItems;
+
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.collections.model.CollectionFacade;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Random;
+import java.util.UUID;
+
+public class CollectionFacadingTest extends AbstractFacadingTest {
+
+ @Test
+ public void testCollectionFacading() throws RepositoryException {
+
+ final Random rnd = new Random();
+ final Date a, b, c, d, e, now;
+ now = new Date(60000*(System.currentTimeMillis()/60000L));
+
+ // Start 10Yrs back;
+ final int tenYrsInMin = 10 * 365 * 24 * 60;
+ a = new Date(now.getTime() - tenYrsInMin * 60000L);
+ b = new Date(a.getTime() + rnd.nextInt(tenYrsInMin) * 60000L);
+ c = new Date(a.getTime() + rnd.nextInt(tenYrsInMin) * 60000L);
+ d = new Date(a.getTime() + rnd.nextInt(tenYrsInMin) * 60000L);
+ e = new Date(a.getTime() + rnd.nextInt(tenYrsInMin) * 60000L);
+
+ final RepositoryConnection connection = repositoryRDF.getConnection();
+ try {
+ connection.begin();
+ final Facading facading = FacadingFactory.createFacading(connection);
+
+ URI uri = connection.getValueFactory().createURI("http://www.example.com/rdf/test/collections");
+ CollectionFacade facade = facading.createFacade(uri, CollectionFacade.class);
+
+ facade.setDates(Arrays.asList(a, b, c));
+ Assert.assertThat(facade.getDates(), hasItems(a, b, c));
+
+ facade.addDate(e);
+ Assert.assertThat(facade.getDates(), hasItems(c, e, b, a));
+
+ facade.setDates(Arrays.asList(a, d, now));
+ Assert.assertThat(facade.getDates(), hasItems(a, d, now));
+ Assert.assertThat(facade.getDates(), CoreMatchers.not(hasItems(c, e, b)));
+
+ facade.deleteDates();
+ Assert.assertEquals(facade.getDates().size(), 0);
+
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void testAutorFacading() throws RepositoryException {
+ final RepositoryConnection connection = repositoryRDF.getConnection();
+
+ String a1 = UUID.randomUUID().toString(), a2 = UUID.randomUUID().toString(), a3 = UUID.randomUUID().toString();
+
+ try {
+ final Facading facading = FacadingFactory.createFacading(connection);
+ connection.begin();
+
+ URI uri = connection.getValueFactory().createURI("http://www.example.com/rdf/test/document");
+ CollectionFacade facade = facading.createFacade(uri, CollectionFacade.class);
+
+ facade.setAutors(Arrays.asList(a1, a2));
+
+ facade.addAutor(a3);
+
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/model/CollectionFacade.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/model/CollectionFacade.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/model/CollectionFacade.java
new file mode 100644
index 0000000..72fdf8a
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/collections/model/CollectionFacade.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.facading.collections.model;
+
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+
+public interface CollectionFacade extends Facade {
+
+ @RDF("http://www.example.com/rdf/vocab/date")
+ public List<Date> getDates();
+ public void setDates(List<Date> dates);
+ public void addDate(Date date);
+ public void deleteDates();
+
+ @RDF("http://www.example.com/rdf/vocab/autor")
+ public void addAutor(String autor);
+ public void setAutors(Collection<String> authors);
+
+}