File

src/models/resource/resource.ts

Description

Base class for Resource subclasses (Device, Component) that represents the actual server-side model (properties, etc.).

Extends

ResourceRef

Implements

ISerializable

Index

Properties
Methods

Constructor

constructor()

Methods

deserialize
deserialize(input: any)

Deserializes a JSON object into this class

Parameters :
Name Type Optional Description
input any
Returns : this
Public getPort
getPort(id: string)

Iterates over the 'ports' list to return the port maching the ID (name)

Parameters :
Name Type Optional Description
id string

The unique identifier of the port (i.e., its name).

Returns : port.Port

The Port model (or undefined if invalid)

Public property
property(id: string)

Iterates over the 'properties' list to return the property matching the ID

Parameters :
Name Type Optional Description
id string

The ID of the property to return

Returns : prop.Property

The Property model (or undefined if invalid).

Properties

Public ports
ports: port.Ports
Type : port.Ports

Port listing of the resource

Public properties
properties: prop.PropertySet
Type : prop.PropertySet

Property listing of the resource

Public started
started: boolean
Type : boolean

Indicates if the resource is started

import { ISerializable } from '../serialization/index';
import * as prop from '../property/index';
import * as port from '../port/index';

import { ResourceRef } from './resource-ref';

/**
 * Base class for Resource subclasses (Device, Component) that represents the
 * actual server-side model (properties, etc.).
 */
export class Resource extends ResourceRef implements ISerializable<Resource> {
    /** Indicates if the resource is started */
    public started: boolean;
    /** Property listing of the resource */
    public properties: prop.PropertySet;
    /** Port listing of the resource */
    public ports: port.Ports;

    /** Constructor */
    constructor() {
        super();
        this.properties = [];
        this.ports = [];
    }

    /**
     * Iterates over the 'properties' list to return the property matching the ID
     * @param id The ID of the property to return
     * @returns {prop.Property} The Property model (or undefined if invalid).
     */
    public property(id: string): prop.Property {
        for (let p of this.properties) {
            if (p.id === id) {
                return p;
            }
        }
        return undefined;
    }

    /**
     * Iterates over the 'ports' list to return the port maching the ID (name)
     * @param id The unique identifier of the port (i.e., its name).
     * @returns {port.Port} The Port model (or undefined if invalid)
     */
    public getPort(id: string): port.Port {
        for (let p of this.ports) {
            if (p.name === id) {
                return p;
            }
        }
        return undefined;
    }

    /** Deserializes a JSON object into this class */
    deserialize(input: any) {
        super.deserialize(input);
        this.started = input.started;
        this.ports = port.deserializePorts(input.ports);
        this.properties = prop.deserializeProperties(input.properties);
        return this;
    }
}

results matching ""

    No results matching ""