@Override public DocumentType getDataType() { return doc.getDataType(); }
/** * Creates a document that is a shallow copy of another. * * @param doc The document to copy. */ public Document(Document doc) { this(doc.getDataType(), doc.getId()); header = doc.header; body = doc.body; lastModified = doc.lastModified; }
@Override public boolean isValueCompatible(FieldValue value) { if (!(value instanceof Document)) { return false; } Document doc = (Document) value; if (doc.getDataType().inherits(this)) { //the value is of this type; or the supertype of the value is of this type, etc.... return true; } return false; }
public String toString() { return "document '" + String.valueOf(docId) + "' of type '" + getDataType().getName() + "'"; }
private void verifyType(Document doc) { if (!documentType.equals(doc.getDataType())) { throw new IllegalArgumentException( "Document " + doc.getId() + " with type " + doc.getDataType() + " must have same type as update, which is type " + documentType); } } /**
public void setId(DocumentId id) { internalSetId(id, getDataType()); } private void internalSetId(DocumentId id, DocumentType docType) {
public void write(Document doc) { write(new Field(doc.getDataType().getName(), 0, doc.getDataType(), true), doc); }
public void write(Document doc) { write(new Field(doc.getDataType().getName(), 0, doc.getDataType(), true), doc); }
@SuppressWarnings({ "unchecked" }) @Override public SimpleDocumentAdapter setOutputValue(Expression exp, String fieldName, FieldValue fieldValue) { Field field = output.getField(fieldName); if (field == null) { throw new IllegalArgumentException("Field '" + fieldName + "' not found in document type '" + output.getDataType().getName() + "'."); } output.setFieldValue(field, fieldValue); return this; } }
@Override public void write(Document document) { buffer = new XmlStream(); buffer.setIndent(indent); optionalWrapperMarker.clear(); write(new Field(document.getDataType().getName(), 0, document.getDataType(), true), document); }
public SimpleDocumentAdapter(Document input) { this(input, new Document(input.getDataType(), input.getId())); }
private void internalSetId(DocumentId id, DocumentType docType) { if (id != null && id.hasDocType() && docType != null && !id.getDocType().equals(docType.getName())) { throw new IllegalArgumentException("Trying to set a document id (type " + id.getDocType() + ") that doesn't match the document type (" + getDataType().getName() + ")."); } docId = id; }
@Override public DataType getInputType(Expression exp, String fieldName) { try { return input.getDataType().buildFieldPath(fieldName).getResultingDataType(); } catch (IllegalArgumentException e) { throw new VerificationException(exp, "Input field '" + fieldName + "' not found."); } }
@Override public DocumentUpdate getOutput() { Document doc = adapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); createUpdatesAt(new ArrayList<>(), adapter.getUpdatableOutput(), 0, upd); return upd; }
@Override public DocumentUpdate getOutput() { Document doc = fwdAdapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); upd.addFieldPathUpdate(update); return upd; }
private Document createConcreteDocument(Document document, ContainerDocumentConfig.Doctype typeConfig) { String componentId = typeConfig.factorycomponent(); // Class name of the factory AbstractConcreteDocumentFactory cdf = docFactoryRegistry.getComponent(new ComponentId(componentId)); if (cdf == null) { log.fine("Unable to get document factory component '" + componentId + "' from document factory registry."); return document; } return cdf.getDocumentCopy(document.getDataType().getName(), document, document.getId()); }
private Document createPutDocument(PutDocumentMessage msg) { Document document = msg.getDocumentPut().getDocument(); String typeName = document.getDataType().getName(); ContainerDocumentConfig.Doctype typeConfig = getDocumentConfig(typeName); if (typeConfig == null) { return document; } return createConcreteDocument(document, typeConfig); }
@Override public void tryOutputType(Expression exp, String fieldName, DataType valueType) { Field field = output.getDataType().getField(fieldName); if (field == null) { throw new VerificationException(exp, "Field '" + fieldName + "' not found."); } DataType fieldType = field.getDataType(); if (!fieldType.isAssignableFrom(valueType)) { throw new VerificationException(exp, "Can not assign " + valueType.getName() + " to field '" + fieldName + "' which is " + fieldType.getName() + "."); } }
@SuppressWarnings("deprecation") public static void printDocumentXml(Document doc, XmlStream xml) { xml.addAttribute("documenttype", doc.getDataType().getName()); xml.addAttribute("documentid", doc.getId()); final java.lang.Long lastModified = doc.getLastModified(); if (lastModified != null) { xml.addAttribute("lastmodifiedtime", lastModified); } doc.getHeader().printXml(xml); doc.getBody().printXml(xml); }
@Override public void write(FieldBase field, Document value) { buffer.beginTag("document"); buffer.addAttribute("documenttype", value.getDataType().getName()); buffer.addAttribute("documentid", value.getId()); final java.lang.Long lastModified = value.getLastModified(); if (lastModified != null) { buffer.addAttribute("lastmodifiedtime", lastModified); } write(null, value.getHeader()); write(null, value.getBody()); buffer.endTag(); }