/** * Created by dschulten on 08.12.2014. */ @Term(define = "rdfs", as = "http://www.w3.org/2000/01/rdf-schema#") public class CreativeWork { public final String name; @JsonCreator public CreativeWork(@JsonProperty("name") String name) { this.name = name; } }
@Expose("orderedItem") public List<? extends Product> getItems() { return items; }
/** * Mixin for json-ld serialization of Resources. Created by dschulten on 14.09.2014. */ @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY) @Term(define = "hydra", as = "http://www.w3.org/ns/hydra/core#") @Expose("hydra:Collection") public abstract class ResourcesMixin<T> extends Resources<T> { @Override @JsonProperty("hydra:member") @ContextProvider public Collection<T> getContent() { return super.getContent(); } @Override @JsonSerialize(using = LinkListSerializer.class) @JsonUnwrapped public List<Link> getLinks() { return super.getLinks(); } }
/** * Gets explicitly defined terms, e.g. on package, class or mixin. * * @param annotatedElement to find terms * @param name of annotated element, i.e. class name or package name * @return terms */ private Map<String, Object> getAnnotatedTerms(AnnotatedElement annotatedElement, String name) { final Terms annotatedTerms = getAnnotation(annotatedElement, Terms.class); final Term annotatedTerm = getAnnotation(annotatedElement, Term.class); if (annotatedTerms != null && annotatedTerm != null) { throw new IllegalStateException("found both @Terms and @Term in " + name + ", use either one or the other"); } Map<String, Object> annotatedTermsMap = new LinkedHashMap<String, Object>(); if (annotatedTerms != null) { final Term[] terms = annotatedTerms.value(); for (Term term : terms) { final String define = term.define(); final String as = term.as(); if (annotatedTermsMap.containsKey(as)) { throw new IllegalStateException("duplicate definition of term '" + define + "' in " + name); } annotatedTermsMap.put(define, as); } } if (annotatedTerm != null) { annotatedTermsMap.put(annotatedTerm.define(), annotatedTerm.as()); } return annotatedTermsMap; }
private void collectTerms(String name, Map<String, Object> annotatedTermsMap, Term term) { final String define = term.define(); final String as = term.as(); final boolean reverse = term.reverse(); if (annotatedTermsMap.containsKey(as)) { throw new IllegalStateException("duplicate definition of term '" + define + "' in " + name); } if (!reverse) { annotatedTermsMap.put(define, as); } else { Map<String, String> reverseTerm = new LinkedHashMap<String, String>(); reverseTerm.put(JsonLdKeywords.AT_REVERSE, as); annotatedTermsMap.put(define, reverseTerm); } }
/** * Gets exposed property or parameter name for properties with an appropriate setter (=write) method. * * @param inputParameter for exposure * @return property name */ private String getWritableExposedPropertyOrPropertyName(PropertyDescriptor inputParameter) { final Method writeMethod = inputParameter.getWriteMethod(); final Expose expose = writeMethod .getAnnotation(Expose.class); String propertyName; if (expose != null) { propertyName = expose.value(); } else { propertyName = inputParameter.getName(); } return propertyName; }
public String vocabFromClassOrPackage(Class<?> clazz) { // vocab and terms of defining class: class and package final Vocab packageVocab = findAnnotation(clazz .getPackage(), Vocab.class); final Vocab classVocab = findAnnotation(clazz, Vocab.class); String vocab; if (classVocab != null) { vocab = classVocab.value(); // wins over package } else if (packageVocab != null) { vocab = packageVocab.value(); // wins over context provider } else { vocab = null; } return vocab; }
@ContextProvider @Override public T getContent() { return super.getContent(); } }
private void collectTerms(String name, Map<String, Object> annotatedTermsMap, Term term) { final String define = term.define(); final String as = term.as(); final boolean reverse = term.reverse(); if (annotatedTermsMap.containsKey(as)) { throw new IllegalStateException("duplicate definition of term '" + define + "' in " + name); } if (!reverse) { annotatedTermsMap.put(define, as); } else { Map<String, String> reverseTerm = new LinkedHashMap<String, String>(); reverseTerm.put(JsonLdKeywords.AT_REVERSE, as); annotatedTermsMap.put(define, reverseTerm); } }
/** * Mixin for json-ld serialization of PagedResources. */ @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY) @Term(define = "hydra", as = "http://www.w3.org/ns/hydra/core#") @Expose("hydra:Collection") public abstract class PagedResourcesMixin<T> extends PagedResources<T> { @Override @JsonProperty("hydra:member") @ContextProvider public Collection<T> getContent() { return super.getContent(); } @Override @JsonSerialize(using = LinkListSerializer.class) @JsonUnwrapped public List<Link> getLinks() { return super.getLinks(); } @Override @JsonIgnore // used by PagedResourcesSerializer instead public PageMetadata getMetadata() { return super.getMetadata(); } }
/** * Gets exposed property or parameter name. * * @param inputParameter for exposure * @return property name */ private String getExposedPropertyOrParamName(ActionInputParameter inputParameter) { final Expose expose = inputParameter.getAnnotation(Expose.class); String property; if (expose != null) { property = expose.value(); } else { property = inputParameter.getParameterName(); } return property; }
/** * Created by dschulten on 08.12.2014. */ @Term(define = "rdfs", as = "http://www.w3.org/2000/01/rdf-schema#") public class CreativeWork { public final String name; @JsonCreator public CreativeWork(@JsonProperty("name") String name) { this.name = name; } }
@Expose("orderedItem") public List<? extends Product> getItems() { return items; }
public String vocabFromClassOrPackage(Class<?> clazz) { // vocab and terms of defining class: class and package final Vocab packageVocab = findAnnotation(clazz .getPackage(), Vocab.class); final Vocab classVocab = findAnnotation(clazz, Vocab.class); String vocab; if (classVocab != null) { vocab = classVocab.value(); // wins over package } else if (packageVocab != null) { vocab = packageVocab.value(); // wins over context provider } else { vocab = null; } return vocab; }
@Override @JsonProperty("hydra:member") @ContextProvider public Collection<T> getContent() { return super.getContent(); }
@Term(define = "accessories", as = "isAccessoryOrSparePartFor", reverse = true) @Relation("product") public class Product extends ResourceSupport {
/** * Created by Dietrich on 17.02.2015. */ @Expose("CafeOrCoffeeShop") public class Store extends ResourceSupport { public String name = "Kaffeehaus Hagen"; private List<Offer> offers = new ArrayList<Offer>(); public String getName() { return name; } public List<Offer> getMakesOffer() { return offers; } public void addOffer(Offer offer) { this.offers.add(offer); } }
@Override @JsonProperty("hydra:member") @ContextProvider public Collection<T> getContent() { return super.getContent(); }
@Term(define = "accessories", as = "isAccessoryOrSparePartFor", reverse = true) @Relation("product") public class Product extends ResourceSupport {
/** * Created by Dietrich on 17.02.2015. */ @Expose("CafeOrCoffeeShop") public class Store extends ResourceSupport { public String name = "Kaffeehaus Hagen"; private List<Offer> offers = new ArrayList<Offer>(); public String getName() { return name; } public List<Offer> getMakesOffer() { return offers; } public void addOffer(Offer offer) { this.offers.add(offer); } }