/** * 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; }
/** * Data type of the header fields of this and all inherited document types * @return merged {@link StructDataType} */ public StructDataType allHeader() { StructDataType ret = new StructDataType(header.getName()); for (Field f : header.getFields()) { ret.addField(f); } for (NewDocumentType inherited : getInherited()) { for (Field f : ((StructDataType) inherited.getHeader()).getFields()) { ret.addField(f); } } return ret; }
/** * Data type of the body fields of this and all inherited document types * @return merged {@link StructDataType} */ public StructDataType allBody() { StructDataType ret = new StructDataType(body.getName()); for (Field f : body.getFields()) { ret.addField(f); } for (NewDocumentType inherited : getInherited()) { for (Field f : ((StructDataType) inherited.getBody()).getFields()) { ret.addField(f); } } return ret; }
@Override @SuppressWarnings("deprecation") protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { seenTypes.add(this); for (DocumentType type : getInheritedTypes()) { if (!seenTypes.contains(type)) { type.register(manager, seenTypes); } } // Get parent fields into fields specified in this type StructDataType header = headerType.clone(); StructDataType body = bodyType.clone(); header.clearFields(); body.clearFields(); for (Field field : fieldSet()) { (field.isHeader() ? header : body).addField(field); } headerType.assign(header); bodyType.assign(body); if (!seenTypes.contains(headerType)) { headerType.register(manager, seenTypes); } if (!seenTypes.contains(bodyType)) { bodyType.register(manager, seenTypes); } manager.registerSingleType(this); }
private static void registerStructType(DocumentmanagerConfig config, DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Structtype struct) { StructDataType type = new StructDataType(id, struct.name()); if (config.enablecompression()) { CompressionConfig comp = makeCompressionConfig(struct); type.setCompressionConfig(comp); } for (Object j : struct.field()) { DocumentmanagerConfig.Datatype.Structtype.Field field = (DocumentmanagerConfig.Datatype.Structtype.Field) j; DataType fieldType = (field.datatype() == id) ? manager.getDataTypeAndReturnTemporary(field.datatype(), field.detailedtype()) : manager.getDataType(field.datatype(), field.detailedtype()); if (field.id().size() == 1) { type.addField(new Field(field.name(), field.id().get(0).id(), fieldType, true)); } else { type.addField(new Field(field.name(), fieldType, true)); } } manager.register(type); }
private static StructDataType handleStruct(NewDocumentType dt, SDDocumentType type) { StructDataType s = new StructDataType(type.getName()); for (Field f : type.getDocumentType().contentStruct().getFieldsThisTypeOnly()) { specialHandleAnnotationReference(dt, f); s.addField(f); } for (StructDataType inherited : type.getDocumentType().contentStruct().getInheritedTypes()) { s.inherit(inherited); } extractNestedTypes(dt, s); addType(dt, s); return s; }