View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.resteasy.hypermedia.renderer;
17  
18  import java.util.LinkedHashMap;
19  
20  import org.jboss.resteasy.links.RESTServiceDiscovery.AtomLink;
21  
22  /**
23   * Provides information on a single link.
24   */
25  public final class LinkDescriptorAtom extends LinkDescriptor
26  {
27    // ********************************* Fields *********************************
28  
29    // --- constants ------------------------------------------------------------
30  
31    // --- members --------------------------------------------------------------
32  
33    /**
34     * The basic link information provided by RESTEasy.
35     */
36    private final AtomLink atomLink;
37  
38    // ****************************** Initializer *******************************
39  
40    // ****************************** Constructors ******************************
41  
42    /**
43     * Convenience constructor with empty metadata.
44     *
45     * @param atomLink the basic link information provided by RESTEasy.
46     */
47    public LinkDescriptorAtom(final AtomLink atomLink)
48    {
49      this(atomLink, new LinkMetadata());
50    }
51  
52    /**
53     * Default constructor.
54     *
55     * @param atomLink the basic link information provided by RESTEasy.
56     * @param metadata the additional link metadata about the link.
57     */
58    public LinkDescriptorAtom(final AtomLink atomLink, final LinkMetadata metadata)
59    {
60      super(metadata, new LinkedHashMap<String, String>(), splitRel(atomLink
61          .getRel()));
62      this.atomLink = atomLink;
63    }
64  
65    // ****************************** Inner Classes *****************************
66  
67    // ********************************* Methods ********************************
68  
69    // --- init -----------------------------------------------------------------
70  
71    // --- get&set --------------------------------------------------------------
72  
73    @Override
74    public String getHref()
75    {
76      return atomLink.getHref();
77    }
78  
79    @Override
80    public void setHref(final String href)
81    {
82      atomLink.setHref(href);
83    }
84  
85    @Override
86    public String getType()
87    {
88      return atomLink.getType();
89    }
90  
91    @Override
92    public void setType(final String type)
93    {
94      atomLink.setType(type);
95    }
96  
97    @Override
98    public String getHrefLang()
99    {
100     return atomLink.getHreflang();
101   }
102 
103   @Override
104   public void setHrefLang(final String hreflang)
105   {
106     atomLink.setHreflang(hreflang);
107   }
108 
109   @Override
110   public String getLength()
111   {
112     return atomLink.getLength();
113   }
114 
115   @Override
116   public void setLength(final String length)
117   {
118     atomLink.setLength(length);
119   }
120 
121   @Override
122   public String getTitle()
123   {
124     String title = metadata.getTitle();
125     if (title == null)
126     {
127       title = atomLink.getTitle();
128     }
129     return title;
130   }
131 
132   // --- business -------------------------------------------------------------
133 
134   // --- object basics --------------------------------------------------------
135 
136 }