1 22 package org.jboss.beans.metadata.plugins; 23 24 import java.util.List ; 25 import java.util.Set ; 26 27 import org.jboss.beans.metadata.spi.LifecycleMetaData; 28 import org.jboss.beans.metadata.spi.MetaDataVisitor; 29 import org.jboss.beans.metadata.spi.MetaDataVisitorNode; 30 import org.jboss.beans.metadata.spi.ParameterMetaData; 31 import org.jboss.dependency.spi.ControllerState; 32 import org.jboss.kernel.plugins.config.Configurator; 33 import org.jboss.kernel.spi.dependency.KernelControllerContext; 34 import org.jboss.reflect.spi.ClassInfo; 35 import org.jboss.reflect.spi.MethodInfo; 36 import org.jboss.util.JBossObject; 37 import org.jboss.util.JBossStringBuilder; 38 39 45 public class AbstractLifecycleMetaData extends AbstractFeatureMetaData implements LifecycleMetaData 46 { 47 48 protected ControllerState state; 49 50 51 protected String methodName; 52 53 54 protected List <ParameterMetaData> parameters; 55 56 57 protected String type; 58 59 62 public AbstractLifecycleMetaData() 63 { 64 } 65 66 public ControllerState getState() 67 { 68 return state; 69 } 70 71 public void setState(ControllerState state) 72 { 73 this.state = state; 74 } 75 76 public String getMethodName() 77 { 78 return methodName; 79 } 80 81 86 public void setMethodName(String name) 87 { 88 this.methodName = name; 89 flushJBossObjectCache(); 90 } 91 92 public List <ParameterMetaData> getParameters() 93 { 94 return parameters; 95 } 96 97 102 public void setParameters(List <ParameterMetaData> parameters) 103 { 104 this.parameters = parameters; 105 flushJBossObjectCache(); 106 } 107 108 public String getType() 109 { 110 return type; 111 } 112 113 public void setType(String type) 114 { 115 this.type = type; 116 } 117 118 public void initialVisit(MetaDataVisitor visitor) 119 { 120 visitor.setContextState(state); 121 super.initialVisit(visitor); 122 } 123 124 protected void addChildren(Set <MetaDataVisitorNode> children) 125 { 126 super.addChildren(children); 127 if (parameters != null) 128 children.addAll(parameters); 129 } 130 131 public Class getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable 132 { 133 ParameterMetaData parameter = (ParameterMetaData) previous; 134 KernelControllerContext context = visitor.getControllerContext(); 135 String method = (methodName != null ? methodName : type); 136 String [] parameterTypes = Configurator.getParameterTypes(false, parameters); 137 MethodInfo methodInfo = Configurator.findMethodInfo(getClassInfo(context), method, parameterTypes); 138 return applyCollectionOrMapCheck(methodInfo.getParameterTypes()[parameter.getIndex()].getType()); 139 } 140 141 protected ClassInfo getClassInfo(KernelControllerContext context) throws Throwable 142 { 143 return context.getBeanInfo().getClassInfo(); 144 } 145 146 public void toString(JBossStringBuilder buffer) 147 { 148 if (methodName != null) 149 buffer.append("method=").append(methodName); 150 buffer.append(" parameters="); 151 JBossObject.list(buffer, parameters); 152 buffer.append(" "); 153 super.toString(buffer); 154 } 155 156 public void toShortString(JBossStringBuilder buffer) 157 { 158 buffer.append(methodName); 159 } 160 } 161 | Popular Tags |