當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。