@Override public String id() { return this.template.id(); }
@Override public String toString() { return MoreObjects. toStringHelper(getClass()). omitNullValues(). add("id", this.id). add("path", this.path). add("template.id()", this.template.id()). add("predicate", predicate). toString(); }
/** * {@inheritDoc} */ @Override protected ToStringHelper stringHelper() { return super. stringHelper(). add("memberTemplate",this.memberTemplate.id()). add("memberPath",this.memberPath); }
/** * {@inheritDoc} */ @Override public String toString() { return stringHelper(). add("memberTemplate.id()",this.memberTemplate.id()). add("memberPath",this.memberPath). toString(); }
public static ResourceId createId(Name<?> name, ResourceTemplate template) { checkNotNull(name,"Resource name cannot be null"); checkNotNull(template,"Template cannot be null"); return createId(name,template.id()); }
ResourceId resourceId() { return ResourceId.createId(this.resourceName, this.template.id()); }
public InvalidTemplateClassException(Class<? extends ResourceTemplate> templateClass, ResourceTemplate template) { super("The template {"+template.id()+","+template.handlerClass().getCanonicalName()+"} cannot be casted to '"+templateClass.getCanonicalName()+"' ("+template.getClass().getCanonicalName()+")"); }
@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 public void visitResourceTemplate(ResourceTemplate template) { Class<? extends ResourceHandler> handlerClass = template.handlerClass(); ResourceHandler handler=this.handlers.getInstance(handlerClass); if(handler==null) { try { handler=handlerClass.newInstance(); } catch (Exception e) { String message=String.format("Could not instantiate resource handler from template '%s' (%s)",template.id(),handlerClass.getCanonicalName()); LOGGER.warn(message); throw new ResourceHandlerInstantiationException(message,handlerClass,e); } } this.builder.put(HandlerId.createId(handlerClass), handler); }
@Override protected void processTemplate(ResourceTemplate template) { ResourceTemplate other = library.findById(template.id()); assertThat(other,equalTo(template)); } }
@Override protected void processTemplate(ResourceTemplate template) { ResourceTemplate other = library.findById(template.id()); assertThat(other,not(nullValue())); } }
@Override <T extends DelegatedResourceSnapshot> T createAttachedResource( Class<? extends T> snapshotClass, String attachmentId, Name<?> name, Class<? extends ResourceHandler> handlerClass, DelegatedResourceSnapshot ctx) { AttachedTemplate attachedTemplate = template().attachedTemplate(attachmentId); checkState(attachedTemplate!=null,"No attachment '%s' is defined for template '%s'",attachmentId,template()); checkState(attachedTemplate.template().handlerClass().isAssignableFrom(handlerClass),"Attachment '%s' of template '%s' is not compatible with '%s' (%s)",attachmentId,template().id(),handlerClass.getCanonicalName(),attachedTemplate.template().handlerClass().getCanonicalName()); checkState(nameFilterForAttachment(attachmentId).isValid(name),"Resource name '%s' is already in use",name); T newSnapshot= ctx.newChildResource(ResourceId.createId(name,attachedTemplate.template()),snapshotClass); DelegatedAttachmentSnapshot newAttachment = AttachmentSnapshotCollection.newAttachment(attachmentId, newSnapshot); this.attachments.add(newAttachment); UnitOfWork.getCurrent().registerDirty(ctx); newSnapshot.markNew(); if(LOGGER.isTraceEnabled()) { LOGGER.trace("Attached '{}' as '{}' to '{}'",newSnapshot.resourceId(),attachmentId,ctx.resourceId()); } return snapshotClass.cast(newSnapshot); }