public DataTypeName getDocumentName() { return docType.getDataTypeName(); } public DocumentType getDocumentType() { return docType; }
public ListIterator<DataTypeName> inheritedIterator() { List<DataTypeName> names = new ArrayList<>(inherits.size()); for (DocumentType type : inherits) { names.add(type.getDataTypeName()); } return ImmutableList.copyOf(names).listIterator(); }
public boolean equals(Object o) { if (!(o instanceof DocumentType)) return false; DocumentType other = (DocumentType) o; // Ignore whether one of them have added inheritance to super Document.0 type if (super.equals(o) && headerType.equals(other.headerType) && bodyType.equals(other.bodyType)) { if ((inherits.size() > 1 || other.inherits.size() > 1) || (inherits.size() == 1 && other.inherits.size() == 1)) { return inherits.equals(other.inherits); } return !(((inherits.size() == 1) && !inherits.get(0).getDataTypeName().equals(new DataTypeName("document"))) || ((other.inherits.size() == 1) && !other.inherits.get(0).getDataTypeName().equals(new DataTypeName("document")))); } return false; }
private void registerDefaultDataTypes() { DocumentType superDocType = DataType.DOCUMENT; dataTypes.put(superDocType.getId(), superDocType); documentTypes.put(superDocType.getDataTypeName(), superDocType); Class<? extends DataType> dataTypeClass = DataType.class; for (java.lang.reflect.Field field : dataTypeClass.getFields()) { if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { if (DataType.class.isAssignableFrom(field.getType())) { try { //these are all static final DataTypes listed in DataType: DataType type = (DataType) field.get(null); register(type); } catch (IllegalAccessException e) { //ignore } } } } for (AnnotationType type : AnnotationTypes.ALL_TYPES) { annotationTypeRegistry.register(type); } }
/** * Adds a document to the inherited document types of this. * If this type is already directly inherited, nothing is done * * @param type An already DocumentType object. */ public void inherit(DocumentType type) { //TODO: There is also a check like the following in SDDocumentType addField(), try to move that to this class' addField() to get it proper, // as this method is called only when the doc types are exported. verifyTypeConsistency(type); if (isRegistered()) { throw new IllegalStateException("You cannot add inheritance to a document type that is already registered."); } if (type == null) { throw new IllegalArgumentException("The document type cannot be null in inherit()"); } // If it inherits the exact same type if (inherits.contains(type)) return; // If we inherit a type, don't inherit the supertype if (inherits.size() == 1 && inherits.get(0).getDataTypeName().equals(new DataTypeName("document"))) { inherits.clear(); } inherits.add(type); }
docType.inherit(documentTypes.get(new DataTypeName("document"))); documentTypes.put(docType.getDataTypeName(), docType);