示例#1
0
    void SerializerBase::invokeWrite(Archive &ar)
    {
        Node in("", "", 0, false);

        // Detect polymorphism
        if (!ar.isFlagSet(Archive::PARENT) && isDerived())
        {
            ar.setFlag(Archive::POLYMORPHIC);
            getSerializerPolymorphic(getDerivedTypeName());
            invokeSerializerPolymorphic(ar);
            return;
        }

        // May now assume non-polymorphic object

        if (ar.isFlagSet(Archive::POLYMORPHIC))
        {
            in.type.assign(getTypeName());
        }

        bool bPointer = ar.isFlagSet(Archive::POINTER);
        bool bNonAtomic = isNonAtomic();

        if (isNull())
        {
            in.id = 0;
            in.ref = 1;
            ar.getOstream()->begin(in);
            ar.clearState();
        }
        else if (bPointer || bNonAtomic)
        {
            if (queryOutputContext(ar.getOstream(), in.id ))
            {
                if (bPointer)
                    in.ref = 1;
                ar.getOstream()->begin(in);
                ar.clearState();
                if (!bPointer)
                    serializeContents(ar);
            }
            else
            {
                addToOutputContext(ar.getOstream(), in.id);
                ar.getOstream()->begin(in);
                ar.clearState();
                serializeContents(ar);
            }
        }
        else
        {
            ar.getOstream()->begin(in);
            ar.clearState();
            serializeContents(ar);
        }

        ar.getOstream()->end();
    }
