Skip to content

Commit

Permalink
Introduces the ServiceKey to the MALService class
Browse files Browse the repository at this point in the history
  • Loading branch information
CesarCoelho committed Oct 19, 2023
1 parent 8d2cf17 commit 087281d
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public void createServiceInfoClass(File serviceFolder, AreaType area,

String serviceName = service.getName();
String serviceCAPS = serviceName.toUpperCase();

file.addPackageStatement(area, service, null);
String identifierType = generator.createElementType(file, StdStrings.MAL, null, StdStrings.IDENTIFIER);

// Appends the class name
if (service instanceof ExtendedServiceType) {
Expand All @@ -97,6 +95,17 @@ public void createServiceInfoClass(File serviceFolder, AreaType area,
file.addClassVariable(true, true, StdStrings.PUBLIC, serviceNumberVar, false, "(_" + serviceCAPS + "_SERVICE_NUMBER)");
file.addClassVariable(true, true, StdStrings.PUBLIC, serviceNameVar, false, "(\"" + serviceName + "\")");

// Generate ServiceKey:
CompositeField serviceKeyType = generator.createCompositeElementsDetails(file, false, "SERVICE_KEY",
TypeUtils.createTypeReference(null, null, "org.ccsds.moims.mo.mal.ServiceKey", false),
false, false, "The service key of this service.");

String args = "\n new org.ccsds.moims.mo.mal.structures.UShort(" + area.getNumber() + "),"
+ "\n new org.ccsds.moims.mo.mal.structures.UOctet(" + area.getVersion() + "),"
+ "\n " + serviceCAPS + "_SERVICE_NUMBER";
file.addClassVariableNewInit(true, true, StdStrings.PUBLIC, serviceKeyType, false,
false, "new org.ccsds.moims.mo.mal.ServiceKey(" + args + ")", false);

// Generate the operations:
String operations = "";

Expand All @@ -123,9 +132,9 @@ public void createServiceInfoClass(File serviceFolder, AreaType area,
PubSubOperationType lop = (PubSubOperationType) op.getOriginalOp();
AnyTypeReference subsKeys = lop.getMessages().getSubscriptionKeys();

if (null != subsKeys) {
if (subsKeys != null) {
List<TypeRef> types = TypeUtils.getTypeListViaXSDAny(subsKeys.getAny());
if (null != types && !types.isEmpty()) {
if (types != null && !types.isEmpty()) {
String prefix = "";
for (TypeRef type : types) {
if (type.isField()) {
Expand Down Expand Up @@ -158,17 +167,6 @@ public void createServiceInfoClass(File serviceFolder, AreaType area,
operations += operationName;
}

// Generate ServiceKey:
CompositeField serviceKeyType = generator.createCompositeElementsDetails(file, false, "SERVICE_KEY",
TypeUtils.createTypeReference(null, null, "org.ccsds.moims.mo.mal.ServiceKey", false),
false, false, "The service key of this service.");

String args = "new org.ccsds.moims.mo.mal.structures.UShort(" + area.getNumber() + "), "
+ "new org.ccsds.moims.mo.mal.structures.UShort(" + service.getNumber() + "), "
+ "new org.ccsds.moims.mo.mal.structures.UOctet(" + area.getVersion() + ")";
file.addClassVariableNewInit(true, true, StdStrings.PUBLIC, serviceKeyType, false, false,
"new org.ccsds.moims.mo.mal.ServiceKey(" + args + ")", false);

List<String> elementInstantiations = new LinkedList<>();

if ((service.getDataTypes() != null) && !service.getDataTypes().getCompositeOrEnumeration().isEmpty()) {
Expand Down Expand Up @@ -313,6 +311,7 @@ private List<String> generateOperationArgs(LanguageWriter file, OperationSummary
String initNewLine = "\n ";
// Operation Number
List<String> opArgs = new LinkedList<>();
opArgs.add("SERVICE_KEY");
opArgs.add(op.getName().toUpperCase() + "_OP_NUMBER");
opArgs.add(initNewLine + "new " + generator.createElementType(file, StdStrings.MAL, null, StdStrings.IDENTIFIER) + "(\"" + op.getName() + "\")");
// opArgs.add(initNewLine + "" + op.getReplay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class MALInvokeOperation extends MALOperation {
/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param capabilitySet Capability set of the operation.
Expand All @@ -71,14 +72,15 @@ public class MALInvokeOperation extends MALOperation {
* @throws java.lang.IllegalArgumentException If any argument is null,
* except the operation stage arguments.
*/
public MALInvokeOperation(final UShort number,
public MALInvokeOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final UShort capabilitySet,
final OperationField[] invokeStage,
final OperationField[] invokeAckStage,
final OperationField[] invokeResponseStage)
throws java.lang.IllegalArgumentException {
super(number, name, InteractionType.INVOKE, capabilitySet);
super(serviceKey, number, name, InteractionType.INVOKE, capabilitySet);

this.invokeStage = invokeStage;
this.invokeAckStage = invokeAckStage;
Expand Down
31 changes: 14 additions & 17 deletions apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/MALOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@
*/
public abstract class MALOperation {

private final ServiceKey serviceKey;
private final Identifier name;
private final UShort number;
private final InteractionType interactionType;
private final UShort capabilitySet;
private MALService service;

/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param interactionType Interaction type of the operation
* @param capabilitySet Capability set of the operation.
* @throws java.lang.IllegalArgumentException If any argument is null.
*/
public MALOperation(final UShort number,
public MALOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final InteractionType interactionType,
final UShort capabilitySet)
Expand All @@ -57,12 +59,22 @@ public MALOperation(final UShort number,
|| (capabilitySet == null)) {
throw new IllegalArgumentException("Supplied arguments must not be NULL");
}
this.serviceKey = serviceKey;
this.name = name;
this.number = number;
this.interactionType = interactionType;
this.capabilitySet = capabilitySet;
}

/**
* Returns the Service Key.
*
* @return The Service Key.
*/
public ServiceKey getServiceKey() {
return serviceKey;
}

/**
* Returns the operation name.
*
Expand Down Expand Up @@ -100,21 +112,6 @@ public boolean isPubSub() {
return interactionType == InteractionType.PUBSUB;
}

/**
* Returns the operation service.
*
* @return The operation service.
*/
@Deprecated
public MALService getService() {
return service;
}

@Deprecated
public void setService(final MALService service) throws java.lang.IllegalArgumentException {
this.service = service;
}

/**
* Returns the operation capability set.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class MALProgressOperation extends MALOperation {
/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param capabilitySet Capability set of the operation.
Expand All @@ -83,14 +84,15 @@ public class MALProgressOperation extends MALOperation {
* @throws java.lang.IllegalArgumentException If any argument is null,
* except the operation stage arguments.
*/
public MALProgressOperation(final UShort number,
public MALProgressOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final UShort capabilitySet,
final OperationField[] progressStage,
final OperationField[] progressAckStage,
final OperationField[] progressUpdateStage,
final OperationField[] progressResponseStage) throws java.lang.IllegalArgumentException {
super(number, name, InteractionType.PROGRESS, capabilitySet);
super(serviceKey, number, name, InteractionType.PROGRESS, capabilitySet);

this.progressStage = progressStage;
this.progressAckStage = progressAckStage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public class MALPubSubOperation extends MALOperation {
/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param capabilitySet Capability set of the operation.
Expand All @@ -155,12 +156,13 @@ public class MALPubSubOperation extends MALOperation {
* @throws java.lang.IllegalArgumentException If any argument is null,
* except the operation stage arguments.
*/
public MALPubSubOperation(final UShort number,
public MALPubSubOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final UShort capabilitySet,
final OperationField[] fields)
throws java.lang.IllegalArgumentException {
super(number, name, InteractionType.PUBSUB, capabilitySet);
super(serviceKey, number, name, InteractionType.PUBSUB, capabilitySet);

OperationField[] publishFields = new OperationField[fields.length + 1];
OperationField[] notifyFields = new OperationField[fields.length + 2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class MALRequestOperation extends MALOperation {
/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param capabilitySet Capability set of the operation.
Expand All @@ -62,13 +63,14 @@ public class MALRequestOperation extends MALOperation {
* @throws java.lang.IllegalArgumentException If any argument is null,
* except the operation stage arguments.
*/
public MALRequestOperation(final UShort number,
public MALRequestOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final UShort capabilitySet,
final OperationField[] requestStage,
final OperationField[] responseStage)
throws java.lang.IllegalArgumentException {
super(number, name, InteractionType.REQUEST, capabilitySet);
super(serviceKey, number, name, InteractionType.REQUEST, capabilitySet);

this.requestStage = requestStage;
this.responseStage = responseStage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ public class MALSendOperation extends MALOperation {
/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param capabilitySet Capability set of the operation.
* @param sendStage The stage information for the SEND stage.
* @throws java.lang.IllegalArgumentException If any argument is null,
* except the operation stage arguments.
*/
public MALSendOperation(final UShort number,
public MALSendOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final UShort capabilitySet,
final OperationField[] sendStage)
throws java.lang.IllegalArgumentException {
super(number, name, InteractionType.SEND, capabilitySet);
super(serviceKey, number, name, InteractionType.SEND, capabilitySet);
this.sendStage = sendStage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ private void addOperation(final MALOperation operation) throws java.lang.Illegal
throw new IllegalArgumentException("Operation argument must not be NULL");
}

operation.setService(this);
operationsByNumber.put(operation.getNumber().getValue(), operation);
}

Expand Down Expand Up @@ -112,7 +111,7 @@ public UShort getAreaNumber() {
* @return The version number.
*/
public UOctet getServiceVersion() {
return serviceKey.getServiceVersion();
return serviceKey.getAreaVersion();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@ public class MALSubmitOperation extends MALOperation {
/**
* Initialises the internal variables with the supplied values.
*
* @param serviceKey Service Key for the service of this operation.
* @param number Number of the operation.
* @param name Name of the operation.
* @param capabilitySet Capability set of the operation.
* @param submitStage The stage information for the SUBMIT stage.
* @throws java.lang.IllegalArgumentException If any argument is null,
* except the operation stage arguments.
*/
public MALSubmitOperation(final UShort number,
public MALSubmitOperation(final ServiceKey serviceKey,
final UShort number,
final Identifier name,
final UShort capabilitySet,
final OperationField[] submitStage)
throws java.lang.IllegalArgumentException {
super(number, name, InteractionType.SUBMIT, capabilitySet);
super(serviceKey, number, name, InteractionType.SUBMIT, capabilitySet);

this.submitStage = submitStage;
}
Expand Down
39 changes: 19 additions & 20 deletions apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/ServiceKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,38 @@ public class ServiceKey {
private final UShort areaNumber;

/**
* Service number.
* Area version.
*/
private final UShort serviceNumber;
private final UOctet areaVersion;

/**
* Service version.
* Service number.
*/
private final UOctet serviceVersion;
private final UShort serviceNumber;

/**
* Initializes the ServiceKey class.
*
* @param areaNumber The area number of the service.
* @param areaVersion The area version of the service.
* @param serviceNumber The service number of the service.
* @param serviceVersion The service version of the service.
* @throws java.lang.IllegalArgumentException If any argument is null.
*/
public ServiceKey(final UShort areaNumber, final UShort serviceNumber,
final UOctet serviceVersion) throws IllegalArgumentException {
public ServiceKey(final UShort areaNumber, final UOctet areaVersion,
final UShort serviceNumber) throws IllegalArgumentException {
if (areaNumber == null) {
throw new IllegalArgumentException("The areaNumber argument cannot be null!");
}
if (areaVersion == null) {
throw new IllegalArgumentException("The areaVersion argument cannot be null!");
}
if (serviceNumber == null) {
throw new IllegalArgumentException("The serviceNumber argument cannot be null!");
}
if (serviceVersion == null) {
throw new IllegalArgumentException("The serviceVersion argument cannot be null!");
}

this.areaNumber = areaNumber;
this.areaVersion = areaVersion;
this.serviceNumber = serviceNumber;
this.serviceVersion = serviceVersion;
}

/**
Expand All @@ -78,21 +78,20 @@ public UShort getAreaNumber() {
}

/**
* Returns the service number of the service.
* Returns the area version of the service.
*
* @return The service number of the service.
* @return The area version of the service.
*/
public UShort getServiceNumber() {
return serviceNumber;
public UOctet getAreaVersion() {
return areaVersion;
}

/**
* Returns the service version of the service.
* Returns the service number of the service.
*
* @return The service version of the service.
* @return The service number of the service.
*/
public UOctet getServiceVersion() {
return serviceVersion;
public UShort getServiceNumber() {
return serviceNumber;
}

}
6 changes: 3 additions & 3 deletions mal-impl/src/main/java/esa/mo/mal/impl/MessageTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public MALMessage createMessage(final MALOperation operation,
operation.getInteractionType(),
interactionStage,
transactionId,
operation.getService().getAreaNumber(),
operation.getService().getServiceNumber(),
operation.getServiceKey().getAreaNumber(),
operation.getServiceKey().getServiceNumber(),
operation.getNumber(),
operation.getService().getServiceVersion(),
operation.getServiceKey().getAreaVersion(),
Boolean.FALSE,
new NamedValueList(),
qosProps,
Expand Down

0 comments on commit 087281d

Please sign in to comment.