Beispiel #1
0
void transformer::to_enumeration(const processed_object& o, const profile& p) {
    BOOST_LOG_SEV(lg, debug) << "Object is an enumeration: " << o.id();
    sml::enumeration e;
    update_element(e, o, p);

    dogen::sml::qname qn;
    qn.simple_name(unsigned_int);
    e.underlying_type(qn);

    dogen::sml::enumerator invalid;
    invalid.name("invalid");
    invalid.documentation("Represents an uninitialised enum");
    invalid.value("0");
    e.enumerators().push_back(invalid);

    std::set<std::string> enumerator_names;
    enumerator_names.insert(invalid.name());

    unsigned int pos(1);
    for (const auto& p : o.properties()) {
        auto enumerator(to_enumerator(p, pos++));

        const auto i(enumerator_names.find(enumerator.name()));
        if (i != enumerator_names.end()) {
            BOOST_LOG_SEV(lg, error) << "Duplicate enumerator name: "
                                     << enumerator.name();
            BOOST_THROW_EXCEPTION(transformation_error(
                    "Duplicate enumerator name: " + enumerator.name()));
        }
        e.enumerators().push_back(enumerator);
        enumerator_names.insert(enumerator.name());
    }
    context_.model().enumerations().insert(std::make_pair(e.name(), e));
}
Beispiel #2
0
void transformer::transform(const processed_object& o, const profile& p) {
    BOOST_LOG_SEV(lg, debug) << "Starting to transform: " << o.id();
    BOOST_LOG_SEV(lg, debug) << "Object contents: " << o;

    require_is_transformable(o);
    dispatch(o, p);

    BOOST_LOG_SEV(lg, debug) << "Transformed: " << o.id();
}
Beispiel #3
0
void grapher::add(const processed_object& po) {
    require_not_generated();

    if (po.connection()) {
        process_connections(po);
        return;
    }

    const auto v(vertex_for_id(po.id()));
    graph_[v] = po;
    process_child_node(v, po);
}
Beispiel #4
0
void validator::validate_yarn(const processed_object& po) const {
    if (po.yarn_object_type() == yarn_object_types::object)
        return; // nothing to validate for yarn objects.

    /*
     * Non-yarn objects are not allowed to have stereotypes.
     */
    if (!po.stereotypes().empty()) {
        BOOST_LOG_SEV(lg, error) << stereotypes_require_yarn_object << ": "
                                 << po.stereotypes();
        BOOST_THROW_EXCEPTION(
            validation_error(stereotypes_require_yarn_object));
    }
}
Beispiel #5
0
void transformer::from_note(const processed_object& o) {
    BOOST_LOG_SEV(lg, debug) << "Object is a note: " << o.id()
                             << ". Note text: '"
                             << o.comment().original_content() << "'";

    if (o.comment().original_content().empty() ||
        !o.comment().applicable_to_parent_object())
        return;

    const auto& documentation(o.comment().documentation());
    const auto& kvps(o.comment().key_value_pairs());
    const sml::model& model(context_.model());
    using dynamic::scope_types;
    if (o.child_node_id().empty()) {
        auto& module(module_for_qname(model.name()));
        module.documentation(documentation);

        const auto scope(scope_types::root_module);
        module.extensions(dynamic_workflow_.execute(scope, kvps));
        return;
    }

    sml::module& module(module_for_id(o.child_node_id()));
    module.documentation(documentation);

    const auto scope(scope_types::any_module);
    module.extensions(dynamic_workflow_.execute(scope, kvps));
}
Beispiel #6
0
void transformer::to_module(const processed_object& o, const profile& p) {
    BOOST_LOG_SEV(lg, debug) << "Object is a module: " << o.id();

    sml::module m;
    update_element(m, o, p);
    context_.model().modules().insert(std::make_pair(m.name(), m));
}
Beispiel #7
0
bool transformer::is_transformable(const processed_object& o) const {
    const auto ot(o.object_type());
    return
        ot == object_types::uml_large_package ||
        ot == object_types::uml_generalization ||
        ot == object_types::uml_class ||
        ot == object_types::uml_note;
}
Beispiel #8
0
void transformer::to_value_object(const processed_object& o, const profile& p) {
    BOOST_LOG_SEV(lg, debug) << "Object is a value object: " << o.id();

    sml::object vo;
    update_object(vo, o, p);
    vo.object_type(sml::object_types::user_defined_value_object);
    context_.model().objects().insert(std::make_pair(vo.name(), vo));
}
Beispiel #9
0
void transformer::to_service(const processed_object& po, const profile& p) {
    BOOST_LOG_SEV(lg, debug) << "Object is a factory: " << po.id();

    sml::object o;
    o.object_type(sml::object_types::user_defined_service);
    update_object(o, po, p);
    context_.model().objects().insert(std::make_pair(o.name(), o));
}
Beispiel #10
0
void transformer::require_is_transformable(const processed_object& po) const {
    if (!is_transformable(po)) {
        const auto type(boost::lexical_cast<std::string>(po.object_type()));
        BOOST_LOG_SEV(lg, error) << object_has_invalid_type << type;
        BOOST_THROW_EXCEPTION(
            transformation_error(object_has_invalid_type + type));
    }
}
Beispiel #11
0
void grapher::process_connections(const processed_object& o) {
    BOOST_LOG_SEV(lg, debug) << "Processing connections for object: '"
                             << o.id() << "' of type: '"
                             << o.dia_object_type() << "'";

    const auto parent_id(o.connection()->first);
    const auto child_id(o.connection()->second);

    const auto parent_vertex(vertex_for_id(parent_id));
    const auto child_vertex(vertex_for_id(child_id));
    connected_ids_.insert(parent_id);
    boost::add_edge(child_vertex, parent_vertex, graph_);
    BOOST_LOG_SEV(lg, debug) << "Created edge between '" << child_id
                             << "' and: '" << parent_id << "'";

    auto i(child_id_to_parent_ids_.find(child_id));
    if (i == child_id_to_parent_ids_.end()) {
        std::list<std::string> l = { parent_id };
        child_id_to_parent_ids_.insert(std::make_pair(child_id, l));
        BOOST_LOG_SEV(lg, debug) << "First parent for Child: " << child_id;

    } else {
        i->second.push_back(parent_id);
        BOOST_LOG_SEV(lg, debug) << "Child has more than one parent: "
                                 << child_id;
    }

    if (connected_ids_.find(child_id) == connected_ids_.end()) {
        orphanage_.insert(std::make_pair(child_id, child_vertex));
        BOOST_LOG_SEV(lg, debug) << "Vertex for object joined orphanage: "
                                 << child_id;
    }

    const auto k(orphanage_.find(parent_id));
    if (k != orphanage_.end()) {
        BOOST_LOG_SEV(lg, debug) << "Object is no longer orphan: "
                                 << k->first << "'";
        orphanage_.erase(k);
    }
}
Beispiel #12
0
void transformer::to_concept(const processed_object& o, const profile& p) {
    sml::concept c;
    update_element(c, o, p);

    for (const auto& prop : o.properties()) {
        auto property(to_property(prop));
        property.type(to_nested_qname(prop.type()));
        update_model_references(property.type());
        c.local_properties().push_back(property);
    }

    const auto i(context_.child_id_to_parent_ids().find(o.id()));
    c.is_child(i != context_.child_id_to_parent_ids().end());
    if (c.is_child()) {
        if (i->second.empty()) {
            BOOST_LOG_SEV(lg, error) << empty_parent_container << o.id();
            BOOST_THROW_EXCEPTION(
                transformation_error(empty_parent_container + o.id()));
        }

        for (const auto& concept_id : i->second) {
            const auto j(context_.id_to_qname().find(concept_id));
            if (j == context_.id_to_qname().end()) {
                BOOST_LOG_SEV(lg, error) << "Object has a parent but "
                                         << " there is no QName mapping."
                                         << " Child ID: '" << o.id()
                                         << "' Parent ID: '" << concept_id
                                         << "'";

                BOOST_THROW_EXCEPTION(
                    transformation_error(parent_not_found + o.id()));
            }
            c.refines().push_back(j->second);
        }
    }

    const auto j(context_.parent_ids().find(o.id()));
    c.is_parent(j != context_.parent_ids().end());

    context_.model().concepts().insert(std::make_pair(c.name(), c));
}
Beispiel #13
0
void grapher::
process_child_node(const vertex_descriptor_type& v, const processed_object& o) {
    if (!o.child_node_id().empty()) {
        const std::string id(o.child_node_id());
        const vertex_descriptor_type cv(vertex_for_id(id));
        boost::add_edge(v, cv, graph_);
        BOOST_LOG_SEV(lg, debug) << "Creating edge between '"
                                 << o.id() << "' and '" << id << "'";

        const auto k(orphanage_.find(id));
        if (k != orphanage_.end()) {
            BOOST_LOG_SEV(lg, debug) << "Object is no longer orphan: "
                                     << id << "'";
            orphanage_.erase(k);
        }
        connected_ids_.insert(id);
    }

    if (connected_ids_.find(o.id()) == connected_ids_.end()) {
        orphanage_.insert(std::make_pair(o.id(), v));
        BOOST_LOG_SEV(lg, debug) << "Vertex for object joined orphanage: "
                                 << o.id();
    }
}
Beispiel #14
0
void validator::validate_uml(const processed_object& po) const {
    if (po.dia_object_type() == dia_object_types::invalid) {
        BOOST_LOG_SEV(lg, error) << no_uml_type;
        BOOST_THROW_EXCEPTION(validation_error(no_uml_type));
    }
}
Beispiel #15
0
void transformer::
update_object(sml::object& ao, const processed_object& o, const profile& p) {

    update_element(ao, o, p);

    ao.is_fluent(p.is_fluent());
    ao.is_visitable(p.is_visitable());

    for (const auto us : p.unknown_stereotypes()) {
        const auto qn(to_qname(us));
        using sml::relationship_types;
        ao.relationships()[relationship_types::modeled_concepts].push_back(qn);
    }

    for (const auto& p : o.properties()) {
        const auto property(to_property(p));
        ao.local_properties().push_back(property);
        update_model_references(property.type());
    }

    const auto i(context_.child_id_to_parent_ids().find(o.id()));
    if (i != context_.child_id_to_parent_ids().end()) {
        if (i->second.empty()) {
            BOOST_LOG_SEV(lg, error) << empty_parent_container << o.id();
            BOOST_THROW_EXCEPTION(
                transformation_error(empty_parent_container + o.id()));
        }

        if (i->second.size() > 1) {
            BOOST_LOG_SEV(lg, error) << multiple_inheritance << o.id();
            BOOST_THROW_EXCEPTION(
                transformation_error(multiple_inheritance + o.id()));
        }

        const auto parent_name(i->second.front());
        const auto j(context_.id_to_qname().find(parent_name));
        if (j == context_.id_to_qname().end()) {
            BOOST_LOG_SEV(lg, error) << "Object has a parent but "
                                     << " there is no QName mapping defined."
                                     << " Child ID: '" << o.id()
                                     << "' Parent ID: '" << parent_name << "'";

            BOOST_THROW_EXCEPTION(
                transformation_error(parent_not_found + o.id()));
        }

        BOOST_LOG_SEV(lg, debug) << "Setting parent for: "
                                 << ao.name().simple_name() << " as "
                                 << j->second.simple_name();
        ao.is_child(true);
        using sml::relationship_types;
        ao.relationships()[relationship_types::parents].push_back(j->second);
    } else {
        BOOST_LOG_SEV(lg, debug) << "Object has no parent: "
                                 << ao.name().simple_name();
    }

    const auto j(context_.parent_ids().find(o.id()));
    ao.is_parent(j != context_.parent_ids().end());
    ao.is_final(!ao.is_parent());
    context_.id_to_qname().insert(std::make_pair(o.id(), ao.name()));

    ao.is_immutable(p.is_immutable());
    if ((ao.is_parent() || ao.is_child()) && p.is_immutable())  {
        BOOST_LOG_SEV(lg, error) << immutabilty_with_inheritance
                                 << ao.name().simple_name();

        BOOST_THROW_EXCEPTION(
            transformation_error(immutabilty_with_inheritance +
                ao.name().simple_name()));
    }
}