@Override public <T> T createObject(Class<T> clazz, Resource id) throws RepositoryException, IllegalAccessException, InstantiationException { ObjectFactory objectFactory = connection.getObjectFactory(); Resource resource = (id != null) ? id : IDGenerator.BLANK_RESOURCE; T object = objectFactory.createObject(resource, clazz); return connection.addDesignation(object, clazz); }
/** * Creates an resource object using the {@link ObjectConnection} provided. * @param clazz The concept of the instance to create. * @param id The ID/URI of the instance to create. * @param <T> The type of the instances concept. * @return The created object. * @throws RepositoryException Thrown if an error occurs while instantiating. */ private <T> T createObject(Class<T> clazz, Resource id) throws RepositoryException { ObjectConnection connection = getConnection(); ObjectFactory objectFactory = connection.getObjectFactory(); Resource resource = (id != null) ? id : IDGenerator.BLANK_RESOURCE; T object = objectFactory.createObject(resource, clazz); return connection.addDesignation(object, clazz); }
/** * 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); Object bean = of.createObject(resource, types); assert assertConceptRecorded(bean, concept); return (T) bean; }
/** * 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); }