Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CesarCoelho committed Oct 13, 2023
1 parent ed0e021 commit 010fc6e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,32 +187,41 @@ public void createServiceInfoClass(File serviceFolder, AreaType area,

SupportedFeatures features = eService.getFeatures();

if (null != features) {
if (features != null) {
if (null != features.getObjects()) {
for (ModelObjectType obj : features.getObjects().getObject()) {
createComObjectHelperDetails(file, comObjectCalls, ns, serviceVar, obj, false);
}
}

if (null != features.getEvents()) {
if (features.getEvents() != null) {
for (ModelObjectType obj : features.getEvents().getEvent()) {
createComObjectHelperDetails(file, comObjectCalls, ns, serviceVar, obj, true);
}
}
}
}

// Constructor - shouldn't it be started with the constructor method?
MethodWriter method = file.addConstructor(StdStrings.PUBLIC, serviceName + SERVICE_INFO,
null, null, null, null, null);
method.addLine("super(SERVICE_KEY, " + serviceVar + "_SERVICE_NAME" + ", OPERATIONS)");
boolean hasCOMObjects = !comObjectCalls.isEmpty();

if (!comObjectCalls.isEmpty()) {
if (hasCOMObjects) {
StringBuilder buf = new StringBuilder();
for (String objectCall : comObjectCalls) {
method.addLine(generator.createMethodCall("this.addCOMObject(" + objectCall + "_OBJECT)"));
buf.append("\n ").append(objectCall).append("_OBJECT,");
}

CompositeField objectInstVar = generator.createCompositeElementsDetails(file, false, "COM_OBJECTS",
TypeUtils.createTypeReference(StdStrings.COM, null, "COMObject", false),
false, true, "Object instance.");
file.addClassVariableNewInit(true, true, StdStrings.PUBLIC, objectInstVar,
false, true, buf.toString(), false);
}

// Constructor - shouldn't it be started with the constructor method?
MethodWriter method = file.addConstructor(StdStrings.PUBLIC, serviceName + SERVICE_INFO,
null, null, null, null, null);
String ending = hasCOMObjects ? ", COM_OBJECTS)" : ")";
method.addLine("super(SERVICE_KEY, " + serviceVar + "_SERVICE_NAME" + ", OPERATIONS" + ending);
method.addMethodCloseStatement();
file.addClassCloseStatement();
file.flush();
Expand Down
26 changes: 10 additions & 16 deletions apis/api-com/src/main/java/org/ccsds/moims/mo/com/COMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.ccsds.moims.mo.com;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -31,31 +30,26 @@
import org.ccsds.moims.mo.mal.structures.UShort;

/**
* This class is deprecated. It is only here for backward compatibility with
* the old MAL.
* This class is deprecated. It is only here for backward compatibility with the
* old MAL.
*/
@Deprecated
public class COMService extends MALService {

private final Map<Integer, COMObject> objectsByNumber = new HashMap<>();

public COMService(final ServiceKey serviceKey, final Identifier serviceName, final ArrayList<MALOperation> operations) {
super(serviceKey, serviceName, operations);
public COMService(final ServiceKey serviceKey, final Identifier serviceName,
final MALOperation[] operations) {
this(serviceKey, serviceName, operations, new COMObject[0]);
}

public COMService(final ServiceKey serviceKey, final Identifier serviceName, final MALOperation[] operations) {
public COMService(final ServiceKey serviceKey, final Identifier serviceName,
final MALOperation[] operations, final COMObject[] comObjects) {
super(serviceKey, serviceName, operations);
}

/**
* Adds a COM object to this service specification.
*
* @param object The new object to add.
* @throws java.lang.IllegalArgumentException If the argument is null.
*/
@Proposed
public void addCOMObject(COMObject object) throws java.lang.IllegalArgumentException {
objectsByNumber.put(object.getObjectType().getNumber().getValue(), object);
for (COMObject comObject : comObjects) {
objectsByNumber.put(comObject.getObjectType().getNumber().getValue(), comObject);
}
}

/**
Expand Down
26 changes: 0 additions & 26 deletions apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/MALService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.ccsds.moims.mo.mal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.ccsds.moims.mo.mal.structures.Identifier;
Expand All @@ -41,31 +40,6 @@ public class MALService {
private final ServiceKey serviceKey;
private final Identifier serviceName;

/**
* Constructs a MALService object.
*
* @param serviceKey The key of the service.
* @param serviceName The name of the service.
* @param operations The operations of the service.
* @throws java.lang.IllegalArgumentException If any arguments are null.
*/
public MALService(final ServiceKey serviceKey, final Identifier serviceName,
final ArrayList<MALOperation> operations) throws java.lang.IllegalArgumentException {
if (serviceKey == null) {
throw new IllegalArgumentException("Number argument must not be NULL");
}
if (operations == null) {
throw new IllegalArgumentException("Name argument must not be NULL");
}

this.serviceKey = serviceKey;
this.serviceName = serviceName;

for (MALOperation operation : operations) {
this.addOperation(operation);
}
}

/**
* Constructs a MALService object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public Endpoint(final Transport transport, final String localName,
@Override
public void startMessageDelivery() throws MALException {
Transport.LOGGER.log(Level.FINE,
"GENEndpoint ({0}) Activating message delivery", localName);
"Endpoint ({0}) Activating message delivery", localName);
active = true;
}

@Override
public void stopMessageDelivery() throws MALException {
Transport.LOGGER.log(Level.FINE,
"GENEndpoint ({0}) Deactivating message delivery", localName);
"Endpoint ({0}) Deactivating message delivery", localName);
active = false;
}

Expand Down

0 comments on commit 010fc6e

Please sign in to comment.