001: /*
002: * $Id: InvalidMessageResult.java,v 1.5 2007/09/18 08:45:04 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.server;
008:
009: import java.util.Iterator;
010: import java.util.List;
011: import org.xins.common.xml.ElementBuilder;
012:
013: /**
014: * Result code that indicates that a request or a response parameter is either
015: * missing or invalid.
016: *
017: * @version $Revision: 1.5 $ $Date: 2007/09/18 08:45:04 $
018: * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
019: *
020: * @since XINS 2.0
021: */
022: class InvalidMessageResult extends FunctionResult {
023:
024: /**
025: * Constructs a new <code>InvalidMessageResult</code> object.
026: *
027: * @param errorCode
028: * the error code to return to the client, never <code>null</code>.
029: */
030: InvalidMessageResult(String errorCode) {
031: super (errorCode);
032: }
033:
034: /**
035: * Adds to the response that a paramater that is missing.
036: *
037: * @param parameter
038: * the missing parameter.
039: */
040: public void addMissingParameter(String parameter) {
041: ElementBuilder missingParam = new ElementBuilder(
042: "missing-param");
043: missingParam.setAttribute("param", parameter);
044: add(missingParam.createElement());
045: }
046:
047: /**
048: * Adds to the response a parameter that is missing in an element.
049: *
050: * @param parameter
051: * the missing parameter.
052: *
053: * @param element
054: * the element in which the parameter is missing.
055: */
056: public void addMissingParameter(String parameter, String element) {
057: ElementBuilder missingParam = new ElementBuilder(
058: "missing-param");
059: missingParam.setAttribute("param", parameter);
060: missingParam.setAttribute("element", element);
061: add(missingParam.createElement());
062: }
063:
064: /**
065: * Adds an invalid value for a specified type.
066: *
067: * @param parameter
068: * the parameter passed by the user.
069: *
070: * @param type
071: * the type which this parameter should be compliant with.
072: *
073: * @deprecated since XINS 2.0, use {@link #addInvalidValueForType(String, String, String)}.
074: */
075: public void addInvalidValueForType(String parameter, String type) {
076: ElementBuilder invalidValue = new ElementBuilder(
077: "invalid-value-for-type");
078: invalidValue.setAttribute("param", parameter);
079: invalidValue.setAttribute("type", type);
080: add(invalidValue.createElement());
081: }
082:
083: /**
084: * Adds an invalid value for a specified type.
085: *
086: * @param parameter
087: * the parameter passed by the user.
088: *
089: * @param value
090: * the value of the parameter passed by the user.
091: *
092: * @param type
093: * the type which this parameter should be compliant with.
094: */
095: public void addInvalidValueForType(String parameter, String value,
096: String type) {
097: ElementBuilder invalidValue = new ElementBuilder(
098: "invalid-value-for-type");
099: invalidValue.setAttribute("param", parameter);
100: invalidValue.setAttribute("value", value);
101: invalidValue.setAttribute("type", type);
102: add(invalidValue.createElement());
103: }
104:
105: /**
106: * Adds an invalid value for a specified type.
107: *
108: * @param parameter
109: * the parameter passed by the user.
110: *
111: * @param value
112: * the value of the parameter passed by the user.
113: *
114: * @param type
115: * the type which this parameter should be compliant with.
116: *
117: * @param element
118: * the element in which the parameter is missing.
119: */
120: public void addInvalidValueForType(String parameter, String value,
121: String type, String element) {
122: ElementBuilder invalidValue = new ElementBuilder(
123: "invalid-value-for-type");
124: invalidValue.setAttribute("param", parameter);
125: invalidValue.setAttribute("value", value);
126: invalidValue.setAttribute("type", type);
127: invalidValue.setAttribute("element", element);
128: add(invalidValue.createElement());
129: }
130:
131: /**
132: * Adds an invalid combination of parameters.
133: *
134: * @param type
135: * the type of the combination.
136: *
137: * @param parameters
138: * list of the parameters in the combination passed as a list of
139: * {@link String} objects.
140: */
141: public void addParamCombo(String type, List parameters) {
142:
143: ElementBuilder paramCombo = new ElementBuilder("param-combo");
144: paramCombo.setAttribute("type", type);
145:
146: // Iterate over all parameters
147: Iterator itParameters = parameters.iterator();
148: while (itParameters.hasNext()) {
149: ElementBuilder param = new ElementBuilder("param");
150: param.setAttribute("name", (String) itParameters.next());
151: paramCombo.addChild(param.createElement());
152: }
153:
154: add(paramCombo.createElement());
155: }
156:
157: /**
158: * Adds an invalid combination of attributes.
159: *
160: * @param type
161: * the type of the combination.
162: *
163: * @param attributes
164: * list of the attributes in the combination passed as a list of
165: * {@link String} objects.
166: *
167: * @param elementName
168: * the name of the element to which these attributes belong.
169: *
170: * @since XINS 1.4.0
171: */
172: public void addAttributeCombo(String type, List attributes,
173: String elementName) {
174:
175: ElementBuilder attributeCombo = new ElementBuilder(
176: "attribute-combo");
177: attributeCombo.setAttribute("type", type);
178:
179: // Iterate over all attributes
180: Iterator itAttributes = attributes.iterator();
181: while (itAttributes.hasNext()) {
182: ElementBuilder attribute = new ElementBuilder("attribute");
183: attribute
184: .setAttribute("name", (String) itAttributes.next());
185: attributeCombo.addChild(attribute.createElement());
186: }
187:
188: add(attributeCombo.createElement());
189: }
190: }
|