blob: 4353d1a4abb4f0c77ed59978216d9c79de6ef6f3 [file] [log] [blame]
/*
* Copyright (c) 2020 Kentyou.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kentyou - initial API and implementation
*/
package org.eclipse.sensinact.gateway.core.message;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.sensinact.gateway.common.props.KeysCollection;
import org.eclipse.sensinact.gateway.common.props.TypedKey;
/**
* Error dedicated {@link SnaMessage}
*
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
public interface SnaErrorMessage extends SnaErrorfulMessage<SnaErrorMessage.Error> {
public static final SnaMessage.Type TYPE = SnaMessage.Type.ERROR;
enum Error implements SnaMessageSubType, KeysCollection {
NO_ERROR, UPDATE_ERROR, RESPONSE_ERROR, LIFECYCLE_ERROR, SYSTEM_ERROR;
final Set<TypedKey<?>> keys;
Error() {
List<TypedKey<?>> list = Arrays.asList(new SnaMessage.KeysBuilder(SnaErrorMessage.class).keys());
Set<TypedKey<?>> tmpKeys = new HashSet<TypedKey<?>>();
tmpKeys.addAll(list);
keys = Collections.unmodifiableSet(tmpKeys);
}
/**
* @inheritDoc
*
* @see SnaMessageSubType#getSnaMessageType()
*/
@Override
public SnaMessage.Type getSnaMessageType() {
return SnaErrorMessage.TYPE;
}
/**
* @inheritDoc
*
* @see KeysCollection#keys()
*/
@Override
public Set<TypedKey<?>> keys() {
return this.keys;
}
/**
* @inheritDoc
*
* @see KeysCollection#key(java.lang.String)
*/
@Override
public TypedKey<?> key(String key) {
TypedKey<?> typedKey = null;
Iterator<TypedKey<?>> iterator = this.keys.iterator();
while (iterator.hasNext()) {
typedKey = iterator.next();
if (typedKey.equals(key)) {
break;
}
typedKey = null;
}
return typedKey;
}
}
}