Пример #1
0
 /**
  * Explicitly adds the types to the entity.
  *
  * @return the entity with new composed types
  */
 public Object addDesignations(Object entity, URI... types) throws RepositoryException {
   if (entity instanceof RDFObjectBehaviour) {
     RDFObjectBehaviour support = (RDFObjectBehaviour) entity;
     Object delegate = support.getBehaviourDelegate();
     if (delegate != entity) {
       return addDesignations(delegate, types);
     }
   }
   assert types != null && types.length > 0;
   Resource resource = findResource(entity);
   Set<URI> list = new HashSet<URI>(4);
   getTypes(entity.getClass(), list);
   boolean autoCommit = isAutoCommit();
   if (autoCommit) {
     setAutoCommit(false);
   }
   try {
     for (URI type : types) {
       this.types.addTypeStatement(resource, type);
       list.add(type);
     }
     if (autoCommit) {
       setAutoCommit(true);
     }
   } finally {
     if (autoCommit && !isAutoCommit()) {
       rollback();
       setAutoCommit(true);
     }
   }
   return cache(of.createObject(resource, list));
 }
Пример #2
0
 private <C extends Collection<URI>> C getTypes(Class<?> role, C set) throws RepositoryException {
   URI type = of.getNameOf(role);
   if (type == null) {
     Class<?> superclass = role.getSuperclass();
     if (superclass != null) {
       getTypes(superclass, set);
     }
     Class<?>[] interfaces = role.getInterfaces();
     for (int i = 0, n = interfaces.length; i < n; i++) {
       getTypes(interfaces[i], set);
     }
   } else {
     set.add(type);
   }
   return set;
 }
Пример #3
0
 /**
  * Explicitly adds the concept to the entity.
  *
  * @return the entity with new composed concept
  */
 public <T> T addDesignation(Object entity, Class<T> concept) throws RepositoryException {
   if (entity instanceof RDFObjectBehaviour) {
     RDFObjectBehaviour support = (RDFObjectBehaviour) entity;
     Object delegate = support.getBehaviourDelegate();
     if (delegate != entity) {
       return addDesignation(delegate, concept);
     }
   }
   Resource resource = findResource(entity);
   Set<URI> types = new HashSet<URI>(4);
   getTypes(entity.getClass(), types);
   addConcept(resource, concept, types);
   RDFObject bean = of.createObject(resource, types);
   assert assertConceptRecorded(bean, concept);
   return (T) cache(bean);
 }