/** * Adds an field that can be used with this document type. * * @param field the field to add */ @SuppressWarnings("deprecation") public void addField(Field field) { if (isRegistered()) { throw new IllegalStateException("You cannot add fields to a document type that is already registered."); } StructDataType struct = (field.isHeader() ? headerType : bodyType); struct.addField(field); }
/** * Adds a new body field to this document type and returns the new field object * * @param name The name of the field to add * @param type The datatype of the field to add * @return The field created * TODO Fix searchdefinition so that exception can be thrown if filed is already registerd. */ public Field addField(String name, DataType type) { if (isRegistered()) { throw new IllegalStateException("You cannot add fields to a document type that is already registered."); } Field field = new Field(name, type, false); bodyType.addField(field); return field; }
/** * Adds a new header field to this document type and returns the new field object * * @param name The name of the field to add * @param type The datatype of the field to add * @return The field created * TODO Fix searchdefinition so that exception can be thrown if filed is already registerd */ public Field addHeaderField(String name, DataType type) { if (isRegistered()) { throw new IllegalStateException("You cannot add fields to a document type that is already registered."); } Field field = new Field(name, type, true); headerType.addField(field); return field; }
/** * 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); }
@Override public Field getField(int id) { Field field = headerType.getField(id); if (field == null) { field = bodyType.getField(id); } if (field == null && !isRegistered()) { for (DocumentType inheritedType : inherits) { field = inheritedType.getField(id); if (field != null) break; } } return field; }
/** * Removes an field from the DocumentType. * * @param name The name of the field. * @return The field that was removed or null if it did not exist. */ public Field removeField(String name) { if (isRegistered()) { throw new IllegalStateException("You cannot remove fields from a document type that is already registered."); } Field field = headerType.removeField(name); if (field == null) { field = bodyType.removeField(name); } if (field == null) { for (DocumentType inheritedType : inherits) { field = inheritedType.removeField(name); if (field != null) break; } } return field; }
/** * Gets the field matching a given name. * * @param name The name of a field. * @return Returns the matching field, or null if not found. */ public Field getField(String name) { Field field = headerType.getField(name); if (field == null) { field = bodyType.getField(name); } if (field == null && !isRegistered()) { for (DocumentType inheritedType : inherits) { field = inheritedType.getField(name); if (field != null) break; } } return field; }
/** * Gets the field matching a given ID. * * @param id The ID of a field. * @param version The serialization version of the document. * @return Returns the matching field, or null if not found. */ public Field getField(Integer id, int version) { Field field = headerType.getField(id, version); if (field == null) { field = bodyType.getField(id, version); } if (field == null && !isRegistered()) { for (DocumentType inheritedType : inherits) { field = inheritedType.getField(id, version); if (field != null) break; } } return field; }