private void replaceTemporaryTypeInReference(ReferenceDataType referenceDataType) { if (referenceDataType.getTargetType() instanceof TemporaryStructuredDataType) { referenceDataType.setTargetType((DocumentType) getDataType(referenceDataType.getTargetType().getId())); } // TODO should we recursively invoke replaceTemporaryTypes for the target type? It should only ever be a doc type }
/** * Creates a new type where the numeric ID is based on the hash of targetType */ public static ReferenceDataType createWithInferredId(TemporaryStructuredDataType targetType) { return new ReferenceDataType(targetType); }
/** * Overrides the stored temporary data type with a concrete StructuredDataType instance. Should only * be invoked from configuration or model code when resolving temporary types. * * @throws IllegalStateException if the previously stored target type is already a concrete * instance (not TemporaryStructuredDataType). */ public void setTargetType(StructuredDataType targetType) { if (! (this.targetType instanceof TemporaryStructuredDataType)) { throw new IllegalStateException(String.format( "Unexpected attempt to replace already concrete target " + "type in ReferenceDataType instance (type is '%s')", this.targetType.getName())); } this.targetType = targetType; setName(buildTypeName(targetType)); }
private void buildConfig(ReferenceDataType type, DocumenttypesConfig.Documenttype.Builder documentBuilder) { ReferenceDataType refType = type; DocumenttypesConfig.Documenttype.Referencetype.Builder refBuilder = new DocumenttypesConfig.Documenttype.Referencetype.Builder(); refBuilder.id(refType.getId()); refBuilder.target_type_id(type.getTargetType().getId()); documentBuilder.referencetype(refBuilder); }
private static String getTargetDocumentName(ReferenceDataType reference) { return reference.getTargetType().getName(); }
private DataType createReferenceDataType() { if (!referenceDocumentType.isPresent()) { throw new IllegalStateException("Referenced document type is not set!"); } StructuredDataType type = referenceDocumentType.get(); if (type instanceof DocumentType) { return ReferenceDataType.createWithInferredId((DocumentType) type); } else { return ReferenceDataType.createWithInferredId((TemporaryStructuredDataType) type); } }
private ReferenceDataType(StructuredDataType targetType, int id) { super(buildTypeName(targetType), id); this.targetType = targetType; }
@Override public int compareTo(DataType rhs) { int cmp = super.compareTo(rhs); return (cmp != 0) ? cmp : compareTargetType(rhs); }
private static void requireIdOfMatchingType(ReferenceDataType referenceType, DocumentId id) { final String expectedTypeName = referenceType.getTargetType().getName(); if (!id.getDocType().equals(expectedTypeName)) { throw new IllegalArgumentException(String.format( "Can't assign document ID '%s' (of type '%s') to reference of document type '%s'", id, id.getDocType(), expectedTypeName)); } }
referenceType = referenceType(); jj_consume_token(GREATERTHAN); {if ("" != null) return ReferenceDataType.createWithInferredId(referenceType);} } else { switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
private ReferenceDataType(StructuredDataType targetType) { this(targetType, buildTypeName(targetType).hashCode()); }
} else if (type instanceof ReferenceDataType) { ReferenceDataType t = (ReferenceDataType) type; if (t.getTargetType() instanceof TemporaryStructuredDataType) { DataType targetType = resolveTemporariesRecurse(t.getTargetType(), repo, docs); t.setTargetType((StructuredDataType) targetType);
builder.referencetype(new Datatype.Referencetype.Builder().target_type_id(refType.getTargetType().getId())); } else { throw new IllegalArgumentException("Can not create config for data type '" + type.getName());
/** * Creates a new type where the numeric ID is based on the hash of targetType */ public static ReferenceDataType createWithInferredId(DocumentType targetType) { return new ReferenceDataType(targetType); }
private static void registerReferenceType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Referencetype refType) { ReferenceDataType referenceType; if (manager.hasDataType(refType.target_type_id())) { DocumentType targetDocType = (DocumentType)manager.getDataType(refType.target_type_id()); referenceType = new ReferenceDataType(targetDocType, id); } else { TemporaryStructuredDataType temporaryTargetType = TemporaryStructuredDataType.createById(refType.target_type_id()); referenceType = new ReferenceDataType(temporaryTargetType, id); } // Note: can't combine the above new-statements, as they call different constructors. manager.register(referenceType); }