示例#2
0
/*!
    Returns a deep-copied clone of the QUmlAssociationClass.
*/
QModelingElement *QUmlAssociationClass::clone() const
{
    QUmlAssociationClass *c = new QUmlAssociationClass;
    c->asQModelingObject()->setObjectName(this->asQModelingObject()->objectName());
    c->asQModelingObject()->setProperty("role", this->asQModelingObject()->property("role"));
    foreach (QUmlComment *element, ownedComments())
        c->addOwnedComment(dynamic_cast<QUmlComment *>(element->clone()));
    c->setName(name());
    if (nameExpression())
        c->setNameExpression(dynamic_cast<QUmlStringExpression *>(nameExpression()->clone()));
    foreach (QUmlElementImport *element, elementImports())
        c->addElementImport(dynamic_cast<QUmlElementImport *>(element->clone()));
    foreach (QUmlConstraint *element, ownedRules())
        c->addOwnedRule(dynamic_cast<QUmlConstraint *>(element->clone()));
    foreach (QUmlPackageImport *element, packageImports())
        c->addPackageImport(dynamic_cast<QUmlPackageImport *>(element->clone()));
    c->setVisibility(visibility());
    c->setLeaf(isLeaf());
    foreach (QUmlTemplateBinding *element, templateBindings())
        c->addTemplateBinding(dynamic_cast<QUmlTemplateBinding *>(element->clone()));
    foreach (QUmlCollaborationUse *element, collaborationUses())
        c->addCollaborationUse(dynamic_cast<QUmlCollaborationUse *>(element->clone()));
    foreach (QUmlGeneralization *element, generalizations())
        c->addGeneralization(dynamic_cast<QUmlGeneralization *>(element->clone()));
    c->setFinalSpecialization(isFinalSpecialization());
    if (ownedTemplateSignature())
        c->setOwnedTemplateSignature(dynamic_cast<QUmlRedefinableTemplateSignature *>(ownedTemplateSignature()->clone()));
    foreach (QUmlUseCase *element, ownedUseCases())
        c->addOwnedUseCase(dynamic_cast<QUmlUseCase *>(element->clone()));
    foreach (QUmlSubstitution *element, substitutions())
        c->addSubstitution(dynamic_cast<QUmlSubstitution *>(element->clone()));
    foreach (QUmlConnector *element, ownedConnectors())
        c->addOwnedConnector(dynamic_cast<QUmlConnector *>(element->clone()));
    foreach (QUmlInterfaceRealization *element, interfaceRealizations())
        c->addInterfaceRealization(dynamic_cast<QUmlInterfaceRealization *>(element->clone()));
    foreach (QUmlBehavior *element, ownedBehaviors())
        c->addOwnedBehavior(dynamic_cast<QUmlBehavior *>(element->clone()));
    c->setAbstract(isAbstract());
    c->setActive(isActive());
    foreach (QUmlClassifier *element, nestedClassifiers())
        c->addNestedClassifier(dynamic_cast<QUmlClassifier *>(element->clone()));
    foreach (QUmlProperty *element, ownedAttributes())
        c->addOwnedAttribute(dynamic_cast<QUmlProperty *>(element->clone()));
    foreach (QUmlOperation *element, ownedOperations())
        c->addOwnedOperation(dynamic_cast<QUmlOperation *>(element->clone()));
    foreach (QUmlReception *element, ownedReceptions())
        c->addOwnedReception(dynamic_cast<QUmlReception *>(element->clone()));
    c->setDerived(isDerived());
    foreach (QUmlProperty *element, ownedEnds())
        c->addOwnedEnd(dynamic_cast<QUmlProperty *>(element->clone()));
    return c;
}
示例#3
0
void UmlRelation::gen_uml_decl()
{
    if (isClassMember())
        fw.write("static, ");

    write(visibility());
    writeq(roleName());
    fw.write(" : ");
    roleType()->write();

    QByteArray s;

    s = defaultValue();

    if (!s.isEmpty()) {
        if (s[0] != '=')
            fw.write(" = ");

        writeq(s);
    }

    s = multiplicity();

    if (!s.isEmpty()) {
        fw.write(", multiplicity : ");
        writeq(s);
    }

    if (isDerived())
        fw.write((isDerivedUnion()) ? ", derived union" : ", derived");

    if (isReadOnly())
        fw.write(", read only");

    if (isOrdered())
        fw.write(", ordered");

    if (isUnique())
        fw.write(", unique");

}
示例#4
0
void UmlRelation::write_relation_as_attribute(FileOut & out) {
  UmlRelation * first = side(TRUE);
  Q3CString s;  
  UmlClass * base;

  if ((first->parent()->stereotype() == "stereotype") &&
      (first->roleType()->stereotype() == "metaclass")) {
    if (this != first)
      return;
    
    base = first->roleType();
    s = "base_" + base->name();
  }
  else {
    base = 0;
      
    switch (_lang) {
    case Uml:
      s = roleName();
      break;
    case Cpp:
      if (cppDecl().isEmpty())
	return;
      s = true_name(roleName(), cppDecl());
      break;
    default: // Java
      if (javaDecl().isEmpty())
	return;
      s = true_name(roleName(), javaDecl());
    }
  }
  
  out.indent();
  out << "<ownedAttribute xmi:type=\"uml:Property\" name=\"" << s << '"';
  out.id(this);
  
  if (base != 0)
    out.ref(first, "association", "EXT_");
  else {
    write_visibility(out);
    write_scope(out);
    if (isReadOnly())
      out << " isReadOnly=\"true\"";
    if (isDerived()) {
      out << " isDerived=\"true\"";
      if (isDerivedUnion())
	out << " isDerivedUnion=\"true\"";
    }
    if (isOrdered())
      out << " isOrdered=\"true\"";
    if (isUnique())
      out << " isUnique=\"true\"";
  
    if (first->_assoc_class != 0)
      out.ref(first->_assoc_class, "association");
    else
      out.ref(first, "association", "ASSOC_");
  
    out << " aggregation=\"";
    if (this == first) {
      parent()->memo_relation(this);
      if (_gen_eclipse) {
	switch (relationKind()) {
	case anAggregation:
	case aDirectionalAggregation:
	  out << "shared";
	  break;
	case anAggregationByValue:
	case aDirectionalAggregationByValue:
	  out << "composite";
	  break;
	default:
	  out << "none";
	}
      }
      else
	out << "none";
    }
    else if (_gen_eclipse)
      out << "none";
    else {
      switch (relationKind()) {
      case anAggregation:
      case aDirectionalAggregation:
	out << "shared";
	break;
      case anAggregationByValue:
      case aDirectionalAggregationByValue:
	out << "composite";
	break;
      default:
	out << "none";
      }
    }
    out << '"';
  }
  
  out << ">\n";
  out.indent(+1);
  
  out.indent();
  out << "<type xmi:type=\"uml:Class\"";
  if (base != 0) {
    if (! base->propertyValue("metaclassPath", s))
      s = (_uml_20) ? "http://schema.omg.org/spec/UML/2.0/uml.xml"
		    : "http://schema.omg.org/spec/UML/2.1/uml.xml";
    out << " href=\"" << s << '#' << base->name() << '"';
  }
  else
    out.idref(roleType());
  out << "/>\n";
  write_multiplicity(out, multiplicity(), this);
  write_default_value(out, defaultValue(), this);
  write_constraint(out);
  write_annotation(out);
  write_description_properties(out);
  
  out.indent(-1);
  out.indent();
  out << "</ownedAttribute>\n";

  unload();
}
示例#5
0
文件: lang.cpp 项目: 8l/insieme
	const string& getConstructName(const NodePtr& node) {
		assert_true(isDerived(node)) << "Node not marked as being a derived construct!";
		return node->getAttachedValue<DerivedTag>().name;
	}
