return this.values;
}
- public MJsonValue getValue(String key) throws MValueNotFoundJsonException {
+ public MJsonValue getValue(String key) {
if ((null == key) || ("".equals(key))) {
throw new IllegalArgumentException("Invalid 'key': null or empty.");
}
//
- if (!this.getValuesReference().containsKey(key)) {
- throw new MValueNotFoundJsonException(String.format("Invalid 'key': %s: not available.", key));
+ if (!this.containsKey(key)) {
+ throw new IllegalArgumentException(String.format("Invalid 'key': %s: not available.", key));
}
return this.getValuesReference().get(key).clone();
}
return this.getValuesReference().size();
}
- public void removeValue(String key) throws MValueNotFoundJsonException {
+ public void removeValue(String key) {
if ((null == key) || ("".equals(key))) {
throw new IllegalArgumentException("Invalid 'key': null or empty.");
}
//
- if (!this.getValuesReference().containsKey(key)) {
- throw new MValueNotFoundJsonException(String.format("Invalid 'key': %s: not available.", key));
+ if (!this.containsKey(key)) {
+ throw new IllegalArgumentException(String.format("Invalid 'key': %s: not available.", key));
}
this.getValuesReference().remove(key);
}
this.getValuesReference().clear();
}
+ public boolean containsKey(String key) {
+ if ((null == key) || ("".equals(key))) {
+ throw new IllegalArgumentException("Invalid 'key': null or empty.");
+ }
+ //
+ return this.getValuesReference().containsKey(key);
+ }
+
public LinkedHashSet<String> getKeys() {
LinkedHashSet<String> keys = new LinkedHashSet<String>();
for (String key: this.getValuesReference().keySet()) {
+++ /dev/null
-/**
- * Macaco
- * Copyright (c) 2009-2012 Marco Zanon
- *
- * Released under the MIT License:
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package com.marcozanon.macaco.json;
-
-public class MValueNotFoundJsonException extends MJsonException {
-
- private static final long serialVersionUID = 0L;
-
- /* */
-
- public MValueNotFoundJsonException() {
- super();
- }
-
- public MValueNotFoundJsonException(String message) {
- super(message);
- }
-
- public MValueNotFoundJsonException(Throwable error) {
- super(error);
- }
-
- public MValueNotFoundJsonException(String message, Throwable error) {
- super(message, error);
- }
-
-}
import com.marcozanon.macaco.json.MInvalidValueJsonException;
import com.marcozanon.macaco.json.MJsonObject;
import com.marcozanon.macaco.json.MJsonString;
-import com.marcozanon.macaco.json.MValueNotFoundJsonException;
import java.util.LinkedHashMap;
public class MWebMessage extends MObject {
throw new MMessagingWebException("Invalid 'message': not a Json object."); // no need to propagate exception
}
// parse widget id component
+ if (!jsonMessage.containsKey("widgetId")) {
+ throw new MMessagingWebException("Invalid 'message': no widget id key.");
+ }
try {
this.widgetId = ((MJsonString)jsonMessage.getValue("widgetId")).getValue();
}
catch (ClassCastException exception) {
throw new MMessagingWebException("Invalid 'message': invalid widget id."); // no need to propagate exception
}
- catch (MValueNotFoundJsonException exception) {
- throw new MMessagingWebException("Invalid 'message': no widget id key."); // no need to propagate exception
- }
// parse event component
+ if (!jsonMessage.containsKey("event")) {
+ throw new MMessagingWebException("Invalid 'message': no event key.");
+ }
try {
String temporaryEvent = ((MJsonString)jsonMessage.getValue("event")).getValue();
if ("".equals(temporaryEvent)) {
catch (ClassCastException exception) {
throw new MMessagingWebException("Invalid 'message': invalid event."); // no need to propagate exception
}
- catch (MValueNotFoundJsonException exception) {
- throw new MMessagingWebException("Invalid 'message': no event key."); // no need to propagate exception
- }
// parse parameters component
+ if (!jsonMessage.containsKey("parameters")) {
+ throw new MMessagingWebException("Invalid 'message': no parameters key.");
+ }
this.parameters = new LinkedHashMap<String, String>();
try {
MJsonObject temporaryParameters = (MJsonObject)jsonMessage.getValue("parameters");
catch (ClassCastException exception) {
throw new MMessagingWebException("Invalid 'message': invalid parameters."); // no need to propagate exception
}
- catch (MValueNotFoundJsonException exception) {
- throw new MMessagingWebException("Invalid 'message': no parameters key."); // no need to propagate exception
- }
}
public MWebMessage clone() {