com.sap.it.commons.logging.MessageByText Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of odata-core Show documentation
Show all versions of odata-core Show documentation
SAP Cloud Platform SDK for service development
The newest version!
package com.sap.it.commons.logging;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAttribute;
import com.sap.it.commons.lang.Equals;
import com.sap.it.commons.lang.Hash;
import com.sap.it.commons.layering.Subsystem;
import com.sap.it.commons.layering.SubsystemPart;
final class MessageByText implements CategorizedMessage, Serializable {
private static final long serialVersionUID = -8698398228783082364L;
@XmlAttribute
private final String subsystemName;
@XmlAttribute
private final String subsystemPartName;
@XmlAttribute
private final String messageId;
@XmlAttribute
private final String messageText;
@XmlAttribute
private final String category;
private transient SubsystemPart ssp;
public MessageByText(String category, String subsystemName, String subsystemPartName, String messageId, String messageText) {
super();
this.subsystemName = subsystemName;
this.subsystemPartName = subsystemPartName;
this.messageId = messageId;
this.messageText = messageText;
this.category = category;
}
public MessageByText(String subsystemName, String subsystemPartName, String messageId, String messageText) {
super();
this.subsystemName = subsystemName;
this.subsystemPartName = subsystemPartName;
this.messageId = messageId;
this.messageText = messageText;
this.category = null;
}
public MessageByText() {
this.subsystemName = null;
this.subsystemPartName = null;
this.messageId = null;
this.messageText = null;
this.category = null;
}
public MessageByText(Message message) {
SubsystemPart subsystemPart = message.getSubsystemPart();
this.subsystemName = subsystemPart.getSubsystem().getName();
this.subsystemPartName = subsystemPart.getName();
this.messageId = message.getMessageId();
this.messageText = message.getMessageText();
MessageCategory mc = MessageTools.peekForMessageCategory(message);
this.category = mc != null ? mc.name() : null;
}
@Override
public SubsystemPart getSubsystemPart() {
if (ssp == null) {
ssp = new SubsystemPart() {
private final Subsystem ss = new Subsystem() {
@Override
public String getName() {
return subsystemName;
}
};
@Override
public Subsystem getSubsystem() {
return ss;
}
@Override
public String getName() {
return subsystemPartName;
}
};
}
return ssp;
}
@Override
public String getMessageText() {
return messageText;
}
@Override
public String getMessageId() {
return messageId;
}
@Override
public int hashCode() {
return Hash.hash(subsystemName, subsystemPartName, messageId, category, messageText);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MessageByText)) {
return false;
}
MessageByText other = (MessageByText) obj;
return Equals.equals(subsystemName, other.subsystemName) && //
Equals.equals(subsystemPartName, other.subsystemPartName) && //
Equals.equals(messageId, other.messageId) && //
Equals.equals(category, other.category) && //
Equals.equals(messageText, other.messageText);
}
@Override
public MessageCategory getMessageCategory() {
if (category != null) {
try {
return MessageCategory.valueOf(category);
} catch (IllegalArgumentException e) {
return null;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy