import { Cq } from "../references" ; import ServiceProxy from "./ServiceProxy" ; declare var Cqx ; /**
 * a container for sharing global services and other objects like the cache.
 * Also provides access to the Java API.
 *
 * TODO add cache as a separate field instead of another object in the container.
 */ export class Container { private services : any ; private cqx : Cq ; constructor ( cqx ) { this . services = { } ; if ( ! cqx ) { this . cqx = Cqx ; } else { this . cqx = cqx ; } } param name param service public register ( name , service ) { this . services [ name ] = service ; } param name returns { any } public get ( name ) { return this . services [ name ] ; } param name returns { ServiceProxy } public getOsgiService ( name ) { return this . getServiceProxy ( arguments , ( ) : any => { return this . cqx . getOsgiService ( name ) ; } ) ; } param name returns { ServiceProxy } public getRequestModel ( path , name ) { return this . getServiceProxy ( arguments , ( ) : any => { return this . cqx . getRequestModel ( path , name ) ; } ) ; } param name returns { ServiceProxy } public getResourceModel ( path , name ) { return this . getServiceProxy ( arguments , ( ) : any => { return this . cqx . getResourceModel ( path , name ) ; } ) ; } private getServiceProxy ( args , getter ) { return new ServiceProxy ( this . get ( "cache" ) , getter , this . createKey ( args ) ) ; } private createKey ( params ) { let key = "" ; for ( let i = 0 ; i < params . length ; i ++ ) { if ( i > 0 ) { key += "_" ; } key += params [ i ] ; } return key ; } }