protected final URI createMandatoryURI(String id, String predicate, String uriType) { if(predicate.isEmpty()) { throw new TemplateCreationException(id,uriType+" cannot be empty"); } return createOptionalURI(id, predicate, uriType); }
void postProcess(Annotation annotation, M template, TemplateResolver resolver) { checkArgument(annotationClass.isInstance(annotation),"Invalid annotation"); doPostprocess(annotationClass.cast(annotation),template,resolver); }
M preProcess(Annotation annotation, Class<? extends R> handler) { checkArgument(annotationClass.isInstance(annotation),"Invalid annotation"); return doProcess(annotationClass.cast(annotation),handler); }
private void updateAttachmentPredicate(M template, Attachment attachment, MutableAttachedTemplate attachedTemplate) { String predicate = attachment.predicate(); if(predicate!=null && predicate.length()>0) { try { attachedTemplate.setPredicate(createOptionalURI(template.id(),predicate,"The attachment predicate")); } catch (TemplateCreationException e) { throw new InvalidAttachmentDefinitionException( template.id(), attachment.id(), String.format("Attachment predicate value '%s' of attached template '%s' is not valid",predicate,attachedTemplate.id()), e); } } }
@Override protected void doPostprocess(A annotation, T template, TemplateResolver resolver) { super.doPostprocess(annotation,template, resolver); Class<? extends ResourceHandler> handler = memberHandler(annotation); ResourceTemplate memberTemplate = resolver.resolve(handler); if(memberTemplate==null) { throw new TemplateCreationException(template.id(), "Could not resolve template for member handler '"+handler.getCanonicalName()+"' "); } template.setMemberTemplate(memberTemplate); }
protected void doPostprocess(A annotation, M template, TemplateResolver resolver) { for(Attachment attachment:attachments(annotation)) { try { MutableAttachedTemplate attachedTemplate = template.attachTemplate(attachment.id(), resolver.resolve(attachment.handler()), attachment.path()); updateAttachmentPredicate(template,attachment,attachedTemplate); } catch (IllegalArgumentException e) { throw new InvalidAttachmentDefinitionException(template.id(),attachment.id(),"Invalid attachment definition",e); } } }
protected M doProcess(A annotation, Class<? extends R> handler) { M template = createTemplate(annotation,handler); template.setName(nullable(name(annotation))); template.setDescription(nullable(description(annotation))); return template; }
@Override protected T doProcess(A annotation, Class<? extends ContainerHandler> handler) { T template = super.doProcess(annotation, handler); template.setMemberPath(nullable(memberPath(annotation))); return template; }
ResourceTemplate toTemplate(Annotation annotation, Class<? extends ResourceHandler> targetClass, TemplateRegistry templateRegistry, TemplateResolver templateResolver) { AbstractMutableTemplate<?> template = this.processor.preProcess(annotation,targetClass); templateRegistry.register(targetClass, template); this.processor.postProcess(annotation, template, templateResolver); return template; }