Marshalling an AbstractKernelDeployment
flavia.rainone May 28, 2009 10:25 AMI've been trying to marshal an AbstractKernelDeployment without success:
AbstractKernelDeployment deployment = new AbstractKernelDeployment(); AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(); beanMetaData.setBean(Test.class.getName()); beanMetaData.setName("test"); List<BeanMetaDataFactory> beanFactories = new ArrayList<BeanMetaDataFactory>(); beanFactories.add(beanMetaData); deployment.setBeanFactories(beanFactories); MarshallerImpl marshaller = new MarshallerImpl(); SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver(); marshaller.setSchemaResolver(resolver); StringWriter writer = new StringWriter(); URL url = Test.class.getClassLoader().getResource("schema/bean-deployer_2_0.xsd"); marshaller.marshal(url.toString(), null, deployment, writer);
I'm getting this exception:
Exception in thread "main" org.jboss.xb.binding.JBossXBRuntimeException: Missing value for the required attribute bean of element {urn:jboss:bean-deployer:2.0}lazy at org.jboss.xb.binding.sunday.marshalling.DefaultAttributeMarshaller.marshalValue(DefaultAttributeMarshaller.java:89) at org.jboss.xb.binding.sunday.marshalling.AbstractAttributeMarshaller.marshal(AbstractAttributeMarshaller.java:39) at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalComplexType(MarshallerImpl.java:547) at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElementType(MarshallerImpl.java:430) at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElement(MarshallerImpl.java:329) at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElementOccurence(MarshallerImpl.java:309) at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshallInternal(MarshallerImpl.java:215) at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshal(MarshallerImpl.java:150) at org.jboss.microcontainer.tools.Test.main(Test.java:69)
Debugging the code, I see that MarshallerImpl (lines 211-216) marshals the deployment by iterating through the ElementBindings and marshalling the ocurrences of each of one those elements:
while(elements.hasNext()) { ParticleBinding element = elements.next(); ctx.particle = element; marshalElementOccurence((ElementBinding) element.getTerm(), root, true, true); }
It seems that at some point, between the marshalElementOcurrence() call and the execution of marshalComplexType(), MarshallerImpl assumes that the element at the stack is a lazy element instead of a deployment element. Given that it isn't, MarshallerImpl fails to find the value of the mandatory bean attribute of lazy and throws the exception above.
Taking a look at XsdBinder (lines 476-483), I see that it binds the schema elements with a minOcurrences of 1:
XSNamedMap elements = model.getComponents(XSConstants.ELEMENT_DECLARATION); if (trace) log.trace("Model elements: " + types.getLength()); for(int i = 0; i < elements.getLength(); ++i) { XSElementDeclaration element = (XSElementDeclaration)elements.item(i); bindElement(element, 1, 0, false); }
I'm not sure if this has something to do with the problem or not, but it looks weird from my point of view.
So, am I doing this the wrong way? Or is this a bug?