Add documentation to some missing classes
[smart-dao.git] / smart-exim / smart-exim-api / src / main / java / com / smartitengineering / exim / AssociationConfig.java
blobf86245e98711a5ed2070a304feed0362d0fa3e71
1 /*
2 * This is a common dao with basic CRUD operations and is not limited to any
3 * persistent layer implementation
4 *
5 * Copyright (C) 2008 Imran M Yousuf (imyousuf@smartitengineering.com)
6 *
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;
23 import java.util.Map;
24 import java.util.Set;
26 /**
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.
30 * @author imyousuf
31 * @since 0.4
33 public interface AssociationConfig {
35 /**
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();
41 /**
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();
48 /**
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
52 * resources.
53 * @return True if association is to be fetched eagerly.
54 * @see AssociationConfig#isItToBeExportedAsUri()
55 * @see AssociationConfig#isTransient()
57 public boolean isEagerSet();
59 /**
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();
66 /**
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();
75 /**
76 * Defines the type of association this configuration represents
77 * @return Type of the associaiton
79 public AssociationType getAssociationType();
81 /**
82 * It defimes types that impacts how the data is used in order to be
83 * exported.
85 public enum AssociationType {
87 /**
88 * Represents anything thats not any form of collection
90 TYPE_OBJECT(Object.class),
91 /**
92 * Represents List
94 TYPE_LIST(List.class),
95 /**
96 * Represents Set
98 TYPE_SET(Set.class),
99 /**
100 * Represents Collection
102 TYPE_COLLECTION(Collection.class),
104 * Represents Array
106 TYPE_ARRAY(Object.class),
108 * Represents Map
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() {
122 return rootClass;
126 * Given any {@link Class} it will determine the {@link AssociationType}
127 * for that class.
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()) {
135 return TYPE_ARRAY;
137 if (TYPE_MAP.getRootClass().isAssignableFrom(clazz)) {
138 return TYPE_MAP;
140 if (TYPE_LIST.getRootClass().isAssignableFrom(clazz)) {
141 return TYPE_LIST;
143 if (TYPE_SET.getRootClass().isAssignableFrom(clazz)) {
144 return TYPE_SET;
146 if (TYPE_COLLECTION.getRootClass().isAssignableFrom(clazz)) {
147 return TYPE_COLLECTION;
149 return TYPE_OBJECT;