private URI createOptionalURI(String id, String predicate, String uriType) { try { URI uri = new URI(predicate); if(uri.normalize().equals(URI.create(""))) { throw new TemplateCreationException(id,uriType+" cannot be the null URI"); } else if(uri.isOpaque()) { /** * TODO: Allow using opaque URIs whenever the RDF handling * backend supports it (for the time being we are using * Sesame and it requires using HTTP URIs) */ throw new TemplateCreationException(id,String.format("%s cannot be a opaque URI (%s)",uriType,predicate)); } else if(!uri.isAbsolute()) { throw new TemplateCreationException(id,String.format("%s cannot be a hierarchical relative URI (%s)",uriType,predicate)); } return uri; } catch (URISyntaxException e) { throw new TemplateCreationException(id,String.format("%s value '%s' is not valid",uriType,predicate),e); } }
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); }
@Override public void register(Class<? extends ResourceHandler> handlerClass, ResourceTemplate template) { ResourceTemplate previousTemplate = retrieve(handlerClass); if(previousTemplate!=null) { if(template==previousTemplate) { return; } throw new TemplateCreationException(template.id(), String.format("Cannot register two templates with the same handler (new: %s, registered: %s)",template,previousTemplate)); } previousTemplate=this.templatesById.get(template.id()); if(previousTemplate!=null) { throw new TemplateCreationException(template.id(), String.format("Cannot register two templates with the same identifier (new: %s, registered: %s)",template,previousTemplate)); } this.templatesByHandler.put(HandlerId.createId(handlerClass), template); this.templatesById.put(template.id(), template); }
@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); }