[weld-commits] Weld SVN: r5182 - in core/trunk/impl/src/main: java/org/jboss/weld/xml and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Tue Dec 1 08:24:20 EST 2009


Author: dallen6
Date: 2009-12-01 08:24:19 -0500 (Tue, 01 Dec 2009)
New Revision: 5182

Added:
   core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/XmlMessage.java
   core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
   core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
Log:
Exception conversion for XML parser to support localization

Added: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/XmlMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/XmlMessage.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/XmlMessage.java	2009-12-01 13:24:19 UTC (rev 5182)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.weld.logging.messages;
+
+import org.jboss.weld.logging.MessageId;
+
+import ch.qos.cal10n.BaseName;
+import ch.qos.cal10n.Locale;
+import ch.qos.cal10n.LocaleData;
+
+ at BaseName("org.jboss.weld.messages.xml")
+ at LocaleData({
+   @Locale("en")
+})
+/**
+ * Error messages relating to XML parser
+ * 
+ * Message ids: 001200 - 001299
+ */
+public enum XmlMessage
+{
+   @MessageId("001200") CONFIGURATION_ERROR,
+   @MessageId("001201") LOAD_ERROR,
+   @MessageId("001202") PARSING_ERROR,
+   @MessageId("001203") MULTIPLE_ALTERNATIVES,
+   @MessageId("001204") MULTIPLE_DECORATORS,
+   @MessageId("001205") MULTIPLE_INTERCEPTORS,
+   @MessageId("001206") CANNOT_LOAD_CLASS;
+
+}


Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/XmlMessage.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java	2009-12-01 10:00:30 UTC (rev 5181)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java	2009-12-01 13:24:19 UTC (rev 5182)
@@ -16,19 +16,24 @@
  */
 package org.jboss.weld.xml;
 
+import static org.jboss.weld.logging.messages.XmlMessage.CANNOT_LOAD_CLASS;
+import static org.jboss.weld.logging.messages.XmlMessage.CONFIGURATION_ERROR;
+import static org.jboss.weld.logging.messages.XmlMessage.LOAD_ERROR;
+import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_ALTERNATIVES;
+import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_DECORATORS;
+import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_INTERCEPTORS;
+import static org.jboss.weld.logging.messages.XmlMessage.PARSING_ERROR;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
-import javax.enterprise.inject.InjectionException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.interceptor.Interceptor;
 
 import org.jboss.weld.DeploymentException;
 import org.jboss.weld.resources.spi.ResourceLoader;
@@ -122,7 +127,7 @@
       }
       catch (ParserConfigurationException e)
       {
-         throw new InjectionException("Error configuring XML parser", e);
+         throw new WeldXmlException(CONFIGURATION_ERROR, e);
       }
       List<XmlElement> policiesElements = new ArrayList<XmlElement>(); 
       List<XmlElement> decoratorsElements = new ArrayList<XmlElement>(); 
@@ -138,7 +143,7 @@
          }
          catch (IOException e)
          {
-            throw new InjectionException("Error loading beans.xml " + url.toString(), e);
+            throw new WeldXmlException(LOAD_ERROR, e, url.toString());
          }
          if (fileHasContents)
          {
@@ -150,11 +155,11 @@
             }
             catch (SAXException e)
             {
-               throw new DeploymentException("Error parsing beans.xml " + url.toString(), e);
+               throw new DeploymentException(PARSING_ERROR, e, url.toString());
             }
             catch (IOException e)
             {
-               throw new DeploymentException("Error loading beans.xml " + url.toString(), e);
+               throw new DeploymentException(LOAD_ERROR, e, url.toString());
             }
             Element beans = document.getDocumentElement();
             for (Node child : new NodeListIterable(beans.getChildNodes()))
@@ -178,7 +183,7 @@
       
       if (policiesElements.size() > 1)
       {
-         throw new DeploymentException("<alternatives> can only be specified once, but it is specified muliple times " + policiesElements);
+         throw new DeploymentException(MULTIPLE_ALTERNATIVES, policiesElements);
       }
       else if (policiesElements.size() == 1)
       {
@@ -189,7 +194,7 @@
       
       if (decoratorsElements.size() > 1)
       {
-         throw new DeploymentException("<decorator> can only be specified once, but it is specified muliple times " + decoratorsElements);
+         throw new DeploymentException(MULTIPLE_DECORATORS, decoratorsElements);
       }
       else if (decoratorsElements.size() == 1)
       {
@@ -199,7 +204,7 @@
       
       if (interceptorsElements.size() > 1)
       {
-         throw new DeploymentException("<interceptor> can only be specified once, but it is specified muliple times " + interceptorsElements);
+         throw new DeploymentException(MULTIPLE_INTERCEPTORS, interceptorsElements);
       }
       else if (interceptorsElements.size() == 1)
       {
@@ -230,7 +235,7 @@
             }
             catch (ResourceLoadingException e)
             {
-               throw new DeploymentException("Cannot load class " + className + " defined in " + element.getFile().toString());
+               throw new DeploymentException(CANNOT_LOAD_CLASS, className, element.getFile());
             }
          }
       }
@@ -263,7 +268,7 @@
             }
             catch (ResourceLoadingException e)
             {
-               throw new DeploymentException("Cannot load class " + className + " defined in " + element.getFile().toString());
+               throw new DeploymentException(CANNOT_LOAD_CLASS, className, element.getFile());
             }
          }
       }
@@ -287,7 +292,7 @@
             }
             catch (ResourceLoadingException e)
             {
-               throw new DeploymentException("Cannot load class " + className + " defined in " + element.getFile().toString());
+               throw new DeploymentException(CANNOT_LOAD_CLASS, className, element.getFile());
             }
          }
       }

Added: core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java	2009-12-01 13:24:19 UTC (rev 5182)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.weld.xml;
+
+import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
+
+import javax.enterprise.inject.InjectionException;
+
+import ch.qos.cal10n.IMessageConveyor;
+
+/**
+ * Used for exceptions from the Weld XML parser and provides localization
+ * support.
+ * 
+ * @author David Allen
+ *
+ */
+public class WeldXmlException extends InjectionException
+{
+
+   private static final long serialVersionUID = -6716110761385845182L;
+
+   // Exception messages
+   private static final IMessageConveyor messageConveyer = loggerFactory().getMessageConveyor();
+
+   public WeldXmlException(Throwable throwable)
+   {
+      super(throwable.getLocalizedMessage(), throwable);
+   }
+
+   public <E extends Enum<?>> WeldXmlException(E key, Object... args)
+   {
+      super(messageConveyer.getMessage(key, args));
+   }
+}


Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties	                        (rev 0)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties	2009-12-01 13:24:19 UTC (rev 5182)
@@ -0,0 +1,6 @@
+CONFIGURATION_ERROR=Error configuring XML parser
+LOAD_ERROR=Error loading {0}
+PARSING_ERROR=Error parsing {0}
+MULTIPLE_ALTERNATIVES=<alternatives> can only be specified once, but appears multiple times\:  {0}
+MULTIPLE_DECORATORS=<decorator> can only be specified once, but is specified multiple times\:  {0}
+MULTIPLE_INTERCEPTORS=<interceptor> can only be specified once, but it is specified multiple times\:  {0}


Property changes on: core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the weld-commits mailing list