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];