1 25 package org.objectweb.easybeans.tests.common.helper; 26 27 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.UNDEFINED; 28 import static org.objectweb.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance; 29 30 import java.util.ArrayList ; 31 import java.util.List ; 32 33 import javax.interceptor.InvocationContext; 34 import javax.jms.Message ; 35 36 import org.objectweb.easybeans.log.JLog; 37 import org.objectweb.easybeans.log.JLogFactory; 38 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess; 39 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.SLSBCallbackLoggerAccess; 40 41 46 public final class InterceptorHelper { 47 48 51 private static JLog logger = JLogFactory.getLog(InterceptorHelper.class); 52 53 56 private InterceptorHelper() { 57 } 58 59 70 @SuppressWarnings ("unchecked") 71 public static <E> Object addValue(final InvocationContext invocationContext, final E value, final String className) 72 throws Exception { 73 ItfCallbackLoggerAccess beanLogger = getBeanRemoteInstance(SLSBCallbackLoggerAccess.class, 74 ItfCallbackLoggerAccess.class); 75 boolean added = false; 76 77 Object [] arObj = invocationContext.getParameters(); 78 79 List <E> arOrder = null; 80 81 if (arObj[0] instanceof List ) { 82 arOrder = (List <E>) arObj[0]; 84 added = arOrder.add(value); 85 86 }else if (arObj[0] instanceof Message ){ 87 beanLogger.insertCallbackLogger(invocationContext.getTarget().getClass().toString(), UNDEFINED, className); 89 added = true; 90 } 91 92 if (!added) { 94 throw new IllegalStateException (className + " can not add the value " + value + "."); 95 } 96 logger.debug("Added: target={0}, interceptorName={1}, order={2}", 97 invocationContext.getTarget().toString(), className, value); 98 return invocationContext.proceed(); 99 } 100 101 106 public static String getString(final List list){ 107 StringBuffer result = new StringBuffer (""); 108 if (list != null){ 109 for(Object o : list){ 110 result.append(","); 111 result.append(o.toString()); 112 } 113 result.replace(0, 0, ""); 114 } 115 logger.debug("Result string = {0}", result.toString()); 116 return result.toString(); 117 } 118 119 124 @SuppressWarnings ({"boxing", "unchecked"}) 125 public static List getArray(final String str){ 126 List lst = new ArrayList <Integer >(); 127 128 if (str != null){ 129 String [] values = str.split(","); 130 for(int i = 0; i < values.length; i++){ 131 lst.add(Integer.parseInt(values[i])); 132 } 133 } 134 return lst; 135 } 136 137 144 public static String getPrintOrderErrorMsg(final List expected, final List result, final String seedMessage) { 145 String strMessage = seedMessage; 146 147 if (expected == null & result == null) { 148 strMessage += " Result=[null], Expected=[null]."; 149 } else if (expected == null) { 150 strMessage += " Result=" + result.toString() + ", Expected=[null]."; 151 } else if (result == null) { 152 strMessage += " Result=[null], Expected=" + expected.toString() + "."; 153 } else { 154 strMessage += " Actual=" + result.toString() + ", Expected=" + expected.toString() + "."; 155 } 156 return strMessage; 157 } 158 } 159 | Popular Tags |