1 22 package org.jboss.beans.metadata.plugins; 23 24 import org.jboss.beans.metadata.spi.InstallMetaData; 25 import org.jboss.beans.metadata.spi.MetaDataVisitor; 26 import org.jboss.dependency.plugins.AbstractDependencyItem; 27 import org.jboss.dependency.spi.ControllerState; 28 import org.jboss.dependency.spi.DependencyItem; 29 import org.jboss.dependency.spi.ControllerContext; 30 import org.jboss.kernel.spi.dependency.KernelControllerContext; 31 import org.jboss.kernel.spi.dependency.KernelController; 32 import org.jboss.kernel.spi.config.KernelConfigurator; 33 import org.jboss.util.JBossStringBuilder; 34 import org.jboss.reflect.spi.ClassInfo; 35 36 42 public class AbstractInstallMetaData extends AbstractLifecycleMetaData implements InstallMetaData 43 { 44 45 protected String bean; 46 47 48 protected ControllerState dependentState = ControllerState.INSTALLED; 49 50 53 public AbstractInstallMetaData() 54 { 55 setState(ControllerState.INSTALLED); 56 } 57 58 public String getBean() 59 { 60 return bean; 61 } 62 63 68 public void setBean(String bean) 69 { 70 this.bean = bean; 71 } 72 73 78 public void setDependentState(ControllerState dependentState) 79 { 80 this.dependentState = dependentState; 81 flushJBossObjectCache(); 82 } 83 84 public ControllerState getDependentState() 85 { 86 return dependentState; 87 } 88 89 public void initialVisit(MetaDataVisitor visitor) 90 { 91 KernelControllerContext context = visitor.getControllerContext(); 92 if (bean != null) 93 { 94 DependencyItem item = new InstallationDependencyItem(context.getName()); 95 visitor.addDependency(item); 96 } 97 super.initialVisit(visitor); 98 } 99 100 protected ClassInfo getClassInfo(KernelControllerContext context) throws Throwable 101 { 102 if (bean != null) 103 { 104 KernelController controller = (KernelController) context.getController(); 105 ControllerContext beanContext = controller.getContext(bean, ControllerState.INSTANTIATED); 106 if (beanContext != null) 107 { 108 KernelConfigurator configurator = controller.getKernel().getConfigurator(); 109 Object target = beanContext.getTarget(); 110 return configurator.getClassInfo(target.getClass()); 111 } 112 else 113 { 114 throw new IllegalArgumentException ("Cannot determine install bean class: " + this); 115 } 116 } 117 return super.getClassInfo(context); 118 } 119 120 public void toString(JBossStringBuilder buffer) 121 { 122 if (bean != null) 123 buffer.append("bean=").append(bean); 124 if (dependentState != ControllerState.INSTALLED); 125 buffer.append(" dependentState=" + dependentState); 126 buffer.append(" "); 127 super.toString(buffer); 128 } 129 130 public void toShortString(JBossStringBuilder buffer) 131 { 132 if (bean != null) 133 buffer.append(bean); 134 if (methodName != null) 135 buffer.append(".").append(methodName); 136 } 137 138 141 public class InstallationDependencyItem extends AbstractDependencyItem 142 { 143 148 public InstallationDependencyItem(Object name) 149 { 150 super(name, bean, state, dependentState); 151 } 152 } 153 } 154 | Popular Tags |