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


Java GroovyObject类代码示例

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


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

示例1: determineName

import groovy.lang.GroovyObject; //导入依赖的package包/类
public String determineName(Object thing) {
    Object name;
    try {
        if (thing instanceof Named) {
            name = ((Named) thing).getName();
        } else if (thing instanceof Map) {
            name = ((Map) thing).get("name");
        } else if (thing instanceof GroovyObject) {
            name = ((GroovyObject) thing).getProperty("name");
        } else {
            name = DynamicObjectUtil.asDynamicObject(thing).getProperty("name");
        }
    } catch (MissingPropertyException e) {
        throw new NoNamingPropertyException(thing);
    }

    if (name == null) {
        throw new NullNamingPropertyException(thing);
    }

    return name.toString();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:DynamicPropertyNamer.java

示例2: execPlugIn

import groovy.lang.GroovyObject; //导入依赖的package包/类
public GroovyObject execPlugIn(String name, GroovyObject groovyObject,
		GroovyObject proxyObject) throws Exception {
	Field[] fields=groovyObject.getClass().getDeclaredFields();
	int size=fields.length;
	for(int i=0;i<size;i++){
		Field field=fields[i];
		Resource anno=field.getAnnotation(Resource.class);
		if(anno!=null){
			String beanId=anno.name();
			if(beanId==null || "".equals(beanId)){
				beanId=field.getName();
			}
			Object beanObj=MicroContextHolder.getContext().getBean(beanId);
			field.set(groovyObject, beanObj);
		}
	}
	return proxyObject;
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:19,代码来源:MicroInjectPlugin.java

示例3: execGroovy

import groovy.lang.GroovyObject; //导入依赖的package包/类
public static boolean execGroovy(String groovyName, String methodName,
		Object... paramArray) {
	try {
		GroovyObject groovyObject = (GroovyObject) getGroovyObj(groovyName);
		//groovyObject.invokeMethod(methodName, paramArray);
		//GroovyAopInter groovyAop=(GroovyAopInter) MicroContextHolder.getContextMap().get("groovyAop");
		GroovyAopInter firstAop=GroovyAopChain.getFirstAop();
		Object retObj=null;
		if(firstAop==null){
			retObj=groovyObject.invokeMethod(methodName, paramArray);
		}else{
			retObj=firstAop.invokeMethod(groovyObject,groovyName, methodName, paramArray);
		}			
		return true;
	} catch (Throwable t) {
		logger.error(t.toString(), t);
		if(throwFlag){
			throw new RuntimeException(t);
		}
		return false;
	}
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:23,代码来源:GroovyExecUtil.java

示例4: execGroovyRetObj

import groovy.lang.GroovyObject; //导入依赖的package包/类
public static Object execGroovyRetObj(String groovyName, String methodName,
		Object... paramArray) {
	try {
		GroovyObject groovyObject = (GroovyObject) getGroovyObj(groovyName);
		//GroovyAopInter groovyAop=(GroovyAopInter) MicroContextHolder.getContextMap().get("groovyAop");
		GroovyAopInter firstAop=GroovyAopChain.getFirstAop();
		Object retObj=null;
		if(firstAop==null){
			retObj=groovyObject.invokeMethod(methodName, paramArray);
		}else{
			retObj=firstAop.invokeMethod(groovyObject,groovyName, methodName, paramArray);
		}
		return retObj;
	} catch (Throwable t) {
		logger.error(t.toString(), t);
		if(throwFlag){
			throw new RuntimeException(t);
		}
		return null;
	}
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:22,代码来源:GroovyExecUtil.java

示例5: loadGroovy

import groovy.lang.GroovyObject; //导入依赖的package包/类
public static void loadGroovy(String name, String content) throws Exception {
	logger.info("begin load groovy name=" + name);
	logger.debug("groovy content=" + content);
	if(name.toLowerCase().contains("abstract")){
		logger.info("skip load groovy name=" + name);
		return;
	}
	ClassLoader parent = GroovyLoadUtil.class.getClassLoader();
	GroovyClassLoader loader = new GroovyClassLoader(parent);
	Class<?> groovyClass = loader.parseClass(content,name+".groovy");
	GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
	
	GroovyObject proxyObject=groovyObject;		
	if(pluginList!=null){
		
		int size=pluginList.size();
		for(int i=0;i<size;i++){
			IGroovyLoadPlugin plugin=(IGroovyLoadPlugin) pluginList.get(i);
			proxyObject=plugin.execPlugIn(name, groovyObject, proxyObject);
		}
	}		
	GroovyExecUtil.getGroovyMap().put(name, proxyObject);		
	//GroovyExecUtil.getGroovyMap().put(name, groovyObject);
	logger.info("finish load groovy name=" + name);
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:26,代码来源:GroovyLoadUtil.java

示例6: testScript

import groovy.lang.GroovyObject; //导入依赖的package包/类
@Test(groups = {"groovy"})
public void testScript() throws Exception {
    String f1 = new File("./src/test/resources/StoreProc.groovy").getCanonicalPath();
    URL url = new URL("file://"+f1);
    ExtendedGroovyLoader classLoader = new ExtendedGroovyLoader();
    Class cls = classLoader.parseClass(new File(f1));
    GroovyObject groovyObj = (GroovyObject) cls.newInstance();
    System.out.println((String) groovyObj.invokeMethod("sayHello", new Object[] { "test" }) );
    groovyObj.getMetaClass().setProperty(groovyObj, "city", "cypress");
    System.out.println( groovyObj.getMetaClass().getProperty(groovyObj,"city"));
    Method[] methods = cls.getDeclaredMethods();
    System.out.println("methods "+ methods.length);
    dumpMethod( methods);
    if ( classLoader.isSourceChange(url, cls)) {
        System.out.println("source change for f1 "+f1);
        Class cls1 = classLoader.recompile(url, groovyObj.getClass().getName(), cls);
        GroovyObject groovyObj1 = (GroovyObject) cls1.newInstance();
        System.out.println( groovyObj1.invokeMethod("sayHello", new Object[]{"test"}) );
        //assert "hello test".equals( output);

    }

}
 
开发者ID:viant,项目名称:CacheStore,代码行数:24,代码来源:TestGroovyScript.java

示例7: customize

import groovy.lang.GroovyObject; //导入依赖的package包/类
@Override
public void customize(GroovyObject goo) {
	DelegatingMetaClass dmc = new DelegatingMetaClass(goo.getMetaClass()) {
		@Override
		public Object invokeMethod(Object arg0, String mName, Object[] arg2) {
			if (mName.contains("Missing")) {
				throw new IllegalStateException("Gotcha");
			}
			else {
				return super.invokeMethod(arg0, mName, arg2);
			}
		}
	};
	dmc.initialize();
	goo.setMetaClass(dmc);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:GroovyScriptFactoryTests.java

示例8: getGroovyObject

import groovy.lang.GroovyObject; //导入依赖的package包/类
@SuppressWarnings("resource")
private static final GroovyObject getGroovyObject(String rule)
		throws IllegalAccessException, InstantiationException {
	if (!RULE_CLASS_CACHE.containsKey(rule)) {
		synchronized (GroovyRuleEngine.class) {
			if (!RULE_CLASS_CACHE.containsKey(rule)) {
				Matcher matcher = DimensionRule.RULE_COLUMN_PATTERN.matcher(rule);
				StringBuilder engineClazzImpl = new StringBuilder(200)
						.append("class RuleEngineBaseImpl extends " + RuleEngineBase.class.getName() + "{")
						.append("Object execute(Map context) {").append(matcher.replaceAll("context.get(\"$1\")"))
						.append("}").append("}");
				GroovyClassLoader loader = new GroovyClassLoader(AbstractDimensionRule.class.getClassLoader());
				Class<?> engineClazz = loader.parseClass(engineClazzImpl.toString());
				RULE_CLASS_CACHE.put(rule, engineClazz);
			}
		}
	}
	return (GroovyObject) RULE_CLASS_CACHE.get(rule).newInstance();
}
 
开发者ID:dianping,项目名称:zebra,代码行数:20,代码来源:GroovyRuleEngine.java

示例9: createProxyClass

import groovy.lang.GroovyObject; //导入依赖的package包/类
static Class<?> createProxyClass(Class<?> persistentClass, Class<?>[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        Set<Class<?>> allInterfaces = new HashSet<>();
        if(interfaces != null) {
            allInterfaces.addAll(Arrays.asList(interfaces));
        }
        allInterfaces.add(GroovyObject.class);
        allInterfaces.add(EntityProxy.class);
        ProxyFactory factory = createJavassistProxyFactory(persistentClass, allInterfaces.toArray(new Class<?>[allInterfaces.size()]));
        Class<?> proxyClass = factory.createClass();
        HibernateUtils.enhanceProxyClass(proxyClass);
        return proxyClass;
    }
    catch (Throwable t) {
        LogFactory.getLog(BasicLazyInitializer.class).error(
                "Javassist Enhancement failed: " + persistentClass.getName(), t);
        throw new HibernateException("Javassist Enhancement failed: " + persistentClass.getName(), t);
    }
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:22,代码来源:JavassistEntityProxyUtils.java

示例10: getProxyFactory

import groovy.lang.GroovyObject; //导入依赖的package包/类
private static Class<?> getProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        Set<Class<?>> allInterfaces = new HashSet<Class<?>>();
        if(interfaces != null) {
            allInterfaces.addAll(Arrays.asList(interfaces));
        }
        allInterfaces.add(GroovyObject.class);
        allInterfaces.add(EntityProxy.class);
        ProxyFactory factory = createProxyFactory(persistentClass, allInterfaces.toArray(new Class<?>[allInterfaces.size()]));
        Class<?> proxyClass = factory.createClass();
        HibernateUtils.enhanceProxyClass(proxyClass);
        return proxyClass;
    }
    catch (Throwable t) {
        LogFactory.getLog(BasicLazyInitializer.class).error(
                "Javassist Enhancement failed: " + persistentClass.getName(), t);
        throw new HibernateException("Javassist Enhancement failed: " + persistentClass.getName(), t);
    }
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:22,代码来源:GroovyAwareJavassistLazyInitializer.java

示例11: getActionBeanType

import groovy.lang.GroovyObject; //导入依赖的package包/类
@Override
public Class<? extends ActionBean> getActionBeanType(String path) {
    if(path.startsWith(APIRoot.PATH_PREFIX)) {
        return null; //Not an ActionBean (as far as Stripes is concerned)
    }
    Dispatch dispatch = getDispatch(path);
    if(dispatch != null) {
        Class<? extends ActionBean> actionBeanClass = dispatch.getActionBeanClass();
        if(GroovyObject.class.isAssignableFrom(actionBeanClass) &&
           !eventMappings.containsKey(actionBeanClass)) {
            synchronized (this) {
                addActionBean(actionBeanClass);
            }
        }
        return actionBeanClass;
    } else {
        return super.getActionBeanType(path);
    }
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:20,代码来源:ModelActionResolver.java

示例12: getBody

import groovy.lang.GroovyObject; //导入依赖的package包/类
/**
 * Creates a Closure representing the body of this GPathResult.
 *
 * @return the body of this GPathResult, converted to a <code>Closure</code>
 */
public Closure getBody() {
    return new Closure(this.parent,this) {
        public void doCall(Object[] args) {
            final GroovyObject delegate = (GroovyObject)getDelegate();
            final GPathResult thisObject = (GPathResult)getThisObject();

            Node node = (Node)thisObject.getAt(0);
            List children = node.children();

            for (Object child : children) {
                delegate.getProperty("mkp");
                if (child instanceof Node) {
                    delegate.invokeMethod("yield", new Object[]{new NodeChild((Node) child, thisObject, "*", null)});
                } else {
                    delegate.invokeMethod("yield", new Object[]{child});
                }
            }                
        }
    };
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:GPathResult.java

示例13: invokeMethod

import groovy.lang.GroovyObject; //导入依赖的package包/类
/**
 * Invokes the given method on the object.
 */
public static Object invokeMethod(Object object, String methodName, Object arguments) {
    if (object == null) {
        object = NullObject.getNullObject();
        //throw new NullPointerException("Cannot invoke method " + methodName + "() on null object");
    }

    // if the object is a Class, call a static method from that class
    if (object instanceof Class) {
        Class theClass = (Class) object;
        MetaClass metaClass = metaRegistry.getMetaClass(theClass);
        return metaClass.invokeStaticMethod(object, methodName, asArray(arguments));
    }

    // it's an instance; check if it's a Java one
    if (!(object instanceof GroovyObject)) {
        return invokePojoMethod(object, methodName, arguments);
    }

    // a groovy instance (including builder, closure, ...)
    return invokePogoMethod(object, methodName, arguments);
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:InvokerHelper.java

示例14: createPogoMetaClassGetPropertySite

import groovy.lang.GroovyObject; //导入依赖的package包/类
private CallSite createPogoMetaClassGetPropertySite(GroovyObject receiver) {
    MetaClass metaClass = receiver.getMetaClass();

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PogoMetaClassGetPropertySite(this, metaClass);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(this.array.owner, receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePogoFieldSite(this, metaClass, (CachedField) effective);
            else
                site = new GetEffectivePogoPropertySite(this, metaClass, effective);
        } else {
            site = new PogoMetaClassGetPropertySite(this, metaClass);
        }
    }

    array.array[index] = site;
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AbstractCallSite.java

示例15: callCurrent

import groovy.lang.GroovyObject; //导入依赖的package包/类
public final Object callCurrent(GroovyObject receiver, Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(array.owner, receiver, name, args, false, true);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException)e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the object's own invokeMethod()
                    return ((GroovyObject)receiver).invokeMethod(name, args);
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
      return CallSiteArray.defaultCallCurrent(this, receiver, args);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:PogoMetaClassSite.java


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