1 22 package org.jboss.beans.metadata.plugins.factory; 23 24 import java.util.ArrayList ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.Set ; 29 30 import org.jboss.beans.metadata.plugins.AbstractBeanMetaData; 31 import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData; 32 import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData; 33 import org.jboss.beans.metadata.plugins.AbstractMapMetaData; 34 import org.jboss.beans.metadata.plugins.AbstractParameterMetaData; 35 import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData; 36 import org.jboss.beans.metadata.plugins.AbstractValueMetaData; 37 import org.jboss.beans.metadata.spi.*; 38 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants; 39 import org.jboss.kernel.spi.config.KernelConfigurator; 40 41 47 public class GenericBeanFactoryMetaData extends AbstractBeanMetaData 48 { 49 52 public GenericBeanFactoryMetaData() 53 { 54 setBean(GenericBeanFactory.class.getName()); 55 AbstractConstructorMetaData constructor = new AbstractConstructorMetaData(); 56 ArrayList <ParameterMetaData> parameters = new ArrayList <ParameterMetaData>(); 57 parameters.add(new AbstractParameterMetaData(KernelConfigurator.class.getName(), new AbstractDependencyValueMetaData(KernelConstants.KERNEL_CONFIGURATOR_NAME))); 58 constructor.setParameters(parameters); 59 setConstructor(constructor); 60 setProperties(new HashSet <PropertyMetaData>()); 61 } 62 63 68 public GenericBeanFactoryMetaData(String name) 69 { 70 this(); 71 setName(name); 72 } 73 74 80 public GenericBeanFactoryMetaData(String name, String bean) 81 { 82 this(name); 83 setBeanClass(bean); 84 } 85 86 91 public String getBeanClass() 92 { 93 AbstractPropertyMetaData prop = (AbstractPropertyMetaData) getProperty("bean"); 94 if (prop != null) 95 { 96 AbstractValueMetaData value = (AbstractValueMetaData) prop.getValue(); 97 if (value != null) 98 return (String ) value.getUnderlyingValue(); 99 } 100 return null; 101 } 102 103 108 public void setBeanClass(String beanClass) 109 { 110 Set <PropertyMetaData> properties = getProperties(); 111 properties.add(new AbstractPropertyMetaData("bean", new AbstractValueMetaData(beanClass))); 112 } 113 114 public void setClassLoader(ClassLoaderMetaData classLoader) 115 { 116 super.setClassLoader(classLoader); 117 Set <PropertyMetaData> properties = getProperties(); 118 properties.add(new AbstractPropertyMetaData("classLoader", new AbstractValueMetaData(classLoader))); 119 } 120 121 126 public void setBeanConstructor(ConstructorMetaData constructor) 127 { 128 Set <PropertyMetaData> properties = getProperties(); 129 properties.add(new AbstractPropertyMetaData("constructor", new AbstractValueMetaData(constructor))); 130 } 131 132 138 public ValueMetaData getBeanProperty(String name) 139 { 140 if (name == null) 141 throw new IllegalArgumentException ("Null name"); 142 PropertyMetaData properties = getProperty("properties"); 143 if (properties == null) 144 return null; 145 AbstractMapMetaData map = (AbstractMapMetaData) properties.getValue(); 146 for (Iterator i = map.entrySet().iterator(); i.hasNext();) 147 { 148 Map.Entry entry = (Map.Entry ) i.next(); 149 ValueMetaData key = (ValueMetaData) entry.getKey(); 150 if (key.getUnderlyingValue().equals(name)) 151 { 152 ValueMetaData vmd = (ValueMetaData) entry.getValue(); 153 return (ValueMetaData) vmd.getUnderlyingValue(); 154 } 155 } 156 return null; 157 } 158 159 164 public void addBeanProperty(PropertyMetaData property) 165 { 166 PropertyMetaData properties = getProperty("properties"); 167 168 AbstractMapMetaData map; 169 if (properties == null) 170 { 171 map = new AbstractMapMetaData(); 172 properties = new AbstractPropertyMetaData("properties", map); 173 addProperty(properties); 174 } 175 else 176 { 177 map = (AbstractMapMetaData) properties.getValue(); 178 } 179 180 ValueMetaData valueMetaData = property.getValue(); 181 valueMetaData = new AbstractValueMetaData(valueMetaData); 182 map.put(new AbstractValueMetaData(property.getName()), valueMetaData); 183 } 184 185 public void setBeanCreate(LifecycleMetaData lifecycle) 186 { 187 Set <PropertyMetaData> properties = getProperties(); 188 properties.add(new AbstractPropertyMetaData("create", new AbstractValueMetaData(lifecycle))); 189 } 190 191 public void setBeanStart(LifecycleMetaData lifecycle) 192 { 193 Set <PropertyMetaData> properties = getProperties(); 194 properties.add(new AbstractPropertyMetaData("start", new AbstractValueMetaData(lifecycle))); 195 } 196 } 197 | Popular Tags |