public RelationshipDefinition ifNotBound(String token) { if (linkBuilder == null) throw new RelationshipException("Attempt to set ifNotBound() on null link: " + token + ". Call 'rel()' first."); linkBuilder.ifNotBound(token); return this; }
/** * Indicates that the link should not be included in a response if it would be marked 'templated'. * This is useful for links that are 'pagination' related, or otherwise conditional in the response. * * @return this relationship definition instance to facilitate method chaining. */ public RelationshipDefinition optional() { if (linkBuilder == null) throw new RelationshipException("Attempt to set optional on null link. Call 'rel()' first."); linkBuilder.optional(); return this; }
/** * Add an optional query-string argument to the latest rel(). If the query-string segment contains * tokens and is not fully populate, it will not appear in the generated link. * * @param querySegment an optional query-string segment. Optionally contains tokens. * @return this relationship definition instance to facilitate method chaining. */ public RelationshipDefinition withQuery(String querySegment) { if (linkBuilder == null) throw new RelationshipException("Attempt to set query-string segment on null link: " + querySegment + ". Call 'rel()' first."); linkBuilder.withQuery(querySegment); return this; }
/** * General-purpose. Can be used to set arbitrary string-value properties on the link definition. * May not actually show up in the output depending on whether the out-bound link format supports * the attribute. * </p> * Must call 'rel()' before attribute() is called to create a new link. * * @param name * @param value * @return this relationship definition instance to facilitate method chaining. */ public RelationshipDefinition attribute(String name, String value) { if (linkBuilder == null) throw new RelationshipException("Attempt to set attribute on null link: " + name + ". Call 'rel()' first."); linkBuilder.set(name, value); return this; }
/** * Define a relationship for the give rel name to a LinkBuilder. * * @param rel the relationship name (rel name). * @param builder an OptionalLinkBuilder instance. * @return this relationship definition instance to facilitate method chaining. */ public RelationshipDefinition rel(String rel, ConditionalLinkBuilder builder) { builder.rel(rel); this.linkBuilder = builder; if (linkBuildersForClass == null) { throw new RelationshipException("Attempt to call rel() before forClass() or forCollectionOf()"); } linkBuildersForClass.add(builder); return this; }
/** * Indicates that the link should be included in a response if the provided token * gets bound. This is useful for links that are conditional in the response depending * on information NOT in the link URL. * <p/> * For example: definition.optional("{adminRole}"); * <p/> * Then for binding, anything other than "false" or null will include the link in the output. * <p/> * For example: HyperExpress.bind("adminRole", (role.equals("admin") ? "true" : "false"));<br/> * or HyperExpress.bind("adminRole", (role.equals("admin") ? "admin" : null)); * * @param token a URL token name, with or without beginning and ending curly-braces. * @return this relationship definition instance to facilitate method chaining. */ public RelationshipDefinition ifBound(String token) { if (linkBuilder == null) throw new RelationshipException("Attempt to set ifBound() on null link: " + token + ". Call 'rel()' first."); linkBuilder.ifBound(token); return this; }