当前位置: 首页>>代码示例>>Java>>正文


Java GroovyObject.setProperty方法代码示例

本文整理汇总了Java中groovy.lang.GroovyObject.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyObject.setProperty方法的具体用法?Java GroovyObject.setProperty怎么用?Java GroovyObject.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在groovy.lang.GroovyObject的用法示例。


在下文中一共展示了GroovyObject.setProperty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_groovy

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public void test_groovy() throws Exception {
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    GroovyClassLoader loader = new GroovyClassLoader(parent);

    // A类
    Class AClass = loader.parseClass("class A {\n" + //
                                     "    int id\n" + //
                                     "}");

    // A实例
    GroovyObject a = (GroovyObject) AClass.newInstance();
    a.setProperty("id", 33);
    String textA = JSON.toJSONString(a);
    
    GroovyObject aa = (GroovyObject) JSON.parseObject(textA, AClass);
    Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));
    
    System.out.println(a);

    // B类,继承于A
    Class BClass = loader.parseClass("class B extends A {\n" + //
    		"    String name\n" + //
    		"}");

    // B实例
    GroovyObject b = (GroovyObject) BClass.newInstance();
    b.setProperty("name", "jobs");
    String textB = JSON.toJSONString(b);
    GroovyObject bb = (GroovyObject) JSON.parseObject(textB, BClass);
    Assert.assertEquals(b.getProperty("id"), bb.getProperty("id"));
    Assert.assertEquals(b.getProperty("name"), bb.getProperty("name"));
    

    // 序列化失败
    System.out.println(JSON.toJSONString(b, true));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:GroovyTest.java

示例2: setGroovyObjectProperty

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static void setGroovyObjectProperty(Object messageArgument, Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
    try {
        receiver.setProperty(messageName, messageArgument);
    } catch (GroovyRuntimeException gre) {
        throw unwrap(gre);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:ScriptBytecodeAdapter.java

示例3: setProperty

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static void setProperty(Object object, String property, Object newValue) {
    if (object == null) {
        object = NullObject.getNullObject();
    }

    if (object instanceof GroovyObject) {
        GroovyObject pogo = (GroovyObject) object;
        pogo.setProperty(property, newValue);
    } else if (object instanceof Class) {
        metaRegistry.getMetaClass((Class) object).setProperty((Class) object, property, newValue);
    } else {
        ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:InvokerHelper.java

示例4: testProperty

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public void testProperty() throws Exception {
    GroovyObject object = compile("src/test/org/codehaus/groovy/classgen/MyBean.groovy");
    System.out.println("Got object: " + object);

    Object value = object.getProperty("name");
    assertEquals("name property", "James", value);

    object.setProperty("name", "Bob");
    assertEquals("name property", "Bob", object.getProperty("name"));
}
 
开发者ID:apache,项目名称:groovy,代码行数:11,代码来源:GetPropertyTest.java

示例5: main

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static void main(String[] args) {
    if (args.length <= 0) {
        System.out.println("Usage: home [configuaration] [localcopy]");
        return;
    }

    String home = args[0];

    Properties p = new Properties();
    System.setProperty("openejb.home", home);
    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory");
    p.put("openejb.loader", "embed");
    p.put("openejb.home", home);

    if (args.length > 1) {
        String conf = args[1];
        System.setProperty("openejb.configuration", conf);
        p.put("openejb.configuration", conf);
    }
    if (args.length > 2) {
        String copy = args[2];
        System.setProperty("openejb.localcopy", copy);
        p.put("openejb.localcopy", copy);
    }
    try {
        InitialContext ctx = new InitialContext(p);

        GroovyShell shell = new GroovyShell();
        shell.setVariable("context", ctx);
        //shell.evaluate("src/test/groovy/j2ee/CreateData.groovy");

        //shell.evaluate("src/main/groovy/ui/Console.groovy");
        GroovyObject console = (GroovyObject) InvokerHelper.invokeConstructorOf("groovy.ui.Console", null);
        console.setProperty("shell", shell);
        console.invokeMethod("run", null);
        /*
        */
    }
    catch (Exception e) {
        System.out.println("Caught: " + e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:43,代码来源:J2eeConsole.java

示例6: setGroovyObjectPropertySafe

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static void setGroovyObjectPropertySafe(Object messageArgument, Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
    if (receiver == null) return;
    receiver.setProperty(messageName, messageArgument);
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:ScriptBytecodeAdapter.java

示例7: setGroovyObjectProperty

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
/**
 * This is so we don't have to reorder the stack when we call this method.
 * At some point a better name might be in order.
 */
public static void setGroovyObjectProperty(Object newValue, GroovyObject object, String property) {
    object.setProperty(property, newValue);
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:InvokerHelper.java


注:本文中的groovy.lang.GroovyObject.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。