/** * <p>Copyright: Copyright (c) 2013</p> * <p>Company: �������ӹɷ����޹�˾</p> */ package com.hundsun.ares.studio.atom.compiler.macro.handlers; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import com.hundsun.ares.studio.atom.compiler.constant.IAtomEngineContextConstant; import com.hundsun.ares.studio.atom.compiler.macro.MacroConstant; import com.hundsun.ares.studio.atom.compiler.token.NestPackAddValueToken; import com.hundsun.ares.studio.engin.constant.IEngineContextConstant; import com.hundsun.ares.studio.engin.constant.ITokenConstant; import com.hundsun.ares.studio.engin.macrohandler.IMacroTokenHandler; import com.hundsun.ares.studio.engin.skeleton.ISkeletonAttributeHelper; import com.hundsun.ares.studio.engin.token.DefaultTokenEvent; import com.hundsun.ares.studio.engin.token.ICodeToken; import com.hundsun.ares.studio.engin.token.ITokenListenerManager; import com.hundsun.ares.studio.engin.token.macro.IMacroToken; /** * @author liaogc * */ public class NestPackAddValueMacroHandler implements IMacroTokenHandler{ /* (non-Javadoc) * @see com.hundsun.ares.studio.engin.macrohandler.IMacroTokenHandler#getKey() */ @Override public String getKey() { return MacroConstant.NEST_PACK_ADD_VALUE_MACRONAME; } /* (non-Javadoc) * @see com.hundsun.ares.studio.engin.macrohandler.IMacroTokenHandler#handle(com.hundsun.ares.studio.engin.token.macro.IMacroToken, java.util.Map) */ @Override public Iterator<ICodeToken> handle(IMacroToken token, Map<Object, Object> context) throws Exception { ISkeletonAttributeHelper helper = (ISkeletonAttributeHelper)context.get(IAtomEngineContextConstant.SKELETON_ATTRIBUTE_HELPER); List<ICodeToken> codeTokens= new ArrayList<ICodeToken>(); if (token.getParameters().length !=2) { ITokenListenerManager manager =(ITokenListenerManager) context.get(IEngineContextConstant.TOKEN_LISTENER_MANAGER); String message = String.format("��[%s]ȱ�ٲ�����", MacroConstant.NEST_PACK_ADD_VALUE_MACRONAME); manager.fireEvent(new DefaultTokenEvent(ITokenConstant.EVENT_ENGINE_WARNNING,message)); }else{ String param1 = StringUtils.trim(token.getParameters()[0]); String param2 = StringUtils.trim(token.getParameters()[1]); if(StringUtils.indexOf(param2,"@")>-1){//��ȡȡ����Ӧ�IJ�������Ķ����� param2 = StringUtils.substring(param2,StringUtils.indexOf(param2,"@")+1); if(StringUtils.endsWith(param2,"ResultSet")){ param2 = StringUtils.substring(param2,0,StringUtils.indexOf(param2,"ResultSet")); } } if(StringUtils.indexOf(param1,"@")>-1){ param1 = StringUtils.substring(param1,StringUtils.indexOf(param1,"@")+1); if(!StringUtils.endsWith(param1,"ResultSet")){ param1+="ResultSet"; } } codeTokens.add(new NestPackAddValueToken(param1,param2));//������Ӧ��token helper.addAttribute(IAtomEngineContextConstant.ATTR_OUT_OBJECT_INIT_VARIABLE_LIST, param2);//���뵽Ҫ�����Ķ�����������б��� List<String> popObjectVarList = (List<String>)context.get(IEngineContextConstant.PSEUDO_CODE_OBJECT_PARA_LIST); popObjectVarList.add(param2);//���뵽����α�����б��� List<String> popVarList = (List<String>)context.get(IEngineContextConstant.PSEUDO_CODE_PARA_LIST); popVarList.remove(param2);//����ͨα�����б� ��ɾ�� } return codeTokens.iterator(); } }