Index: src/test/java/org/xmpp/packet/PacketErrorApplicationConditionTest.java
===================================================================
--- src/test/java/org/xmpp/packet/PacketErrorApplicationConditionTest.java	(revision 0)
+++ src/test/java/org/xmpp/packet/PacketErrorApplicationConditionTest.java	(revision 0)
@@ -0,0 +1,118 @@
+package org.xmpp.packet;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.xmpp.packet.PacketError.Condition;
+import org.xmpp.packet.PacketError.Type;
+
+/**
+ * Tests compliance of Application-Specific Conditions provided by 
+ * {@link PacketError} with the restrictions defined in RFC-3920.
+ * 
+ * @author G&uuml;nther Nie&szlig;, guenther.niess@web.de
+ * @see <a href="http://www.ietf.org/rfc/rfc3920.txt">RFC 3920 - Extensible
+ *      Messaging and Presence Protocol (XMPP): Core</a>
+ */
+public class PacketErrorApplicationConditionTest {
+
+	/**
+	 * XML namespace name for stanza-related error data.
+	 */
+	public static final String ERROR_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-stanzas";
+
+	/**
+	 * Fallback namespace for generalized error conditions (see XEP-0182).
+	 */
+	public static final String GENERAL_ERROR_NAMESPACE = "urn:xmpp:errors";
+
+	/**
+	 * A text describing a sample packet-error.
+	 */
+	public static final String ERROR_TEXT = "Some special application information...";
+
+	/**
+	 * A simple error for testing application specific error conditions.
+	 */
+	private PacketError stanzaError;
+
+	/**
+	 * A more complex error for testing application specific error conditions.
+	 */
+	private PacketError applicationError;
+
+
+	/**
+	 * Initialize the used packet-errors.
+	 */
+	@Before
+	public void setUp() {
+		stanzaError = new PacketError(Condition.not_acceptable);
+		applicationError = new PacketError(
+				Condition.undefined_condition,
+				Type.modify,
+				ERROR_TEXT,
+				"en");
+	}
+
+	/**
+	 * Testing the default behavior of the setter and getter methods.
+	 */
+	@Test
+	public void testValidBehavior() {
+		String requestErrorName = "stanza-too-big";
+		stanzaError.setApplicationCondition(requestErrorName);
+		if (!requestErrorName.equals(stanzaError.getApplicationConditionName())) {
+			fail("Don't get the applied name of the application-specific "
+					+ "error condition.");
+		}
+		if (!GENERAL_ERROR_NAMESPACE.equals(
+				stanzaError.getApplicationConditionNamespaceURI())) {
+			fail("According to the XEP-0182 the default namespace of general "
+					+ "application-specific error conditions is " 
+					+ GENERAL_ERROR_NAMESPACE + ". "
+					+ "This namespace should be applied as fallback.");
+		}
+
+		String appErrorName = "special-application-condition";
+		String appNS = "application-ns";
+		applicationError.setApplicationCondition(appErrorName, appNS);
+		if (!appNS.equals(applicationError.getApplicationConditionNamespaceURI())) {
+			fail("Don't get the expected namespace of the application-specific "
+					+ "error condition.");
+		}
+		if (Condition.undefined_condition != applicationError.getCondition()) {
+			fail("The application-specific error condition don't have to modify "
+					+ "the standard error condition.");
+		}
+		if (!ERROR_TEXT.equals(applicationError.getText())) {
+			fail("The application-specific error condition don't have to modify "
+					+ "the text of the packet-error.");
+		}
+
+		applicationError.setApplicationCondition(null);
+		if (applicationError.getApplicationConditionNamespaceURI() != null) {
+			fail("Removing the application-specific error condition don't "
+					+ "remove the namespace of the application.");
+		}
+		if (Condition.undefined_condition != applicationError.getCondition()) {
+			fail("Removing the application-specific error condition don't have "
+					+ "to modify the standard error condition.");
+		}
+		if (!ERROR_TEXT.equals(applicationError.getText())) {
+			fail("Removing the application-specific error condition don't have "
+					+ "to modify the text of the packet-error.");
+		}
+	}
+
+	/**
+	 * Insert an application-specific error, using the namespace 
+	 * urn:ietf:params:xml:ns:xmpp-stanzas isn't allowed by RFC 3920.
+	 */
+	@Test(expected = IllegalArgumentException.class)
+	public void testInvalidParameters() throws Exception {
+		// verify
+		applicationError.setApplicationCondition("invalid-ns", ERROR_NAMESPACE);
+	}
+}
Index: src/main/java/org/xmpp/packet/PacketError.java
===================================================================
--- src/main/java/org/xmpp/packet/PacketError.java	(revision 11069)
+++ src/main/java/org/xmpp/packet/PacketError.java	(working copy)
@@ -247,6 +247,90 @@
     }
 
     /**
+     * Sets an application-specific error condition.
+     * 
+     * @param name the name of the application-specific error condition.
+     */
+    public void setApplicationCondition(String name) {
+        setApplicationCondition(name, null);
+    }
+
+    /**
+     * Sets an application-specific error condition. Optionally, a
+     * application-specific namespace can be specified to define its
+     * own application-specific error .
+     * 
+     * @param name the name of the application-specific error condition.
+     * @param namespaceURI the namespace of the application.
+     */
+    @SuppressWarnings("unchecked")
+    public void setApplicationCondition(String name, String namespaceURI) {
+        if (ERROR_NAMESPACE.equals(namespaceURI)) {
+            throw new IllegalArgumentException();
+        }
+
+        Element applicationError = null;
+        for (Iterator i=element.elementIterator(); i.hasNext(); ) {
+            Element el = (Element)i.next();
+            if (!el.getNamespaceURI().equals(ERROR_NAMESPACE))
+            {
+                applicationError = el;
+            }
+        }
+        if (applicationError != null) {
+            element.remove(applicationError);
+        }
+
+        // If name is null, clear the application condition.
+        if (name == null) {
+            return;
+        }
+
+        if (namespaceURI == null) {
+            // Set fallback namespace (see XEP-0182)
+            namespaceURI = "urn:xmpp:errors";
+        }
+        applicationError = docFactory.createElement(name, namespaceURI);
+        element.add(applicationError);
+    }
+
+    /**
+     * Returns the name of the application-specific error condition,
+     * or <tt>null</tt> if there is no application-specific error.
+     *
+     * @return the name of the application-specific error condition, if it exists.
+     */
+    @SuppressWarnings("unchecked")
+    public String getApplicationConditionName() {
+        for (Iterator i=element.elementIterator(); i.hasNext(); ) {
+            Element el = (Element)i.next();
+            if (!el.getNamespaceURI().equals(ERROR_NAMESPACE))
+            {
+                return el.getName();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the namespace of the application-specific error condition,
+     * or <tt>null</tt> if there is no application-specific error.
+     *
+     * @return the namespace of the application-specific error condition, if it exists.
+     */
+    @SuppressWarnings("unchecked")
+    public String getApplicationConditionNamespaceURI() {
+        for (Iterator i=element.elementIterator(); i.hasNext(); ) {
+            Element el = (Element)i.next();
+            if (!el.getNamespaceURI().equals(ERROR_NAMESPACE))
+            {
+                return el.getNamespaceURI();
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns the DOM4J Element that backs the error. The element is the definitive
      * representation of the error and can be manipulated directly to change
      * error contents.

