| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package net.sf.beanform.integration; |
| 16 |
|
|
| 17 |
|
import java.util.SortedMap; |
| 18 |
|
import java.util.TreeMap; |
| 19 |
|
|
| 20 |
|
import javax.persistence.Basic; |
| 21 |
|
import javax.persistence.Column; |
| 22 |
|
|
| 23 |
|
import net.sf.beanform.prop.BeanProperty; |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
13 |
public class Ejb3Integrator implements Integrator { |
| 32 |
|
|
| 33 |
|
public static final boolean COLUMN_NULLABLE_DEFAULT = true; |
| 34 |
|
public static final int COLUMN_LENGTH_DEFAULT = 255; |
| 35 |
|
public static final boolean BASIC_OPTIONAL_DEFAULT = true; |
| 36 |
|
|
| 37 |
|
public SortedMap<String, String> getValidation( BeanProperty prop ) { |
| 38 |
|
|
| 39 |
180 |
SortedMap<String, String> validations = new TreeMap<String, String>(); |
| 40 |
|
|
| 41 |
180 |
Column c = prop.getAnnotation( Column.class ); |
| 42 |
180 |
if( c != null ) { |
| 43 |
6 |
if( c.nullable() == false ) { |
| 44 |
2 |
validations.put( REQUIRED, REQUIRED ); |
| 45 |
|
} |
| 46 |
6 |
if( prop.isString() ) { |
| 47 |
6 |
int maxLength = c.length(); |
| 48 |
6 |
validations.put( MAX_LENGTH, MAX_LENGTH + "=" + maxLength ); |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
|
| 52 |
180 |
Basic b = prop.getAnnotation( Basic.class ); |
| 53 |
180 |
if( b != null ) { |
| 54 |
2 |
if( b.optional() == false ) { |
| 55 |
1 |
validations.put( REQUIRED, REQUIRED ); |
| 56 |
|
} |
| 57 |
|
} |
| 58 |
|
|
| 59 |
180 |
return validations; |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
public Integer getMaxLength( BeanProperty prop ) { |
| 63 |
|
|
| 64 |
75 |
Integer maxLength = null; |
| 65 |
|
|
| 66 |
75 |
Column c = prop.getAnnotation( Column.class ); |
| 67 |
75 |
if( c != null ) { |
| 68 |
17 |
maxLength = c.length(); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
75 |
return maxLength; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
public boolean isNullable( BeanProperty prop ) { |
| 75 |
|
|
| 76 |
14 |
boolean nullable = true; |
| 77 |
|
|
| 78 |
14 |
Column c = prop.getAnnotation( Column.class ); |
| 79 |
14 |
if( c != null ) { |
| 80 |
3 |
if( c.nullable() == false ) { |
| 81 |
1 |
nullable = false; |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|
| 85 |
14 |
Basic b = prop.getAnnotation( Basic.class ); |
| 86 |
14 |
if( b != null ) { |
| 87 |
2 |
if( b.optional() == false ) { |
| 88 |
1 |
nullable = false; |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
|
| 92 |
14 |
return nullable; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
} |