@Override public Iterable<ReferenceInfo> getReferenceInfo() { List<ReferenceInfo> result = new ArrayList<ReferenceInfo>(); String parentId = getParentId(); result.add(new ReferenceInfo(parentId, DynamicType.class)); DynamicTypeImpl type = getType(); for (Map.Entry<String, List<String>> entry : data.entrySet()) { String key = entry.getKey(); Attribute attribute = type.getAttribute(key); if (attribute == null) { continue; } Class<? extends Entity> refType = attribute.getRefType(); if (refType == null) { continue; } List<String> values = entry.getValue(); if (values != null) { for (String value : values) { result.add(new ReferenceInfo(value, refType)); } } } return result; }
public String format(Locale locale, String annotationName) { DynamicTypeImpl type = getType(); ParsedText parsedAnnotation = type.getParsedAnnotation(annotationName); if (parsedAnnotation == null) { return ""; } EvalContext evalContext = type.createEvalContext(locale, annotationName, this); String nameString = parsedAnnotation.formatName(evalContext).trim(); return nameString; }
public String format(Locale locale, String annotationName) { DynamicTypeImpl type = (DynamicTypeImpl) getType(); ParsedText parsedAnnotation = type.getParsedAnnotation(annotationName); if (parsedAnnotation == null) { return ""; } EvalContext evalContext = new EvalContext(locale, annotationName, Collections.singletonList(this)); String nameString = parsedAnnotation.formatName(evalContext).trim(); return nameString; }
public DynamicTypeImpl clone() { DynamicTypeImpl clone = new DynamicTypeImpl(); super.deepClone(clone); clone.permissions.clear(); for (PermissionImpl perm : permissions) { PermissionImpl permClone = perm.clone(); clone.permissions.add(permClone); } clone.lastChanged = lastChanged; clone.createDate = createDate; clone.name = (MultiLanguageName) name.clone(); clone.key = key; for (AttributeImpl att : clone.getSubEntities()) { ((AttributeImpl) att).setParent(clone); } clone.annotations = new LinkedHashMap<String, ParsedText>(); DynamicTypeParseContext parseContext = new DynamicTypeParseContext(clone); for (Map.Entry<String, ParsedText> entry : annotations.entrySet()) { String annotation = entry.getKey(); ParsedText parsedAnnotation = entry.getValue(); String parsedValue = parsedAnnotation.getExternalRepresentation(parseContext); try { clone.setAnnotation(annotation, parsedValue); } catch (IllegalAnnotationException e) { throw new IllegalStateException("Can't parse annotation back", e); } } return clone; }
public String getName(Locale locale, String keyNameFormat) { DynamicTypeImpl type = (DynamicTypeImpl) getType(); ParsedText parsedAnnotation = type.getParsedAnnotation(keyNameFormat); if (parsedAnnotation == null) { return type.toString(); } if (nameString != null) { if (parsedAnnotation.equals(lastParsedAnnotation)) return nameString; } lastParsedAnnotation = parsedAnnotation; nameString = format(locale, keyNameFormat); return nameString; }
public Attribute findAttribute(DynamicTypeImpl type) { Attribute attribute = type.findAttributeForId(id); if (attribute != null) { return attribute; } return null; }
/** * @param newType * @param attributeId */ public boolean hasAttributeChanged(DynamicTypeImpl newType, String attributeId) { Attribute oldAttribute = findAttributeForId(attributeId); Attribute newAttribute = newType.findAttributeForId(attributeId); if (oldAttribute == null && newAttribute == null) { return false; } if ((newAttribute == null) || (oldAttribute == null)) { return true; } String newKey = newAttribute.getKey(); String oldKey = oldAttribute.getKey(); if (!newKey.equals(oldKey)) { return true; } if (!newAttribute.getType().equals(oldAttribute.getType())) { return true; } { String[] keys = newAttribute.getConstraintKeys(); String[] oldKeys = oldAttribute.getConstraintKeys(); if (keys.length != oldKeys.length) { return true; } for (int i = 0; i < keys.length; i++) { if (!keys[i].equals(oldKeys[i])) return true; Object oldConstr = oldAttribute.getConstraint(keys[i]); Object newConstr = newAttribute.getConstraint(keys[i]); if (oldConstr == null && newConstr == null) continue; if (oldConstr == null || newConstr == null) return true; if (!oldConstr.equals(newConstr)) return true; } } return false; }
public boolean needsChange(DynamicType newType) { if (!hasType(newType)) { return false; } DynamicTypeImpl type = getType(); if (!newType.getKey().equals(type.getKey())) return true; for (String key : data.keySet()) { Attribute attribute = getType().getAttribute(key); if (attribute == null) { return true; } String attributeId = attribute.getId(); if (type.hasAttributeChanged((DynamicTypeImpl) newType, attributeId)) return true; } return false; }
public Function resolveVariableFunction(String variableName) throws IllegalAnnotationException { Attribute attribute = type.getAttribute(variableName); if (attribute != null) { return new AttributeFunction(attribute); } else if (variableName.equals(type.getKey())) { return new TypeFunction(type); } else if (variableName.equals("type:type")) { return new ThisTypeFunction(); } else if (variableName.equals("event:allocatables") || variableName.equals("event:resources")) { return new AllocatableFunction(type); } else if (variableName.equals("event:appointments")) { return new AppointmentFunction(type); } else if (variableName.equals("appointmentBlock:number")) { return new AppointmentBlockFunction(type); } else if (variableName.equals("appointment:allocatables")) { return new AllocatableFunction(type); } else if (variableName.equals("appointmentBlock:allocatables")) { return new AllocatableFunction(type); } return null; }
ClassificationImpl(DynamicTypeImpl dynamicType) { typeId = dynamicType.getId(); type = dynamicType.getKey(); }