Skip to content

Commit

Permalink
Added XML support for resource properties
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 14, 2017
1 parent 0aea380 commit c4f206e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/resource/IResource.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { FSManager, FSPath } from '../manager/FSManager';
import { XMLElement } from '../helper/XML';
import { LockKind } from './lock/LockKind';
import { Lock } from './lock/Lock';
export declare type SimpleCallback = (error: Error) => void;
export declare type ReturnCallback<T> = (error: Error, data: T) => void;
export declare type Return2Callback<T, Q> = (error: Error, x: T, y: Q) => void;
export declare type ResourcePropertyValue = string | XMLElement | XMLElement[];
export declare class ResourceType {
isFile: boolean;
isDirectory: boolean;
Expand Down Expand Up @@ -39,8 +41,8 @@ export interface IResource {
addChild(resource: IResource, callback: SimpleCallback): any;
removeChild(resource: IResource, callback: SimpleCallback): any;
getChildren(callback: ReturnCallback<IResource[]>): any;
setProperty(name: string, value: string, callback: SimpleCallback): any;
getProperty(name: string, callback: ReturnCallback<string>): any;
setProperty(name: string, value: ResourcePropertyValue, callback: SimpleCallback): any;
getProperty(name: string, callback: ReturnCallback<ResourcePropertyValue>): any;
removeProperty(name: string, callback: SimpleCallback): any;
getProperties(callback: ReturnCallback<object>): any;
creationDate(callback: ReturnCallback<number>): any;
Expand Down
6 changes: 3 additions & 3 deletions lib/resource/std/StandardResource.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IResource, ReturnCallback, SimpleCallback, Return2Callback, ResourceType } from '../IResource';
import { IResource, ReturnCallback, SimpleCallback, Return2Callback, ResourceType, ResourcePropertyValue } from '../IResource';
import { FSManager, FSPath } from '../../manager/FSManager';
import { LockKind } from '../lock/LockKind';
import { LockBag } from '../lock/LockBag';
Expand All @@ -20,8 +20,8 @@ export declare abstract class StandardResource implements IResource {
removeLock(uuid: string, owner: string, callback: ReturnCallback<boolean>): void;
canRemoveLock(uuid: string, owner: string, callback: ReturnCallback<boolean>): void;
canLock(lockKind: LockKind, callback: ReturnCallback<boolean>): void;
setProperty(name: string, value: string, callback: SimpleCallback): void;
getProperty(name: string, callback: ReturnCallback<string>): void;
setProperty(name: string, value: ResourcePropertyValue, callback: SimpleCallback): void;
getProperty(name: string, callback: ReturnCallback<ResourcePropertyValue>): void;
removeProperty(name: string, callback: SimpleCallback): void;
getProperties(callback: ReturnCallback<object>): void;
abstract create(callback: SimpleCallback): any;
Expand Down
7 changes: 5 additions & 2 deletions src/resource/IResource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FSManager, FSPath } from '../manager/FSManager'
import { XMLElement } from '../helper/XML'
import { LockKind } from './lock/LockKind'
import { Lock } from './lock/Lock'
import * as crypto from 'crypto'
Expand All @@ -7,6 +8,8 @@ export type SimpleCallback = (error : Error) => void
export type ReturnCallback<T> = (error : Error, data : T) => void
export type Return2Callback<T, Q> = (error : Error, x : T, y : Q) => void

export type ResourcePropertyValue = string | XMLElement | XMLElement[]

export class ResourceType
{
static File = new ResourceType(true, false)
Expand Down Expand Up @@ -63,8 +66,8 @@ export interface IResource
getChildren(callback : ReturnCallback<IResource[]>)

// ****************************** Properties ****************************** //
setProperty(name : string, value : string, callback : SimpleCallback)
getProperty(name : string, callback : ReturnCallback<string>)
setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback)
getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>)
removeProperty(name : string, callback : SimpleCallback)
getProperties(callback : ReturnCallback<object>)

Expand Down
6 changes: 3 additions & 3 deletions src/resource/std/StandardResource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IResource, ReturnCallback, SimpleCallback, Return2Callback, ResourceType } from '../IResource'
import { IResource, ReturnCallback, SimpleCallback, Return2Callback, ResourceType, ResourcePropertyValue } from '../IResource'
import { FSManager, FSPath } from '../../manager/FSManager'
import { LockScope } from '../lock/LockScope'
import { LockType } from '../lock/LockType'
Expand Down Expand Up @@ -123,13 +123,13 @@ export abstract class StandardResource implements IResource
}

// ****************************** Properties ****************************** //
setProperty(name : string, value : string, callback : SimpleCallback)
setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback)
{
this.properties[name] = value;
this.updateLastModified();
callback(null);
}
getProperty(name : string, callback : ReturnCallback<string>)
getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>)
{
const value = this.properties[name];
if(value === undefined)
Expand Down

0 comments on commit c4f206e

Please sign in to comment.