std::cout << "Single type resource created [URI: " << resource->getURI() << " ]" << std::endl;
SimulatorSingleResourceSP singleRes =
std::dynamic_pointer_cast<SimulatorSingleResource>(resource);
+ if (!singleRes)
+ {
+ std::cout << "Error occured while converting SimulatorResource to SimulatorSingleResource!" << std::endl;
+ return;
+ }
+
singleRes->setModelChangeCallback(modelChangeCB);
singleRes->setObserverCallback(observerCB);
g_singleResources.push_back(singleRes);
std::cout << "Collection type resource created [URI: " << resource->getURI() << " ]" << std::endl;
SimulatorCollectionResourceSP collectionRes =
std::dynamic_pointer_cast<SimulatorCollectionResource>(resource);
+ if (!collectionRes)
+ {
+ std::cout << "Error occured while converting SimulatorResource to SimulatorCollectionResource!" << std::endl;
+ return;
+ }
+
collectionRes->setObserverCallback(observerCB);
g_collectionResources.push_back(collectionRes);
}
// Ignore the response if the resource is a device or
// platform.
Vector<String> resTypes = resourceN.getResourceTypes();
- if (null != resTypes && resTypes.contains("oic.wk.d")
- || resTypes.contains("oic.wk.p")) {
+ if (null != resTypes
+ && (resTypes.contains("oic.wk.d") || resTypes
+ .contains("oic.wk.p"))) {
return;
}
}
public boolean isResourceObserved(String resourceURI) {
- boolean observed = false;
+ boolean observed;
synchronized (observedResourceURIList) {
observed = observedResourceURIList.contains(resourceURI);
}
public void deleteResources(final Set<String> searchTypes) {
synchronized (resourceMap) {
- if (null == resourceMap && resourceMap.isEmpty()) {
+ if (null == resourceMap || resourceMap.isEmpty()) {
return;
}
}
public List<MetaProperty> getDefaultProperties(RemoteResource resource) {
if (null != resource) {
String propName;
- String propValue;
+ StringBuilder propValue;
List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
propName = Constants.META_PROPERTIES[index];
+ propValue = new StringBuilder();
if (propName.equals(Constants.RESOURCE_URI)) {
- propValue = resource.getRemoteResourceRef().getURI();
+ propValue.append(resource.getRemoteResourceRef().getURI());
} else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
- propValue = resource.getRemoteResourceRef()
- .getConnectivityType().toString();
+ propValue.append(resource.getRemoteResourceRef()
+ .getConnectivityType().toString());
} else if (propName.equals(Constants.ADDRESS)) {
- propValue = resource.getRemoteResourceRef().getHost();
+ propValue.append(resource.getRemoteResourceRef().getHost());
} else if (propName.equals(Constants.OBSERVABLE)) {
- propValue = Utility.getObservableInString(resource
- .getRemoteResourceRef().isObservable());
+ propValue.append(Utility.getObservableInString(resource
+ .getRemoteResourceRef().isObservable()));
} else if (propName.equals(Constants.RESOURCE_TYPES)) {
Vector<String> resTypes = resource.getRemoteResourceRef()
.getResourceTypes();
if (null != resTypes && !resTypes.isEmpty()) {
- propValue = "";
Iterator<String> itr = resTypes.iterator();
while (itr.hasNext()) {
- propValue += itr.next();
+ propValue.append(itr.next());
if (itr.hasNext()) {
- propValue += ", ";
+ propValue.append(", ");
}
}
} else {
- propValue = Constants.NOT_AVAILABLE;
+ propValue.append(Constants.NOT_AVAILABLE);
}
} else if (propName.equals(Constants.RESOURCE_INTERFACES)) {
Vector<String> interfaces = resource.getRemoteResourceRef()
.getResourceInterfaces();
if (null != interfaces && !interfaces.isEmpty()) {
- propValue = "";
Iterator<String> itr = interfaces.iterator();
while (itr.hasNext()) {
- propValue += itr.next();
+ propValue.append(itr.next());
if (itr.hasNext()) {
- propValue += ", ";
+ propValue.append(", ");
}
}
} else {
- propValue = Constants.NOT_AVAILABLE;
+ propValue.append(Constants.NOT_AVAILABLE);
}
} else {
propValue = null;
}
if (null != propValue) {
- metaPropertyList.add(new MetaProperty(propName, propValue));
+ metaPropertyList.add(new MetaProperty(propName, propValue
+ .toString()));
}
}
package oic.simulator.clientcontroller.remoteresource;
+import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
+import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+import oic.simulator.clientcontroller.utils.Utility;
public class AttributeElement {
private Object mParent = null;
SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
.value().get();
- ArrayProperty arrProp = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
+ ArrayProperty arrProp;
arrProp = attribute.property().asArray();
if (null != arrProp
&& null != arrProp.getElementProperty()) {
SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp
&& null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
- ArrayProperty arrChildPropLevel2 = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp
&& null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
- arrChildPropLevel2 = arrChildPropLevel1
+ ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
.getElementProperty().asArray();
if (null != arrChildPropLevel2
&& null != arrChildPropLevel2
}
public void setAttributeProperty(SimulatorResourceAttribute attribute)
- throws Exception {
+ throws NullPointerException {
if (attribute == null)
return;
SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
.value().get();
- ArrayProperty arrProp = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp && null != arrProp.getElementProperty()) {
modelProp = arrProp.getElementProperty().asModel();
}
SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp && null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
- ArrayProperty arrChildPropLevel2 = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp && null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
- arrChildPropLevel2 = arrChildPropLevel1
+ ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
.getElementProperty().asArray();
if (null != arrChildPropLevel2
&& null != arrChildPropLevel2
((AttributeElement) mParent)
.deepSetChildValue(mAttribute);
} catch (InvalidArgsException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the resource model.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e, null));
}
}
}
public boolean updateAttributeProperties(
SimulatorRequestModel requestModel,
- SimulatorResourceModel resourceModelRef) throws Exception {
+ SimulatorResourceModel resourceModelRef)
+ throws NullPointerException {
if (null == requestModel || null == resourceModelRef) {
return false;
}
package oic.simulator.clientcontroller.remoteresource;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
this.m_favorites = favorites;
}
- public void serialize(String filePath) throws Exception {
+ public void serialize(String filePath) throws FileNotFoundException,
+ IOException {
+ FileOutputStream fileOut = null;
+ ObjectOutputStream out = null;
try {
- FileOutputStream fileOut = new FileOutputStream(filePath);
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
+ fileOut = new FileOutputStream(filePath);
+ out = new ObjectOutputStream(fileOut);
out.writeObject(this);
- out.close();
- fileOut.close();
- } catch (IOException i) {
- throw new Exception("Failed to Serialize data : IOException");
+ } finally {
+ if (null != fileOut)
+ fileOut.close();
+
+ if (null != out)
+ out.close();
}
}
public static SerializedClientController deSerialize(String filePath)
- throws Exception {
+ throws FileNotFoundException, IOException, ClassNotFoundException {
+ FileInputStream fileIn = null;
+ ObjectInputStream in = null;
SerializedClientController r = null;
try {
- FileInputStream fileIn = new FileInputStream(filePath);
- ObjectInputStream in = new ObjectInputStream(fileIn);
+ fileIn = new FileInputStream(filePath);
+ in = new ObjectInputStream(fileIn);
r = (SerializedClientController) in.readObject();
- in.close();
- fileIn.close();
- } catch (IOException i) {
- throw new Exception("Failed to DeSerialize data : IOException");
- } catch (ClassNotFoundException c) {
- throw new Exception("Failed to DeSerialize data : ClassNotFound");
+ } finally {
+ if (null != fileIn)
+ fileIn.close();
+
+ if (null != in)
+ in.close();
}
+
return r;
}
public class AttributeValueBuilder {
public static AttributeValue build(String valueString,
- AttributeValue.ValueType valueType) throws Exception {
+ AttributeValue.ValueType valueType) throws NullPointerException {
int depth = findDepth(valueString);
if (0 == depth) {
return handleDepth0(valueString, valueType);
return null;
}
- private static String[] splitIntoArrays(String value) {
+ private static String[] splitIntoArrays(String valueString) {
Vector<String> values = new Vector<String>();
- String valueString = new String(value);
valueString = valueString.substring(valueString.indexOf('[') + 1,
valueString.lastIndexOf(']'));
for (int index = 0; index < valuesString.length; index++) {
if (null != valuesString[index]
&& !valuesString[index].isEmpty()) {
- Integer value = (Integer) handleDepth0(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth0(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Integer value = (Integer) attValue.get();
if (null == value)
return null;
result[index] = value;
for (int index = 0; index < valuesString.length; index++) {
if (null != valuesString[index]
&& !valuesString[index].isEmpty()) {
- Double value = (Double) handleDepth0(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth0(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Double value = (Double) attValue.get();
if (null == value)
return null;
result[index] = value;
for (int index = 0; index < valuesString.length; index++) {
if (null != valuesString[index]
&& !valuesString[index].isEmpty()) {
- Boolean value = (Boolean) handleDepth0(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth0(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Boolean value = (Boolean) attValue.get();
if (null == value)
return null;
result[index] = value;
if (valueType == AttributeValue.ValueType.INTEGER) {
Integer[][] result = new Integer[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- Integer[] value = (Integer[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Integer[] value = (Integer[]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.DOUBLE) {
Double[][] result = new Double[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- Double[] value = (Double[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Double[] value = (Double[]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.BOOLEAN) {
Boolean[][] result = new Boolean[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- Boolean[] value = (Boolean[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Boolean[] value = (Boolean[]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.STRING) {
String[][] result = new String[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- String[] value = (String[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ String[] value = (String[]) attValue.get();
if (null == value)
return null;
result[index] = value;
if (valueType == AttributeValue.ValueType.INTEGER) {
Integer[][][] result = new Integer[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- Integer[][] value = (Integer[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Integer[][] value = (Integer[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.DOUBLE) {
Double[][][] result = new Double[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- Double[][] value = (Double[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Double[][] value = (Double[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.BOOLEAN) {
Boolean[][][] result = new Boolean[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- Boolean[][] value = (Boolean[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Boolean[][] value = (Boolean[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.STRING) {
String[][][] result = new String[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- String[][] value = (String[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ String[][] value = (String[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
@Override
public String visitingValue(String value) {
- return new String(value);
+ return value;
}
@Override
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorResourceModel;
}
public static Map<String, String> getResourceInterfaces() {
- Map<String, String> ifTypes = null;
- ifTypes = new HashMap<String, String>();
+ Map<String, String> ifTypes = new HashMap<String, String>();
ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline");
ifTypes.put(Constants.LINKS_LIST_INTERFACE, "Links List");
ifTypes.put(Constants.BATCH_INTERFACE, "Batch");
value = value.trim();
String token[] = value.split(",");
- String result = "";
+ StringBuilder result = new StringBuilder();
for (int i = 0; i < token.length; i++) {
- result += token[i].trim();
+ result.append(token[i].trim());
if (i + 1 < token.length) {
- result += ",";
+ result.append(",");
}
}
- return result;
+ return result.toString();
}
public static AttributeValue cloneAttributeValue(AttributeValue value)
- throws Exception {
+ throws InvalidArgsException, NullPointerException {
AttributeValue clone = null;
AttributeValue.TypeInfo typeInfo = value.typeInfo();
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import java.util.Date;
import java.util.List;
import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.SimulatorResourceAttribute;
attValue = AttributeValueBuilder.build(newValue,
type.mBaseType);
} catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while creating the new attribute value.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
}
if (null == attValue) {
invalid = true;
attributesExist = true;
}
}
- if (!attributesExist) {
- MessageDialog
- .openInformation(Display.getDefault()
- .getActiveShell(), "PUT Request",
- "No attributes exist in the resource model.");
- return;
- }
- PutRequestDialog putDialog = new PutRequestDialog(
- Display.getDefault().getActiveShell());
- if (putDialog.open() == Window.OK) {
- // Call the native PUT method
- String ifType = putDialog.getIfType();
- resourceManager.sendPutRequest(ifType,
- resourceInSelection, putDialog
- .getUpdatedRepresentation()
- .getModel());
+ if (attributesExist) {
+ PutRequestDialog putDialog = new PutRequestDialog(
+ Display.getDefault().getActiveShell());
+ if (putDialog.open() == Window.OK) {
+ // Call the native PUT method
+ String ifType = putDialog.getIfType();
+ ResourceRepresentation updatedRepresentation = putDialog
+ .getUpdatedRepresentation();
+ if (null != updatedRepresentation) {
+ resourceManager.sendPutRequest(ifType,
+ resourceInSelection,
+ updatedRepresentation.getModel());
+ return;
+ }
+
+ MessageDialog
+ .openInformation(Display.getDefault()
+ .getActiveShell(),
+ "PUT Request",
+ "No attributes exist in the resource model.");
+ }
}
}
});
attributesExist = true;
}
}
- if (!attributesExist) {
- MessageDialog
- .openInformation(Display.getDefault()
- .getActiveShell(), "POST Request",
- "No attributes exist in the resource model.");
- return;
- }
+ if (attributesExist) {
+ PostRequestDialog postDialog = new PostRequestDialog(
+ Display.getDefault().getActiveShell());
+ if (postDialog.open() == Window.OK) {
+ // Call the native POST method
+ String ifType = postDialog.getIfType();
+ ResourceRepresentation updatedRepresentation = postDialog
+ .getUpdatedRepresentation();
+ if (null != updatedRepresentation) {
+ resourceManager.sendPostRequest(ifType,
+ resourceInSelection,
+ updatedRepresentation
+ .getSelectedModel());
+ return;
+ }
- PostRequestDialog postDialog = new PostRequestDialog(
- Display.getDefault().getActiveShell());
- if (postDialog.open() == Window.OK) {
- // Call the native POST method
- String ifType = postDialog.getIfType();
- ResourceRepresentation representation = postDialog
- .getUpdatedRepresentation();
- resourceManager.sendPostRequest(ifType,
- resourceInSelection,
- representation.getSelectedModel());
+ MessageDialog
+ .openInformation(Display.getDefault()
+ .getActiveShell(),
+ "POST Request",
+ "No attributes exist in the resource model.");
+ }
}
}
});
status = "Failed to perform the requested operation.";
} else {
// GET
- if (oldStatus.get(Constants.GET) != autoStatus
- .get(Constants.GET)) {
+ if (!oldStatus.get(Constants.GET).equals(
+ autoStatus.get(Constants.GET))) {
if (autoStatus.get(Constants.GET)) {
startMsg += Constants.GET;
startCount++;
}
}
// PUT
- if (oldStatus.get(Constants.PUT) != autoStatus
- .get(Constants.PUT)) {
+ if (!oldStatus.get(Constants.PUT).equals(
+ autoStatus.get(Constants.PUT))) {
if (autoStatus.get(Constants.PUT)) {
if (startCount == 1) {
startMsg += ", ";
}
// POST
- if (oldStatus.get(Constants.POST) != autoStatus
- .get(Constants.POST)) {
+ if (!oldStatus.get(Constants.POST).equals(
+ autoStatus.get(Constants.POST))) {
if (autoStatus.get(Constants.POST)) {
if (startCount > 0) {
startMsg += ", ";
import org.eclipse.ui.PlatformUI;
import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Date;
+import org.oic.simulator.ILogger.Level;
+
+import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
/**
* This dialog is used for loading the RAML file.
if (null == configFilePath) {
return;
}
+
+ FileInputStream fileStream = null;
try {
- new FileInputStream(configFilePath);
+ fileStream = new FileInputStream(configFilePath);
} catch (Exception e) {
MessageDialog
.openError(getShell(), "Invalid File",
"File doesn't exist. Either the file path or file name is invalid.");
return;
+ } finally {
+ if (null != fileStream) {
+ try {
+ fileStream.close();
+ } catch (IOException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while closing the file stream.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
+ }
+ }
}
close();
}
gd.grabExcessHorizontalSpace = true;
l5.setLayoutData(gd);
- new Label(container, SWT.NONE); // separator
+ Label seperator = new Label(container, SWT.NONE); // separator
+ seperator.setText("");
Label l6 = new Label(container, SWT.NONE);
l6.setText("Message details");
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
+import java.util.Map;
+
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.SimulatorResourceAttribute;
@Override
public Object[] getChildren(Object attribute) {
if (attribute instanceof AttributeElement) {
- return ((AttributeElement) attribute).getChildren().values()
- .toArray();
+ Map<String, AttributeElement> children = ((AttributeElement) attribute)
+ .getChildren();
+ if (null != children) {
+ return children.values().toArray();
+ }
}
return new Object[0];
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
createTreeViewer(container);
// Clone the resource model for maintaining a local copy of attributes
- // for PUT requests.
+ // for POST requests.
SimulatorResourceModel resourceModel = null;
try {
- resourceModel = (SimulatorResourceModel) Utility
- .cloneAttributeValue(
- new AttributeValue(resource.getResourceModelRef()))
- .get();
- } catch (Exception e2) {
+ AttributeValue attValue = Utility
+ .cloneAttributeValue(new AttributeValue(resource
+ .getResourceModelRef()));
+ if (null != attValue)
+ resourceModel = (SimulatorResourceModel) attValue.get();
+ } catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while forming an instance of the attribute value.\n"
+ + Utility.getSimulatorErrorString(e, null));
}
if (null == resourceModel) {
updatedRepresentation.updateAttributeProperties(resource
.getRequestModels().get(RequestType.POST),
resourceModel);
- } catch (Exception e1) {
+ } catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while forming an instance of the attribute value.\n"
+ + Utility.getSimulatorErrorString(e,
+ null));
}
}
}
if (null != parent
- && !(parent instanceof ResourceRepresentation)) {
+ && parent instanceof AttributeElement) {
Object grandParent = ((AttributeElement) parent)
.getParent();
if (null == grandParent
.value().get();
AttributeElement attElement = getSelectedElement();
+ if (null == attElement) {
+ MessageDialog
+ .openError(Display.getDefault()
+ .getActiveShell(),
+ "Unable to perform the operation.",
+ "Failed to obtain the required data. Operation cannot be performed.");
+ return;
+ }
+
SimulatorResourceAttribute attribute = attElement
.getSimulatorResourceAttribute();
SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
// Removing the element from the child map.
Map<String, AttributeElement> elements = parentElement
.getChildren();
+ if (null == elements) {
+ MessageDialog
+ .openError(Display.getDefault().getActiveShell(),
+ "Operation failed.",
+ "There is an error while removing the array items.");
+ return;
+ }
+
List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
attElementList.addAll(elements.values());
Collections.sort(attElementList, Utility.attributeComparator);
}
private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
- ResourceRepresentation representation = null;
+ ResourceRepresentation representation;
- AttributeValue value = null;
+ AttributeValue value;
ModelProperty property = null;
AttributeElement element = getSelectedElement();
public Object[] getChildren(Object attribute) {
if (attribute instanceof AttributeElement) {
List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
- attElementList.addAll(((AttributeElement) attribute)
- .getChildren().values());
- Collections.sort(attElementList, Utility.attributeComparator);
- return attElementList.toArray();
+ Map<String, AttributeElement> children = ((AttributeElement) attribute)
+ .getChildren();
+ if (null != children) {
+ attElementList.addAll(children.values());
+ Collections.sort(attElementList,
+ Utility.attributeComparator);
+ return attElementList.toArray();
+ }
}
return new Object[0];
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
// for PUT requests.
SimulatorResourceModel resourceModel = null;
try {
- resourceModel = (SimulatorResourceModel) Utility
- .cloneAttributeValue(
- new AttributeValue(resource.getResourceModelRef()))
- .get();
- } catch (Exception e2) {
+ AttributeValue attValue = Utility
+ .cloneAttributeValue(new AttributeValue(resource
+ .getResourceModelRef()));
+ if (null != attValue)
+ resourceModel = (SimulatorResourceModel) attValue.get();
+ } catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while forming an instance of the attribute value.\n"
+ + Utility.getSimulatorErrorString(e, null));
}
if (null == resourceModel) {
updatedRepresentation.updateAttributeProperties(resource
.getRequestModels().get(RequestType.POST),
resourceModel);
- } catch (Exception e1) {
+ } catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while forming an instance of the attribute value.\n"
+ + Utility.getSimulatorErrorString(e,
+ null));
}
}
}
if (null != parent
- && !(parent instanceof ResourceRepresentation)) {
+ && parent instanceof AttributeElement) {
Object grandParent = ((AttributeElement) parent)
.getParent();
if (null == grandParent
.value().get();
AttributeElement attElement = getSelectedElement();
+ if (null == attElement) {
+ MessageDialog
+ .openError(Display.getDefault()
+ .getActiveShell(),
+ "Unable to perform the operation.",
+ "Failed to obtain the required data. Operation cannot be performed.");
+ return;
+ }
+
SimulatorResourceAttribute attribute = attElement
.getSimulatorResourceAttribute();
SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
// Removing the element from the child map.
Map<String, AttributeElement> elements = parentElement
.getChildren();
+ if (null == elements) {
+ MessageDialog
+ .openError(Display.getDefault().getActiveShell(),
+ "Operation failed.",
+ "There is an error while removing the array items.");
+ return;
+ }
+
List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
attElementList.addAll(elements.values());
Collections.sort(attElementList, Utility.attributeComparator);
}
private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
- ResourceRepresentation representation = null;
+ ResourceRepresentation representation;
- AttributeValue value = null;
+ AttributeValue value;
ModelProperty property = null;
AttributeElement element = getSelectedElement();
public Object[] getChildren(Object attribute) {
if (attribute instanceof AttributeElement) {
List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
- attElementList.addAll(((AttributeElement) attribute)
- .getChildren().values());
- Collections.sort(attElementList, Utility.attributeComparator);
- return attElementList.toArray();
+ Map<String, AttributeElement> children = ((AttributeElement) attribute)
+ .getChildren();
+ if (null != children) {
+ attElementList.addAll(children.values());
+ Collections.sort(attElementList,
+ Utility.attributeComparator);
+ return attElementList.toArray();
+ }
}
return new Object[0];
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import java.util.Date;
+
import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.IntegerProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.StringProperty;
+import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
import oic.simulator.clientcontroller.utils.Utility;
ArrayProperty arrProp = attribute.property().asArray();
AttributeProperty elementProp = arrProp.getElementProperty();
- String values = "";
+ StringBuilder values = new StringBuilder();
if (elementProp.isInteger()) {
IntegerProperty intProp = elementProp.asInteger();
if (intProp.hasRange()) {
- values = intProp.min() + " - " + intProp.max();
+ values.append(intProp.min() + " - " + intProp.max());
} else if (intProp.hasValues()) {
int[] arr = intProp.getValues();
for (int i = 0; i < arr.length; i++) {
- values += arr[i];
+ values.append(arr[i]);
if (i + 1 < arr.length) {
- values += ", ";
+ values.append(", ");
}
}
- if (!values.isEmpty()) {
- values = "[" + values + "]";
+ if (!values.toString().isEmpty()) {
+ values.append("[" + values + "]");
}
}
} else if (elementProp.isDouble()) {
DoubleProperty dblProp = elementProp.asDouble();
if (dblProp.hasRange()) {
- values = dblProp.min() + " - " + dblProp.max();
+ values.append(dblProp.min() + " - " + dblProp.max());
} else if (dblProp.hasValues()) {
double[] arr = dblProp.getValues();
for (int i = 0; i < arr.length; i++) {
- values += arr[i];
+ values.append(arr[i]);
if (i + 1 < arr.length) {
- values += ", ";
+ values.append(", ");
}
}
- if (!values.isEmpty()) {
- values = "[" + values + "]";
+ if (!values.toString().isEmpty()) {
+ values.append("[" + values + "]");
}
}
} else if (elementProp.isBoolean()) {
- values = "[true, false]";
+ values.append("[true, false]");
} else if (elementProp.isString()) {
StringProperty strProp = elementProp.asString();
if (strProp.hasValues()) {
String[] arr = strProp.getValues();
for (int i = 0; i < arr.length; i++) {
- values += arr[i];
+ values.append(arr[i]);
if (i + 1 < arr.length) {
- values += ", ";
+ values.append(", ");
}
}
- if (!values.isEmpty()) {
- values = "[" + values + "]";
+ if (!values.toString().isEmpty()) {
+ values.append("[" + values + "]");
}
}
}
- allowedValuesTxt.setText(values);
+
+ allowedValuesTxt.setText(values.toString());
// Set the current value.
currentValueTxt.setText(new AttributeValueStringConverter(attribute
return;
}
- // ArrayProperty arrProp = attribute.property().asArray();
try {
String value = Utility.removeWhiteSpacesInArrayValues(newValue);
- if (value.startsWith("[") && value.endsWith("]")) {
+ if (null != value && value.startsWith("[") && value.endsWith("]")) {
newAttValueObj = AttributeValueBuilder.build(value, attribute
.value().typeInfo().mBaseType);
- if (null != newAttValueObj/* && arrProp.validate(newAttValueObj) */) {
+ if (null != newAttValueObj) {
close();
return;
}
}
} catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while building the new attribute value.\n"
+ + Utility.getSimulatorErrorString(e, null));
}
MessageBox dialog = new MessageBox(Display.getDefault()
public Resource createResourceByRAML(String configFilePath)
throws SimulatorException {
- Resource resource = null;
+ SimulatorResource jSimulatorResource;
try {
// Create the resource
- SimulatorResource jSimulatorResource = SimulatorManager
+ jSimulatorResource = SimulatorManager
.createResource(configFilePath);
if (null == jSimulatorResource) {
return null;
}
- if (jSimulatorResource instanceof SimulatorSingleResource) {
- resource = new SingleResource();
- } else {
- return null;
- }
- resource.setSimulatorResource(jSimulatorResource);
-
- // Fetch and locally store the resource name and uri.
- String uri = jSimulatorResource.getURI();
- if (null == uri || uri.trim().isEmpty()) {
- return null;
- }
- resource.setResourceURI(uri.trim());
-
- String name = jSimulatorResource.getName();
- if (null == name || name.trim().isEmpty()) {
- return null;
- }
- resource.setResourceName(name.trim());
} catch (SimulatorException e) {
Activator
.getDefault()
Utility.getSimulatorErrorString(e, null));
throw e;
}
+
+ if (!(jSimulatorResource instanceof SimulatorSingleResource)) {
+ return null;
+ }
+
+ Resource resource = new SingleResource();
+ resource.setSimulatorResource(jSimulatorResource);
+
+ // Fetch and locally store the resource name and uri.
+ String uri = jSimulatorResource.getURI();
+ if (null == uri || uri.trim().isEmpty()) {
+ return null;
+ }
+ resource.setResourceURI(uri.trim());
+
+ String name = jSimulatorResource.getName();
+ if (null == name || name.trim().isEmpty()) {
+ return null;
+ }
+
+ resource.setResourceName(name.trim());
+
return resource;
}
public List<MetaProperty> getMetaProperties(Resource resource) {
if (null != resource) {
String propName;
- String propValue;
-
+ StringBuilder propValue;
List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
propName = Constants.META_PROPERTIES[index];
+ propValue = new StringBuilder();
if (propName.equals(Constants.RESOURCE_NAME)) {
- propValue = resource.getResourceName();
+ propValue.append(resource.getResourceName());
} else if (propName.equals(Constants.RESOURCE_URI)) {
- propValue = resource.getResourceURI();
+ propValue.append(resource.getResourceURI());
} else if (propName.equals(Constants.RESOURCE_TYPE)) {
- propValue = resource.getResourceType();
+ propValue.append(resource.getResourceType());
} else if (propName.equals(Constants.INTERFACE_TYPES)) {
Set<String> ifTypes = resource.getResourceInterfaces();
if (null != ifTypes && !ifTypes.isEmpty()) {
- propValue = "";
Iterator<String> itr = ifTypes.iterator();
while (itr.hasNext()) {
- propValue += itr.next();
+ propValue.append(itr.next());
if (itr.hasNext()) {
- propValue += ", ";
+ propValue.append(", ");
}
}
} else {
propValue = null;
}
if (null != propValue) {
- metaPropertyList.add(new MetaProperty(propName, propValue));
+ metaPropertyList.add(new MetaProperty(propName, propValue
+ .toString()));
}
}
return metaPropertyList;
if (null == resource || null == newIfSet || newIfSet.isEmpty()) {
return false;
}
+
SimulatorResource jResource = resource.getSimulatorResource();
if (null == jResource) {
return false;
}
+
Set<String> curIfSet = resource.getResourceInterfaces();
+ if (null == curIfSet || curIfSet.isEmpty()) {
+ return false;
+ }
+
Iterator<String> itr = curIfSet.iterator();
String interfaceType;
boolean resourceRestartRequired = false;
package oic.simulator.serviceprovider.model;
+import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.IntegerProperty;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.ModelProperty;
import org.oic.simulator.StringProperty;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
+import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
public class AttributeElement {
private Object mParent = null;
SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
.value().get();
- ArrayProperty arrProp = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp
&& null != arrProp.getElementProperty()) {
modelProp = arrProp.getElementProperty().asModel();
SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp
&& null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
- ArrayProperty arrChildPropLevel2 = null;
ModelProperty modelProp = null;
if (null != attribute.property()) {
- arrProp = attribute.property().asArray();
+ ArrayProperty arrProp = attribute.property().asArray();
if (null != arrProp
&& null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
- arrChildPropLevel2 = arrChildPropLevel1
+ ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
.getElementProperty().asArray();
if (null != arrChildPropLevel2
&& null != arrChildPropLevel2
AttributeValue currentValue = mAttribute.value();
SimulatorResourceModel curModel = (SimulatorResourceModel) currentValue
.get();
- try {
- curModel.set(attName, entry.getValue());
- } catch (InvalidArgsException e) {
- }
+ if (null != curModel) {
+ try {
+ curModel.set(attName, entry.getValue());
+ } catch (InvalidArgsException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the resource model.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e, null));
+ }
- mChildAttributes.put(attName, newAttribute);
+ mChildAttributes.put(attName, newAttribute);
- // Refresh UI to display the new attribute.
- UiListenerHandler.getInstance()
- .attributeAddedUINotification(newAttribute);
+ // Refresh UI to display the new attribute.
+ UiListenerHandler.getInstance()
+ .attributeAddedUINotification(newAttribute);
+ }
}
}
} else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
.value().get();
- ArrayProperty arrProp = null;
ModelProperty modelProp = null;
if (null != mAttribute.property()) {
- arrProp = mAttribute.property().asArray();
+ ArrayProperty arrProp = mAttribute.property().asArray();
if (null != arrProp && null != arrProp.getElementProperty()) {
modelProp = arrProp.getElementProperty().asModel();
}
SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
ModelProperty modelProp = null;
if (null != mAttribute.property()) {
- arrProp = mAttribute.property().asArray();
+ ArrayProperty arrProp = mAttribute.property().asArray();
if (null != arrProp && null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
.value().get();
- ArrayProperty arrProp = null;
- ArrayProperty arrChildPropLevel1 = null;
- ArrayProperty arrChildPropLevel2 = null;
ModelProperty modelProp = null;
if (null != mAttribute.property()) {
- arrProp = mAttribute.property().asArray();
+ ArrayProperty arrProp = mAttribute.property().asArray();
if (null != arrProp && null != arrProp.getElementProperty()) {
- arrChildPropLevel1 = arrProp.getElementProperty()
- .asArray();
+ ArrayProperty arrChildPropLevel1 = arrProp
+ .getElementProperty().asArray();
if (null != arrChildPropLevel1
&& null != arrChildPropLevel1
.getElementProperty()) {
- arrChildPropLevel2 = arrChildPropLevel1
+ ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
.getElementProperty().asArray();
if (null != arrChildPropLevel2
&& null != arrChildPropLevel2
((AttributeElement) mParent)
.deepSetChildValue(mAttribute);
} catch (InvalidArgsException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the resource model.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e, null));
}
}
UiListenerHandler.getInstance().attributeUpdatedUINotification(
dflValue = Double.parseDouble(value);
boolean found = false;
for (double val = min; val <= max; val += 1.0) {
- if (dflValue == val) {
+ if (Double.compare(dflValue, val) == 0) {
found = true;
break;
}
String val = itr.next();
double v1 = Double.parseDouble(val);
double v2 = Double.parseDouble(value);
- if (v1 == v2) {
+ if (Double.compare(v1, v2) == 0) {
found = true;
break;
}
public static List<AutomationSettingHelper> getAutomationSettings(
AttributeElement attribute) {
- List<AutomationSettingHelper> settingList = null;
boolean invalidSetting;
-
- settingList = new ArrayList<AutomationSettingHelper>();
+ List<AutomationSettingHelper> settingList = new ArrayList<AutomationSettingHelper>();
for (int count = 0; count < Constants.AUTOMATION_SETTINGS_COUNT; count++) {
invalidSetting = false;
AutomationSettingHelper setting = new AutomationSettingHelper();
package oic.simulator.serviceprovider.model;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
this.m_resourceAttributesMap = resourceAttributesMap;
}
- public void serialize(String filePath) throws IOException {
- FileOutputStream fileOut = new FileOutputStream(filePath);
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
- out.writeObject(this);
- out.close();
- fileOut.close();
+ public void serialize(String filePath) throws FileNotFoundException,
+ IOException {
+ FileOutputStream fileOut = null;
+ ObjectOutputStream out = null;
+ try {
+ fileOut = new FileOutputStream(filePath);
+ out = new ObjectOutputStream(fileOut);
+ out.writeObject(this);
+ } finally {
+ if (null != fileOut)
+ fileOut.close();
+
+ if (null != out)
+ out.close();
+ }
}
public static SerializedServiceProvider deSerialize(String filePath)
- throws Exception {
- SerializedServiceProvider r = null;
- FileInputStream fileIn = new FileInputStream(filePath);
- ObjectInputStream in = new ObjectInputStream(fileIn);
- r = (SerializedServiceProvider) in.readObject();
- in.close();
- fileIn.close();
+ throws FileNotFoundException, IOException, ClassNotFoundException {
+ FileInputStream fileIn = null;
+ ObjectInputStream in = null;
+ SerializedServiceProvider r;
+ try {
+ fileIn = new FileInputStream(filePath);
+ in = new ObjectInputStream(fileIn);
+ r = (SerializedServiceProvider) in.readObject();
+ } finally {
+ if (null != fileIn)
+ fileIn.close();
+
+ if (null != in)
+ in.close();
+ }
return r;
}
public class AttributeValueBuilder {
public static AttributeValue build(String valueString,
- AttributeValue.ValueType valueType) throws Exception {
+ AttributeValue.ValueType valueType) throws NullPointerException {
int depth = findDepth(valueString);
if (0 == depth) {
return handleDepth0(valueString, valueType);
return null;
}
- private static String[] splitIntoArrays(String value) {
+ private static String[] splitIntoArrays(String valueString) {
Vector<String> values = new Vector<String>();
- String valueString = new String(value);
valueString = valueString.substring(valueString.indexOf('[') + 1,
valueString.lastIndexOf(']'));
for (int index = 0; index < valuesString.length; index++) {
if (null != valuesString[index]
&& !valuesString[index].isEmpty()) {
- Integer value = (Integer) handleDepth0(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth0(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Integer value = (Integer) attValue.get();
if (null == value)
return null;
result[index] = value;
for (int index = 0; index < valuesString.length; index++) {
if (null != valuesString[index]
&& !valuesString[index].isEmpty()) {
- Double value = (Double) handleDepth0(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth0(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Double value = (Double) attValue.get();
if (null == value)
return null;
result[index] = value;
for (int index = 0; index < valuesString.length; index++) {
if (null != valuesString[index]
&& !valuesString[index].isEmpty()) {
- Boolean value = (Boolean) handleDepth0(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth0(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Boolean value = (Boolean) attValue.get();
if (null == value)
return null;
result[index] = value;
if (valueType == AttributeValue.ValueType.INTEGER) {
Integer[][] result = new Integer[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- Integer[] value = (Integer[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Integer[] value = (Integer[]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.DOUBLE) {
Double[][] result = new Double[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- Double[] value = (Double[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Double[] value = (Double[]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.BOOLEAN) {
Boolean[][] result = new Boolean[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- Boolean[] value = (Boolean[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Boolean[] value = (Boolean[]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.STRING) {
String[][] result = new String[valuesString.length][];
for (int index = 0; index < valuesString.length; index++) {
- String[] value = (String[]) handleDepth1(valuesString[index],
- valueType).get();
+ AttributeValue attValue = handleDepth1(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ String[] value = (String[]) attValue.get();
if (null == value)
return null;
result[index] = value;
if (valueType == AttributeValue.ValueType.INTEGER) {
Integer[][][] result = new Integer[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- Integer[][] value = (Integer[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Integer[][] value = (Integer[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.DOUBLE) {
Double[][][] result = new Double[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- Double[][] value = (Double[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Double[][] value = (Double[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.BOOLEAN) {
Boolean[][][] result = new Boolean[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- Boolean[][] value = (Boolean[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ Boolean[][] value = (Boolean[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
} else if (valueType == AttributeValue.ValueType.STRING) {
String[][][] result = new String[valuesString.length][][];
for (int index = 0; index < valuesString.length; index++) {
- String[][] value = (String[][]) handleDepth2(
- valuesString[index], valueType).get();
+ AttributeValue attValue = handleDepth2(valuesString[index],
+ valueType);
+ if (null == attValue)
+ return null;
+
+ String[][] value = (String[][]) attValue.get();
if (null == value)
return null;
result[index] = value;
@Override
public String visitingValue(String value) {
- return new String(value);
+ return value;
}
@Override
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorResourceModel;
Set<String> resultSet = new HashSet<String>();
Enumeration<String> e = vector.elements();
while (e.hasMoreElements()) {
- resultSet.add(e.nextElement().toString());
+ resultSet.add(e.nextElement());
}
return resultSet;
}
if (null == e) {
return null;
}
- String detail = "";
+ String detail;
if (e instanceof SimulatorException) {
SimulatorException simEx = (SimulatorException) e;
detail = simEx.message() + "\n";
val = Integer.parseInt(itr.next());
resultSet.add(val);
} catch (NumberFormatException nfe) {
- // Added for safety. Nothing to do.
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while doing internal convertion(string set to object set).\n"
+ + Utility.getSimulatorErrorString(
+ nfe, null));
}
}
} else if (AttributeValue.ValueType.DOUBLE == type) {
val = Double.parseDouble(itr.next());
resultSet.add(val);
} catch (NumberFormatException nfe) {
- // Added for safety. Nothing to do.
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while doing internal convertion(string set to object set).\n"
+ + Utility.getSimulatorErrorString(
+ nfe, null));
}
}
} else if (AttributeValue.ValueType.BOOLEAN == type) {
value = value.trim();
String token[] = value.split(",");
- String result = "";
+ StringBuilder result = new StringBuilder();
for (int i = 0; i < token.length; i++) {
- result += token[i].trim();
+ result.append(token[i].trim());
if (i + 1 < token.length) {
- result += ",";
+ result.append(",");
}
}
- return result;
+ return result.toString();
}
public static AttributeValue cloneAttributeValue(AttributeValue value)
- throws Exception {
+ throws InvalidArgsException, NullPointerException {
AttributeValue clone = null;
AttributeValue.TypeInfo typeInfo = value.typeInfo();
private AttributeValueEditor attValueEditor;
private AutomationEditor automationEditor;
- private Boolean valueChangeInProgress;
+ class SyncValueUpdate {
+ private Boolean valueChangeInProgress;
+
+ public boolean isValueChangeInProgress() {
+ return valueChangeInProgress;
+ }
+
+ public void setValueChangeInProgress(boolean value) {
+ valueChangeInProgress = value;
+ }
+ }
+
+ private final SyncValueUpdate syncValueChange = new SyncValueUpdate();
public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer,
Boolean nativeUpdateValueCall) {
attValueEditor = new AttributeValueEditor(viewer, nativeUpdateValueCall);
- valueChangeInProgress = false;
+ syncValueChange.setValueChangeInProgress(false);
return attValueEditor;
}
return automationEditor;
}
- public synchronized boolean isValueChangeInProgress() {
- return valueChangeInProgress;
- }
-
- public synchronized void setValueChangeInProgress(boolean value) {
- valueChangeInProgress = value;
- }
-
class AttributeValueEditor extends EditingSupport {
private final TreeViewer viewer;
public void partDeactivated(IWorkbenchPartReference partRef) {
String viewId = partRef.getId();
if (viewId.equals(AttributeView.VIEW_ID)) {
- synchronized (valueChangeInProgress) {
+ synchronized (syncValueChange) {
updateUnSavedData();
}
}
Activator.getDefault().getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.addPartListener(partListener);
- } catch (NullPointerException e) {
+ } catch (Exception e) {
Activator
.getDefault()
.getLogManager()
return;
}
- if (!isValueChangeInProgress()) {
+ synchronized (syncValueChange) {
+ if (!syncValueChange.isValueChangeInProgress()) {
- AttributeValue value = att.value();
- if (value == null)
- return;
+ AttributeValue value = att.value();
+ if (value == null)
+ return;
- TypeInfo type = value.typeInfo();
+ TypeInfo type = value.typeInfo();
- if (type.mBaseType == ValueType.RESOURCEMODEL
- || type.mType == ValueType.ARRAY) {
- return;
- }
+ if (type.mBaseType == ValueType.RESOURCEMODEL
+ || type.mType == ValueType.ARRAY) {
+ return;
+ }
- if (null == value.get()) {
- return;
- }
+ if (null == value.get()) {
+ return;
+ }
- String oldValue = String.valueOf(Utility
- .getAttributeValueAsString(value));
+ String oldValue = String.valueOf(Utility
+ .getAttributeValueAsString(value));
- attElement.setEditLock(true);
- compareAndUpdateAttribute(oldValue, comboBox.getText(),
- element, att, type);
- attElement.setEditLock(false);
+ attElement.setEditLock(true);
+ compareAndUpdateAttribute(oldValue, comboBox.getText(),
+ element, att, type);
+ attElement.setEditLock(false);
- viewer.refresh();
+ viewer.refresh();
+ }
}
}
return null;
}
- setValueChangeInProgress(false);
+ synchronized (syncValueChange) {
+ syncValueChange.setValueChangeInProgress(false);
+ }
CellEditor editor;
if (type.mType == ValueType.ARRAY) {
.getCurrentResourceInSelection();
SimulatorResourceAttribute result = getResultantAttribute();
+ if (null == result) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the attribute value.\n");
+ return;
+ }
boolean updated = resourceManager
.attributeValueUpdated(
currentAttValue,
type.mBaseType));
} catch (Exception ex) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the attribute value.\n"
+ + Utility
+ .getSimulatorErrorString(
+ ex,
+ null));
}
MessageDialog
.openInformation(Display
@Override
protected void setValue(Object element, Object value) {
- synchronized (valueChangeInProgress) {
- if (isValueChangeInProgress()) {
+ synchronized (syncValueChange) {
+ if (syncValueChange.isValueChangeInProgress()) {
return;
}
return;
}
- setValueChangeInProgress(true);
+ synchronized (syncValueChange) {
+ syncValueChange.setValueChangeInProgress(true);
+ }
if (!oldValue.equals(newValue)) {
boolean invalid = false;
attValue = AttributeValueBuilder.build(newValue,
type.mBaseType);
} catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while creating the new attribute value.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
}
if (null == attValue) {
try {
attValue = AttributeValueBuilder.build(
oldValue, type.mBaseType);
+ updateAttributeValue(att, attValue);
} catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the attribute value.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e, null));
}
- updateAttributeValue(att, attValue);
-
} else {
ResourceManager resourceManager;
resourceManager = Activator.getDefault()
.getCurrentResourceInSelection();
SimulatorResourceAttribute result = getResultantAttribute();
+ if (null == result) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(),
+ "There is an error while updating the attribute value.\n");
+ return;
+ }
boolean updated = resourceManager
.attributeValueUpdated(
try {
attValue = AttributeValueBuilder.build(
oldValue, type.mBaseType);
+ updateAttributeValue(att, attValue);
} catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the attribute value.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e,
+ null));
}
- updateAttributeValue(att, attValue);
MessageDialog
.openInformation(Display.getDefault()
.getActiveShell(),
public void updateAttributeValue(SimulatorResourceAttribute att,
AttributeValue value) {
+ if (null == att || null == value) {
+ return;
+ }
+
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (null == selection) {
try {
((AttributeElement) data).deepSetChildValue(att);
} catch (InvalidArgsException e) {
- e.printStackTrace();
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the attribute value.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e, null));
}
}
}
return null;
}
- SimulatorResourceAttribute result = null;
+ SimulatorResourceAttribute result;
TreeItem parent = item.getParentItem();
if (null == parent) {
Object data = item.getData();
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
// displayed by this view.
Resource resourceInSelection = resourceManager
.getCurrentResourceInSelection();
- if (null == resourceInSelection) {
- return;
- }
if (resource != resourceInSelection) {
return;
}
}
if (null != parent
- && !(parent instanceof ResourceRepresentation)) {
+ && parent instanceof AttributeElement) {
Object grandParent = ((AttributeElement) parent)
.getParent();
if (null == grandParent
// the array property of the current attribute in
// selection(Model Array type attribute).
AttributeElement attElement = getSelectedElement();
+ if (null == attElement) {
+ MessageDialog
+ .openError(Display.getDefault()
+ .getActiveShell(),
+ "Unable to perform the operation.",
+ "Failed to obtain the required data. Operation cannot be performed.");
+ return;
+ }
+
SimulatorResourceAttribute attribute = attElement
.getSimulatorResourceAttribute();
"Failed to insert a new item in the array.");
} else {
// Highlight the newly added item.
- AttributeElement addedElement = attElement
- .getChildren().get("[" + i + "]");
- attViewer.setSelection(new StructuredSelection(
- addedElement), true);
+ if (attElement.hasChildren()) {
+ AttributeElement addedElement = attElement
+ .getChildren().get("[" + i + "]");
+ attViewer.setSelection(new StructuredSelection(
+ addedElement), true);
+ }
}
}
}
// Removing the element from the child map.
Map<String, AttributeElement> elements = parentElement
.getChildren();
+ if (null == elements) {
+ MessageDialog
+ .openError(Display.getDefault().getActiveShell(),
+ "Operation failed.",
+ "There is an error while removing the array items.");
+ return;
+ }
+
List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
attElementList.addAll(elements.values());
Collections.sort(attElementList, Utility.attributeComparator);
}
private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
- ResourceRepresentation representation = null;
+ ResourceRepresentation representation;
AttributeValue value = null;
ModelProperty property = null;
value = Utility.cloneAttributeValue(new AttributeValue(
modelValue[0]));
} catch (Exception e) {
- return null;
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while creating an instance of the model element.\n"
+ + Utility.getSimulatorErrorString(e, null));
}
if (null == value) {
updatedIfSet = resource.getResourceInterfaces();
}
} else {
- boolean result = false;
Resource resourceInSelection = resourceManagerRef
.getCurrentResourceInSelection();
if (null != resourceInSelection) {
// Null Check
- result = resourceManagerRef.isPropertyValueInvalid(
- resourceInSelection, properties,
- Constants.RESOURCE_URI);
+ boolean result = resourceManagerRef
+ .isPropertyValueInvalid(resourceInSelection,
+ properties, Constants.RESOURCE_URI);
if (result) {
MessageDialog.openError(parent.getShell(),
"Invalid Resource URI.",
// interfaces by
// comparing the current interface set and updated
// interface set.
- if (null != updatedIfSet) {
- Set<String> curIfSet = resourceInSelection
- .getResourceInterfaces();
+ Set<String> curIfSet = resourceInSelection
+ .getResourceInterfaces();
+ if (null != curIfSet && null != updatedIfSet) {
if (curIfSet.size() != updatedIfSet.size()) {
update = true;
interfaceChange = true;
// Update the local copy of the current resource
// interfaces to keep the state for save operation.
updatedIfSet.clear();
- String newPropValue = "";
+ StringBuilder newPropValue = new StringBuilder();
for (Map.Entry<String, String> entry : curResInterfaces
.entrySet()) {
- if (!newPropValue.isEmpty()) {
- newPropValue += ", ";
+ if (!newPropValue.toString().isEmpty()) {
+ newPropValue.append(", ");
}
String value = ifTypes.get(entry.getKey());
- newPropValue += value;
+ newPropValue.append(value);
updatedIfSet.add(value);
}
// Update the model
MetaProperty prop = (MetaProperty) element;
- prop.setPropValue(newPropValue);
+ prop.setPropValue(newPropValue.toString());
// Update the viewer in a separate UI thread.
Display.getDefault().asyncExec(new Runnable() {
@Override
import org.eclipse.ui.part.ViewPart;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
+import oic.simulator.serviceprovider.view.dialogs.MainPage;
import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog;
if (open == WizardDialog.OK
|| createWizard.isDlgForceClosed()) {
- Option option = createWizard.getMainPage()
- .getOption();
+ MainPage mainPage = createWizard.getMainPage();
+ if (null == mainPage) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(),
+ "There is an error while creating the wizard.\n");
+ return;
+ }
+
+ Option option = mainPage.getOption();
if (option == Option.SIMPLE_FROM_RAML
|| option == Option.SIMPLE) {
SingleResource res = (SingleResource) createWizard
import org.eclipse.swt.widgets.Display;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Date;
}
} else if (curPage == loadRamlPage) {
// Validate the file path.
+ FileInputStream fileStream = null;
try {
- new FileInputStream(loadRamlPage.getConfigFilePath());
- } catch (Exception e) {
+ fileStream = new FileInputStream(
+ loadRamlPage.getConfigFilePath());
+ } catch (FileNotFoundException e) {
MessageDialog
.openError(getShell(), "Invalid File",
"File doesn't exist. Either the file path or file name is invalid.");
return false;
+ } finally {
+ if (null != fileStream) {
+ try {
+ fileStream.close();
+ } catch (IOException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(),
+ "There is an error while closing the file stream.\n");
+ }
+ }
}
// Handling multiple instance creation of simple resource with RAML
Activator.getDefault().getResourceManager()
.removeSingleResources(resources);
} catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the resource model.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
}
return 0;
}
return;
}
for (Object obj : selection) {
- if (obj instanceof Resource) {
+ if (obj instanceof SingleResource) {
singles.add((SingleResource) obj);
}
}
import org.eclipse.ui.PlatformUI;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
@Override
public IWizardPage getNextPage() {
// Validate the file path.
+ FileInputStream fileStream = null;
try {
- new FileInputStream(configFilePath);
- } catch (Exception e) {
+ fileStream = new FileInputStream(configFilePath);
+ } catch (FileNotFoundException e) {
MessageDialog
.openError(getShell(), "Invalid File",
"File doesn't exist. Either the file path or file name is invalid.");
return null;
+ } finally {
+ if (null != fileStream)
+ try {
+ fileStream.close();
+ } catch (IOException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while closing the file stream.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
+ }
}
// Checking the resource count
gd.grabExcessHorizontalSpace = true;
l5.setLayoutData(gd);
- new Label(container, SWT.NONE); // separator
+ Label seperator = new Label(container, SWT.NONE); // separator
+ seperator.setText("");
Label l6 = new Label(container, SWT.NONE);
l6.setText("Message details");
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
+import java.util.Map;
+
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.SimulatorResourceAttribute;
@Override
public Object[] getChildren(Object attribute) {
if (attribute instanceof AttributeElement) {
- return ((AttributeElement) attribute).getChildren().values()
- .toArray();
+ Map<String, AttributeElement> childs = ((AttributeElement) attribute)
+ .getChildren();
+ if (null == childs) {
+ return new Object[0];
+ }
+
+ return childs.values().toArray();
}
return new Object[0];
.getDefault().getActiveShell(), att, rTypes, attributes);
if (dialog.open() != Window.OK) {
AttributeHelper newAtt = dialog.getAttClone();
- att.setAttributeName(newAtt.getAttributeName());
- att.setAttributeType(newAtt.getAttributeType());
- att.setAttributeDflValue(newAtt.getAttributeDflValue());
- att.setValidValuesType(newAtt.getValidValuesType());
- att.setMin(newAtt.getMin());
- att.setMax(newAtt.getMax());
- att.setAllowedValues(newAtt.getAllowedValues());
+ if (null != newAtt) {
+ att.setAttributeName(newAtt.getAttributeName());
+ att.setAttributeType(newAtt.getAttributeType());
+ att.setAttributeDflValue(newAtt.getAttributeDflValue());
+ att.setValidValuesType(newAtt.getValidValuesType());
+ att.setMin(newAtt.getMin());
+ att.setMax(newAtt.getMax());
+ att.setAllowedValues(newAtt.getAllowedValues());
+ }
}
attTblViewer.update(att, null);
}
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import java.util.Date;
+
import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.IntegerProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.StringProperty;
+import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
import oic.simulator.serviceprovider.utils.Utility;
ArrayProperty arrProp = attribute.property().asArray();
AttributeProperty elementProp = arrProp.getElementProperty();
- String values = "";
+ StringBuilder values = new StringBuilder();
if (elementProp.isInteger()) {
IntegerProperty intProp = elementProp.asInteger();
if (intProp.hasRange()) {
- values = intProp.min() + " - " + intProp.max();
+ values.append(intProp.min() + " - " + intProp.max());
} else if (intProp.hasValues()) {
int[] arr = intProp.getValues();
for (int i = 0; i < arr.length; i++) {
- values += arr[i];
+ values.append(arr[i]);
if (i + 1 < arr.length) {
- values += ", ";
+ values.append(", ");
}
}
- if (!values.isEmpty()) {
- values = "[" + values + "]";
+ if (!values.toString().isEmpty()) {
+ values.append("[" + values + "]");
}
}
} else if (elementProp.isDouble()) {
DoubleProperty dblProp = elementProp.asDouble();
if (dblProp.hasRange()) {
- values = dblProp.min() + " - " + dblProp.max();
+ values.append(dblProp.min() + " - " + dblProp.max());
} else if (dblProp.hasValues()) {
double[] arr = dblProp.getValues();
for (int i = 0; i < arr.length; i++) {
- values += arr[i];
+ values.append(arr[i]);
if (i + 1 < arr.length) {
- values += ", ";
+ values.append(", ");
}
}
- if (!values.isEmpty()) {
- values = "[" + values + "]";
+ if (!values.toString().isEmpty()) {
+ values.append("[" + values + "]");
}
}
} else if (elementProp.isBoolean()) {
- values = "[true, false]";
+ values.append("[true, false]");
} else if (elementProp.isString()) {
StringProperty strProp = elementProp.asString();
if (strProp.hasValues()) {
String[] arr = strProp.getValues();
for (int i = 0; i < arr.length; i++) {
- values += arr[i];
+ values.append(arr[i]);
if (i + 1 < arr.length) {
- values += ", ";
+ values.append(", ");
}
}
- if (!values.isEmpty()) {
- values = "[" + values + "]";
+ if (!values.toString().isEmpty()) {
+ values.append("[" + values + "]");
}
}
}
- allowedValuesTxt.setText(values);
+ allowedValuesTxt.setText(values.toString());
// Set the current value.
currentValueTxt.setText(new AttributeValueStringConverter(attribute
ArrayProperty arrProp = attribute.property().asArray();
try {
String value = Utility.removeWhiteSpacesInArrayValues(newValue);
- if (value.startsWith("[") && value.endsWith("]")) {
+ if (null != value && value.startsWith("[") && value.endsWith("]")) {
newAttValueObj = AttributeValueBuilder.build(value, attribute
.value().typeInfo().mBaseType);
if (null != newAttValueObj && arrProp.validate(newAttValueObj)) {
}
}
} catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while building the new attribute value.\n"
+ + Utility.getSimulatorErrorString(e, null));
}
MessageBox dialog = new MessageBox(Display.getDefault()
}
private void initInterfaceList() {
- for (Map.Entry<String, String> entry : updatedResInterfaces.entrySet()) {
- ifTypesList.add(entry.getKey());
+ if (null != updatedResInterfaces) {
+ for (Map.Entry<String, String> entry : updatedResInterfaces
+ .entrySet()) {
+ ifTypesList.add(entry.getKey());
+ }
}
}
return false;
}
- if (false == elementProperty.asInteger().validate(value))
+ IntegerProperty intProperty = elementProperty.asInteger();
+ if (null == intProperty) {
+ return false;
+ }
+
+ if (false == intProperty.validate(value))
return false;
}
return false;
}
- if (false == elementProperty.asDouble().validate(value))
+ DoubleProperty dblProperty = elementProperty.asDouble();
+ if (null == dblProperty) {
+ return false;
+ }
+
+ if (false == dblProperty.validate(value))
return false;
}
return false;
}
- if (false == elementProperty.asBoolean().validate(value))
+ BooleanProperty boolProperty = elementProperty.asBoolean();
+ if (null == boolProperty) {
+ return false;
+ }
+
+ if (false == boolProperty.validate(value))
return false;
}
return false;
}
- if (false == elementProperty.asString().validate(value))
+ StringProperty stringProperty = elementProperty.asString();
+ if (null == stringProperty) {
+ return false;
+ }
+
+ if (false == stringProperty.validate(value))
return false;
}
}
for (SimulatorResourceModel value : values) {
- if (false == elementProperty.asModel().validate(value))
+ ModelProperty modelProperty = elementProperty.asModel();
+ if (null == modelProperty) {
+ return false;
+ }
+
+ if (false == modelProperty.validate(value))
return false;
}
* boolean type value.
*/
public AttributeValue(boolean value) {
- mValue = new Boolean(value);
+ mValue = Boolean.valueOf(value);
}
/**
*/
public SimulatorException(SimulatorResult code, String message) {
this.code = code;
- this.message = new String(message);
+ this.message = message;
}
/**
public static SimulatorResource createResource(SimulatorResource.Type type,
String name, String uri, String resourceType)
throws InvalidArgsException, SimulatorException {
- SimulatorResource resource = null;
+ SimulatorResource resource;
if (type == SimulatorResource.Type.SINGLE)
resource = nativeCreateSingleResource(name, uri, resourceType);
else
*/
public SimulatorResourceAttribute(String name, AttributeValue value,
AttributeProperty property) {
- mName = new String(name);
+ mName = name;
mValue = value;
mProperty = property;
}
* Value of the attribute.
*/
public SimulatorResourceAttribute(String name, AttributeValue value) {
- mName = new String(name);
+ mName = name;
mValue = value;
mProperty = null;
}
}
public static class Builder {
- private String mDefaultValue = new String();
+ private String mDefaultValue;
private int mMin;
private int mMax;
private String[] mValues;
- private boolean mHasRange = false;
+ private boolean mHasRange = false;
public void setDefaultValue(String value) {
if (null != value)
{\r
// Parse the RAML file\r
std::shared_ptr<RAML::RamlParser> ramlParser = std::make_shared<RAML::RamlParser>(configPath);\r
+ if (!ramlParser)\r
+ {\r
+ OIC_LOG(ERROR, TAG, "RAML parser returned NULL!");\r
+ return nullptr;\r
+ }\r
+\r
RAML::RamlPtr raml = ramlParser->getRamlPtr();\r
+ if (!raml)\r
+ {\r
+ OIC_LOG(ERROR, TAG, "RAML pointer is NULL!");\r
+ return nullptr;\r
+ }\r
\r
// Get the first resource model from RAML\r
RAML::RamlResourcePtr ramlResource;\r
\r
// Parse the RAML file\r
std::shared_ptr<RAML::RamlParser> ramlParser = std::make_shared<RAML::RamlParser>(configPath);\r
+ if (!ramlParser)\r
+ {\r
+ OIC_LOG(ERROR, TAG, "RAML parser returned NULL!");\r
+ return resources;\r
+ }\r
+\r
RAML::RamlPtr raml = ramlParser->getRamlPtr();\r
+ if (!raml)\r
+ {\r
+ OIC_LOG(ERROR, TAG, "RAML pointer is NULL!");\r
+ return resources;\r
+ }\r
\r
// Get the first resource model from RAML\r
RAML::RamlResourcePtr ramlResource;\r