예제 #1
0
bool
FreezeScript::SliceVisitor::visitStructStart(const Slice::StructPtr& v)
{
    if(v->isLocal())
    {
        return false;
    }

    string scoped = v->scoped();
    if(ignoreType(scoped))
    {
        return false;
    }

    _out.newline();
    _out.newline();
    _out << "<!-- struct " << scoped << " -->";
    _out << se("dump") << attr("type", scoped) << ee;

    return false;
}
예제 #2
0
bool
FreezeScript::invokeGlobalFunction(const Ice::CommunicatorPtr& communicator, const string& name, const DataList& args,
                                   DataPtr& result, const DataFactoryPtr& factory, 
                                   const ErrorReporterPtr& errorReporter)
{
    //
    // Global function.
    //
    if(name == "typeOf")
    {
        if(args.size() != 1)
        {
            errorReporter->error("typeOf() requires one argument");
        }
        result = factory->createString(typeToString(args.front()->getType()), false);
        return true;
    }
    else if(name == "generateUUID")
    {
        if(args.size() != 0)
        {
            errorReporter->error("generateUUID() accepts no arguments");
        }
        result = factory->createString(IceUtil::generateUUID(), false);
        return true;
    }
    else if(name == "stringToIdentity")
    {
        StringDataPtr str;
        if(args.size() > 0)
        {
            str = StringDataPtr::dynamicCast(args.front());
        }
        if(args.size() != 1 || !str)
        {
            errorReporter->error("stringToIdentity() requires a string argument");
        }

        //
        // Parse the identity string.
        //
        string idstr = str->stringValue();
        Ice::Identity id;
        try
        {
            id = communicator->stringToIdentity(idstr);
        }
        catch(const Ice::IdentityParseException& ex)
        {
            errorReporter->error("error in stringToIdentity():\n" + ex.str);
        }

        //
        // Create a data representation of Ice::Identity.
        //
        Slice::UnitPtr unit = str->getType()->unit();
        Slice::TypeList l = unit->lookupType("::Ice::Identity", false);
        assert(!l.empty());
        DataPtr identity = factory->create(l.front(), false);
        StringDataPtr member;
        member = StringDataPtr::dynamicCast(identity->getMember("name"));
        assert(member);
        member->setValue(id.name);
        member = StringDataPtr::dynamicCast(identity->getMember("category"));
        assert(member);
        member->setValue(id.category);
        result = identity;
        return true;
    }
    else if(name == "identityToString")
    {
        StructDataPtr identity;
        if(args.size() > 0)
        {
            identity = StructDataPtr::dynamicCast(args.front());
        }
        if(identity)
        {
            Slice::TypePtr argType = identity->getType();
            Slice::StructPtr st = Slice::StructPtr::dynamicCast(argType);
            if(!st || st->scoped() != "::Ice::Identity")
            {
                identity = 0;
            }
        }
        if(args.size() != 1 || !identity)
        {
            errorReporter->error("identityToString() requires a argument of type ::Ice::Identity");
        }

        //
        // Compose the identity.
        //
        Ice::Identity id;
        StringDataPtr member;
        member = StringDataPtr::dynamicCast(identity->getMember("name"));
        assert(member);
        id.name = member->stringValue();
        member = StringDataPtr::dynamicCast(identity->getMember("category"));
        assert(member);
        id.category = member->stringValue();

        result = factory->createString(communicator->identityToString(id), false);
        return true;
    }
    else if(name == "stringToProxy")
    {
        StringDataPtr str;
        if(args.size() > 0)
        {
            str = StringDataPtr::dynamicCast(args.front());
        }
        if(args.size() != 1 || !str)
        {
            errorReporter->error("stringToProxy() requires a string argument");
        }

        //
        // Parse the proxy;
        //
        string sprx = str->stringValue();
        Ice::ObjectPrx prx;
        try
        {
            prx = factory->getCommunicator()->stringToProxy(sprx);
        }
        catch(const Ice::ProxyParseException& ex)
        {
            errorReporter->error("error in stringToProxy():\n" + ex.str);
        }

        Slice::UnitPtr unit = str->getType()->unit();
        ProxyDataPtr p =
            ProxyDataPtr::dynamicCast(factory->create(unit->builtin(Slice::Builtin::KindObjectProxy), false));
        p->setValue(prx);
        result = p;
        return true;
    }
    else if(name == "proxyToString")
    {
        ProxyDataPtr prx;
        if(args.size() > 0)
        {
            prx = ProxyDataPtr::dynamicCast(args.front());
        }
        if(args.size() != 1 || !prx)
        {
            errorReporter->error("proxyToString() requires a proxy argument");
        }

        result = factory->createString(prx->toString(), false);
        return true;
    }
    else if(name == "lowercase")
    {
        StringDataPtr str;
        if(args.size() > 0)
        {
            str = StringDataPtr::dynamicCast(args.front());
        }
        if(args.size() != 1 || !str)
        {
            errorReporter->error("lowercase() requires a string argument");
        }
        string val = IceUtilInternal::toLower(str->stringValue());
        result = factory->createString(val, false);
        return true;
    }

    return false;
}