// ignore XB property replacement
schemaBinding.setReplacePropertyRefs(false);
// deployment binding
TypeBinding deploymentType = schemaBinding.getType(deploymentTypeQName);
deploymentType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractKernelDeployment();
}
});
// deployment has a classloader
deploymentType.pushInterceptor(classloaderQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractKernelDeployment deployment = (AbstractKernelDeployment) parent;
AbstractClassLoaderMetaData classloader = (AbstractClassLoaderMetaData) child;
deployment.setClassLoader(classloader);
// add classloaders as value beans
List<BeanMetaDataFactory> beans = deployment.getBeanFactories();
if (beans == null)
{
beans = new ArrayList<BeanMetaDataFactory>();
deployment.setBeanFactories(beans);
}
}
});
// deployment has a list beans
deploymentType.pushInterceptor(beanQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractKernelDeployment deployment = (AbstractKernelDeployment) parent;
AbstractBeanMetaData bean = (AbstractBeanMetaData) child;
List<BeanMetaDataFactory> beans = deployment.getBeanFactories();
if (beans == null)
{
beans = new ArrayList<BeanMetaDataFactory>();
deployment.setBeanFactories(beans);
}
beans.add(bean);
}
});
// deployment has a list beanfactorys
deploymentType.pushInterceptor(beanFactoryQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractKernelDeployment deployment = (AbstractKernelDeployment) parent;
AbstractBeanMetaData bean = (AbstractBeanMetaData) child;
List<BeanMetaDataFactory> beans = deployment.getBeanFactories();
if (beans == null)
{
beans = new ArrayList<BeanMetaDataFactory>();
deployment.setBeanFactories(beans);
}
beans.add(bean);
}
});
// bean binding
TypeBinding beanType = schemaBinding.getType(beanTypeQName);
/*
ClassMetaData classMetaData = new ClassMetaData();
classMetaData.setImpl(AbstractBeanMetaData.class.getName());
beanType.setClassMetaData(classMetaData);
QName CLASS = new QName("class");
AttributeBinding attribute = beanType.getAttribute(CLASS);
PropertyMetaData propertyMetaData = new PropertyMetaData();
propertyMetaData.setName("bean");
attribute.setPropertyMetaData(propertyMetaData);
QName MODE = new QName("mode");
attribute = beanType.getAttribute(MODE);
ValueAdapter modeAdapter = new ValueAdapter()
{
public Object cast(Object o, Class c)
{
String string = (String) o;
return new ControllerMode(string);
}
};
attribute.setValueAdapter(modeAdapter);
*/
beanType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractBeanMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("name".equals(localName))
bean.setName(attrs.getValue(i));
else if ("class".equals(localName))
bean.setBean(attrs.getValue(i));
else if ("mode".equals(localName))
bean.setMode(ControllerMode.getInstance(attrs.getValue(i)));
}
}
});
// beanfactory binding
TypeBinding beanFactoryType = schemaBinding.getType(beanFactoryTypeQName);
beanFactoryType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("name".equals(localName))
bean.setName(attrs.getValue(i));
else if ("class".equals(localName))
bean.setBeanClass(attrs.getValue(i));
else if ("factoryClass".equals(localName))
bean.setFactoryClass(attrs.getValue(i));
else if ("mode".equals(localName))
bean.setMode(ControllerMode.getInstance(attrs.getValue(i)));
}
}
});
// bean has a classloader
beanType.pushInterceptor(classloaderQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractClassLoaderMetaData classloader = (AbstractClassLoaderMetaData) child;
bean.setClassLoader(classloader);
}
});
// beanfactory has a classloader
beanFactoryType.pushInterceptor(classloaderQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) parent;
AbstractClassLoaderMetaData classloader = (AbstractClassLoaderMetaData) child;
bean.setClassLoader(classloader);
}
});
// bean has a constructor
beanType.pushInterceptor(constructorQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) child;
bean.setConstructor(constructor);
}
});
// beanfactory has a constructor
beanFactoryType.pushInterceptor(constructorQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) parent;
AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) child;
bean.setBeanConstructor(constructor);
}
});
// classloader binding
TypeBinding classloaderType = schemaBinding.getType(classloaderTypeQName);
configureValueBindings(classloaderType);
classloaderType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractClassLoaderMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
}
});
// constructor binding
TypeBinding constructorType = schemaBinding.getType(constructorTypeQName);
constructorType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractConstructorMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("factoryClass".equals(localName))
constructor.setFactoryClass(attrs.getValue(i));
else if ("factoryMethod".equals(localName))
constructor.setFactoryMethod(attrs.getValue(i));
}
}
});
// constructor has a factory
constructorType.pushInterceptor(factoryQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) parent;
AbstractDependencyValueMetaData factory = (AbstractDependencyValueMetaData) child;
constructor.setFactory(factory);
}
});
// constructor has a list parameters
constructorType.pushInterceptor(parameterQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) parent;
AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
List<ParameterMetaData> parameters = constructor.getParameters();
if (parameters == null)
{
parameters = new ArrayList<ParameterMetaData>();
constructor.setParameters(parameters);
}
parameter.setIndex(parameters.size());
parameters.add(parameter);
}
});
// parameter binding
TypeBinding parameterType = schemaBinding.getType(parameterTypeQName);
configureValueBindings(parameterType);
parameterType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractParameterMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractParameterMetaData parameter = (AbstractParameterMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
parameter.setType(attrs.getValue(i));
else if ("replace".equals(localName) || "trim".equals(localName))
{
ValueMetaData vmd = parameter.getValue();
StringValueMetaData stringValueMetaData;
if (vmd != null && vmd instanceof StringValueMetaData)
stringValueMetaData = (StringValueMetaData)vmd;
else
{
stringValueMetaData = new StringValueMetaData();
parameter.setValue(stringValueMetaData);
}
if ("replace".equals(localName))
stringValueMetaData.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
else if ("trim".equals(localName))
stringValueMetaData.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
});
// parameter can take a value
parameterType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return new StringValueMetaData(value);
}
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
AbstractParameterMetaData parameter = (AbstractParameterMetaData) owner;
StringValueMetaData svmd = (StringValueMetaData) value;
ValueMetaData vmd = parameter.getValue();
if (vmd != null && vmd instanceof StringValueMetaData)
{
StringValueMetaData previous = (StringValueMetaData) vmd;
svmd.setReplace(previous.isReplace());
svmd.setTrim(previous.isTrim());
String type = previous.getType();
if (type != null)
svmd.setType(type);
}
parameter.setValue(svmd); }
});
// bean has a create
beanType.pushInterceptor(createQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
lifecycle.setType("create");
bean.setCreate(lifecycle);
}
});
// beanfactory has a create
beanFactoryType.pushInterceptor(createQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) parent;
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
lifecycle.setType("create");
bean.setBeanCreate(lifecycle);
}
});
// bean has a start
beanType.pushInterceptor(startQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
lifecycle.setType("start");
bean.setStart(lifecycle);
}
});
// beanfactory has a start
beanFactoryType.pushInterceptor(startQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) parent;
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
lifecycle.setType("start");
bean.setBeanStart(lifecycle);
}
});
// bean has a stop
beanType.pushInterceptor(stopQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
lifecycle.setType("stop");
bean.setStop(lifecycle);
}
});
// bean has a destroy
beanType.pushInterceptor(destroyQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
lifecycle.setType("destroy");
bean.setDestroy(lifecycle);
}
});
// lifecycle binding
TypeBinding lifecycleType = schemaBinding.getType(lifecycleTypeQName);
lifecycleType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractLifecycleMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("method".equals(localName))
lifecycle.setMethodName(attrs.getValue(i));
else if ("ignored".equals(localName))
lifecycle.setIgnored(Boolean.parseBoolean(attrs.getValue(i)));
}
}
});
// lifecycle has a list parameters
lifecycleType.pushInterceptor(parameterQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) parent;
AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
List<ParameterMetaData> parameters = lifecycle.getParameters();
if (parameters == null)
{
parameters = new ArrayList<ParameterMetaData>();
lifecycle.setParameters(parameters);
}
parameter.setIndex(parameters.size());
parameters.add(parameter);
}
});
// bean has a set of properties
beanType.pushInterceptor(propertyQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractPropertyMetaData property = (AbstractPropertyMetaData) child;
Set<PropertyMetaData> properties = bean.getProperties();
if (properties == null)
{
properties = new HashSet<PropertyMetaData>();
bean.setProperties(properties);
}
properties.add(property);
}
});
// beanfactory has a set of properties
beanFactoryType.pushInterceptor(propertyQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) parent;
AbstractPropertyMetaData property = (AbstractPropertyMetaData) child;
bean.addBeanProperty(property);
}
});
// bean has a set of depends
beanType.pushInterceptor(dependsQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractDependencyMetaData dependency = (AbstractDependencyMetaData) child;
Set<DependencyMetaData> depends = bean.getDepends();
if (depends == null)
{
depends = new HashSet<DependencyMetaData>();
bean.setDepends(depends);
}
depends.add(dependency);
}
});
// beanfactory has a set of depends
beanFactoryType.pushInterceptor(dependsQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData bean = (org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData) parent;
AbstractDependencyMetaData dependency = (AbstractDependencyMetaData) child;
Set<DependencyMetaData> depends = bean.getDepends();
if (depends == null)
{
depends = new HashSet<DependencyMetaData>();
bean.setDepends(depends);
}
depends.add(dependency);
}
});
// bean has a set of demands
beanType.pushInterceptor(demandQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractDemandMetaData demand = (AbstractDemandMetaData) child;
Set<DemandMetaData> demands = bean.getDemands();
if (demands == null)
{
demands = new HashSet<DemandMetaData>();
bean.setDemands(demands);
}
demands.add(demand);
}
});
// beanfactory has a set of demands
beanFactoryType.pushInterceptor(demandQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractDemandMetaData demand = (AbstractDemandMetaData) child;
Set<DemandMetaData> demands = bean.getDemands();
if (demands == null)
{
demands = new HashSet<DemandMetaData>();
bean.setDemands(demands);
}
demands.add(demand);
}
});
// bean has a set of supplies
beanType.pushInterceptor(supplyQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractSupplyMetaData supply = (AbstractSupplyMetaData) child;
Set<SupplyMetaData> supplies = bean.getSupplies();
if (supplies == null)
{
supplies = new HashSet<SupplyMetaData>();
bean.setSupplies(supplies);
}
supplies.add(supply);
}
});
// beanfactory has a set of supplies
beanFactoryType.pushInterceptor(supplyQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
AbstractSupplyMetaData supply = (AbstractSupplyMetaData) child;
Set<SupplyMetaData> supplies = bean.getSupplies();
if (supplies == null)
{
supplies = new HashSet<SupplyMetaData>();
bean.setSupplies(supplies);
}
supplies.add(supply);
}
});
// property binding
TypeBinding propertyType = schemaBinding.getType(propertyTypeQName);
configureValueBindings(propertyType);
propertyType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractPropertyMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractPropertyMetaData property = (AbstractPropertyMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("name".equals(localName))
property.setName(attrs.getValue(i));
else if ("preinstantiate".equals(localName))
property.setPreInstantiate(Boolean.parseBoolean(attrs.getValue(i)));
else if ("class".equals(localName) || "replace".equals(localName) || "trim".equals(localName))
{
StringValueMetaData svmd;
ValueMetaData vmd = property.getValue();
if (vmd == null || vmd instanceof StringValueMetaData == false)
{
svmd = new StringValueMetaData();
property.setValue(svmd);
}
else
{
svmd = (StringValueMetaData)vmd;
}
if ("class".equals(localName))
svmd.setType(attrs.getValue(i));
else if ("replace".equals(localName))
svmd.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
else if ("trim".equals(localName))
svmd.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
public Object endElement(Object o, QName qName, ElementBinding element)
{
AbstractPropertyMetaData x = (AbstractPropertyMetaData) o;
String name = x.getName();
if (name == null || name.trim().length() == 0)
throw new IllegalArgumentException("Null or empty property name.");
return o;
}
});
// property can take a value
propertyType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return new StringValueMetaData(value);
}
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
AbstractPropertyMetaData property = (AbstractPropertyMetaData) owner;
StringValueMetaData svmd = (StringValueMetaData) value;
ValueMetaData vmd = property.getValue();
if (vmd != null && vmd instanceof StringValueMetaData)
{
StringValueMetaData previous = (StringValueMetaData) vmd;
svmd.setReplace(previous.isReplace());
svmd.setTrim(previous.isTrim());
String type = previous.getType();
if (type != null)
svmd.setType(type);
}
property.setValue(svmd);
}
});
// dependency binding
TypeBinding dependsType = schemaBinding.getType(dependsTypeQName);
dependsType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractDependencyMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
}
public Object endElement(Object o, QName qName, ElementBinding element)
{
AbstractDependencyMetaData x = (AbstractDependencyMetaData) o;
String name = (String) x.getDependency();
if (name == null || name.trim().length() == 0)
throw new IllegalArgumentException("Null or empty dependency.");
return o;
}
});
// depends can take a value
dependsType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return value;
}
public void setValue(QName qname, ElementBinding element, Object owner, Object value)
{
AbstractDependencyMetaData depends = (AbstractDependencyMetaData) owner;
depends.setDependency(value);
}
});
// demand binding
TypeBinding demandType = schemaBinding.getType(demandTypeQName);
demandType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractDemandMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractDemandMetaData demand = (AbstractDemandMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("state".equals(localName))
demand.setWhenRequired(new ControllerState(attrs.getValue(i)));
}
}
public Object endElement(Object o, QName qName, ElementBinding element)
{
AbstractDemandMetaData x = (AbstractDemandMetaData) o;
String name = (String) x.getDemand();
if (name == null || name.trim().length() == 0)
throw new IllegalArgumentException("Null or empty demand.");
return o;
}
});
// demand can take a value
demandType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return value;
}
public void setValue(QName qname, ElementBinding element, Object owner, Object value)
{
AbstractDemandMetaData demand = (AbstractDemandMetaData) owner;
demand.setDemand(value);
}
});
// supply binding
TypeBinding supplyType = schemaBinding.getType(supplyTypeQName);
supplyType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractSupplyMetaData();
}
public Object endElement(Object o, QName qName, ElementBinding element)
{
AbstractSupplyMetaData x = (AbstractSupplyMetaData) o;
String name = (String) x.getSupply();
if (name == null || name.trim().length() == 0)
throw new IllegalArgumentException("Null or empty supply.");
return o;
}
});
// supply can take a value
supplyType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return value;
}
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
AbstractSupplyMetaData supply = (AbstractSupplyMetaData) owner;
supply.setSupply(value);
}
});
// dependency binding
TypeBinding dependencyType = schemaBinding.getType(dependencyTypeQName);
dependencyType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractDependencyValueMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractDependencyValueMetaData dependency = (AbstractDependencyValueMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("bean".equals(localName))
dependency.setValue(attrs.getValue(i));
else if ("property".equals(localName))
dependency.setProperty(attrs.getValue(i));
else if ("state".equals(localName))
dependency.setDependentState(new ControllerState(attrs.getValue(i)));
else if ("whenRequired".equals(localName))
dependency.setWhenRequiredState(new ControllerState(attrs.getValue(i)));
}
}
public Object endElement(Object o, QName qName, ElementBinding element)
{
AbstractDependencyValueMetaData x = (AbstractDependencyValueMetaData) o;
String name = (String) x.getUnderlyingValue();
if (name == null || name.trim().length() == 0)
throw new IllegalArgumentException("Null or empty bean in injection/factory.");
return o;
}
});
// injection binding
TypeBinding injectionType = schemaBinding.getType(injectionTypeQName);
injectionType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
AbstractInjectionValueMetaData vmd = new AbstractInjectionValueMetaData();
if (parent instanceof AbstractPropertyMetaData)
{
AbstractPropertyMetaData x = (AbstractPropertyMetaData) parent;
vmd.setPropertyMetaData(x);
}
return vmd;
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractInjectionValueMetaData injection = (AbstractInjectionValueMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("bean".equals(localName))
injection.setValue(attrs.getValue(i));
else if ("property".equals(localName))
injection.setProperty(attrs.getValue(i));
else if ("state".equals(localName))
injection.setDependentState(new ControllerState(attrs.getValue(i)));
else if ("whenRequired".equals(localName))
injection.setWhenRequiredState(new ControllerState(attrs.getValue(i)));
else if ("type".equals(localName))
injection.setInjectionType(AutowireType.getInstance(attrs.getValue(i)));
else if ("option".equals(localName))
injection.setInjectionOption(InjectOption.getInstance(attrs.getValue(i)));
else if ("fromContext".equals(localName))
injection.setFromContext(FromContext.getInstance(attrs.getValue(i)));
}
}
});
// value binding
TypeBinding plainValueType = schemaBinding.getType(plainValueTypeQName);
plainValueType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new StringValueMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
StringValueMetaData value = (StringValueMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
value.setType(attrs.getValue(i));
else if ("replace".equals(localName))
value.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
else if ("trim".equals(localName))
value.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
});
// value can take a value
plainValueType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return value;
}
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
StringValueMetaData valueMetaData = (StringValueMetaData) owner;
valueMetaData.setValue(value);
}
});
// value binding
TypeBinding valueType = schemaBinding.getType(valueTypeQName);
configureValueBindings(valueType);
valueType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractValueMetaData(new StringValueMetaData());
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractValueMetaData value = (AbstractValueMetaData) o;
StringValueMetaData string = (StringValueMetaData) value.getValue();
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
string.setType(attrs.getValue(i));
else if ("replace".equals(localName))
string.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
else if ("trim".equals(localName))
string.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
});
// value can take a value
valueType.setSimpleType(new CharactersHandler()
{
public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
{
return value;
}
public void setValue(QName qName, ElementBinding element, Object owner, Object value)
{
AbstractValueMetaData valueMetaData = (AbstractValueMetaData) owner;
StringValueMetaData string = (StringValueMetaData) valueMetaData.getValue();
string.setValue(value);
}
});
// collection binding
configureCollection(collectionTypeQName);
// list binding
configureCollection(listTypeQName);
// set binding
configureCollection(setTypeQName);
// array binding
configureCollection(arrayTypeQName);
// map binding
TypeBinding mapType = schemaBinding.getType(mapTypeQName);
mapType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new AbstractMapMetaData();
}
public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
{
AbstractMapMetaData collection = (AbstractMapMetaData) o;
for (int i = 0; i < attrs.getLength(); ++i)
{
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
collection.setType(attrs.getValue(i));
else if ("keyClass".equals(localName))
collection.setKeyType(attrs.getValue(i));
else if ("valueClass".equals(localName))
collection.setValueType(attrs.getValue(i));
}
}
});
// map has a map entries
mapType.pushInterceptor(entryQName, new DefaultElementInterceptor()
{
public void add(Object parent, Object child, QName name)
{
AbstractMapMetaData map = (AbstractMapMetaData) parent;
MapEntry entry = (MapEntry) child;
AbstractValueMetaData entryKey = (AbstractValueMetaData) entry.key;
if (entryKey == null)
throw new IllegalArgumentException("No key in map entry");
AbstractValueMetaData entryValue = (AbstractValueMetaData) entry.value;
if (entryValue == null)
throw new IllegalArgumentException("No value in map entry");
map.put((MetaDataVisitorNode) entryKey.getValue(), (MetaDataVisitorNode) entryValue.getValue());
}
});
// entry binding
TypeBinding entryType = schemaBinding.getType(entryTypeQName);
entryType.setHandler(new DefaultElementHandler()
{
public Object startElement(Object parent, QName name, ElementBinding element)
{
return new MapEntry();
}