View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
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  
17  package net.sf.ehcache.search.attribute;
18  
19  import java.io.Serializable;
20  
21  import net.sf.ehcache.Element;
22  
23  /***
24   * Used to extract a search attribute value for a given cache element.<br>
25   * <br>
26   * Instances must be {@link Serializable} in order to ensure identical
27   * extractors are used in distributed caches
28   *
29   * @author teck
30   */
31  public interface AttributeExtractor extends Serializable {
32  
33      /***
34       * Extract the attribute value. The instance returned from this method must
35       * be one of:
36       * <ul>
37       * <li>java.lang.Boolean
38       * <li>java.lang.Byte
39       * <li>java.lang.Character
40       * <li>java.lang.Double
41       * <li>java.lang.Float
42       * <li>java.lang.Integer
43       * <li>java.lang.Long
44       * <li>java.lang.Short
45       * <li>java.lang.String
46       * <li>java.util.Date
47       * <li>java.sql.Date
48       * <li>java.lang.Enum
49       * </ul>
50       * <p/>
51       * NOTE: null is a legal return here as well indicating that this attribute will not be available for the given element
52       *
53       * @param element the cache element to inspect
54       * @param attributeName the name of the requested attribute
55       * @return the attribute value
56       * @throws AttributeExtractorException if the attribute cannot be found or extracted
57       */
58      Object attributeFor(Element element, String attributeName) throws AttributeExtractorException;
59  }