Skip to content

Commit

Permalink
More Json; #40
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 20, 2020
1 parent 7f5b71e commit caf1686
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ private PModePartyJsonConverter ()
@Nonnull
public static IJsonObject convertToJson (@Nonnull final PModeParty aValue)
{
return new JsonObject ().add (ID_TYPE, aValue.getIDType ())
.add (ID_VALUE, aValue.getIDValue ())
.add (ROLE, aValue.getRole ())
.add (USER_NAME, aValue.getUserName ())
.add (PASSWORD, aValue.getPassword ());
final IJsonObject ret = new JsonObject ();
if (aValue.hasIDType ())
ret.add (ID_TYPE, aValue.getIDType ());
ret.add (ID_VALUE, aValue.getIDValue ());
ret.add (ROLE, aValue.getRole ());
if (aValue.hasUserName ())
ret.add (USER_NAME, aValue.getUserName ());
if (aValue.hasPassword ())
ret.add (PASSWORD, aValue.getPassword ());
return ret;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public final EAS4CompressionMode getCompressionMode ()
return m_eCompressionMode;
}

/**
* @return <code>true</code> if a compression mode is set, <code>false</code>
* if not.
*/
public final boolean hasCompressionMode ()
{
return m_eCompressionMode != null;
}

/**
* @return The ID of the used compression mode or <code>null</code> if no
* compression mode is set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ private PModePayloadServiceJsonConverter ()
@Nonnull
public static IJsonObject convertToJson (@Nonnull final PModePayloadService aValue)
{
return new JsonObject ().add (COMPRESSION_MODE, aValue.getCompressionModeID ());
final IJsonObject ret = new JsonObject ();
if (aValue.hasCompressionMode ())
ret.add (COMPRESSION_MODE, aValue.getCompressionModeID ());
return ret;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
@Immutable
public final class PModeLegJsonConverter
{
private static final String ELEMENT_PROTOCOL = "Protocol";
private static final String ELEMENT_BUSINESS_INFORMATION = "BusinessInfo";
private static final String ELEMENT_ERROR_HANDLING = "ErrorHandling";
private static final String ELEMENT_RELIABILITY = "Reliability";
private static final String ELEMENT_SECURITY = "Security";
private static final String PROTOCOL = "Protocol";
private static final String BUSINESS_INFORMATION = "BusinessInfo";
private static final String ERROR_HANDLING = "ErrorHandling";
private static final String RELIABILITY = "Reliability";
private static final String SECURITY = "Security";

private PModeLegJsonConverter ()
{}
Expand All @@ -45,38 +45,37 @@ public static IJsonObject convertToJson (@Nonnull final PModeLeg aValue)
{
final IJsonObject ret = new JsonObject ();
if (aValue.hasProtocol ())
ret.addJson (ELEMENT_PROTOCOL, PModeLegProtocolJsonConverter.convertToJson (aValue.getProtocol ()));
ret.addJson (PROTOCOL, PModeLegProtocolJsonConverter.convertToJson (aValue.getProtocol ()));
if (aValue.hasBusinessInfo ())
ret.addJson (ELEMENT_BUSINESS_INFORMATION,
ret.addJson (BUSINESS_INFORMATION,
PModeLegBusinessInformationJsonConverter.convertToJson (aValue.getBusinessInfo ()));
if (aValue.hasErrorHandling ())
ret.addJson (ELEMENT_ERROR_HANDLING,
PModeLegErrorHandlingJsonConverter.convertToJson (aValue.getErrorHandling ()));
ret.addJson (ERROR_HANDLING, PModeLegErrorHandlingJsonConverter.convertToJson (aValue.getErrorHandling ()));
if (aValue.hasReliability ())
ret.addJson (ELEMENT_RELIABILITY, PModeLegReliabilityJsonConverter.convertToJson (aValue.getReliability ()));
ret.addJson (RELIABILITY, PModeLegReliabilityJsonConverter.convertToJson (aValue.getReliability ()));
if (aValue.hasSecurity ())
ret.addJson (ELEMENT_SECURITY, PModeLegSecurityJsonConverter.convertToJson (aValue.getSecurity ()));
ret.addJson (SECURITY, PModeLegSecurityJsonConverter.convertToJson (aValue.getSecurity ()));
return ret;
}

@Nonnull
public static PModeLeg convertToNative (@Nonnull final IJsonObject aElement)
{
final IJsonObject aProt = aElement.getAsObject (ELEMENT_PROTOCOL);
final IJsonObject aProt = aElement.getAsObject (PROTOCOL);
final PModeLegProtocol aProtocol = aProt == null ? null : PModeLegProtocolJsonConverter.convertToNative (aProt);

final IJsonObject aBI = aElement.getAsObject (ELEMENT_BUSINESS_INFORMATION);
final IJsonObject aBI = aElement.getAsObject (BUSINESS_INFORMATION);
final PModeLegBusinessInformation aBusinessInformation = aBI == null ? null
: PModeLegBusinessInformationJsonConverter.convertToNative (aBI);

final IJsonObject aEH = aElement.getAsObject (ELEMENT_ERROR_HANDLING);
final IJsonObject aEH = aElement.getAsObject (ERROR_HANDLING);
final PModeLegErrorHandling aErrorHandling = aEH == null ? null
: PModeLegErrorHandlingJsonConverter.convertToNative (aEH);

final IJsonObject aR = aElement.getAsObject (ELEMENT_RELIABILITY);
final IJsonObject aR = aElement.getAsObject (RELIABILITY);
final PModeLegReliability aReliability = aR == null ? null : PModeLegReliabilityJsonConverter.convertToNative (aR);

final IJsonObject aS = aElement.getAsObject (ELEMENT_SECURITY);
final IJsonObject aS = aElement.getAsObject (SECURITY);
final PModeLegSecurity aSecurity = aS == null ? null : PModeLegSecurityJsonConverter.convertToNative (aS);

return new PModeLeg (aProtocol, aBusinessInformation, aErrorHandling, aReliability, aSecurity);
Expand Down

0 comments on commit caf1686

Please sign in to comment.