public <T extends ResourceTemplate> T templateOfId(String templateId, Class<? extends T> templateClass) { checkNotNull(templateClass,"Template class cannot be null"); ResourceTemplate found = templateOfId(templateId); if(found==null) { return null; } else if(!templateClass.isInstance(found)) { throw new IllegalArgumentException("Cannot cast template '"+templateId+"' to '"+templateClass.getCanonicalName()+"' ("+found.getClass().getCanonicalName()+")"); } return templateClass.cast(found); }
ResourceTemplate loadTemplate(String templateId) { return this.writeSessionService.templateManagementService().templateOfId(templateId); }
private Class<? extends ResourceHandler> resolveHandler(ResourceId resourceId) { ResourceTemplate template = this.templateManagementService.templateOfId(resourceId.templateId()); return template!=null?template.handlerClass():null; }
ResourceTemplate resourceTemplate(Resource resource) { return this.engine().templateManagementService().templateOfId(resource.id().templateId()); }
private <T extends Resource> Adapter adapter(T resource, WriteSessionConfiguration configuration) { ResourceTemplate template=this.templateManagementService.templateOfId(resource.id().templateId()); Class<? extends ResourceHandler> handlerClass = template.handlerClass(); ResourceHandler delegate=this.templateManagementService.getHandler(handlerClass); return AdapterFactory.newAdapter(resource,delegate,this.writeSessionService,configuration); }
protected final Container rootContainer(Name<?> name, String templateId) { return (Container)this.delegate.getModelFactory().createResource(ServiceRegistry.getInstance().getService(TemplateManagementService.class).templateOfId(templateId), name); }
protected final Resource rootResource(Name<?> name, String templateId) { return this.delegate.getModelFactory().createResource(ServiceRegistry.getInstance().getService(TemplateManagementService.class).templateOfId(templateId), name); }
private URI getIndirectId(Container container, DataSet dataSet) { TemplateIntrospector introspector= TemplateIntrospector. newInstance( this.templateManagementService. templateOfId(container.id().templateId())); if(!introspector.isIndirectContainer()) { return null; } URI insertedContentRelation=introspector.getInsertedContentRelation(); IndirectIdCollector collector= new IndirectIdCollector( false, insertedContentRelation, getInsertedContentRelationProperty(dataSet,insertedContentRelation)); return collector.getIndirectId(); }
private String generatePathForMember(Resource child, Container parent, String desiredPath) throws EndpointNotFoundException { Member member = parent.findMember(child.id()); if(member!=null) { Endpoint endpoint=getResourceEndpoint(parent.id()); ContainerTemplate parentTemplate=this.templateManagementService.templateOfId(parent.id().templateId(),ContainerTemplate.class); if(parentTemplate==null) { throw new IllegalStateException("Could not find template resource '"+parent+"'"); } String slugPath=getSlugPath(parent, desiredPath); return PathBuilder. create(). addSegment(endpoint.path()). addSegment(parentTemplate.memberPath().or("")). addSegment(member.number()). addSegment(slugPath). build(); } return null; }
private void prepareSession(final Action action, final ResourceSnapshot snapshot) { logAction(Stage.PREPARATION,action,snapshot); final Resource resource= this.modelFactory. createResource(this.templateManagementService.templateOfId(snapshot.templateId()), snapshot.name()); doPrepareSession(resource); }
private <T extends Resource> T publishResource(Class<? extends T> clazz, String templateId, Name<?> resourceName, String path) { Transaction transaction = RuntimeDelegate.getInstance().getTransactionManager().currentTransaction(); transaction.begin(); Resource newResource=this.modelFactory.createResource(this.tms.templateOfId(templateId),resourceName); T resource=clazz.cast(newResource); RuntimeDelegate.getInstance().getResourceRepository().add(resource); Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); transaction.commit(); return resource; }
private String generatePathForAttachment(Resource child, Resource parent) throws EndpointNotFoundException { Attachment attachment=parent.findAttachment(child.id()); if(attachment==null) { return null; } Endpoint endpoint=getResourceEndpoint(parent.id()); ResourceTemplate parentTemplate=this.templateManagementService.templateOfId(parent.id().templateId()); AttachedTemplate attachedTemplate = parentTemplate.attachedTemplate(attachment.id()); return PathBuilder. create(). addSegment(endpoint.path()). addSegment(attachedTemplate.path()). addSegment(attachment.version()>0?attachment.version():null). build(); }
private Resource initialize(final String id, final String path) { final Transaction transaction= RuntimeDelegate. getInstance(). getTransactionManager(). currentTransaction(); transaction.begin(); try { this.uow = UnitOfWork.newCurrent(); final Resource resource= this.modelFactory.createResource( this.templateManagementService.templateOfId("personTemplate"), name(id)); final Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getResourceRepository().add(resource); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); UnitOfWork.setCurrent(null); transaction.commit(); return resource; } finally { if(transaction.isActive()) { transaction.rollback(); } } }