001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package service.tut.pori.facebookjazz;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlElement;
024import javax.xml.bind.annotation.XmlRootElement;
025
026import com.restfb.types.CategorizedFacebookType;
027
028/**
029 * A Facebook like.
030 * 
031 * <h3>XML Example</h3>
032 * 
033 * {@doc.restlet service="[service.tut.pori.facebookjazz.reference.Definitions#SERVICE_FBJ_REFERENCE_EXAMPLE]" method="[service.tut.pori.facebookjazz.Definitions#ELEMENT_LIKE]" type="GET" query="" body_uri=""}
034 *
035 * @see com.restfb.types.CategorizedFacebookType
036 */
037@XmlRootElement(name=Definitions.ELEMENT_LIKE)
038@XmlAccessorType(XmlAccessType.NONE)
039public class FacebookLike {
040  private CategorizedFacebookType _facebookType = null;
041  
042  /**
043   * 
044   */
045  public FacebookLike() {
046    _facebookType = new CategorizedFacebookType();
047  }
048  
049  /**
050   * 
051   * @param type
052   * @throws IllegalArgumentException
053   */
054  public FacebookLike(CategorizedFacebookType type) throws IllegalArgumentException{
055    if(type == null){
056      throw new IllegalArgumentException("Invalid type.");
057    }
058    _facebookType = type;
059  }
060
061  /**
062   * @see com.restfb.types.CategorizedFacebookType#getCategory()
063   * 
064   * @return category
065   */
066  @XmlElement(name = Definitions.ELEMENT_CATEGORY)
067  public String getCategory() {
068    return _facebookType.getCategory();
069  }
070
071  /**
072   * @see com.restfb.types.NamedFacebookType#getName()
073   * 
074   * @return name of the like
075   */
076  @XmlElement(name = Definitions.ELEMENT_NAME)
077  public String getName() {
078    return _facebookType.getName(); 
079  }
080  
081  /**
082   * 
083   * @param types
084   * @return the types wrapped to likes or null if null or empty list was passed
085   */
086  public static List<FacebookLike> getFacebookLikes(List<CategorizedFacebookType> types){
087    if(types == null || types.isEmpty()){
088      return null;
089    }
090    List<FacebookLike> likes = new ArrayList<>(types.size());
091    for(CategorizedFacebookType t : types){
092      likes.add(new FacebookLike(t));
093    }
094    return likes;
095  }
096
097  /**
098   * @param name
099   * @see com.restfb.types.NamedFacebookType#setName(java.lang.String)
100   */
101  public void setName(String name) {
102    _facebookType.setName(name);
103  }
104
105  /**
106   * @param category
107   * @see com.restfb.types.CategorizedFacebookType#setCategory(java.lang.String)
108   */
109  public void setCategory(String category) {
110    _facebookType.setCategory(category);
111  }
112}