1 16 package org.outerj.daisy.repository.commonimpl.schema; 17 18 import java.math.BigDecimal ; 19 import java.util.Date ; 20 import java.util.GregorianCalendar ; 21 import java.util.Locale ; 22 23 import org.outerj.daisy.repository.ValueType; 24 import org.outerj.daisy.repository.VariantKey; 25 import org.outerj.daisy.repository.schema.StaticListItem; 26 import org.outerx.daisy.x10.ListItemDocument; 27 28 31 public class StaticListItemImpl implements StaticListItem { 32 private Object value; 33 private LocaleMap labelMap = new LocaleMap(); 34 private IntimateAccess intimateAccess = new IntimateAccess(); 35 private SchemaStrategy creatingStrategy = null; 36 private FieldTypeImpl owner; 37 private ValueType valueType; 38 private long localizedLabelId = -1; 39 40 44 public StaticListItemImpl(Object value, ValueType valueType, SchemaStrategy creatingStrategy, 45 FieldTypeImpl owner) { 46 this.value = value; 47 this.creatingStrategy = creatingStrategy; 48 this.valueType = valueType; 49 this.owner = owner; 50 } 51 52 public Object getValue() { 53 return value; 54 } 55 56 public void setLabel(Locale locale, String label) { 57 if (owner.isReadOnly()) 58 throw new RuntimeException (FieldTypeImpl.READ_ONLY_MESSAGE); 59 60 labelMap.put(locale, label); 61 } 62 63 public String getLabel(Locale locale) { 64 return (String ) labelMap.get(locale); 65 } 66 67 public String getLabelExact(Locale locale) { 68 return (String ) labelMap.getExact(locale); 69 } 70 71 public void setValue(Object value) { 72 if (owner.isReadOnly()) 73 throw new RuntimeException (FieldTypeImpl.READ_ONLY_MESSAGE); 74 75 this.value = value; 76 } 77 78 public IntimateAccess getIntimateAccess(SchemaStrategy strategy) { 79 if (strategy == creatingStrategy) { 80 return intimateAccess; 81 } else { 82 return null; 83 } 84 } 85 86 public class IntimateAccess { 87 private IntimateAccess() { 88 } 89 90 public LocaleMap getLabels() { 91 return labelMap; 92 } 93 94 public void setLocalizedLabelId(long localizedLabelId) { 95 StaticListItemImpl.this.localizedLabelId = localizedLabelId; 96 } 97 98 public long getLocalizedLabelId() { 99 return localizedLabelId; 100 } 101 } 102 103 public ListItemDocument getXml() { 104 ListItemDocument listItemDocument = 105 ListItemDocument.Factory.newInstance(); 106 ListItemDocument.ListItem listItem = listItemDocument.addNewListItem(); 107 108 listItem.setLabels(labelMap.getAsLabelsXml()); 109 110 if (valueType == ValueType.STRING) { 111 listItem.setString((String ) value); 112 } else if (valueType == ValueType.DATE) { 113 GregorianCalendar calendar = new GregorianCalendar (); 114 calendar.setTime((Date ) value); 115 listItem.setDate(calendar); 116 } else if (valueType == ValueType.DATETIME) { 117 GregorianCalendar calendar = new GregorianCalendar (); 118 calendar.setTime((Date ) value); 119 listItem.setDateTime(calendar); 120 } else if (valueType == ValueType.DECIMAL) { 121 listItem.setDecimal((BigDecimal ) value); 122 } else if (valueType == ValueType.DOUBLE) { 123 listItem.setDouble(((Double ) value).doubleValue()); 124 } else if (valueType == ValueType.LONG) { 125 listItem.setLong(((Long ) value).longValue()); 126 } else if (valueType == ValueType.BOOLEAN) { 127 listItem.setBoolean(((Boolean )value).booleanValue()); 128 } else if (valueType == ValueType.LINK) { 129 ListItemDocument.ListItem.Link link = listItem.addNewLink(); 130 VariantKey variantKey = (VariantKey)value; 131 link.setDocumentId(variantKey.getDocumentId()); 132 link.setBranchId(variantKey.getBranchId()); 133 link.setLanguageId(variantKey.getLanguageId()); 134 } else { 135 throw new RuntimeException ("Unsupported ValueType: " + valueType); 136 } 137 return listItemDocument; 138 } 139 } 140 | Popular Tags |