Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/******************************************************************************
* Copyright 2009-2023 Exactpro (Exactpro Systems Limited)
*
* 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 com.exactpro.sf.common.impl.messages;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.exactpro.sf.common.impl.messages.xml.configuration.JavaType;
import com.exactpro.sf.common.messages.FieldMetaData;
import com.exactpro.sf.common.messages.IFieldInfo;
import com.exactpro.sf.common.messages.IMessage;
import com.exactpro.sf.common.messages.MetadataProperty;
import com.exactpro.sf.common.messages.MsgMetaData;
import com.exactpro.sf.common.util.EPSCommonException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
public class MapMessage implements IMessage
{
private static final Logger logger = LoggerFactory.getLogger(MapMessage.class );
private final Map fieldsMap = new HashMap<>();
private final Map fieldsMetaData = new HashMap<>();
private MsgMetaData msgMetaData;
private String namespace;
private String name;
public MapMessage(MsgMetaData metaData) {
this.msgMetaData = metaData;
this.namespace = metaData.getMsgNamespace();
this.name = metaData.getMsgName();
}
@JsonCreator
public MapMessage(@JsonProperty("namespace") String namespace, @JsonProperty("name") String name)
{
if ( namespace == null )
{
throw new IllegalArgumentException("[namespace] could not be null");
}
if ( name == null )
{
throw new IllegalArgumentException("[name] could not be null");
}
this.namespace = namespace;
this.name = name;
this.msgMetaData = new MsgMetaData(namespace, name);
}
@Override
public boolean isFieldSet(String name)
{
return getField(name) != null;
}
@Override
public void addField(String name, Object value)
{
if ( name == null )
{
throw new IllegalArgumentException("[name] could not be null");
}
fieldsMap.put(name, value);
}
public Map getFieldsMap(){
Map resultFieldsMap = new HashMap<>();
resultFieldsMap.putAll(fieldsMap);
return resultFieldsMap;
}
@JsonSetter("fieldsMap")
@SuppressWarnings("ControlFlowStatementWithoutBraces")
public void addFieldsMap(Map fieldsMap){
this.fieldsMap.putAll(fieldsMap);
while (this.fieldsMap.values().remove(null));
}
public void removeAllFields(){
fieldsMap.clear();
}
@SuppressWarnings("unchecked")
@Override
public T getField(String name)
{
if ( name == null )
{
throw new IllegalArgumentException("[name] could not be null");
}
return (T)fieldsMap.get(name);
}
@Override
public MsgMetaData getMetaData()
{
return msgMetaData ;
}
/**
* JSON and XML setter. Don't use it in your code
*/
@Deprecated
public void setMetaData(MsgMetaData msgMetaData) {
this.msgMetaData = msgMetaData;
}
@Override
public String getName()
{
return name;
}
@Override
public String getNamespace()
{
return namespace;
}
@Override
public Object removeField(String name)
{
if(name == null)
{
throw new IllegalArgumentException("[name] could not be null");
}
return fieldsMap.remove(name);
}
@Override
public MapMessage cloneMessage()
{
MapMessage cloned = new MapMessage(namespace, name);
for(String fldName : fieldsMap.keySet()) {
cloned.addField(fldName, clone(fieldsMap.get(fldName)));
}
cloned.msgMetaData = msgMetaData.clone();
return cloned;
}
private Object clone (Object o)
{
if(o instanceof IMessage) {
return ((IMessage)o).cloneMessage();
}
if (o instanceof List)
{
List