1 // Copyright 2008 Thiago H. de Paula Figueiredo
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package br.com.arsmachina.tapestrycrud.services;
16
17 import org.apache.tapestry5.PrimaryKeyEncoder;
18 import org.apache.tapestry5.corelib.components.ActionLink;
19 import org.apache.tapestry5.corelib.components.EventLink;
20 import org.apache.tapestry5.corelib.components.PageLink;
21
22 import br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder;
23
24 /**
25 * Service that informs the primary key field type of a given entity class. Implementations
26 * are not obliged to provide this service for any entity class
27 *
28 * @author Thiago H. de Paula Figueiredo
29 */
30 public interface PrimaryKeyTypeService {
31
32 /**
33 * <p>
34 * Returns the {@link Class} instance representing the primary key field type for a given entity
35 * class. It must return null if the given class is not supported.
36 * </p>
37 * <p>
38 * The primary key field type of a given class may not be the one used as primary key column
39 * in the database. This can be used to provide prettier URLs for {@link ActionLink}s,
40 * {@link EventLink}s or {@link PageLink}s (when no {@link ActivationContextEncoder} is
41 * explicitly provided and one is automatically created from a {@link PrimaryKeyEncoder}).
42 * </p>
43 *
44 * @param entityClass a {@link Class} instance. It cannot be null.
45 * @return a {@link Class} or null.
46 */
47 @SuppressWarnings("unchecked")
48 Class getPrimaryKeyType(Class entityClass);
49
50 /**
51 * Returns the name of the property used as primary key in a given class. The same
52 * assumptions made to {@link #getPrimaryKeyType(Class)} applies here.
53 *
54 * @param entityClass a {@link Class} instance. It cannot be null.
55 * @return a {@link String} or null.
56 */
57 @SuppressWarnings("unchecked")
58 String getPrimaryKeyPropertyName(Class entityClass);
59
60 }