2 * This is a common dao with basic CRUD operations and is not limited to any
3 * persistent layer implementation
5 * Copyright (C) 2008 Imran M Yousuf (imyousuf@smartitengineering.com)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 package com
.smartitengineering
.exim
;
21 import java
.util
.Collection
;
22 import java
.util
.List
;
27 * A configuration API for all association in an exim-able object. Since in Java
28 * all types are of type {@link Object} we will considering every member (a
29 * field or a property) an association and thus store a configuration for it.
33 public interface AssociationConfig
{
36 * Defines whether the associate is to be exported as URI or not.
37 * @return True if its expected to export as URI else false
39 public boolean isItToBeExportedAsUri();
42 * Defines whether the association is to be ignored for when the domain is
43 * exported or imported.
44 * @return True if it is to be ignored for Ex-Im.
46 public boolean isTransient();
49 * Defines whether the object should be imported eagerly or on demand. It
50 * will only be supported if the resource is exported using properties. If
51 * any association config has it set then it will use CGLIB for proxying the
53 * @return True if association is to be fetched eagerly.
54 * @see AssociationConfig#isItToBeExportedAsUri()
55 * @see AssociationConfig#isTransient()
57 public boolean isEagerSet();
60 * Defines the name representing the association in the exported doc.
61 * @return Name to be used in export/import; if null then field/property
62 * name will be used instead.
64 public String
getName();
67 * Defines whether the association has its own string value generator
68 * implementation, (if its not exported as URI) if it does have a provider
69 * then it will be used else toString will be used.
70 * @return True if it has a string provider implemented.
71 * @see AssociationConfig#isItToBeExportedAsUri()
73 public boolean isStringProviderImplemented();
76 * Defines the type of association this configuration represents
77 * @return Type of the associaiton
79 public AssociationType
getAssociationType();
82 * It defimes types that impacts how the data is used in order to be
85 public enum AssociationType
{
88 * Represents anything thats not any form of collection
90 TYPE_OBJECT(Object
.class),
94 TYPE_LIST(List
.class),
100 * Represents Collection
102 TYPE_COLLECTION(Collection
.class),
106 TYPE_ARRAY(Object
.class),
110 TYPE_MAP(Map
.class),;
111 private Class rootClass
;
113 AssociationType(Class rootClass
) {
114 this.rootClass
= rootClass
;
118 * The root {@link Class} of the type its representing
119 * @return The class type
121 public Class
getRootClass() {
126 * Given any {@link Class} it will determine the {@link AssociationType}
128 * @param clazz The class whose type to determine
129 * @return Type of the clazz
130 * @throws NullPointerException If clazz is null
132 public static AssociationType
getAssociationType(Class clazz
)
133 throws NullPointerException
{
134 if (clazz
.isArray()) {
137 if (TYPE_MAP
.getRootClass().isAssignableFrom(clazz
)) {
140 if (TYPE_LIST
.getRootClass().isAssignableFrom(clazz
)) {
143 if (TYPE_SET
.getRootClass().isAssignableFrom(clazz
)) {
146 if (TYPE_COLLECTION
.getRootClass().isAssignableFrom(clazz
)) {
147 return TYPE_COLLECTION
;