Skip to content

Commit cc8feb4

Browse files
alesjbstansberry
authored andcommitted
Add real cause to parsing exception.
1 parent c6b216a commit cc8feb4

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

pojo/src/main/java/org/jboss/as/pojo/KernelDeploymentParsingProcessor.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
package org.jboss.as.pojo;
2424

25+
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.util.ArrayList;
28+
import java.util.Collection;
29+
import java.util.Collections;
30+
import java.util.List;
31+
32+
import javax.xml.namespace.QName;
33+
import javax.xml.stream.XMLInputFactory;
34+
import javax.xml.stream.XMLStreamReader;
35+
2536
import org.jboss.as.pojo.descriptor.KernelDeploymentXmlDescriptor;
2637
import org.jboss.as.pojo.descriptor.KernelDeploymentXmlDescriptorParser;
2738
import org.jboss.as.pojo.descriptor.LegacyKernelDeploymentXmlDescriptorParser;
@@ -37,16 +48,6 @@
3748
import org.jboss.vfs.VirtualFileFilter;
3849
import org.jboss.vfs.util.SuffixMatchFilter;
3950

40-
import javax.xml.namespace.QName;
41-
import javax.xml.stream.XMLInputFactory;
42-
import javax.xml.stream.XMLStreamReader;
43-
import java.io.IOException;
44-
import java.io.InputStream;
45-
import java.util.ArrayList;
46-
import java.util.Collection;
47-
import java.util.Collections;
48-
import java.util.List;
49-
5051
/**
5152
* DeploymentUnitProcessor responsible for parsing a jboss-beans.xml
5253
* descriptor and attaching the corresponding KernelDeploymentXmlDescriptor.
@@ -73,6 +74,7 @@ public KernelDeploymentParsingProcessor() {
7374
*
7475
* @param phaseContext the deployment unit context
7576
* @throws DeploymentUnitProcessingException
77+
*
7678
*/
7779
@Override
7880
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
@@ -91,15 +93,16 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
9193
*
9294
* @param unit the deployment unit
9395
* @param root the root
94-
* @throws DeploymentUnitProcessingException for any error
96+
* @throws DeploymentUnitProcessingException
97+
* for any error
9598
*/
9699
protected void parseDescriptors(DeploymentUnit unit, VirtualFile root) throws DeploymentUnitProcessingException {
97100
if (root == null || root.exists() == false)
98101
return;
99102

100103
Collection<VirtualFile> beans;
101104
final String name = root.getName();
102-
if(name.endsWith("jboss-beans.xml")) {
105+
if (name.endsWith("jboss-beans.xml")) {
103106
beans = Collections.singleton(root);
104107
} else {
105108
VirtualFileFilter filter = new SuffixMatchFilter("jboss-beans.xml");
@@ -131,12 +134,13 @@ protected void parseDescriptors(DeploymentUnit unit, VirtualFile root) throws De
131134
/**
132135
* Parse -jboss-beans.xml file.
133136
*
134-
* @param unit the deployment unit
137+
* @param unit the deployment unit
135138
* @param beansXmlFile the beans xml file
136-
* @throws DeploymentUnitProcessingException for any error
139+
* @throws DeploymentUnitProcessingException
140+
* for any error
137141
*/
138142
protected void parseDescriptor(DeploymentUnit unit, VirtualFile beansXmlFile) throws DeploymentUnitProcessingException {
139-
if(beansXmlFile == null || beansXmlFile.exists() == false)
143+
if (beansXmlFile == null || beansXmlFile.exists() == false)
140144
return;
141145

142146
InputStream xmlStream = null;
@@ -146,14 +150,14 @@ protected void parseDescriptor(DeploymentUnit unit, VirtualFile beansXmlFile) th
146150
final ParseResult<KernelDeploymentXmlDescriptor> result = new ParseResult<KernelDeploymentXmlDescriptor>();
147151
xmlMapper.parseDocument(result, reader);
148152
final KernelDeploymentXmlDescriptor xmlDescriptor = result.getResult();
149-
if(xmlDescriptor != null)
153+
if (xmlDescriptor != null)
150154
unit.addToAttachmentList(KernelDeploymentXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
151155
else
152156
throw PojoMessages.MESSAGES.failedToParse(beansXmlFile);
153-
} catch(DeploymentUnitProcessingException e) {
157+
} catch (DeploymentUnitProcessingException e) {
154158
throw e;
155-
} catch(Exception e) {
156-
throw PojoMessages.MESSAGES.failedToParse(beansXmlFile);
159+
} catch (Exception e) {
160+
throw PojoMessages.MESSAGES.parsingException(beansXmlFile, e);
157161
} finally {
158162
VFSUtils.safeClose(xmlStream);
159163
}

pojo/src/main/java/org/jboss/as/pojo/PojoMessages.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
package org.jboss.as.pojo;
2424

25+
import java.util.Set;
26+
2527
import org.jboss.as.pojo.descriptor.BeanMetaDataConfig;
2628
import org.jboss.as.pojo.descriptor.ConfigVisitorNode;
2729
import org.jboss.as.server.deployment.DeploymentUnit;
@@ -33,8 +35,6 @@
3335
import org.jboss.msc.service.StartException;
3436
import org.jboss.vfs.VirtualFile;
3537

36-
import java.util.Set;
37-
3838
/**
3939
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
4040
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
@@ -145,7 +145,7 @@ public interface PojoMessages {
145145
/**
146146
* Invalid match size.
147147
*
148-
* @param set whole set
148+
* @param set whole set
149149
* @param type the type to match
150150
* @return a {@link IllegalArgumentException} for the error.
151151
*/
@@ -264,7 +264,7 @@ public interface PojoMessages {
264264
/**
265265
* Ctor not found.
266266
*
267-
* @param args the args
267+
* @param args the args
268268
* @param clazz the class
269269
* @return a {@link IllegalArgumentException} for the error.
270270
*/
@@ -274,8 +274,8 @@ public interface PojoMessages {
274274
/**
275275
* Method not found.
276276
*
277-
* @param name the method name
278-
* @param args the args
277+
* @param name the method name
278+
* @param args the args
279279
* @param clazz the class
280280
* @return a {@link IllegalArgumentException} for the error.
281281
*/
@@ -285,7 +285,7 @@ public interface PojoMessages {
285285
/**
286286
* Getter not found.
287287
*
288-
* @param type the type
288+
* @param type the type
289289
* @param clazz the class
290290
* @return a {@link IllegalArgumentException} for the error.
291291
*/
@@ -295,7 +295,7 @@ public interface PojoMessages {
295295
/**
296296
* Setter not found.
297297
*
298-
* @param type the type
298+
* @param type the type
299299
* @param clazz the class
300300
* @return a {@link IllegalArgumentException} for the error.
301301
*/
@@ -314,8 +314,8 @@ public interface PojoMessages {
314314
/**
315315
* Ambiguous match.
316316
*
317-
* @param info the info
318-
* @param name the name
317+
* @param info the info
318+
* @param name the name
319319
* @param clazz the class
320320
* @return a {@link IllegalArgumentException} for the error.
321321
*/
@@ -325,10 +325,20 @@ public interface PojoMessages {
325325
/**
326326
* Field not found.
327327
*
328-
* @param name the method name
328+
* @param name the method name
329329
* @param clazz the class
330330
* @return a {@link IllegalArgumentException} for the error.
331331
*/
332332
@Message(id = 17081, value = "Field not found %s for class %s.")
333333
IllegalArgumentException fieldNotFound(String name, String clazz);
334+
335+
/**
336+
* Parsing exception.
337+
*
338+
* @param beansXml the beans xml file
339+
* @param cause the cause
340+
* @return a {@link DeploymentUnitProcessingException} for the error.
341+
*/
342+
@Message(id = 17082, value = "Exception while parsing POJO descriptor file: %s")
343+
DeploymentUnitProcessingException parsingException(VirtualFile beansXml, @Cause Throwable cause);
334344
}

0 commit comments

Comments
 (0)