001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2014 Richard "Shred" Körber 005 * http://flattr4j.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License / GNU Lesser 009 * General Public License as published by the Free Software Foundation, 010 * either version 3 of the License, or (at your option) any later version. 011 * 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 018 */ 019package org.shredzone.flattr4j.async.thing; 020 021import org.shredzone.flattr4j.FlattrService; 022import org.shredzone.flattr4j.async.AbstractFlattrCallable; 023import org.shredzone.flattr4j.async.FlattrCallable; 024import org.shredzone.flattr4j.exception.FlattrException; 025import org.shredzone.flattr4j.model.AutoSubmission; 026import org.shredzone.flattr4j.model.Thing; 027import org.shredzone.flattr4j.model.ThingId; 028 029/** 030 * {@link FlattrCallable} for invoking {@link FlattrService#getThing(ThingId)}, 031 * {@link FlattrService#getThingByUrl(String)} or 032 * {@link FlattrService#getThingBySubmission(AutoSubmission)} 033 * 034 * @author Iulius Gutberlet 035 * @author Richard "Shred" Körber 036 */ 037public class GetThingMethod extends AbstractFlattrCallable<Thing> { 038 039 private ThingId thingId; 040 private String url; 041 private AutoSubmission submission; 042 043 public GetThingMethod() { 044 // default constructor 045 } 046 047 public GetThingMethod(ThingId thingId) { 048 setThingId(thingId); 049 } 050 051 public GetThingMethod(String url) { 052 setUrl(url); 053 } 054 055 public GetThingMethod(AutoSubmission submission) { 056 setAutoSubmission(submission); 057 } 058 059 public ThingId getThingId() { return thingId; } 060 public void setThingId(ThingId thingId) { 061 this.thingId = thingId; 062 this.url = null; 063 this.submission = null; 064 } 065 066 public String getUrl() { return url; } 067 public void setUrl(String url) { 068 this.url = url; 069 this.submission = null; 070 this.thingId = null; 071 } 072 073 public AutoSubmission getAutoSubmission() { return submission; } 074 public void setAutoSubmission(AutoSubmission submission) { 075 this.submission = submission; 076 this.thingId = null; 077 this.url = null; 078 } 079 080 @Override 081 public Thing call(FlattrService service) throws FlattrException { 082 if (thingId != null) { 083 return service.getThing(thingId); 084 } else if (url != null) { 085 return service.getThingByUrl(url); 086 } else { 087 return service.getThingBySubmission(submission); 088 } 089 } 090 091}