All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.guise.framework.platform.web.WebCommandDepictEvent Maven / Gradle / Ivy

There is a newer version: 0.5.3
Show newest version
/*
 * Copyright © 2005-2008 GlobalMentor, Inc. 
 *
 * 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 io.guise.framework.platform.web;

import java.util.*;

import static java.util.Collections.*;
import static java.util.Objects.*;

import static com.globalmentor.collections.Maps.*;

import com.globalmentor.model.NameValuePair;

import io.guise.framework.platform.DepictedObject;

/**
 * A command to or from a depicted object on the web platform.
 * @param  The type of command.
 * @author Garret Wilson Copyright (c) 2007 GlobalMentor, Inc.
 */
public class WebCommandDepictEvent & WebPlatformCommand> extends AbstractWebDepictEvent implements WebPlatformCommandMessage {

	/** The command. */
	private final WebPlatformCommand command;

	@SuppressWarnings("unchecked")
	@Override
	public C getCommand() {
		return (C)command;
	}

	/** The read-only map of parameters, which will be encoded in JavaScript Object Notation (JSON). */
	private final Map parameters;

	@Override
	public Map getParameters() {
		return parameters;
	}

	/**
	 * Depicted object, command, and parameters constructor.
	 * @param depictedObject The depicted object on which the event initially occurred.
	 * @param command The command.
	 * @param parameters The parameters of the command; parameters with duplicate names replace earlier parameters of the same name.
	 * @throws NullPointerException if the given depicted object, command, and/or parameters is null.
	 */
	public WebCommandDepictEvent(final DepictedObject depictedObject, final C command, final NameValuePair... parameters) {
		super(depictedObject); //construct the parent class
		this.command = requireNonNull(command, "Command cannot be null.");
		this.parameters = unmodifiableMap(addAll(new HashMap(parameters.length), parameters)); //add all the parameters to a new map
	}

	/**
	 * Depicted object, command, and parameters map constructor.
	 * @param depictedObject The depicted object on which the event initially occurred.
	 * @param command The command.
	 * @param parameters The map representing the parameters of the command.
	 * @throws NullPointerException if the given depicted object, command, and/or parameters is null.
	 */
	public WebCommandDepictEvent(final DepictedObject depictedObject, final C command, final Map parameters) {
		super(depictedObject); //construct the parent class
		this.command = requireNonNull(command, "Command cannot be null.");
		this.parameters = unmodifiableMap(new HashMap(requireNonNull(parameters, "Parameters cannot be null.")));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy