-
1. Re: How to use factory method from a bean in jboss:pojo:7?
alesj Aug 7, 2012 5:09 AM (in response to saltnlight5)This should still work (apart from the factoryMethod --> factory-method):
private ConstructorConfig parseConstructor(final XMLExtendedStreamReader reader) throws XMLStreamException {
final ConstructorConfig ctorConfig = new ConstructorConfig();
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final Attribute attribute = Attribute.of(reader.getAttributeLocalName(i));
final String attributeValue = reader.getAttributeValue(i);
switch (attribute) {
case FACTORY_CLASS:
ctorConfig.setFactoryClass(attributeValue);
break;
case FACTORY_METHOD:
ctorConfig.setFactoryMethod(attributeValue);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
List<ValueConfig> parameters = new ArrayList<ValueConfig>();
while (reader.hasNext()) {
switch (reader.next()) {
case END_ELEMENT:
ctorConfig.setParameters(parameters.toArray(new ValueConfig[parameters.size()]));
return ctorConfig;
case START_ELEMENT:
switch (Element.of(reader.getLocalName())) {
case FACTORY:
ctorConfig.setFactory(parseFactory(reader));
break;
case PARAMETER:
ValueConfig p = parseParameter(reader);
p.setIndex(parameters.size());
parameters.add(p);
break;
default:
throw unexpectedElement(reader);
}
}
}
throw unexpectedElement(reader);
}
private FactoryConfig parseFactory(final XMLExtendedStreamReader reader) throws XMLStreamException {
final FactoryConfig factoryConfig = new FactoryConfig();
final Set<Attribute> required = EnumSet.of(Attribute.BEAN);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final Attribute attribute = Attribute.of(reader.getAttributeLocalName(i));
required.remove(attribute);
final String attributeValue = reader.getAttributeValue(i);
switch (attribute) {
case BEAN:
factoryConfig.setBean(attributeValue); /// <----------------- bean
break;
case STATE:
factoryConfig.setState(BeanState.valueOf(attributeValue.toUpperCase(Locale.ENGLISH)));
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.isEmpty() == false) {
throw missingRequired(reader, required);
}
while (reader.hasNext()) {
switch (reader.next()) {
case END_ELEMENT:
return factoryConfig;
}
}
throw unexpectedElement(reader);
}
-
2. Re: How to use factory method from a bean in jboss:pojo:7?
saltnlight5 Aug 7, 2012 9:21 AM (in response to alesj)Hi Ales,
So is the xsd outdated or I read it wrong that it didn't have the "bean" attribute defined by the "factory" element? I was looking at https://github.com/jbossas/jboss-as/blob/master/build/src/main/resources/docs/schema/jboss-pojo_7_0.xsd
Also, when I tried the following jboss-beans.xml, it won't deploy.
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="urn:jboss:pojo:7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:pojo:7.0 jboss-pojo_7_0.xsd"> <bean name="schedulerFactory" class="timemachine.scheduler.SchedulerFactory"> <constructor> <parameter>${user.home}/timemachine-scheduler.properties</parameter> </constructor> </bean> <bean name="scheduler" class="timemachine.scheduler.Scheduler"> <constructor factory-method="createScheduler"> <factory bean="schedulerFactory"/> </constructor> </bean> </deployment>
I get the follwing error:
08:48:16,363 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."scheduler-jboss-pojo-1.0.0-SNAPSHOT.jar".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."scheduler-jboss-pojo-1.0.0-SNAPSHOT.jar".PARSE: Failed to process phase PARSE of deployment "scheduler-jboss-pojo-1.0.0-SNAPSHOT.jar" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA] at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_05] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_05] at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_05] Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS017052: Failed to parse POJO xml [ "/content/scheduler-jboss-pojo-1.0.0-SNAPSHOT.jar/META-INF/jboss-beans.xml" ] at org.jboss.as.pojo.KernelDeploymentParsingProcessor.parseDescriptor(KernelDeploymentParsingProcessor.java:156) at org.jboss.as.pojo.KernelDeploymentParsingProcessor.parseDescriptors(KernelDeploymentParsingProcessor.java:128) at org.jboss.as.pojo.KernelDeploymentParsingProcessor.deploy(KernelDeploymentParsingProcessor.java:83) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final] ... 5 more
Would you able to spot anything I amissed?
Thanks,
Zemian
Added xsd notes.
-
3. Re: How to use factory method from a bean in jboss:pojo:7?
alesj Aug 7, 2012 9:34 AM (in response to saltnlight5)Can you debug and catch that exception on line 156 in
KernelDeploymentParsingProcessor
? -
4. Re: How to use factory method from a bean in jboss:pojo:7?
yzl00000 Aug 14, 2012 12:10 AM (in response to saltnlight5)Hi,
I'm also using old deployment descriptors. 'bean' attribute is ok for <factory> element. But text content is not allowed as child of <parameter> element. You can try <parameter><value class="java.lang.String">
${user.home}/timemachine-scheduler.properties
</value></parameter>. -
5. Re: How to use factory method from a bean in jboss:pojo:7?
alesj Aug 14, 2012 4:07 AM (in response to yzl00000)But text content is not allowed as child of <parameter> element.
Did we support this before?
-
6. Re: How to use factory method from a bean in jboss:pojo:7?
yzl00000 Aug 14, 2012 8:50 PM (in response to alesj)Yes, it can be directly added in <parameter> for previous JBoss
-
7. Re: How to use factory method from a bean in jboss:pojo:7?
ctomc Aug 15, 2012 5:44 AM (in response to yzl00000)David,
Ales has prepared fix for this and it is already avaliable in upstream. so if you take latest nightly build this should work.
--
tomaz
-
8. Re: How to use factory method from a bean in jboss:pojo:7?
saltnlight5 Aug 18, 2012 5:01 PM (in response to ctomc)Hi Tomaz+Ales,
Sorry for the long delay. I did a build on latest code (rev : 886bb7e43374b5040f4edbe880a6c2163ec1a819) and my xml above worked without the error now! Thanks for the fix Ales.
I am still newbie with Git searching, may I ask which revision did you fixed on?
Thanks,
Zemian
-
9. Re: How to use factory method from a bean in jboss:pojo:7?
ctomc Aug 19, 2012 5:09 AM (in response to saltnlight5)Hey,
this is the commit that fixed it:
https://github.com/jbossas/jboss-as/commit/2cd952c7174180794aae7e61b2d96adf38f57fe5
--
tomaz
-
10. Re: How to use factory method from a bean in jboss:pojo:7?
claprun Sep 25, 2012 10:52 AM (in response to ctomc)The XSD needs to be updated then since the parameter type doesn't allow such usage…