Exemplo n.º 1
0
void UmlArtifact::importIt(FileIn & in, Token & token, UmlItem * where)
{
    where = where->container(anArtifact, token, in);

    if (where == 0)
        return;

    WrapperStr s = token.valueOf("name");

    if (s.isEmpty()) {
        static unsigned n = 0;

        s.sprintf("anonymous_artifact_%u", ++n);
    }

    UmlArtifact * artifact = create((UmlDeploymentView *) where, s);

    if (artifact == 0)
        in.error("cannot create artifact '" + s +
                 "' in '" + where->name() + "'");

    artifact->addItem(token.xmiId(), in);

    if (! token.closed()) {
        WrapperStr k = token.what();
        const char * kstr = k;

        while (in.read(), !token.close(kstr)) {
            if (token.what() == "manifestation")
                Manifestation::import(in, token, artifact);
            else
                artifact->UmlItem::import(in, token);
        }
    }

    artifact->unload(TRUE, FALSE);
}
Exemplo n.º 2
0
void Package::reverse_file(WrapperStr path, WrapperStr name)
{
    if (! Lex::open(path)) {
        // very strange !
        if (! scan)
            UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot open <i>")
                          + path + "</i></b></font><br>");
    }
    else {
        UmlArtifact * art = 0;
        WrapperStr file_start;
        WrapperStr file_end;

        UmlCom::message(((scan) ? "scan " : "reverse ") + path);

        // go after <?[php]
        Lex::mark();

        bool redo;
        bool before_class;

        do {
            redo = FALSE;
            before_class = TRUE;

            WrapperStr s;
            char c = Lex::read_word_bis();

            while (c != 0) {
                if (c == '<') {
                    c = Lex::read_word_bis();

                    if (c == '?') {
                        if (!scan) file_start = Lex::region();

                        s = Lex::read_word();

                        if (s.lower() == "php") {
                            if (!scan) file_start = Lex::region();

                            s = Lex::read_word();
                        }

                        break;
                    }
                }
                else
                    c = Lex::read_word_bis();
            }

            aVisibility visibility = PackageVisibility;
            bool abstractp = FALSE;
            bool finalp = FALSE;
            bool inside_namespace_brace = FALSE;

            while (!s.isEmpty()) {
                if ((s == "class") || (s == "interface")) {
#ifdef REVERSE

                    if (!scan && (art == 0)) {
                        UmlPackage * pack = get_uml(TRUE);

                        if ((art = UmlBaseArtifact::create(pack->get_deploymentview(Namespace::current()), name)) == 0) {
                            UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create<i> artifact ")
                                          + name + "</i></b></font><br>");
                            Namespace::exit();
                            Lex::close();
                            return;
                        }

                        art->set_Stereotype("source");
                    }

#endif

                    if (!Class::reverse(this, s, abstractp, finalp, path, art))
                        break;

                    visibility = PackageVisibility;
                    abstractp = FALSE;
                    finalp = FALSE;

                    before_class = FALSE;
                    Lex::mark();
                }
                else if (s == "public")
                    visibility = PublicVisibility;
                else if (s == "protected")
                    visibility = ProtectedVisibility;
                else if (s == "private")
                    visibility = PrivateVisibility;
                else if (s == "final")
                    finalp = TRUE;
                else if (s == "abstract")
                    abstractp = TRUE;
                else if ((s == "namespace") && before_class) {
                    Namespace::exit();

                    s = Lex::read_word();

                    if (s == "{")
                        inside_namespace_brace = TRUE;
                    else if (s.isEmpty()) {
                        if (!scan)
                            Lex::premature_eof();

                        break;
                    }
                    else {
                        Namespace::enter(s);
                        s = Lex::read_word();

                        if (s == "{")
                            inside_namespace_brace = TRUE;

                        // else is ';'
                    }
                }
                else if ((s == "use") && before_class) {
                    if (!scan)
                        use();
                    else
                        UmlOperation::skip_body(0);

                    Lex::finish_line();
                    Lex::clear_comments();
                }
                else if ((s == "}") && inside_namespace_brace) {
                    inside_namespace_brace = FALSE;
                    Namespace::exit();
                }
                else if (s != ";") {
                    if (before_class) {
                        if ((s == "?") && ((s = Lex::read_word()) == ">")) {
                            // this <?php ..?> doesn't contains classes
                            // search for a next <?php ..?>
                            redo = TRUE;
                            Lex::clear_comments();

                            if (!scan)
                                file_start = Lex::region();

                            break;
                        }

                        UmlOperation::skip_body(0);
                        Lex::finish_line();
                        Lex::clear_comments();

                        if (!scan)
                            file_start = Lex::region();
                    }
                    else if (!scan) {
                        // go to end of file
                        while (Lex::read_word_bis() != 0)
                            ;

                        file_end = Lex::region();
                        break;
                    }
                    else
                        break;
                }

                s = Lex::read_word();
            }
        }
        while (redo);

#ifdef REVERSE

        if (! scan) {
            if (art == 0) {
                UmlPackage * pack = get_uml(TRUE);

                if ((art = UmlBaseArtifact::create(pack->get_deploymentview(Namespace::current()), name)) == 0) {
                    UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create<i> artifact ")
                                  + name + "</i></b></font><br>");
                    Namespace::exit();
                    Lex::close();
                    return;
                }

                art->set_Stereotype("source");
            }

            if (before_class)
                art->set_PhpSource(file_start);
            else if (!Namespace::current().isEmpty()) {
                int p1 = file_start.operator QString().lastIndexOf("namespace");
                int p2 = file_start.find(';', p1);
                int p3 = file_start.find('{', p1);

                if ((p3 != -1) && ((p3 < p2) || (p2 == -1)))
                    file_start.replace(p1, p3 - p1 + 1, "${namespace}");
                else
                    file_start.replace(p1, p2 - p1 + 1, "${namespace}");

                art->set_PhpSource(file_start + "\n${definition}\n\n" + file_end);
            }
            else
                art->set_PhpSource(file_start + "\n${definition}\n\n" + file_end);

            art->unload();
        }

#endif

        Namespace::exit();

        Lex::close();
    }
}