/** * Returns a registered document type * * @param name the type name of the document type * @return returns the document type having this name, or null if none */ public DocumentType getDocumentType(String name) { return documentTypes.get(new DataTypeName(name)); }
/** * Returns the name of this as a DataTypeName * * @return Return the Documentname of this doumenttype. */ public DataTypeName getDataTypeName() { return new DataTypeName(getName()); }
private SDDocumentType find(String name) { SDDocumentType sdDocType = createdSDTypes.get(new DataTypeName(name)); if (sdDocType != null) { return sdDocType; } for(SDDocumentType sdoc : createdSDTypes.values()) { for (SDDocumentType stype : sdoc.getTypes()) { if (stype.getName().equals(name)) { return stype; } } } return null; } private void visit(DataType type) {
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; }
/** * 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); }
/** * Consumes a document inheritance statement. * * @param document The document type to modify. */ final public void inheritsDocument(SDDocumentType document) throws ParseException {String name; jj_consume_token(INHERITS); name = identifier(); document.inherit(new DataTypeName(name)); label_21: while (true) { switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { case COMMA:{ break; } default: jj_la1[29] = jj_gen; break label_21; } jj_consume_token(COMMA); name = identifier(); document.inherit(new DataTypeName(name)); } }
DocumentType docType = (DocumentType) type; if (docType.getInheritedTypes().size() == 0) { docType.inherit(documentTypes.get(new DataTypeName("document")));
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); }