示例#6
0
    void SerializerBase::invokeRead(Archive &ar)
    {
        Node node( "", "", 0, false );
        Node * pNode = NULL;

        if (ar.isFlagSet(Archive::NODE_ALREADY_READ))
        {
            LocalStorage & localStorage = ar.getIstream()->getLocalStorage();
            pNode = reinterpret_cast<Node *>(localStorage.getNode());
        }
        else
        {
            if ( ! ar.getIstream()->begin(node) )
                return;
            pNode = &node;
        }

        // Detect polymorphism, either through pointers or through references
        if (!ar.isFlagSet(Archive::POLYMORPHIC))
        {
            if (    ar.isFlagSet(Archive::POINTER) 
                ||  (!ar.isFlagSet(Archive::PARENT) && isDerived()))
            {
                if (pNode->type.length() > 0)
                {
                    ar.setFlag(Archive::POLYMORPHIC, true );
                    std::string derivedTypeName = pNode->type.cpp_str();
                    getSerializerPolymorphic(derivedTypeName);
                    ar.getIstream()->getLocalStorage().setNode(pNode);
                    ar.setFlag(Archive::NODE_ALREADY_READ);
                    invokeSerializerPolymorphic(ar);
                    return;
                }
            }
        }

        // May now assume that the object is not polymorphic
        UInt32 nid = pNode->id;
        bool bId = pNode->id ? true : false;
        bool bNode = pNode->ref ? false : true;
        bool bPointer = ar.isFlagSet(Archive::POINTER);
        ar.clearState();

        if (bId && bNode && bPointer)
        {
            newObject(ar);
            addToInputContext(ar.getIstream(), nid);
            serializeContents(ar);
        }
        else if ( !bId && bNode && bPointer )
        {
            newObject(ar);
            serializeContents(ar);
        }
        else if (bId && !bNode && bPointer)
        {
            queryInputContext(ar.getIstream(), nid);
            setFromId();
        }
        else if (bId && bNode && !bPointer)
        {
            addToInputContext(ar.getIstream(), nid);
            serializeContents(ar);
        }
        else if (!bId && bNode && !bPointer )
        {
            serializeContents(ar);
        }
        else if (!bId && !bNode && bPointer)
        {
            setToNull();
        }
        else if (!bId && !bNode && !bPointer)
        {
            RCF::Exception e(RCF::_RcfError_DeserializationNullPointer());
            RCF_THROW(e);
        }
        else if (bId && !bNode && !bPointer)
        {
            RCF::Exception e(RCF::_SfError_RefMismatch());
            RCF_THROW(e);
        }

        ar.getIstream()->end();
    }