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
.Date
;
23 import java
.util
.List
;
28 * A configuration API for all association in an exim-able object. Since in Java
29 * all types are of type {@link Object} we will considering every member (a
30 * field or a property) an association and thus store a configuration for it.
34 public interface AssociationConfig
{
37 * The accessor name for the property, if field is being used to access then
38 * it will be the name of the field else it will be the name of the method
39 * being used to read it.
40 * @return Accessor string, it will be non-blank
42 public String
getAccessorName();
45 * Defines whether the associate is to be exported as URI or not.
46 * @return True if its expected to export as URI else false
48 public boolean isItToBeExportedAsUri();
51 * Defines whether the association is to be ignored for when the domain is
52 * exported or imported.
53 * @return True if it is to be ignored for Ex-Im.
55 public boolean isTransient();
58 * Defines whether the object should be imported eagerly or on demand. It
59 * will only be supported if the resource is exported using properties. If
60 * any association config has it set then it will use CGLIB for proxying the
62 * @return True if association is to be fetched eagerly.
63 * @see AssociationConfig#isItToBeExportedAsUri()
64 * @see AssociationConfig#isTransient()
66 public boolean isEagerSet();
69 * Defines the name representing the association in the exported doc.
70 * @return Name to be used in export/import; if null then field/property
71 * name will be used instead.
73 public String
getName();
76 * Defines whether the association has its own string value generator
77 * implementation, (if its not exported as URI) if it does have a provider
78 * then it will be used else toString will be used.
79 * @return True if it has a string provider implemented.
80 * @see AssociationConfig#isItToBeExportedAsUri()
82 public boolean isStringProviderImplemented();
85 * Defines the type of association this configuration represents
86 * @return Type of the associaiton
88 public AssociationType
getAssociationType();
91 * It defimes types that impacts how the data is used in order to be
94 public enum AssociationType
{
97 * Represents anything thats not any form of collection
99 TYPE_OBJECT("array", Object
.class),
103 TYPE_LIST("list", List
.class),
107 TYPE_SET("set", Set
.class),
109 * Represents Collection
111 TYPE_COLLECTION("collection", Collection
.class),
115 TYPE_ARRAY("object", Object
.class),
119 TYPE_MAP("map", Map
.class),
121 * Represents type 'double'
123 TYPE_DOUBLE("double", double.class, Double
.class),
125 * Represents type 'float'
127 TYPE_FLOAT("float", float.class, Float
.class),
129 * Represents type 'long'
131 TYPE_LONG("long", long.class, Long
.class),
133 * Represents type 'int'
135 TYPE_INTEGER("integer", int.class, Integer
.class),
137 * Represents type 'String'
139 TYPE_STRING("string", String
.class),
141 * Represents type 'boolean'
143 TYPE_BOOLEAN("boolean", boolean.class, Boolean
.class),
145 * Represents type 'java.util.Date'
147 TYPE_DATE("date", Date
.class),;
148 private Class
[] rootClasses
;
149 private String simpleName
;
151 AssociationType(String simpleName
,
152 Class
... rootClass
) {
153 if (rootClass
== null || rootClass
.length
<= 0) {
154 throw new IllegalArgumentException(
155 "There should be at least one type!");
157 this.rootClasses
= rootClass
;
158 this.simpleName
= simpleName
;
162 * The root {@link Class} of the type its representing
163 * @return The class type
165 public Class
[] getRootClasses() {
169 public String
getSimpleName() {
173 public boolean isAssignableFrom(Class clazz
) {
177 for (Class myClazz
: getRootClasses()) {
178 if (myClazz
.isAssignableFrom(clazz
)) {
186 * Given any {@link Class} it will determine the {@link AssociationType}
188 * @param clazz The class whose type to determine
189 * @return Type of the clazz
190 * @throws NullPointerException If clazz is null
192 public static AssociationType
getAssociationType(Class clazz
)
193 throws NullPointerException
{
194 if (clazz
.isArray()) {
197 if (TYPE_MAP
.isAssignableFrom(clazz
)) {
200 if (TYPE_LIST
.isAssignableFrom(clazz
)) {
203 if (TYPE_SET
.isAssignableFrom(clazz
)) {
206 if (TYPE_COLLECTION
.isAssignableFrom(clazz
)) {
207 return TYPE_COLLECTION
;
209 if (TYPE_DATE
.isAssignableFrom(clazz
)) {
212 if (TYPE_BOOLEAN
.isAssignableFrom(clazz
)) {
215 if (TYPE_STRING
.isAssignableFrom(clazz
)) {
218 if (TYPE_INTEGER
.isAssignableFrom(clazz
)) {
221 if (TYPE_LONG
.isAssignableFrom(clazz
)) {
224 if (TYPE_FLOAT
.isAssignableFrom(clazz
)) {
227 if (TYPE_DOUBLE
.isAssignableFrom(clazz
)) {