private static DocumentType getDocumentTypeFromString(String docTypeString, DocumentTypeManager typeManager) { final DocumentType docType = typeManager.getDocumentType(docTypeString); if (docType == null) { throw new IllegalArgumentException(String.format("Document type %s does not exist", docTypeString)); } return docType; }
FieldSet parseFieldCollection(DocumentTypeManager docMan, String docType, String fieldNames) { DocumentType type = docMan.getDocumentType(docType); if (type == null) { throw new IllegalArgumentException("Unknown document type " + docType); } StringTokenizer tokenizer = new StringTokenizer(fieldNames, ","); FieldCollection collection = new FieldCollection(type); for (; tokenizer.hasMoreTokens(); ) { String token = tokenizer.nextToken(); Field f = type.getField(token); if (f == null) { throw new IllegalArgumentException("No such field " + token); } collection.add(f); } return collection; }
static void validate(DocumentTypeManager manager, String documentTypeName, String arrayFieldName) { DocumentType docType = manager.getDocumentType(documentTypeName); if (docType == null) { //the document type does not exist, return throw new IllegalStateException("The document type " + documentTypeName + " is not deployed."); } if (docType.getField(arrayFieldName) == null) { //the document type does not have the field, return throw new IllegalStateException("The document type " + documentTypeName + " does not have a field named " + arrayFieldName + "."); } if (!(docType.getField(arrayFieldName).getDataType() instanceof ArrayDataType)) { //the data type of the field is wrong, return throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array type"); } ArrayDataType fieldDataType = (ArrayDataType) docType.getField(arrayFieldName).getDataType(); if (!(fieldDataType.getNestedType() instanceof DocumentType)) { //the subtype of tye array data type of the field is wrong, return throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array of Document."); } }
DocumentType doctype = docTypeManager.getDocumentType(typeName); if (doctype == null) { throw newDeserializeException(field, "Must specify an existing document type, not '" + typeName + "'");
update.setId(new DocumentId(attributeValue)); } else if ("documenttype".equals(attributeName) || "type".equals(attributeName)) { doctype = docTypeManager.getDocumentType(attributeValue); update.setDocumentType(doctype); } else if ("create-if-non-existent".equals(attributeName)) {
public DocumentType readDocumentType() { Utf8Array docTypeName = parseNullTerminatedString(); int ignored = getShort(null); // used to hold the version DocumentType docType = manager.getDocumentType(new DataTypeName(docTypeName)); if (docType == null) { throw new DeserializationException("No known document type with name " + new Utf8String(docTypeName).toString()); } return docType; }
public DocumentType readDocumentType() { Utf8Array docTypeName = parseNullTerminatedString(); int ignored = getShort(null); // used to hold the version DocumentType docType = manager.getDocumentType(new DataTypeName(docTypeName)); if (docType == null) { throw new DeserializationException("No known document type with name " + new Utf8String(docTypeName).toString()); } return docType; }
@SuppressWarnings("deprecation") private static void registerDocumentType(DocumentTypeManager manager, DocumentmanagerConfig.Datatype.Documenttype doc) { StructDataType header = (StructDataType) manager.getDataType(doc.headerstruct(), ""); StructDataType body = (StructDataType) manager.getDataType(doc.bodystruct(), ""); for (Field field : body.getFields()) { field.setHeader(false); } DocumentType type = new DocumentType(doc.name(), header, body); for (Object j : doc.inherits()) { DocumentmanagerConfig.Datatype.Documenttype.Inherits parent = (DocumentmanagerConfig.Datatype.Documenttype.Inherits) j; DataTypeName name = new DataTypeName(parent.name()); DocumentType parentType = manager.getDocumentType(name); if (parentType == null) { throw new IllegalArgumentException("Could not find document type '" + name.toString() + "'."); } type.inherit(parentType); } manager.register(type); }