Source Code Cross Referenced for ConstrainedProperty.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » site » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » com.uwyn.rife.site 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003:         * Distributed under the terms of either:
0004:         * - the common development and distribution license (CDDL), v1.0; or
0005:         * - the GNU Lesser General Public License, v2.1 or later
0006:         * $Id: ConstrainedProperty.java 3732 2007-05-02 20:45:59Z gbevin $
0007:         */
0008:        package com.uwyn.rife.site;
0009:
0010:        import java.util.*;
0011:
0012:        import com.uwyn.rife.cmf.MimeType;
0013:        import com.uwyn.rife.cmf.transform.ContentTransformer;
0014:        import com.uwyn.rife.database.queries.CreateTable;
0015:        import com.uwyn.rife.tools.ClassUtils;
0016:        import com.uwyn.rife.tools.Convert;
0017:        import java.text.Format;
0018:
0019:        /**
0020:         * A <code>ConstrainedProperty</code> object makes it possible to easily
0021:         * define all constraints for a named property of a bean.
0022:         * <p>The property name refers to the actual name of the bean property.
0023:         * However, this sometimes doesn't correspond to its conceptual usage. It can
0024:         * be handy to receive constraint violation reports with another conceptual
0025:         * name: the subject name. Notice that this corresponds to the subject that is
0026:         * used in a {@link ValidationError}. If no subject name is specified, the
0027:         * property name will be used instead.
0028:         * <p>It's possible to add constraints to a ConstrainedProperty instance
0029:         * through regular setters, but chainable setters are also available to make
0030:         * it possible to easily define a series of constraints, for example:
0031:         * <pre>ConstrainedProperty constrained = new ConstrainedProperty("password")
0032:         *    .maxLength(8)
0033:         *    .notNull(true);</pre>
0034:         * <p>
0035:         * <p>Constrained properties are typically added to a {@link Constrained} bean
0036:         * in its constructor. These are the static constraints that will be set for
0037:         * each and every instance of the bean. You'll however most of the time use
0038:         * the {@link MetaData} class that provides the {@link
0039:         * MetaData#activateMetaData activateMetaData} method which initializes
0040:         * the constraints on a need-to-have basis. This dramatically reduces memory
0041:         * usage since otherwise all constraints will be initialized for every bean
0042:         * instance, even though you don't use them, for example:
0043:         * <pre>public class Credentials extends MetaData
0044:         *{
0045:         *    private String mLogin = null;
0046:         *    private String mPassword = null;
0047:         *    private String mLanguage = null;
0048:         *
0049:         *    public Credentials()
0050:         *    {
0051:         *    }
0052:         *
0053:         *    public activateMetaData()
0054:         *    {
0055:         *        addConstraint(new ConstrainedProperty("login").maxLength(6).notNull(true));
0056:         *        addConstraint(new ConstrainedProperty("password").maxLength(8).notNull(true));
0057:         *        addConstraint(new ConstrainedProperty("language").notNull(true));
0058:         *    }
0059:         *
0060:         *    public void setLogin(String login) { mLogin = login; }
0061:         *    public String getLogin() { return mLogin; }
0062:         *    public void setPassword(String password) { mPassword = password; }
0063:         *    public String getPassword() { return mPassword; }
0064:         *    public void setLanguage(String language) { mLanguage = language; }
0065:         *    public String getLanguage() { return mLanguage; }
0066:         *}</pre>
0067:         * <p>
0068:         * <p>It's however also possible to add constraints to a single bean instance
0069:         * whenever they can't be determined beforehand. These are then dynamic
0070:         * constraints than can be populated at runtime, for example:
0071:         * <pre>Credentials credentials = new Credentials();
0072:         *credentials.addConstraint(new ConstrainedProperty("language").inList(new String[] {"nl", "fr", "en"}));
0073:         *</pre>
0074:         *
0075:         * @author Geert Bevin (gbevin[remove] at uwyn dot com)
0076:         * @see Constrained
0077:         * @see ConstrainedBean
0078:         * @version $Revision: 3732 $
0079:         * @since 1.0
0080:         */
0081:        public class ConstrainedProperty<T extends ConstrainedProperty>
0082:                implements  Cloneable {
0083:            // standard constraint identifiers
0084:            public final static String NOT_NULL = "NOT_NULL";
0085:            public final static String NOT_EMPTY = "NOT_EMPTY";
0086:            public final static String NOT_EQUAL = "NOT_EQUAL";
0087:            public final static String UNIQUE = "UNIQUE";
0088:            public final static String IDENTIFIER = "IDENTIFIER";
0089:            public final static String EDITABLE = "EDITABLE";
0090:            public final static String PERSISTENT = "PERSISTENT";
0091:            public final static String SAVED = "SAVED";
0092:            public final static String DISPLAYED_RAW = "DISPLAYED_RAW";
0093:            public final static String MIN_LENGTH = "MIN_LENGTH";
0094:            public final static String MAX_LENGTH = "MAX_LENGTH";
0095:            public final static String SCALE = "SCALE";
0096:            public final static String REGEXP = "REGEXP";
0097:            public final static String EMAIL = "EMAIL";
0098:            public final static String URL = "URL";
0099:            public final static String MIN_DATE = "MIN_DATE";
0100:            public final static String MAX_DATE = "MAX_DATE";
0101:            public final static String IN_LIST = "IN_LIST";
0102:            public final static String RANGE_BEGIN = "RANGE_BEGIN";
0103:            public final static String RANGE_END = "RANGE_END";
0104:            public final static String DEFAULT_VALUE = "DEFAULT_VALUE";
0105:            public final static String SAME_AS = "SAME_AS";
0106:            public final static String MANY_TO_ONE = "MANY_TO_ONE";
0107:            public final static String MANY_TO_ONE_ASSOCIATION = "MANY_TO_ONE_ASSOCIATION";
0108:            public final static String MANY_TO_MANY = "MANY_TO_MANY";
0109:            public final static String MANY_TO_MANY_ASSOCIATION = "MANY_TO_MANY_ASSOCIATION";
0110:            public final static String FORMAT = "FORMAT";
0111:            public final static String FILE = "FILE";
0112:            public final static String SPARSE = "SPARSE";
0113:
0114:            // standard CMF constraint identifiers
0115:            public final static String LISTED = "LISTED";
0116:            public final static String POSITION = "POSITION";
0117:            public final static String MIMETYPE = "MIMETYPE";
0118:            public final static String AUTO_RETRIEVED = "AUTO_RETRIEVED";
0119:            public final static String FRAGMENT = "FRAGMENT";
0120:            public final static String NAME = "NAME";
0121:            public final static String REPOSITORY = "REPOSITORY";
0122:            public final static String ORDINAL = "ORDINAL";
0123:            public final static String ORDINAL_RESTRICTION = "ORDINAL_RESTRICTION";
0124:            public final static String CONTENT_ATTRIBUTES = "CONTENT_ATTRIBUTES";
0125:            public final static String TRANSFORMER = "TRANSFORMER";
0126:            public final static String CACHED_LOADED_DATA = "CACHED_LOADED_DATA";
0127:
0128:            // required member variables
0129:            private String mPropertyName = null;
0130:            private String mSubjectName = null;
0131:
0132:            // constraints
0133:            protected Map<String, Object> mConstraints = new HashMap<String, Object>();
0134:
0135:            // listeners
0136:            protected List<ConstrainedPropertyListener> mListeners;
0137:
0138:            /**
0139:             * Adds a new listener.
0140:             * <p>
0141:             * Listeners will be notified when events occur that are specified in the
0142:             * {@code ConstrainedPropertyListener} interface.
0143:             *
0144:             * @param listener the listener instance that will be added
0145:             * @since 1.6
0146:             */
0147:            public void addListener(ConstrainedPropertyListener listener) {
0148:                if (null == listener) {
0149:                    return;
0150:                }
0151:
0152:                if (null == mListeners) {
0153:                    mListeners = new ArrayList<ConstrainedPropertyListener>();
0154:                }
0155:
0156:                synchronized (mListeners) {
0157:                    if (!mListeners.contains(listener)) {
0158:                        mListeners.add(listener);
0159:                    }
0160:                }
0161:            }
0162:
0163:            /**
0164:             * Removes a listener.
0165:             * <p>
0166:             * Once the listener has been removed, it will not receive any events anymore.
0167:             *
0168:             * @param listener the listener instance that will be removed
0169:             *
0170:             * @return {@code true} when the listener could be found and has been removed; or
0171:             * <p>{@code false} when the listener wasn't registered before
0172:             * @since 1.6
0173:             */
0174:            public boolean removeListener(ConstrainedPropertyListener listener) {
0175:                if (null == mListeners) {
0176:                    return false;
0177:                }
0178:
0179:                synchronized (mListeners) {
0180:                    return mListeners.remove(listener);
0181:                }
0182:            }
0183:
0184:            private void fireConstraintSet(String name, Object constraintData) {
0185:                if (null == mListeners) {
0186:                    return;
0187:                }
0188:
0189:                synchronized (mListeners) {
0190:                    for (ConstrainedPropertyListener listener : mListeners) {
0191:                        listener.constraintSet(this , name, constraintData);
0192:                    }
0193:                }
0194:            }
0195:
0196:            /**
0197:             * Creates a new <code>ConstrainedProperty</code> for the specified
0198:             * property name.
0199:             *
0200:             * @param propertyName the name of the property that has to be
0201:             * constrained
0202:             * @since 1.0
0203:             */
0204:            public ConstrainedProperty(String propertyName) {
0205:                if (null == propertyName)
0206:                    throw new IllegalArgumentException(
0207:                            "propertyName can't be null.");
0208:                if (0 == propertyName.length())
0209:                    throw new IllegalArgumentException(
0210:                            "propertyName can't be empty.");
0211:
0212:                mPropertyName = propertyName;
0213:            }
0214:
0215:            /**
0216:             * Sets the subject name.
0217:             *
0218:             * @param name the subject name
0219:             * @return this <code>ConstrainedProperty</code>
0220:             * @since 1.0
0221:             */
0222:            public T subjectName(String name) {
0223:                setSubjectName(name);
0224:
0225:                return (T) this ;
0226:            }
0227:
0228:            /**
0229:             * Sets the subject name.
0230:             *
0231:             * @param name the subject name
0232:             * @since 1.0
0233:             */
0234:            public void setSubjectName(String name) {
0235:                mSubjectName = name;
0236:            }
0237:
0238:            /**
0239:             * Retrieves the subject name.
0240:             *
0241:             * @return the subject name; or
0242:             * <p>the property name if no subject was specified.
0243:             * @since 1.0
0244:             */
0245:            public String getSubjectName() {
0246:                if (null == mSubjectName) {
0247:                    return mPropertyName;
0248:                }
0249:
0250:                return mSubjectName;
0251:            }
0252:
0253:            /**
0254:             * Retrieves the property name.
0255:             *
0256:             * @return the property name
0257:             * @since 1.0
0258:             */
0259:            public String getPropertyName() {
0260:                return mPropertyName;
0261:            }
0262:
0263:            /**
0264:             * Set whether the property value can be <code>null</code>.
0265:             * <p>Note that this has different meanings in different contexts:
0266:             * <ul>
0267:             * <li>for values in java this is only applicable to object references
0268:             * as primitive values are never <code>null</code>,
0269:             * <li>for values that are stored in a database, it's applicable to
0270:             * every column.
0271:             * </ul>
0272:             *
0273:             * @param notNull <code>true</code> when the value can't be
0274:             * <code>null</code>; or <code>false</code> when the value can be
0275:             * <code>null</code>.
0276:             * @return this <code>ConstrainedProperty</code>
0277:             * @see #isNotNull()
0278:             * @since 1.0
0279:             */
0280:            public T notNull(boolean notNull) {
0281:                setNotNull(notNull);
0282:
0283:                return (T) this ;
0284:            }
0285:
0286:            /**
0287:             * Set whether the property value can be <code>null</code>.
0288:             *
0289:             * @see #notNull(boolean)
0290:             * @since 1.0
0291:             */
0292:            public void setNotNull(boolean notNull) {
0293:                setConstraint(NOT_NULL, notNull);
0294:            }
0295:
0296:            /**
0297:             * Retrieves whether the property value can be <code>null</code>.
0298:             *
0299:             * @return <code>true</code> when the value can't be <code>null</code>;
0300:             * or
0301:             * <p><code>false</code> when the value can be <code>null</code>.
0302:             * @see #notNull(boolean)
0303:             * @since 1.0
0304:             */
0305:            public boolean isNotNull() {
0306:                return Convert.toBoolean(mConstraints.get(NOT_NULL), false);
0307:            }
0308:
0309:            /**
0310:             * Set whether the property value can be empty.
0311:             * <p>Note that this has different meanings for different datatypes
0312:             * <ul>
0313:             * <li>for textual types this is an empty string, ie. "",
0314:             * <li>for numeric types this is 0 (zero).
0315:             * </ul>
0316:             *
0317:             * @param notEmpty <code>true</code> when the value can't be empty; or
0318:             * <code>false</code> when the value can be empty.
0319:             * @return this <code>ConstrainedProperty</code>
0320:             * @see #isNotEmpty()
0321:             * @since 1.0
0322:             */
0323:            public T notEmpty(boolean notEmpty) {
0324:                setNotEmpty(notEmpty);
0325:
0326:                return (T) this ;
0327:            }
0328:
0329:            /**
0330:             * Set whether the property value can be empty.
0331:             *
0332:             * @see #notEmpty(boolean)
0333:             * @since 1.0
0334:             */
0335:            public void setNotEmpty(boolean notEmpty) {
0336:                setConstraint(NOT_EMPTY, notEmpty);
0337:            }
0338:
0339:            /**
0340:             * Retrieves whether the property value can be empty.
0341:             *
0342:             * @return <code>true</code> when the value can't be empty; or
0343:             * <p><code>false</code> when the value can be empty.
0344:             * @see #notEmpty(boolean)
0345:             * @since 1.0
0346:             */
0347:            public boolean isNotEmpty() {
0348:                return Convert.toBoolean(mConstraints.get(NOT_EMPTY), false);
0349:            }
0350:
0351:            /**
0352:             * Set that the property value can't be equal to a specified
0353:             * <code>boolean</code> reference value.
0354:             *
0355:             * @param reference the reference value it will be checked against
0356:             * @return this <code>ConstrainedProperty</code>
0357:             * @see #isNotEqual()
0358:             * @since 1.0
0359:             */
0360:            public T notEqual(boolean reference) {
0361:                setNotEqual(reference);
0362:
0363:                return (T) this ;
0364:            }
0365:
0366:            /**
0367:             * Set that the property value can't be equal to a specified
0368:             * <code>byte</code> reference value.
0369:             *
0370:             * @see #notEqual(boolean)
0371:             * @since 1.0
0372:             */
0373:            public T notEqual(byte reference) {
0374:                setNotEqual(reference);
0375:
0376:                return (T) this ;
0377:            }
0378:
0379:            /**
0380:             * Set that the property value can't be equal to a specified
0381:             * <code>char</code> reference value.
0382:             *
0383:             * @see #notEqual(boolean)
0384:             * @since 1.0
0385:             */
0386:            public T notEqual(char reference) {
0387:                setNotEqual(reference);
0388:
0389:                return (T) this ;
0390:            }
0391:
0392:            /**
0393:             * Set that the property value can't be equal to a specified
0394:             * <code>short</code> reference value.
0395:             *
0396:             * @see #notEqual(boolean)
0397:             * @since 1.0
0398:             */
0399:            public T notEqual(short reference) {
0400:                setNotEqual(reference);
0401:
0402:                return (T) this ;
0403:            }
0404:
0405:            /**
0406:             * Set that the property value can't be equal to a specified
0407:             * <code>int</code> reference value.
0408:             *
0409:             * @see #notEqual(boolean)
0410:             * @since 1.0
0411:             */
0412:            public T notEqual(int reference) {
0413:                setNotEqual(reference);
0414:
0415:                return (T) this ;
0416:            }
0417:
0418:            /**
0419:             * Set that the property value can't be equal to a specified
0420:             * <code>long</code> reference value.
0421:             *
0422:             * @see #notEqual(boolean)
0423:             * @since 1.0
0424:             */
0425:            public T notEqual(long reference) {
0426:                setNotEqual(reference);
0427:
0428:                return (T) this ;
0429:            }
0430:
0431:            /**
0432:             * Set that the property value can't be equal to a specified
0433:             * <code>float</code> reference value.
0434:             *
0435:             * @see #notEqual(boolean)
0436:             * @since 1.0
0437:             */
0438:            public T notEqual(float reference) {
0439:                setNotEqual(reference);
0440:
0441:                return (T) this ;
0442:            }
0443:
0444:            /**
0445:             * Set that the property value can't be equal to a specified
0446:             * <code>double</code> reference value.
0447:             *
0448:             * @see #notEqual(boolean)
0449:             * @since 1.0
0450:             */
0451:            public T notEqual(double reference) {
0452:                setNotEqual(reference);
0453:
0454:                return (T) this ;
0455:            }
0456:
0457:            /**
0458:             * Set that the property value can't be equal to a specified
0459:             * <code>Object</code> reference value.
0460:             *
0461:             * @see #notEqual(boolean)
0462:             * @since 1.0
0463:             */
0464:            public T notEqual(Object reference) {
0465:                setNotEqual(reference);
0466:
0467:                return (T) this ;
0468:            }
0469:
0470:            /**
0471:             * Set that the property value can't be equal to a specified
0472:             * <code>boolean</code> reference value.
0473:             *
0474:             * @see #notEqual(boolean)
0475:             * @since 1.0
0476:             */
0477:            public void setNotEqual(boolean reference) {
0478:                setNotEqual(Boolean.valueOf(reference));
0479:            }
0480:
0481:            /**
0482:             * Set that the property value can't be equal to a specified
0483:             * <code>byte</code> reference value.
0484:             *
0485:             * @see #notEqual(boolean)
0486:             * @since 1.0
0487:             */
0488:            public void setNotEqual(byte reference) {
0489:                setNotEqual(new Byte(reference));
0490:            }
0491:
0492:            /**
0493:             * Set that the property value can't be equal to a specified
0494:             * <code>char</code> reference value.
0495:             *
0496:             * @see #notEqual(boolean)
0497:             * @since 1.0
0498:             */
0499:            public void setNotEqual(char reference) {
0500:                setNotEqual(new Character(reference));
0501:            }
0502:
0503:            /**
0504:             * Set that the property value can't be equal to a specified
0505:             * <code>short</code> reference value.
0506:             *
0507:             * @see #notEqual(boolean)
0508:             * @since 1.0
0509:             */
0510:            public void setNotEqual(short reference) {
0511:                setNotEqual(new Short(reference));
0512:            }
0513:
0514:            /**
0515:             * Set that the property value can't be equal to a specified
0516:             * <code>int</code> reference value.
0517:             *
0518:             * @see #notEqual(boolean)
0519:             * @since 1.0
0520:             */
0521:            public void setNotEqual(int reference) {
0522:                setNotEqual(new Integer(reference));
0523:            }
0524:
0525:            /**
0526:             * Set that the property value can't be equal to a specified
0527:             * <code>long</code> reference value.
0528:             *
0529:             * @see #notEqual(boolean)
0530:             * @since 1.0
0531:             */
0532:            public void setNotEqual(long reference) {
0533:                setNotEqual(new Long(reference));
0534:            }
0535:
0536:            /**
0537:             * Set that the property value can't be equal to a specified
0538:             * <code>float</code> reference value.
0539:             *
0540:             * @see #notEqual(boolean)
0541:             * @since 1.0
0542:             */
0543:            public void setNotEqual(float reference) {
0544:                setNotEqual(new Float(reference));
0545:            }
0546:
0547:            /**
0548:             * Set that the property value can't be equal to a specified
0549:             * <code>double</code> reference value.
0550:             *
0551:             * @see #notEqual(boolean)
0552:             * @since 1.0
0553:             */
0554:            public void setNotEqual(double reference) {
0555:                setNotEqual(new Double(reference));
0556:            }
0557:
0558:            /**
0559:             * Set that the property value can't be equal to a specified
0560:             * <code>Object</code> reference value.
0561:             *
0562:             * @see #notEqual(boolean)
0563:             * @since 1.0
0564:             */
0565:            public void setNotEqual(Object reference) {
0566:                if (null == reference) {
0567:                    mConstraints.remove(NOT_EQUAL);
0568:                } else {
0569:                    setConstraint(NOT_EQUAL, reference);
0570:                }
0571:            }
0572:
0573:            /**
0574:             * Retrieves whether the property can't be equal to a specific
0575:             * reference value.
0576:             *
0577:             * @return <code>true</code> when the value can't be equal; or
0578:             * <p><code>false</code> when the value can be equal.
0579:             * @see #notEqual(boolean)
0580:             * @since 1.0
0581:             */
0582:            public boolean isNotEqual() {
0583:                return mConstraints.containsKey(NOT_EQUAL);
0584:            }
0585:
0586:            /**
0587:             * Retrieves the reference object to which the property value can't be
0588:             * equal.
0589:             *
0590:             * @return the requested reference object instance; or
0591:             * <p><code>null</code> when the property has no notEqual constraint.
0592:             * @see #notEqual(boolean)
0593:             * @since 1.0
0594:             */
0595:            public Object getNotEqual() {
0596:                return mConstraints.get(NOT_EQUAL);
0597:            }
0598:
0599:            /**
0600:             * Set whether the property value has to be unique.
0601:             * <p>Note that this is only applicable to contexts where a collection
0602:             * of the data is stored an that uniqueness can apply against the
0603:             * other entries. In a singular context, uniqueness is always
0604:             * guaranteed.
0605:             *
0606:             * @param unique <code>true</code> when the value has to be unique; or
0607:             * <code>false</code> when it doesn't have to be.
0608:             * @return this <code>ConstrainedProperty</code>
0609:             * @see #isUnique()
0610:             * @since 1.0
0611:             */
0612:            public T unique(boolean unique) {
0613:                setUnique(unique);
0614:
0615:                return (T) this ;
0616:            }
0617:
0618:            /**
0619:             * Set whether the property value has to be unique.
0620:             *
0621:             * @see #unique(boolean)
0622:             * @since 1.0
0623:             */
0624:            public void setUnique(boolean unique) {
0625:                setConstraint(UNIQUE, unique);
0626:            }
0627:
0628:            /**
0629:             * Retrieves whether the property value has to be unique.
0630:             *
0631:             * @return <code>true</code> when the value has to be unique; or
0632:             * <p><code>false</code> it doesn't have to be.
0633:             * @see #unique(boolean)
0634:             * @since 1.0
0635:             */
0636:            public boolean isUnique() {
0637:                return Convert.toBoolean(mConstraints.get(UNIQUE), false);
0638:            }
0639:
0640:            /**
0641:             * Set whether the property value is an identifier.
0642:             * <p>Note that this is only applicable to contexts where a collection
0643:             * of the data is stored an that identification can apply against the
0644:             * other entries. In a singular context, identification is
0645:             * meaningless.
0646:             *
0647:             * @param identifier <code>true</code> when the value is an
0648:             * identifier; or <code>false</code> when it isn't.
0649:             * @return this <code>ConstrainedProperty</code>
0650:             * @see #isIdentifier()
0651:             * @since 1.0
0652:             */
0653:            public T identifier(boolean identifier) {
0654:                setIdentifier(identifier);
0655:
0656:                return (T) this ;
0657:            }
0658:
0659:            /**
0660:             * Set whether the property value is an identifier.
0661:             *
0662:             * @see #identifier(boolean)
0663:             * @since 1.0
0664:             */
0665:            public void setIdentifier(boolean identifier) {
0666:                setConstraint(IDENTIFIER, identifier);
0667:            }
0668:
0669:            /**
0670:             * Retrieves whether the property is an identifier.
0671:             *
0672:             * @return <code>true</code> when the property is an identifier; or
0673:             * <p><code>false</code> it isn't.
0674:             * @see #identifier(boolean)
0675:             * @since 1.0
0676:             */
0677:            public boolean isIdentifier() {
0678:                return Convert.toBoolean(mConstraints.get(IDENTIFIER), false);
0679:            }
0680:
0681:            public T editable(boolean editable) {
0682:                setEditable(editable);
0683:
0684:                return (T) this ;
0685:            }
0686:
0687:            public void setEditable(boolean editable) {
0688:                setConstraint(EDITABLE, editable);
0689:            }
0690:
0691:            public boolean isEditable() {
0692:                return Convert.toBoolean(mConstraints.get(EDITABLE), true);
0693:            }
0694:
0695:            public T persistent(boolean persistent) {
0696:                setPersistent(persistent);
0697:
0698:                return (T) this ;
0699:            }
0700:
0701:            public void setPersistent(boolean persistent) {
0702:                if (hasMimeType() && persistent) {
0703:                    throw new IllegalArgumentException(
0704:                            "Can't make a property persistent that has a content mime type assigned to it.");
0705:                }
0706:
0707:                setConstraint(PERSISTENT, persistent);
0708:            }
0709:
0710:            public boolean isPersistent() {
0711:                return Convert.toBoolean(mConstraints.get(PERSISTENT), true);
0712:            }
0713:
0714:            public T saved(boolean saved) {
0715:                setSaved(saved);
0716:
0717:                return (T) this ;
0718:            }
0719:
0720:            public void setSaved(boolean saved) {
0721:                setConstraint(SAVED, saved);
0722:            }
0723:
0724:            public boolean isSaved() {
0725:                return Convert.toBoolean(mConstraints.get(SAVED), true);
0726:            }
0727:
0728:            public T displayedRaw(boolean displayedRaw) {
0729:                setDisplayedRaw(displayedRaw);
0730:
0731:                return (T) this ;
0732:            }
0733:
0734:            public void setDisplayedRaw(boolean displayedRaw) {
0735:                if (hasMimeType() && !displayedRaw) {
0736:                    throw new IllegalArgumentException(
0737:                            "Can't make a property not ùbeing displayed raw that has a content mime type assigned to it.");
0738:                }
0739:
0740:                setConstraint(DISPLAYED_RAW, displayedRaw);
0741:            }
0742:
0743:            public boolean isDisplayedRaw() {
0744:                return Convert
0745:                        .toBoolean(mConstraints.get(DISPLAYED_RAW), false);
0746:            }
0747:
0748:            public boolean hasLimitedLength() {
0749:                return mConstraints.containsKey(MIN_LENGTH)
0750:                        || mConstraints.containsKey(MAX_LENGTH);
0751:            }
0752:
0753:            public boolean hasMixLength() {
0754:                return mConstraints.containsKey(MAX_LENGTH);
0755:            }
0756:
0757:            public boolean hasMaxLength() {
0758:                return mConstraints.containsKey(MAX_LENGTH);
0759:            }
0760:
0761:            public T minLength(int minLength) {
0762:                setMinLength(minLength);
0763:
0764:                return (T) this ;
0765:            }
0766:
0767:            public void setMinLength(int minLength) {
0768:                if (minLength <= 0) {
0769:                    mConstraints.remove(MIN_LENGTH);
0770:                } else {
0771:                    setConstraint(MIN_LENGTH, minLength);
0772:                }
0773:            }
0774:
0775:            public int getMinLength() {
0776:                return Convert.toInt(mConstraints.get(MIN_LENGTH), -1);
0777:            }
0778:
0779:            public T maxLength(int maxLength) {
0780:                setMaxLength(maxLength);
0781:
0782:                return (T) this ;
0783:            }
0784:
0785:            public void setMaxLength(int maxLength) {
0786:                if (maxLength < 0) {
0787:                    mConstraints.remove(MAX_LENGTH);
0788:                } else {
0789:                    setConstraint(MAX_LENGTH, maxLength);
0790:                }
0791:            }
0792:
0793:            public int getMaxLength() {
0794:                return Convert.toInt(mConstraints.get(MAX_LENGTH), -1);
0795:            }
0796:
0797:            public boolean hasPrecision() {
0798:                return mConstraints.containsKey(MAX_LENGTH);
0799:            }
0800:
0801:            public T precision(int precision) {
0802:                setPrecision(precision);
0803:
0804:                return (T) this ;
0805:            }
0806:
0807:            public void setPrecision(int precision) {
0808:                setMaxLength(precision);
0809:            }
0810:
0811:            public int getPrecision() {
0812:                return getMaxLength();
0813:            }
0814:
0815:            public boolean hasScale() {
0816:                return mConstraints.containsKey(SCALE);
0817:            }
0818:
0819:            public T scale(int scale) {
0820:                setScale(scale);
0821:
0822:                return (T) this ;
0823:            }
0824:
0825:            public void setScale(int scale) {
0826:                if (scale < 0) {
0827:                    mConstraints.remove(SCALE);
0828:                } else {
0829:                    setConstraint(SCALE, scale);
0830:                }
0831:            }
0832:
0833:            public int getScale() {
0834:                return Convert.toInt(mConstraints.get(SCALE), -1);
0835:            }
0836:
0837:            public T regexp(String regexp) {
0838:                setRegexp(regexp);
0839:
0840:                return (T) this ;
0841:            }
0842:
0843:            public void setRegexp(String regexp) {
0844:                if (null == regexp) {
0845:                    mConstraints.remove(REGEXP);
0846:                } else {
0847:                    setConstraint(REGEXP, regexp);
0848:                }
0849:            }
0850:
0851:            public String getRegexp() {
0852:                return (String) mConstraints.get(REGEXP);
0853:            }
0854:
0855:            public boolean matchesRegexp() {
0856:                return mConstraints.containsKey(REGEXP);
0857:            }
0858:
0859:            public T email(boolean email) {
0860:                setEmail(email);
0861:
0862:                return (T) this ;
0863:            }
0864:
0865:            public void setEmail(boolean email) {
0866:                setConstraint(EMAIL, email);
0867:            }
0868:
0869:            public boolean isEmail() {
0870:                return Convert.toBoolean(mConstraints.get(EMAIL), false);
0871:            }
0872:
0873:            public T url(boolean url) {
0874:                setUrl(url);
0875:
0876:                return (T) this ;
0877:            }
0878:
0879:            public void setUrl(boolean url) {
0880:                setConstraint(URL, url);
0881:            }
0882:
0883:            public boolean isUrl() {
0884:                return Convert.toBoolean(mConstraints.get(URL), false);
0885:            }
0886:
0887:            public T minDate(Date minDate) {
0888:                setMinDate(minDate);
0889:
0890:                return (T) this ;
0891:            }
0892:
0893:            public void setMinDate(Date minDate) {
0894:                if (null == minDate) {
0895:                    mConstraints.remove(MIN_DATE);
0896:                } else {
0897:                    setConstraint(MIN_DATE, minDate);
0898:                }
0899:            }
0900:
0901:            public Date getMinDate() {
0902:                return (Date) mConstraints.get(MIN_DATE);
0903:            }
0904:
0905:            public T maxDate(Date maxDate) {
0906:                setMaxDate(maxDate);
0907:
0908:                return (T) this ;
0909:            }
0910:
0911:            public void setMaxDate(Date maxDate) {
0912:                if (null == maxDate) {
0913:                    mConstraints.remove(MAX_DATE);
0914:                } else {
0915:                    setConstraint(MAX_DATE, maxDate);
0916:                }
0917:            }
0918:
0919:            public Date getMaxDate() {
0920:                return (Date) mConstraints.get(MAX_DATE);
0921:            }
0922:
0923:            public boolean isLimitedDate() {
0924:                return mConstraints.containsKey(MIN_DATE)
0925:                        || mConstraints.containsKey(MAX_DATE);
0926:            }
0927:
0928:            public T inList(String... inList) {
0929:                setInList(inList);
0930:
0931:                return (T) this ;
0932:            }
0933:
0934:            public void setInList(String... inList) {
0935:                if (null == inList) {
0936:                    mConstraints.remove(IN_LIST);
0937:                } else {
0938:                    setConstraint(IN_LIST, inList);
0939:                }
0940:            }
0941:
0942:            public T inList(int... inList) {
0943:                setInList(inList);
0944:
0945:                return (T) this ;
0946:            }
0947:
0948:            public void setInList(int... inList) {
0949:                String[] list = null;
0950:                if (inList != null) {
0951:                    list = new String[inList.length];
0952:                    for (int i = 0; i < inList.length; i++) {
0953:                        list[i] = String.valueOf(inList[i]);
0954:                    }
0955:                }
0956:
0957:                setInList(list);
0958:            }
0959:
0960:            public T inList(byte... inList) {
0961:                setInList(inList);
0962:
0963:                return (T) this ;
0964:            }
0965:
0966:            public void setInList(byte... inList) {
0967:                String[] list = null;
0968:                if (inList != null) {
0969:                    list = new String[inList.length];
0970:                    for (int i = 0; i < inList.length; i++) {
0971:                        list[i] = String.valueOf(inList[i]);
0972:                    }
0973:                }
0974:
0975:                setInList(list);
0976:            }
0977:
0978:            public T inList(char... inList) {
0979:                setInList(inList);
0980:
0981:                return (T) this ;
0982:            }
0983:
0984:            public void setInList(char... inList) {
0985:                String[] list = null;
0986:                if (inList != null) {
0987:                    list = new String[inList.length];
0988:                    for (int i = 0; i < inList.length; i++) {
0989:                        list[i] = String.valueOf(inList[i]);
0990:                    }
0991:                }
0992:
0993:                setInList(list);
0994:            }
0995:
0996:            public T inList(short... inList) {
0997:                setInList(inList);
0998:
0999:                return (T) this ;
1000:            }
1001:
1002:            public void setInList(short... inList) {
1003:                String[] list = null;
1004:                if (inList != null) {
1005:                    list = new String[inList.length];
1006:                    for (int i = 0; i < inList.length; i++) {
1007:                        list[i] = String.valueOf(inList[i]);
1008:                    }
1009:                }
1010:
1011:                setInList(list);
1012:            }
1013:
1014:            public T inList(long... inList) {
1015:                setInList(inList);
1016:
1017:                return (T) this ;
1018:            }
1019:
1020:            public void setInList(long... inList) {
1021:                String[] list = null;
1022:                if (inList != null) {
1023:                    list = new String[inList.length];
1024:                    for (int i = 0; i < inList.length; i++) {
1025:                        list[i] = String.valueOf(inList[i]);
1026:                    }
1027:                }
1028:
1029:                setInList(list);
1030:            }
1031:
1032:            public T inList(float... inList) {
1033:                setInList(inList);
1034:
1035:                return (T) this ;
1036:            }
1037:
1038:            public void setInList(float... inList) {
1039:                String[] list = null;
1040:                if (inList != null) {
1041:                    list = new String[inList.length];
1042:                    for (int i = 0; i < inList.length; i++) {
1043:                        list[i] = String.valueOf(inList[i]);
1044:                    }
1045:                }
1046:
1047:                setInList(list);
1048:            }
1049:
1050:            public T inList(double... inList) {
1051:                setInList(inList);
1052:
1053:                return (T) this ;
1054:            }
1055:
1056:            public void setInList(double... inList) {
1057:                String[] list = null;
1058:                if (inList != null) {
1059:                    list = new String[inList.length];
1060:                    for (int i = 0; i < inList.length; i++) {
1061:                        list[i] = String.valueOf(inList[i]);
1062:                    }
1063:                }
1064:
1065:                setInList(list);
1066:            }
1067:
1068:            public T inList(Collection inList) {
1069:                setInList(inList);
1070:
1071:                return (T) this ;
1072:            }
1073:
1074:            public void setInList(Collection inList) {
1075:                String[] list = null;
1076:                if (inList != null) {
1077:                    list = new String[inList.size()];
1078:                    int i = 0;
1079:                    for (Object entry : inList) {
1080:                        list[i++] = String.valueOf(entry);
1081:                    }
1082:                }
1083:
1084:                setInList(list);
1085:            }
1086:
1087:            public String[] getInList() {
1088:                return (String[]) mConstraints.get(IN_LIST);
1089:            }
1090:
1091:            public boolean isInList() {
1092:                return mConstraints.containsKey(IN_LIST)
1093:                        && ((String[]) mConstraints.get(IN_LIST)).length > 0;
1094:            }
1095:
1096:            public T rangeBegin(byte value) {
1097:                setRangeBegin(value);
1098:
1099:                return (T) this ;
1100:            }
1101:
1102:            public T rangeBegin(char value) {
1103:                setRangeBegin(value);
1104:
1105:                return (T) this ;
1106:            }
1107:
1108:            public T rangeBegin(short value) {
1109:                setRangeBegin(value);
1110:
1111:                return (T) this ;
1112:            }
1113:
1114:            public T rangeBegin(int value) {
1115:                setRangeBegin(value);
1116:
1117:                return (T) this ;
1118:            }
1119:
1120:            public T rangeBegin(long value) {
1121:                setRangeBegin(value);
1122:
1123:                return (T) this ;
1124:            }
1125:
1126:            public T rangeBegin(float value) {
1127:                setRangeBegin(value);
1128:
1129:                return (T) this ;
1130:            }
1131:
1132:            public T rangeBegin(double value) {
1133:                setRangeBegin(value);
1134:
1135:                return (T) this ;
1136:            }
1137:
1138:            public T rangeBegin(Comparable value) {
1139:                setRangeBegin(value);
1140:
1141:                return (T) this ;
1142:            }
1143:
1144:            public void setRangeBegin(byte value) {
1145:                setRangeBegin(new Byte(value));
1146:            }
1147:
1148:            public void setRangeBegin(char value) {
1149:                setRangeBegin(new Character(value));
1150:            }
1151:
1152:            public void setRangeBegin(short value) {
1153:                setRangeBegin(new Short(value));
1154:            }
1155:
1156:            public void setRangeBegin(int value) {
1157:                setRangeBegin(new Integer(value));
1158:            }
1159:
1160:            public void setRangeBegin(long value) {
1161:                setRangeBegin(new Long(value));
1162:            }
1163:
1164:            public void setRangeBegin(float value) {
1165:                setRangeBegin(new Float(value));
1166:            }
1167:
1168:            public void setRangeBegin(double value) {
1169:                setRangeBegin(new Double(value));
1170:            }
1171:
1172:            public void setRangeBegin(Comparable rangeBegin) {
1173:                if (null == rangeBegin) {
1174:                    mConstraints.remove(RANGE_BEGIN);
1175:                } else {
1176:                    setConstraint(RANGE_BEGIN, rangeBegin);
1177:                }
1178:            }
1179:
1180:            public Comparable getRangeBegin() {
1181:                return (Comparable) mConstraints.get(RANGE_BEGIN);
1182:            }
1183:
1184:            public T rangeEnd(char value) {
1185:                setRangeEnd(value);
1186:
1187:                return (T) this ;
1188:            }
1189:
1190:            public T rangeEnd(byte value) {
1191:                setRangeEnd(value);
1192:
1193:                return (T) this ;
1194:            }
1195:
1196:            public T rangeEnd(double value) {
1197:                setRangeEnd(value);
1198:
1199:                return (T) this ;
1200:            }
1201:
1202:            public T rangeEnd(float value) {
1203:                setRangeEnd(value);
1204:
1205:                return (T) this ;
1206:            }
1207:
1208:            public T rangeEnd(int value) {
1209:                setRangeEnd(value);
1210:
1211:                return (T) this ;
1212:            }
1213:
1214:            public T rangeEnd(long value) {
1215:                setRangeEnd(value);
1216:
1217:                return (T) this ;
1218:            }
1219:
1220:            public T rangeEnd(short value) {
1221:                setRangeEnd(value);
1222:
1223:                return (T) this ;
1224:            }
1225:
1226:            public T rangeEnd(Comparable value) {
1227:                setRangeEnd(value);
1228:
1229:                return (T) this ;
1230:            }
1231:
1232:            public void setRangeEnd(byte value) {
1233:                setRangeEnd(new Byte(value));
1234:            }
1235:
1236:            public void setRangeEnd(char value) {
1237:                setRangeEnd(new Character(value));
1238:            }
1239:
1240:            public void setRangeEnd(short value) {
1241:                setRangeEnd(new Short(value));
1242:            }
1243:
1244:            public void setRangeEnd(int value) {
1245:                setRangeEnd(new Integer(value));
1246:            }
1247:
1248:            public void setRangeEnd(long value) {
1249:                setRangeEnd(new Long(value));
1250:            }
1251:
1252:            public void setRangeEnd(float value) {
1253:                setRangeEnd(new Float(value));
1254:            }
1255:
1256:            public void setRangeEnd(double value) {
1257:                setRangeEnd(new Double(value));
1258:            }
1259:
1260:            public void setRangeEnd(Comparable rangeEnd) {
1261:                if (null == rangeEnd) {
1262:                    mConstraints.remove(RANGE_END);
1263:                } else {
1264:                    setConstraint(RANGE_END, rangeEnd);
1265:                }
1266:            }
1267:
1268:            public Comparable getRangeEnd() {
1269:                return (Comparable) mConstraints.get(RANGE_END);
1270:            }
1271:
1272:            public boolean isRange() {
1273:                return mConstraints.containsKey(RANGE_BEGIN)
1274:                        || mConstraints.containsKey(RANGE_END);
1275:            }
1276:
1277:            public T defaultValue(boolean value) {
1278:                return defaultValue(Boolean.valueOf(value));
1279:            }
1280:
1281:            public T defaultValue(char value) {
1282:                return defaultValue(new Character(value));
1283:            }
1284:
1285:            public T defaultValue(byte value) {
1286:                return defaultValue(new Byte(value));
1287:            }
1288:
1289:            public T defaultValue(short value) {
1290:                return defaultValue(new Short(value));
1291:            }
1292:
1293:            public T defaultValue(int value) {
1294:                return defaultValue(new Integer(value));
1295:            }
1296:
1297:            public T defaultValue(long value) {
1298:                return defaultValue(new Long(value));
1299:            }
1300:
1301:            public T defaultValue(float value) {
1302:                return defaultValue(new Float(value));
1303:            }
1304:
1305:            public T defaultValue(double value) {
1306:                return defaultValue(new Double(value));
1307:            }
1308:
1309:            public T defaultValue(Object value) {
1310:                setDefaultValue(value);
1311:
1312:                return (T) this ;
1313:            }
1314:
1315:            public void setDefaultValue(Object value) {
1316:                if (null == value) {
1317:                    mConstraints.remove(DEFAULT_VALUE);
1318:                } else {
1319:                    setConstraint(DEFAULT_VALUE, value);
1320:                }
1321:            }
1322:
1323:            public Object getDefaultValue() {
1324:                return mConstraints.get(DEFAULT_VALUE);
1325:            }
1326:
1327:            public boolean hasDefaultValue() {
1328:                return mConstraints.containsKey(DEFAULT_VALUE);
1329:            }
1330:
1331:            public T sameAs(String reference) {
1332:                setSameAs(reference);
1333:
1334:                return (T) this ;
1335:            }
1336:
1337:            public void setSameAs(String reference) {
1338:                if (null == reference) {
1339:                    mConstraints.remove(SAME_AS);
1340:                } else {
1341:                    setConstraint(SAME_AS, reference);
1342:                }
1343:            }
1344:
1345:            public String getSameAs() {
1346:                return (String) mConstraints.get(SAME_AS);
1347:            }
1348:
1349:            public boolean isSameAs() {
1350:                return mConstraints.containsKey(SAME_AS);
1351:            }
1352:
1353:            public void setManyToOne() {
1354:                setConstraint(MANY_TO_ONE, new ManyToOne());
1355:            }
1356:
1357:            public void setManyToOne(Class klass) {
1358:                setConstraint(MANY_TO_ONE, new ManyToOne(klass));
1359:            }
1360:
1361:            public void setManyToOne(Class klass, String columnReference) {
1362:                setConstraint(MANY_TO_ONE, new ManyToOne(klass,
1363:                        columnReference, null, null));
1364:            }
1365:
1366:            public void setManyToOne(String table, String columnReference) {
1367:                setConstraint(MANY_TO_ONE, new ManyToOne(table,
1368:                        columnReference, null, null));
1369:            }
1370:
1371:            public void setManyToOne(Class klass, String columnReference,
1372:                    CreateTable.ViolationAction onUpdate,
1373:                    CreateTable.ViolationAction onDelete) {
1374:                setConstraint(MANY_TO_ONE, new ManyToOne(klass,
1375:                        columnReference, onUpdate, onDelete));
1376:            }
1377:
1378:            public void setManyToOne(String table, String columnReference,
1379:                    CreateTable.ViolationAction onUpdate,
1380:                    CreateTable.ViolationAction onDelete) {
1381:                setConstraint(MANY_TO_ONE, new ManyToOne(table,
1382:                        columnReference, onUpdate, onDelete));
1383:            }
1384:
1385:            public ManyToOne getManyToOne() {
1386:                return (ManyToOne) mConstraints.get(MANY_TO_ONE);
1387:            }
1388:
1389:            public T manyToOne() {
1390:                setManyToOne();
1391:
1392:                return (T) this ;
1393:            }
1394:
1395:            public T manyToOne(Class klass) {
1396:                setManyToOne(klass);
1397:
1398:                return (T) this ;
1399:            }
1400:
1401:            public T manyToOne(Class klass, String columnReference) {
1402:                setManyToOne(klass, columnReference);
1403:
1404:                return (T) this ;
1405:            }
1406:
1407:            public T manyToOne(String table, String columnReference) {
1408:                setManyToOne(table, columnReference);
1409:
1410:                return (T) this ;
1411:            }
1412:
1413:            public T manyToOne(Class klass, String columnReference,
1414:                    CreateTable.ViolationAction onUpdate,
1415:                    CreateTable.ViolationAction onDelete) {
1416:                setManyToOne(klass, columnReference, onUpdate, onDelete);
1417:
1418:                return (T) this ;
1419:            }
1420:
1421:            public T manyToOne(String table, String columnReference,
1422:                    CreateTable.ViolationAction onUpdate,
1423:                    CreateTable.ViolationAction onDelete) {
1424:                setManyToOne(table, columnReference, onUpdate, onDelete);
1425:
1426:                return (T) this ;
1427:            }
1428:
1429:            public boolean hasManyToOne() {
1430:                return mConstraints.containsKey(MANY_TO_ONE);
1431:            }
1432:
1433:            public void setManyToOneAssociation() {
1434:                setConstraint(MANY_TO_ONE_ASSOCIATION,
1435:                        new ManyToOneAssociation());
1436:            }
1437:
1438:            public void setManyToOneAssociation(String property) {
1439:                setConstraint(MANY_TO_ONE_ASSOCIATION,
1440:                        new ManyToOneAssociation(property));
1441:            }
1442:
1443:            public void setManyToOneAssociation(Class klass, String property) {
1444:                setConstraint(MANY_TO_ONE_ASSOCIATION,
1445:                        new ManyToOneAssociation(klass, property));
1446:            }
1447:
1448:            public ManyToOneAssociation getManyToOneAssociation() {
1449:                return (ManyToOneAssociation) mConstraints
1450:                        .get(MANY_TO_ONE_ASSOCIATION);
1451:            }
1452:
1453:            public T manyToOneAssociation() {
1454:                setManyToOneAssociation();
1455:
1456:                return (T) this ;
1457:            }
1458:
1459:            public T manyToOneAssociation(String property) {
1460:                setManyToOneAssociation(property);
1461:
1462:                return (T) this ;
1463:            }
1464:
1465:            public T manyToOneAssociation(Class klass, String property) {
1466:                setManyToOneAssociation(klass, property);
1467:
1468:                return (T) this ;
1469:            }
1470:
1471:            public boolean hasManyToOneAssociation() {
1472:                return mConstraints.containsKey(MANY_TO_ONE_ASSOCIATION);
1473:            }
1474:
1475:            public void setManyToMany() {
1476:                setConstraint(MANY_TO_MANY, new ManyToMany());
1477:            }
1478:
1479:            public void setManyToMany(Class klass) {
1480:                setConstraint(MANY_TO_MANY, new ManyToMany(klass));
1481:            }
1482:
1483:            public void setManyToMany(CreateTable.ViolationAction onUpdate,
1484:                    CreateTable.ViolationAction onDelete) {
1485:                setConstraint(MANY_TO_MANY, new ManyToMany(onUpdate, onDelete));
1486:            }
1487:
1488:            public void setManyToMany(Class klass,
1489:                    CreateTable.ViolationAction onUpdate,
1490:                    CreateTable.ViolationAction onDelete) {
1491:                setConstraint(MANY_TO_MANY, new ManyToMany(klass, onUpdate,
1492:                        onDelete));
1493:            }
1494:
1495:            public ManyToMany getManyToMany() {
1496:                return (ManyToMany) mConstraints.get(MANY_TO_MANY);
1497:            }
1498:
1499:            public T manyToMany() {
1500:                setManyToMany();
1501:
1502:                return (T) this ;
1503:            }
1504:
1505:            public T manyToMany(Class klass) {
1506:                setManyToMany(klass);
1507:
1508:                return (T) this ;
1509:            }
1510:
1511:            public T manyToMany(CreateTable.ViolationAction onUpdate,
1512:                    CreateTable.ViolationAction onDelete) {
1513:                setManyToMany(onUpdate, onDelete);
1514:
1515:                return (T) this ;
1516:            }
1517:
1518:            public T manyToMany(Class klass,
1519:                    CreateTable.ViolationAction onUpdate,
1520:                    CreateTable.ViolationAction onDelete) {
1521:                setManyToMany(klass, onUpdate, onDelete);
1522:
1523:                return (T) this ;
1524:            }
1525:
1526:            public boolean hasManyToMany() {
1527:                return mConstraints.containsKey(MANY_TO_MANY);
1528:            }
1529:
1530:            public void setManyToManyAssociation() {
1531:                setConstraint(MANY_TO_MANY_ASSOCIATION,
1532:                        new ManyToManyAssociation());
1533:            }
1534:
1535:            public void setManyToManyAssociation(String property) {
1536:                setConstraint(MANY_TO_MANY_ASSOCIATION,
1537:                        new ManyToManyAssociation(property));
1538:            }
1539:
1540:            public void setManyToManyAssociation(Class klass, String property) {
1541:                setConstraint(MANY_TO_MANY_ASSOCIATION,
1542:                        new ManyToManyAssociation(klass, property));
1543:            }
1544:
1545:            public ManyToManyAssociation getManyToManyAssociation() {
1546:                return (ManyToManyAssociation) mConstraints
1547:                        .get(MANY_TO_MANY_ASSOCIATION);
1548:            }
1549:
1550:            public T manyToManyAssociation() {
1551:                setManyToManyAssociation();
1552:
1553:                return (T) this ;
1554:            }
1555:
1556:            public T manyToManyAssociation(String property) {
1557:                setManyToManyAssociation(property);
1558:
1559:                return (T) this ;
1560:            }
1561:
1562:            public T manyToManyAssociation(Class klass, String property) {
1563:                setManyToManyAssociation(klass, property);
1564:
1565:                return (T) this ;
1566:            }
1567:
1568:            public boolean hasManyToManyAssociation() {
1569:                return mConstraints.containsKey(MANY_TO_MANY_ASSOCIATION);
1570:            }
1571:
1572:            public T format(Format format) {
1573:                setFormat(format);
1574:
1575:                return (T) this ;
1576:            }
1577:
1578:            public void setFormat(Format format) {
1579:                if (null == format) {
1580:                    mConstraints.remove(FORMAT);
1581:                } else {
1582:                    setConstraint(FORMAT, format);
1583:                }
1584:            }
1585:
1586:            public Format getFormat() {
1587:                return (Format) mConstraints.get(FORMAT);
1588:            }
1589:
1590:            public boolean isFormatted() {
1591:                return mConstraints.containsKey(FORMAT);
1592:            }
1593:
1594:            public T file(boolean file) {
1595:                setFile(file);
1596:
1597:                return (T) this ;
1598:            }
1599:
1600:            public void setFile(boolean file) {
1601:                setConstraint(FILE, file);
1602:            }
1603:
1604:            public boolean isFile() {
1605:                return Convert.toBoolean(mConstraints.get(FILE), false);
1606:            }
1607:
1608:            public T sparse(boolean sparse) {
1609:                setSparse(sparse);
1610:
1611:                return (T) this ;
1612:            }
1613:
1614:            public void setSparse(boolean sparse) {
1615:                setConstraint(SPARSE, sparse);
1616:            }
1617:
1618:            public boolean isSparse() {
1619:                return Convert.toBoolean(mConstraints.get(SPARSE), false);
1620:            }
1621:
1622:            /**
1623:             * Sets whether the property should be included in data lists.
1624:             * <p>This is not actually used by the CMF itself, but is very useful when
1625:             * integrating with automatic user interface generation libraries.
1626:             * 
1627:             * @param listed <code>true</code> if the property should be listed; or
1628:             * <p><code>false</code> if it shouldn't
1629:             * @return the current <code>ConstrainedProperty</code> instance
1630:             * @see #setListed(boolean)
1631:             * @see #isListed()
1632:             * @since 1.0
1633:             */
1634:            public T listed(boolean listed) {
1635:                setListed(listed);
1636:
1637:                return (T) this ;
1638:            }
1639:
1640:            /**
1641:             * Sets whether the property should be included in data lists.
1642:             * 
1643:             * @param listed <code>true</code> if the property should be listed; or
1644:             * <p><code>false</code> if it shouldn't
1645:             * @see #listed(boolean)
1646:             * @see #isListed()
1647:             * @since 1.0
1648:             */
1649:            public void setListed(boolean listed) {
1650:                setConstraint(LISTED, listed);
1651:            }
1652:
1653:            /**
1654:             * Retrieves whether the property should be included in data lists.
1655:             * 
1656:             * @return <code>true</code> if the property should be listed; or
1657:             * <p><code>false</code> if it shouldn't
1658:             * @see #listed(boolean)
1659:             * @see #setListed(boolean)
1660:             * @since 1.0
1661:             */
1662:            public boolean isListed() {
1663:                return Convert.toBoolean(mConstraints.get(LISTED), false);
1664:            }
1665:
1666:            /**
1667:             * Sets the position in which the property should be displayed.
1668:             * <p>This is not actually used by the CMF itself, but is very useful when
1669:             * integrating with automatic user interface generation libraries.
1670:             * 
1671:             * @param position an integer value with the position; or
1672:             * <p><code>-1</code> if the property shouldn't be positioned
1673:             * @return the current <code>ConstrainedProperty</code> instance
1674:             * @see #setPosition(int)
1675:             * @see #hasPosition()
1676:             * @see #getPosition()
1677:             * @since 1.0
1678:             */
1679:            public T position(int position) {
1680:                setPosition(position);
1681:
1682:                return (T) this ;
1683:            }
1684:
1685:            /**
1686:             * Sets the position in which the property should be displayed.
1687:             * 
1688:             * @param position an integer value with the position; or
1689:             * <p><code>-1</code> if the property shouldn't be positioned
1690:             * @see #position(int)
1691:             * @see #hasPosition()
1692:             * @see #getPosition()
1693:             * @since 1.0
1694:             */
1695:            public void setPosition(int position) {
1696:                if (position < 0) {
1697:                    mConstraints.remove(POSITION);
1698:                } else {
1699:                    setConstraint(POSITION, position);
1700:                }
1701:            }
1702:
1703:            /**
1704:             * Indicates whether the position of the property is set.
1705:             * 
1706:             * @return <code>true</code> if the property has a position; or
1707:             * <p><code>false</code> if it hasn't
1708:             * @see #position(int)
1709:             * @see #setPosition(int)
1710:             * @see #getPosition()
1711:             * @since 1.0
1712:             */
1713:            public boolean hasPosition() {
1714:                return mConstraints.containsKey(POSITION);
1715:            }
1716:
1717:            /**
1718:             * Retrieves the position in which the property should be displayed.
1719:             * 
1720:             * @return an integer value with the position; or
1721:             * <p><code>-1</code> if the property shouldn't be positioned
1722:             * @see #position(int)
1723:             * @see #setPosition(int)
1724:             * @see #hasPosition()
1725:             * @since 1.0
1726:             */
1727:            public int getPosition() {
1728:                return Convert.toInt(mConstraints.get(POSITION), -1);
1729:            }
1730:
1731:            /**
1732:             * Sets the mime type of the property.
1733:             * <p>Setting this constraint will make the {@link
1734:             * com.uwyn.rife.cmf.dam.ContentQueryManager ContentQueryManager}
1735:             * automatically store the data in this property in the content management
1736:             * back-end. This column will not be stored in a regular database table.
1737:             * All this is handled transparently and automatically.
1738:             * 
1739:             * @param mimeType the <code>MimeType</code> of the property
1740:             * @return the current <code>ConstrainedProperty</code> instance
1741:             * @see #setMimeType(MimeType)
1742:             * @see #hasMimeType()
1743:             * @see #getMimeType()
1744:             * @since 1.0
1745:             */
1746:            public T mimeType(MimeType mimeType) {
1747:                setMimeType(mimeType);
1748:
1749:                return (T) this ;
1750:            }
1751:
1752:            /**
1753:             * Sets the mime type of the property.
1754:             * 
1755:             * @param mimeType the <code>MimeType</code> of the property
1756:             * @see #mimeType(MimeType)
1757:             * @see #hasMimeType()
1758:             * @see #getMimeType()
1759:             * @since 1.0
1760:             */
1761:            public void setMimeType(MimeType mimeType) {
1762:                if (null == mimeType) {
1763:                    mConstraints.remove(MIMETYPE);
1764:                } else {
1765:                    setConstraint(MIMETYPE, mimeType);
1766:                    persistent(false);
1767:                    displayedRaw(true);
1768:                }
1769:            }
1770:
1771:            /**
1772:             * Indicates whether the property has a mime type.
1773:             * 
1774:             * @return <code>true</code> if the property has a mime type; or
1775:             * <p><code>false</code> if it hasn't
1776:             * @see #mimeType(MimeType)
1777:             * @see #setMimeType(MimeType)
1778:             * @see #getMimeType()
1779:             * @since 1.0
1780:             */
1781:            public boolean hasMimeType() {
1782:                return mConstraints.containsKey(MIMETYPE);
1783:            }
1784:
1785:            /**
1786:             * Retrieves the mime type of the property.
1787:             * 
1788:             * @return the mime type of the property; or
1789:             * <p><code>null</code> if the property has no mime type
1790:             * @see #mimeType(MimeType)
1791:             * @see #setMimeType(MimeType)
1792:             * @see #hasMimeType()
1793:             * @since 1.0
1794:             */
1795:            public MimeType getMimeType() {
1796:                return (MimeType) mConstraints.get(MIMETYPE);
1797:            }
1798:
1799:            /**
1800:             * Sets whether the content data of this property should be retrieved
1801:             * automatically from the back-end.
1802:             * <p>This is only useful when the property also has a mime type
1803:             * constraint.
1804:             * <p>It's not recommended to enable this constraint for large data since
1805:             * everything will be stored in memory, only use this for text snippets or
1806:             * something relatively small.
1807:             * 
1808:             * @param autoRetrieved <code>true</code> if the data should be
1809:             * automatically retrieved; or
1810:             * <p><code>false</code> otherwise
1811:             * @return the current <code>ConstrainedProperty</code> instance
1812:             * @see #mimeType(MimeType)
1813:             * @see #setAutoRetrieved(boolean)
1814:             * @see #isAutoRetrieved()
1815:             * @since 1.0
1816:             */
1817:            public T autoRetrieved(boolean autoRetrieved) {
1818:                setAutoRetrieved(autoRetrieved);
1819:
1820:                return (T) this ;
1821:            }
1822:
1823:            /**
1824:             * Sets whether the content data of this property should be retrieved
1825:             * automatically from the back-end.
1826:             * 
1827:             * @param autoRetrieved <code>true</code> if the data should be
1828:             * automatically retrieved; or
1829:             * <p><code>false</code> otherwise
1830:             * @see #autoRetrieved(boolean)
1831:             * @see #isAutoRetrieved()
1832:             * @since 1.0
1833:             */
1834:            public void setAutoRetrieved(boolean autoRetrieved) {
1835:                setConstraint(AUTO_RETRIEVED, autoRetrieved);
1836:            }
1837:
1838:            /**
1839:             * Indicates whether the content data of this property is automatically
1840:             * retrieved from the back-end.
1841:             * 
1842:             * @return <code>true</code> if the data should be automatically
1843:             * retrieved; or
1844:             * <p><code>false</code> otherwise
1845:             * @see #autoRetrieved(boolean)
1846:             * @see #setAutoRetrieved(boolean)
1847:             * @since 1.0
1848:             */
1849:            public boolean isAutoRetrieved() {
1850:                return Convert.toBoolean(mConstraints.get(AUTO_RETRIEVED),
1851:                        false);
1852:            }
1853:
1854:            /**
1855:             * Sets whether the content data of this property is a fragment.
1856:             * <p>This is only useful when the property also has a mime type
1857:             * constraint. A fragment means that it's not a complete document or a
1858:             * file, but rather a small part that is intended to be used within a
1859:             * larger document. For example a HTML snippet. This information is for
1860:             * example important when validating the data.
1861:             * 
1862:             * @param fragment <code>true</code> if the content is a fragment; or
1863:             * <p><code>false</code> otherwise
1864:             * @return the current <code>ConstrainedProperty</code> instance
1865:             * @see #mimeType(MimeType)
1866:             * @see #setFragment(boolean)
1867:             * @see #isFragment()
1868:             * @since 1.0
1869:             */
1870:            public T fragment(boolean fragment) {
1871:                setFragment(fragment);
1872:
1873:                return (T) this ;
1874:            }
1875:
1876:            /**
1877:             * Sets whether the content data of this property is a fragment.
1878:             * 
1879:             * @param fragment <code>true</code> if the content is a fragment; or
1880:             * <p><code>false</code> otherwise
1881:             * @see #fragment(boolean)
1882:             * @see #isFragment()
1883:             * @since 1.0
1884:             */
1885:            public void setFragment(boolean fragment) {
1886:                setConstraint(FRAGMENT, fragment);
1887:            }
1888:
1889:            /**
1890:             * Indicates whether the content data of this property is a fragment.
1891:             * 
1892:             * @return <code>true</code> if the content is a fragment; or
1893:             * <p><code>false</code> otherwise
1894:             * @see #fragment(boolean)
1895:             * @see #setFragment(boolean)
1896:             * @since 1.0
1897:             */
1898:            public boolean isFragment() {
1899:                return Convert.toBoolean(mConstraints.get(FRAGMENT), false);
1900:            }
1901:
1902:            /**
1903:             * Sets the name of the content data of this property.
1904:             * <p>This is only useful when the property also has a mime type
1905:             * constraint.
1906:             * 
1907:             * @param name the name
1908:             * @return the current <code>ConstrainedProperty</code> instance
1909:             * @see #mimeType(MimeType)
1910:             * @see #setName(String)
1911:             * @see #getName()
1912:             * @see #hasName()
1913:             * @since 1.0
1914:             */
1915:            public T name(String name) {
1916:                setName(name);
1917:
1918:                return (T) this ;
1919:            }
1920:
1921:            /**
1922:             * Sets the name of the content data of this property.
1923:             * 
1924:             * @param name the name
1925:             * @see #name(String)
1926:             * @see #getName()
1927:             * @see #hasName()
1928:             * @since 1.0
1929:             */
1930:            public void setName(String name) {
1931:                if (null == name) {
1932:                    mConstraints.remove(NAME);
1933:                } else {
1934:                    setConstraint(NAME, name);
1935:                }
1936:            }
1937:
1938:            /**
1939:             * Retrieves the name of this property.
1940:             * 
1941:             * @return <code>null</code> if the content data has no name; or
1942:             * <p>the name of the content
1943:             * @see #name(String)
1944:             * @see #setName(String)
1945:             * @see #hasName()
1946:             * @since 1.0
1947:             */
1948:            public String getName() {
1949:                return (String) mConstraints.get(NAME);
1950:            }
1951:
1952:            /**
1953:             * Indicates whether this property has a name.
1954:             * 
1955:             * @return <code>true</code> if the property has a name; or
1956:             * <p><code>false</code> otherwise
1957:             * @see #name(String)
1958:             * @see #setName(String)
1959:             * @see #getName()
1960:             * @since 1.0
1961:             */
1962:            public boolean hasName() {
1963:                return mConstraints.containsKey(NAME);
1964:            }
1965:
1966:            /**
1967:             * Sets the repository where the content data of this property will be
1968:             * stored.
1969:             * <p>This is only useful when the property also has a mime type
1970:             * constraint.
1971:             * 
1972:             * @param repository the repository
1973:             * @return the current <code>CmrProperty</code> instance
1974:             * @see #mimeType(MimeType)
1975:             * @see #setRepository(String)
1976:             * @see #getRepository()
1977:             * @see #hasRepository()
1978:             * @since 1.0
1979:             */
1980:            public T repository(String repository) {
1981:                setRepository(repository);
1982:
1983:                return (T) this ;
1984:            }
1985:
1986:            /**
1987:             * Sets the repository where the content data of this property will be
1988:             * stored.
1989:             * 
1990:             * @param repository the repository
1991:             * @see #repository(String)
1992:             * @see #getRepository()
1993:             * @see #hasRepository()
1994:             * @since 1.0
1995:             */
1996:            public void setRepository(String repository) {
1997:                if (null == repository) {
1998:                    mConstraints.remove(REPOSITORY);
1999:                } else {
2000:                    setConstraint(REPOSITORY, repository);
2001:                }
2002:            }
2003:
2004:            /**
2005:             * Retrieves the repository where the content data of this property will
2006:             * be stored.
2007:             * 
2008:             * @return <code>null</code> if no repository has been specified; or
2009:             * <p>the name of the repository
2010:             * @see #repository(String)
2011:             * @see #setRepository(String)
2012:             * @see #hasRepository()
2013:             * @since 1.0
2014:             */
2015:            public String getRepository() {
2016:                return (String) mConstraints.get(REPOSITORY);
2017:            }
2018:
2019:            /**
2020:             * Indicates whether this property will be stored in another repository
2021:             * than the default repository.
2022:             * 
2023:             * @return <code>true</code> if the property will be stored in another
2024:             * repository; or
2025:             * <p><code>false</code> otherwise
2026:             * @see #repository(String)
2027:             * @see #setRepository(String)
2028:             * @see #getRepository()
2029:             * @since 1.0
2030:             */
2031:            public boolean hasRepository() {
2032:                return mConstraints.containsKey(REPOSITORY);
2033:            }
2034:
2035:            /**
2036:             * Sets whether this property has to be used as an ordinal.
2037:             * <p>The value of this property will be handled in the back-end by an
2038:             * {@link com.uwyn.rife.cmf.dam.OrdinalManager OrdinalManager}. It will
2039:             * also enable the {@link
2040:             * com.uwyn.rife.cmf.dam.ContentQueryManager#move(Constrained, String, com.uwyn.rife.cmf.dam.OrdinalManager.Direction)
2041:             * move}, {@link
2042:             * com.uwyn.rife.cmf.dam.ContentQueryManager#up(Constrained, String) up}
2043:             * and {@link
2044:             * com.uwyn.rife.cmf.dam.ContentQueryManager#down(Constrained, String)
2045:             * down} methods in the {@link com.uwyn.rife.cmf.dam.ContentQueryManager
2046:             * ContentQueryManager} to easily reorder data rows in the back-end.
2047:             * 
2048:             * @param ordinal <code>true</code> if this property is an ordinal; or
2049:             * <p><code>false</code> otherwise
2050:             * @return the current <code>ConstrainedProperty</code> instance
2051:             * @see #ordinal(boolean, String)
2052:             * @see #setOrdinal(boolean)
2053:             * @see #setOrdinal(boolean, String)
2054:             * @see #isOrdinal()
2055:             * @since 1.0
2056:             */
2057:            public T ordinal(boolean ordinal) {
2058:                setOrdinal(ordinal);
2059:
2060:                return (T) this ;
2061:            }
2062:
2063:            /**
2064:             * Sets whether this property has to be used as an ordinal with a
2065:             * restricting column.
2066:             * 
2067:             * @param ordinal <code>true</code> if this property is an ordinal; or
2068:             * <p><code>false</code> otherwise
2069:             * @param restriction the name of the restricting column
2070:             * @return the current <code>ConstrainedProperty</code> instance
2071:             * @see #ordinal(boolean)
2072:             * @see #setOrdinal(boolean)
2073:             * @see #setOrdinal(boolean, String)
2074:             * @see #isOrdinal()
2075:             * @see #hasOrdinalRestriction()
2076:             * @see #getOrdinalRestriction()
2077:             * @since 1.0
2078:             */
2079:            public T ordinal(boolean ordinal, String restriction) {
2080:                setOrdinal(ordinal, restriction);
2081:
2082:                return (T) this ;
2083:            }
2084:
2085:            /**
2086:             * Sets whether this property has to be used as an ordinal.
2087:             * 
2088:             * @param ordinal <code>true</code> if this property is an ordinal; or
2089:             * <p><code>false</code> otherwise
2090:             * @see #ordinal(boolean)
2091:             * @see #ordinal(boolean, String)
2092:             * @see #setOrdinal(boolean, String)
2093:             * @see #isOrdinal()
2094:             * @since 1.0
2095:             */
2096:            public void setOrdinal(boolean ordinal) {
2097:                setConstraint(ORDINAL, ordinal);
2098:                mConstraints.remove(ORDINAL_RESTRICTION);
2099:            }
2100:
2101:            /**
2102:             * Sets whether this property has to be used as an ordinal with a
2103:             * restricting column.
2104:             * 
2105:             * @param ordinal <code>true</code> if this property is an ordinal; or
2106:             * <p><code>false</code> otherwise
2107:             * @param restriction the name of the restricting column
2108:             * @see #ordinal(boolean)
2109:             * @see #ordinal(boolean, String)
2110:             * @see #setOrdinal(boolean)
2111:             * @see #isOrdinal()
2112:             * @see #hasOrdinalRestriction()
2113:             * @see #getOrdinalRestriction()
2114:             * @since 1.0
2115:             */
2116:            public void setOrdinal(boolean ordinal, String restriction) {
2117:                setConstraint(ORDINAL, ordinal);
2118:
2119:                if (ordinal) {
2120:                    if (null == restriction) {
2121:                        mConstraints.remove(ORDINAL_RESTRICTION);
2122:                    } else {
2123:                        setConstraint(ORDINAL_RESTRICTION, restriction);
2124:                    }
2125:                } else {
2126:                    mConstraints.remove(ORDINAL_RESTRICTION);
2127:                }
2128:            }
2129:
2130:            /**
2131:             * Indicates whether this property has to be used as an ordinal.
2132:             * 
2133:             * @return <code>true</code> if this property is an ordinal; or
2134:             * <p><code>false</code> otherwise
2135:             * @see #ordinal(boolean)
2136:             * @see #ordinal(boolean, String)
2137:             * @see #setOrdinal(boolean)
2138:             * @see #setOrdinal(boolean, String)
2139:             * @since 1.0
2140:             */
2141:            public boolean isOrdinal() {
2142:                return Convert.toBoolean(mConstraints.get(ORDINAL), false);
2143:            }
2144:
2145:            /**
2146:             * Indicates whether this property has an ordinal restricting column.
2147:             * 
2148:             * @return <code>true</code> if this property has an ordinal restricting
2149:             * column; or
2150:             * <p><code>false</code> otherwise
2151:             * @see #ordinal(boolean, String)
2152:             * @see #setOrdinal(boolean, String)
2153:             * @see #getOrdinalRestriction()
2154:             * @since 1.0
2155:             */
2156:            public boolean hasOrdinalRestriction() {
2157:                return mConstraints.containsKey(ORDINAL_RESTRICTION);
2158:            }
2159:
2160:            /**
2161:             * Retrieves the ordinal restriction of this property.
2162:             * 
2163:             * @return the name of the ordinal restricting column; or
2164:             * <p><code>null</code> if no ordinal restricting column has been defined
2165:             * @see #ordinal(boolean, String)
2166:             * @see #setOrdinal(boolean, String)
2167:             * @see #hasOrdinalRestriction()
2168:             * @since 1.0
2169:             */
2170:            public String getOrdinalRestriction() {
2171:                return (String) mConstraints.get(ORDINAL_RESTRICTION);
2172:            }
2173:
2174:            /**
2175:             * Sets a named content attribute for this property that will be converted
2176:             * internally to a <code>String</code> value.
2177:             * 
2178:             * @param name the name of the attribute
2179:             * @param value the value of the attribute
2180:             * @return the current <code>Content</code> instance
2181:             * @see #contentAttribute(String, String)
2182:             * @see #getContentAttributes()
2183:             * @since 1.0
2184:             */
2185:            public T contentAttribute(String name, boolean value) {
2186:                return contentAttribute(name, String.valueOf(value));
2187:            }
2188:
2189:            /**
2190:             * Sets a named content attribute for this property that will be converted
2191:             * internally to a <code>String</code> value.
2192:             * 
2193:             * @param name the name of the attribute
2194:             * @param value the value of the attribute
2195:             * @return the current <code>Content</code> instance
2196:             * @see #contentAttribute(String, String)
2197:             * @see #getContentAttributes()
2198:             * @since 1.0
2199:             */
2200:            public T contentAttribute(String name, char value) {
2201:                return contentAttribute(name, String.valueOf(value));
2202:            }
2203:
2204:            /**
2205:             * Sets a named content attribute for this property that will be converted
2206:             * internally to a <code>String</code> value.
2207:             * 
2208:             * @param name the name of the attribute
2209:             * @param value the value of the attribute
2210:             * @return the current <code>Content</code> instance
2211:             * @see #contentAttribute(String, String)
2212:             * @see #getContentAttributes()
2213:             * @since 1.0
2214:             */
2215:            public T contentAttribute(String name, byte value) {
2216:                return contentAttribute(name, String.valueOf(value));
2217:            }
2218:
2219:            /**
2220:             * Sets a named content attribute for this property that will be converted
2221:             * internally to a <code>String</code> value.
2222:             * 
2223:             * @param name the name of the attribute
2224:             * @param value the value of the attribute
2225:             * @return the current <code>Content</code> instance
2226:             * @see #contentAttribute(String, String)
2227:             * @see #getContentAttributes()
2228:             * @since 1.0
2229:             */
2230:            public T contentAttribute(String name, short value) {
2231:                return contentAttribute(name, String.valueOf(value));
2232:            }
2233:
2234:            /**
2235:             * Sets a named content attribute for this property that will be converted
2236:             * internally to a <code>String</code> value.
2237:             * 
2238:             * @param name the name of the attribute
2239:             * @param value the value of the attribute
2240:             * @return the current <code>Content</code> instance
2241:             * @see #contentAttribute(String, String)
2242:             * @see #getContentAttributes()
2243:             * @since 1.0
2244:             */
2245:            public T contentAttribute(String name, int value) {
2246:                return contentAttribute(name, String.valueOf(value));
2247:            }
2248:
2249:            /**
2250:             * Sets a named content attribute for this property that will be converted
2251:             * internally to a <code>String</code> value.
2252:             * 
2253:             * @param name the name of the attribute
2254:             * @param value the value of the attribute
2255:             * @return the current <code>Content</code> instance
2256:             * @see #contentAttribute(String, String)
2257:             * @see #getContentAttributes()
2258:             * @since 1.0
2259:             */
2260:            public T contentAttribute(String name, long value) {
2261:                return contentAttribute(name, String.valueOf(value));
2262:            }
2263:
2264:            /**
2265:             * Sets a named content attribute for this property that will be converted
2266:             * internally to a <code>String</code> value.
2267:             * 
2268:             * @param name the name of the attribute
2269:             * @param value the value of the attribute
2270:             * @return the current <code>Content</code> instance
2271:             * @see #contentAttribute(String, String)
2272:             * @see #getContentAttributes()
2273:             * @since 1.0
2274:             */
2275:            public T contentAttribute(String name, float value) {
2276:                return contentAttribute(name, String.valueOf(value));
2277:            }
2278:
2279:            /**
2280:             * Sets a named content attribute for this property that will be converted
2281:             * internally to a <code>String</code> value.
2282:             * 
2283:             * @param name the name of the attribute
2284:             * @param value the value of the attribute
2285:             * @return the current <code>Content</code> instance
2286:             * @see #contentAttribute(String, String)
2287:             * @see #getContentAttributes()
2288:             * @since 1.0
2289:             */
2290:            public T contentAttribute(String name, double value) {
2291:                return contentAttribute(name, String.valueOf(value));
2292:            }
2293:
2294:            /**
2295:             * Sets a named content attribute for this property.
2296:             * <p>This is only useful when the property also has a mime type
2297:             * constraint.
2298:             * <p>A content attribute provides additional meta data about how you want
2299:             * to store the content data after loading, this can for example be image
2300:             * dimensions.
2301:             * 
2302:             * @param name the name of the attribute
2303:             * @param value the value of the attribute
2304:             * @return the current <code>Content</code> instance
2305:             * @see #mimeType(MimeType)
2306:             * @see #getContentAttributes()
2307:             * @since 1.0
2308:             */
2309:            @SuppressWarnings("unchecked")
2310:            public T contentAttribute(String name, String value) {
2311:                HashMap<String, String> content_attributes = (HashMap<String, String>) mConstraints
2312:                        .get(CONTENT_ATTRIBUTES);
2313:                if (null == content_attributes) {
2314:                    content_attributes = new HashMap<String, String>();
2315:                    setConstraint(CONTENT_ATTRIBUTES, content_attributes);
2316:                }
2317:                content_attributes.put(name, value);
2318:
2319:                return (T) this ;
2320:            }
2321:
2322:            /**
2323:             * Retrieves the map of named content attributes for this property.
2324:             * 
2325:             * @return the map of named content attributes; or
2326:             * <p><code>null</code> if no attributes are present
2327:             * @see #contentAttribute(String, String)
2328:             * @since 1.0
2329:             */
2330:            @SuppressWarnings("unchecked")
2331:            public Map<String, String> getContentAttributes() {
2332:                return (HashMap<String, String>) mConstraints
2333:                        .get(CONTENT_ATTRIBUTES);
2334:            }
2335:
2336:            /**
2337:             * Sets a content transformer for this property.
2338:             * <p>This is only useful when the property also has a mime type
2339:             * constraint.
2340:             * 
2341:             * @param transformer the content transformer
2342:             * @return the current <code>Content</code> instance
2343:             * @see #mimeType(MimeType)
2344:             * @see #setTransformer(ContentTransformer)
2345:             * @see #hasTransformer()
2346:             * @see #getTransformer()
2347:             * @since 1.0
2348:             */
2349:            public T transformer(ContentTransformer transformer) {
2350:                setTransformer(transformer);
2351:
2352:                return (T) this ;
2353:            }
2354:
2355:            /**
2356:             * Sets a content transformer for this property.
2357:             * 
2358:             * @param transformer the content transformer
2359:             * @see #mimeType(MimeType)
2360:             * @see #transformer(ContentTransformer)
2361:             * @see #hasTransformer()
2362:             * @see #getTransformer()
2363:             * @since 1.0
2364:             */
2365:            public void setTransformer(ContentTransformer transformer) {
2366:                if (null == transformer) {
2367:                    mConstraints.remove(TRANSFORMER);
2368:                } else {
2369:                    setConstraint(TRANSFORMER, transformer);
2370:                }
2371:            }
2372:
2373:            /**
2374:             * Indicates whether this property has a content transformer.
2375:             * 
2376:             * @return <code>true</code> if this property has a content transformer;
2377:             * or
2378:             * <p><code>false</code> otherwise
2379:             * @see #transformer(ContentTransformer)
2380:             * @see #setTransformer(ContentTransformer)
2381:             * @see #getTransformer()
2382:             * @since 1.0
2383:             */
2384:            public boolean hasTransformer() {
2385:                return mConstraints.containsKey(TRANSFORMER);
2386:            }
2387:
2388:            /**
2389:             * Retrieves the content transformer of this property.
2390:             * 
2391:             * @return the requested content transformer; or
2392:             * <p><code>null</code> if no content transformer has been defined
2393:             * @see #transformer(ContentTransformer)
2394:             * @see #setTransformer(ContentTransformer)
2395:             * @see #hasTransformer()
2396:             * @since 1.0
2397:             */
2398:            public ContentTransformer getTransformer() {
2399:                return (ContentTransformer) mConstraints.get(TRANSFORMER);
2400:            }
2401:
2402:            /**
2403:             * Sets the cached loaded data.
2404:             * <p>This is used internally and should never be used explicitly by a
2405:             * developer, see {@link
2406:             * com.uwyn.rife.cmf.Content#cachedLoadedData(Object)
2407:             * Content.cachedLoadedData(Object)} for more information.
2408:             * 
2409:             * @param data the loaded data
2410:             * @see #getCachedLoadedData()
2411:             * @since 1.0
2412:             */
2413:            public void setCachedLoadedData(Object data) {
2414:                if (null == data) {
2415:                    synchronized (mConstraints) {
2416:                        mConstraints.remove(CACHED_LOADED_DATA);
2417:                    }
2418:                } else {
2419:                    setConstraint(CACHED_LOADED_DATA, data);
2420:                }
2421:            }
2422:
2423:            /**
2424:             * Retrieves the cached loaded content data.
2425:             * 
2426:             * @return the cached loaded content data; or
2427:             * <p><code>null</code> if no loaded content data has been cached
2428:             * @see #setCachedLoadedData(Object)
2429:             * @since 1.0
2430:             */
2431:            public Object getCachedLoadedData() {
2432:                return mConstraints.get(CACHED_LOADED_DATA);
2433:            }
2434:
2435:            /**
2436:             * Sets the data of a particular constraint in a generic
2437:             * fashion.
2438:             * <p>Note that it's not recommended to use this to set any of
2439:             * the standard constraints since none of the additional logic
2440:             * and checks are executed.
2441:             * 
2442:             * @see #constraint
2443:             * @see #getConstraint
2444:             * @see #getConstraints
2445:             * @since 1.4
2446:             */
2447:            public void setConstraint(String name, Object constraintData) {
2448:                synchronized (mConstraints) {
2449:                    mConstraints.put(name, constraintData);
2450:                }
2451:                fireConstraintSet(name, constraintData);
2452:            }
2453:
2454:            /**
2455:             * Sets the data of a particular constraint in a generic
2456:             * fashion.
2457:             * <p> Note that it's not recommended to use this to set any of
2458:             * the standard constraints since none of the additional logic
2459:             * and checks are executed.
2460:             * 
2461:             * @return the current <code>Content</code> instance
2462:             * @see #setConstraint
2463:             * @see #getConstraint
2464:             * @see #getConstraints
2465:             * @since 1.4
2466:             */
2467:            public T constraint(String name, Object constraintData) {
2468:                setConstraint(name, constraintData);
2469:
2470:                return (T) this ;
2471:            }
2472:
2473:            /**
2474:             * Retrieves the value of a particular constraint in a
2475:             * generic fashion
2476:             * 
2477:             * @return the data of a particular constraint; or
2478:             * <p><code>null</code> if nothing has been registered for
2479:             * that constraint
2480:             * @see #setConstraint
2481:             * @see #constraint
2482:             * @see #getConstraints
2483:             * @since 1.4
2484:             */
2485:            public Object getConstraint(String name) {
2486:                return mConstraints.get(name);
2487:            }
2488:
2489:            /**
2490:             * Retrieves the map of all the constraints.
2491:             * 
2492:             * @return the map with all the registered constraints
2493:             * @see #setConstraint
2494:             * @see #constraint
2495:             * @see #getConstraint
2496:             * @since 1.4
2497:             */
2498:            public Map<String, Object> getConstraints() {
2499:                return mConstraints;
2500:            }
2501:
2502:            public ConstrainedProperty clone() {
2503:                ConstrainedProperty new_instance = null;
2504:                try {
2505:                    new_instance = (ConstrainedProperty) super .clone();
2506:
2507:                    new_instance.mConstraints = new HashMap<String, Object>(
2508:                            mConstraints);
2509:
2510:                    if (mListeners != null) {
2511:                        new_instance.mListeners = new ArrayList<ConstrainedPropertyListener>(
2512:                                mListeners);
2513:                    }
2514:                } catch (CloneNotSupportedException e) {
2515:                    new_instance = null;
2516:                }
2517:
2518:                return new_instance;
2519:            }
2520:
2521:            public class ManyToOne implements  Cloneable {
2522:                private String mColumn = null;
2523:                private String mTable = null;
2524:                private String mDerivedTable = null;
2525:                private Class mClass = null;
2526:                private CreateTable.ViolationAction mOnUpdate = null;
2527:                private CreateTable.ViolationAction mOnDelete = null;
2528:
2529:                public ManyToOne() {
2530:                    this ((Class) null, null, null, null);
2531:                }
2532:
2533:                public ManyToOne(Class klass) {
2534:                    this (klass, null, null, null);
2535:                }
2536:
2537:                public ManyToOne(String table, String column,
2538:                        CreateTable.ViolationAction onUpdate,
2539:                        CreateTable.ViolationAction onDelete) {
2540:                    mColumn = column;
2541:                    mTable = table;
2542:                    mOnUpdate = onUpdate;
2543:                    mOnDelete = onDelete;
2544:                }
2545:
2546:                public ManyToOne(Class klass, String column,
2547:                        CreateTable.ViolationAction onUpdate,
2548:                        CreateTable.ViolationAction onDelete) {
2549:                    this ((String) null, column, onUpdate, onDelete);
2550:                    mClass = klass;
2551:                }
2552:
2553:                public String getDerivedTable() {
2554:                    if (null == mDerivedTable) {
2555:                        if (mTable != null) {
2556:                            mDerivedTable = mTable;
2557:                        }
2558:
2559:                        if (mClass != null) {
2560:                            mDerivedTable = ClassUtils.shortenClassName(mClass);
2561:                        }
2562:
2563:                    }
2564:
2565:                    return mDerivedTable;
2566:                }
2567:
2568:                public void setColumn(String column) {
2569:                    mColumn = column;
2570:                }
2571:
2572:                public String getColumn() {
2573:                    return mColumn;
2574:                }
2575:
2576:                public void setTable(String table) {
2577:                    mDerivedTable = null;
2578:                    mTable = table;
2579:                }
2580:
2581:                public String getTable() {
2582:                    return mTable;
2583:                }
2584:
2585:                public void setAssociatedClass(Class klass) {
2586:                    mDerivedTable = null;
2587:                    mClass = klass;
2588:                }
2589:
2590:                public Class getAssociatedClass() {
2591:                    return mClass;
2592:                }
2593:
2594:                public void setOnUpdate(CreateTable.ViolationAction onUpdate) {
2595:                    mOnUpdate = onUpdate;
2596:                }
2597:
2598:                public CreateTable.ViolationAction getOnUpdate() {
2599:                    return mOnUpdate;
2600:                }
2601:
2602:                public void setOnDelete(CreateTable.ViolationAction onDelete) {
2603:                    mOnDelete = onDelete;
2604:                }
2605:
2606:                public CreateTable.ViolationAction getOnDelete() {
2607:                    return mOnDelete;
2608:                }
2609:
2610:                public ManyToOne clone() {
2611:                    ManyToOne new_instance = null;
2612:                    try {
2613:                        new_instance = (ManyToOne) super .clone();
2614:                    } catch (CloneNotSupportedException e) {
2615:                        new_instance = null;
2616:                    }
2617:
2618:                    return new_instance;
2619:                }
2620:            }
2621:
2622:            public class ManyToOneAssociation implements  Cloneable {
2623:                private Class mClass = null;
2624:                private String mProperty = null;
2625:
2626:                public ManyToOneAssociation() {
2627:                }
2628:
2629:                public ManyToOneAssociation(String property) {
2630:                    mProperty = property;
2631:                }
2632:
2633:                public ManyToOneAssociation(Class klass, String property) {
2634:                    this (property);
2635:                    mClass = klass;
2636:                }
2637:
2638:                public void setMainClass(Class klass) {
2639:                    mClass = klass;
2640:                }
2641:
2642:                public Class getMainClass() {
2643:                    return mClass;
2644:                }
2645:
2646:                public void setMainProperty(String property) {
2647:                    mProperty = property;
2648:                }
2649:
2650:                public String getMainProperty() {
2651:                    return mProperty;
2652:                }
2653:
2654:                public ManyToOneAssociation clone() {
2655:                    ManyToOneAssociation new_instance = null;
2656:                    try {
2657:                        new_instance = (ManyToOneAssociation) super .clone();
2658:                    } catch (CloneNotSupportedException e) {
2659:                        new_instance = null;
2660:                    }
2661:
2662:                    return new_instance;
2663:                }
2664:            }
2665:
2666:            public class ManyToMany implements  Cloneable {
2667:                private Class mClass = null;
2668:                private CreateTable.ViolationAction mOnUpdate = null;
2669:                private CreateTable.ViolationAction mOnDelete = null;
2670:
2671:                public ManyToMany() {
2672:                    this (null, null, null);
2673:                }
2674:
2675:                public ManyToMany(Class klass) {
2676:                    this (klass, null, null);
2677:                }
2678:
2679:                public ManyToMany(CreateTable.ViolationAction onUpdate,
2680:                        CreateTable.ViolationAction onDelete) {
2681:                    this (null, onUpdate, onDelete);
2682:                    mOnUpdate = onUpdate;
2683:                    mOnDelete = onDelete;
2684:                }
2685:
2686:                public ManyToMany(Class klass,
2687:                        CreateTable.ViolationAction onUpdate,
2688:                        CreateTable.ViolationAction onDelete) {
2689:                    mOnUpdate = onUpdate;
2690:                    mOnDelete = onDelete;
2691:                    mClass = klass;
2692:                }
2693:
2694:                public void setAssociatedClass(Class klass) {
2695:                    mClass = klass;
2696:                }
2697:
2698:                public Class getAssociatedClass() {
2699:                    return mClass;
2700:                }
2701:
2702:                public void setOnUpdate(CreateTable.ViolationAction onUpdate) {
2703:                    mOnUpdate = onUpdate;
2704:                }
2705:
2706:                public CreateTable.ViolationAction getOnUpdate() {
2707:                    return mOnUpdate;
2708:                }
2709:
2710:                public void setOnDelete(CreateTable.ViolationAction onDelete) {
2711:                    mOnDelete = onDelete;
2712:                }
2713:
2714:                public CreateTable.ViolationAction getOnDelete() {
2715:                    return mOnDelete;
2716:                }
2717:
2718:                public ManyToMany clone() {
2719:                    ManyToMany new_instance = null;
2720:                    try {
2721:                        new_instance = (ManyToMany) super .clone();
2722:                    } catch (CloneNotSupportedException e) {
2723:                        new_instance = null;
2724:                    }
2725:
2726:                    return new_instance;
2727:                }
2728:            }
2729:
2730:            public class ManyToManyAssociation implements  Cloneable {
2731:                private Class mClass = null;
2732:                private String mProperty = null;
2733:
2734:                public ManyToManyAssociation() {
2735:                }
2736:
2737:                public ManyToManyAssociation(String property) {
2738:                    mProperty = property;
2739:                }
2740:
2741:                public ManyToManyAssociation(Class klass, String property) {
2742:                    this (property);
2743:                    mClass = klass;
2744:                }
2745:
2746:                public void setAssociatedClass(Class klass) {
2747:                    mClass = klass;
2748:                }
2749:
2750:                public Class getAssociatedClass() {
2751:                    return mClass;
2752:                }
2753:
2754:                public void setAssociatedProperty(String property) {
2755:                    mProperty = property;
2756:                }
2757:
2758:                public String getAssociatedProperty() {
2759:                    return mProperty;
2760:                }
2761:
2762:                public ManyToManyAssociation clone() {
2763:                    ManyToManyAssociation new_instance = null;
2764:                    try {
2765:                        new_instance = (ManyToManyAssociation) super .clone();
2766:                    } catch (CloneNotSupportedException e) {
2767:                        new_instance = null;
2768:                    }
2769:
2770:                    return new_instance;
2771:                }
2772:            }
2773:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.