From 7c45f214ff1a3c478258bf0f9522aeb23dc65251 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 3 Aug 2017 03:52:58 +0900 Subject: [PATCH] ing --- src/ts/@loafer/context/ApplicationContext.ts | 18 +++++++++++++++-- .../context/ConfigurableApplicationContext.ts | 18 +++++++++++++++++ src/ts/@loafer/context/Lifecycle.ts | 7 +++++++ .../context/decorator/Configuration.ts | 2 +- src/ts/@loafer/context/decorator/Pouch.ts | 7 +++++-- src/ts/@loafer/core/annotation/Annotation.ts | 4 ++++ src/ts/@loafer/core/annotation/index.ts | 1 + src/ts/@loafer/core/decorator/Decorator.ts | 3 ++- .../core/env/ConfigurableEnvironment.ts | 11 ++++++++++ .../core/env/ConfigurablePropertyResolver.ts | 6 ++++++ src/ts/@loafer/core/env/Environment.ts | 9 +++++++++ src/ts/@loafer/core/env/EnvironmentCapable.ts | 7 +++++++ src/ts/@loafer/core/env/PropertyResolver.ts | 6 ++++++ src/ts/@loafer/pouches/decorator/Inject.ts | 5 ++++- .../@loafer/pouches/decorator/Injectable.ts | 5 ++++- .../pouches/decorator/PostConstruct.ts | 6 ++++-- .../@loafer/pouches/decorator/PreDestroy.ts | 6 ++++-- src/ts/@loafer/pouches/decorator/Scope.ts | 5 ++++- src/ts/@loafer/pouches/decorator/Value.ts | 7 +++++-- .../factory/HierarchicalPouchFactory.ts | 7 +++++++ .../pouches/factory/ListablePouchFactory.ts | 9 +++++++++ .../@loafer/pouches/factory/PouchFactory.ts | 18 ++++++++++++----- .../ConfigurableListablePouchFactory.ts | 0 .../config/InjectCapablePouchFactory.ts | 20 +++++++++++++++++++ 24 files changed, 167 insertions(+), 20 deletions(-) create mode 100644 src/ts/@loafer/context/ConfigurableApplicationContext.ts create mode 100644 src/ts/@loafer/context/Lifecycle.ts create mode 100644 src/ts/@loafer/core/annotation/Annotation.ts create mode 100644 src/ts/@loafer/core/annotation/index.ts create mode 100644 src/ts/@loafer/core/env/ConfigurableEnvironment.ts create mode 100644 src/ts/@loafer/core/env/ConfigurablePropertyResolver.ts create mode 100644 src/ts/@loafer/core/env/Environment.ts create mode 100644 src/ts/@loafer/core/env/EnvironmentCapable.ts create mode 100644 src/ts/@loafer/core/env/PropertyResolver.ts create mode 100644 src/ts/@loafer/pouches/factory/HierarchicalPouchFactory.ts create mode 100644 src/ts/@loafer/pouches/factory/ListablePouchFactory.ts create mode 100644 src/ts/@loafer/pouches/factory/config/ConfigurableListablePouchFactory.ts create mode 100644 src/ts/@loafer/pouches/factory/config/InjectCapablePouchFactory.ts diff --git a/src/ts/@loafer/context/ApplicationContext.ts b/src/ts/@loafer/context/ApplicationContext.ts index 925dbe5..d1bf503 100644 --- a/src/ts/@loafer/context/ApplicationContext.ts +++ b/src/ts/@loafer/context/ApplicationContext.ts @@ -1,8 +1,22 @@ +import { + PropertyType, +} from '@loafer/core/constants/types'; + +import EnvironmentCapable from '@loafer/core/env/EnvironmentCapable'; + import PouchFactory from '@loafer/pouches/factory/PouchFactory'; import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory'; +import ListablePouchFactory from '@loafer/pouches/factory/ListablePouchFactory'; +import HierarchicalPouchFactory from '@loafer/pouches/factory/HierarchicalPouchFactory'; +import InjectCapablePouchFactory from '@loafer/pouches/factory/config/InjectCapablePouchFactory'; -interface ApplicationContext extends PouchFactory { - getPouchFactory(): DefaultPouchFactory; +export interface ApplicationContext extends EnvironmentCapable, ListablePouchFactory, HierarchicalPouchFactory { + getId?(): PropertyType; + getApplicationName(): string; + getDisplayName(): string; + getParent?(): ApplicationContext; + + getInjectCapablePouchFactory(): InjectCapablePouchFactory; } export default ApplicationContext; diff --git a/src/ts/@loafer/context/ConfigurableApplicationContext.ts b/src/ts/@loafer/context/ConfigurableApplicationContext.ts new file mode 100644 index 0000000..d7b06e8 --- /dev/null +++ b/src/ts/@loafer/context/ConfigurableApplicationContext.ts @@ -0,0 +1,18 @@ +import { + PropertyType, +} from '@loafer/core/constants/types'; +import ConfigurableEnvironment from '@loafer/core/env/ConfigurableEnvironment'; +import ApplicationContext from '@loafer/context/ApplicationContext'; +import Lifecycle from '@loafer/context/Lifecycle'; + +export interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle { + setId(id: PropertyType): void; + setEnvironment(environment: ConfigurableEnvironment): void; + getEnvironment(): ConfigurableEnvironment; + addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor): void; + addApplicationListener(ApplicationListener< ? > listener ): void; + refresh(): void; + getBeanFactory(): ConfigurableListablePouchFactory; +} + +export default ConfigurableApplicationContext; diff --git a/src/ts/@loafer/context/Lifecycle.ts b/src/ts/@loafer/context/Lifecycle.ts new file mode 100644 index 0000000..6cceb49 --- /dev/null +++ b/src/ts/@loafer/context/Lifecycle.ts @@ -0,0 +1,7 @@ +export interface Lifecycle { + start(): void; + stop(): void; + isRunning(): boolean; +} + +export default Lifecycle; diff --git a/src/ts/@loafer/context/decorator/Configuration.ts b/src/ts/@loafer/context/decorator/Configuration.ts index a621278..d98dc45 100644 --- a/src/ts/@loafer/context/decorator/Configuration.ts +++ b/src/ts/@loafer/context/decorator/Configuration.ts @@ -5,7 +5,7 @@ import { import { Decorator, DecoratorHandler, - } from '@loafer/core/decorator'; +} from '@loafer/core/decorator'; import { Class, diff --git a/src/ts/@loafer/context/decorator/Pouch.ts b/src/ts/@loafer/context/decorator/Pouch.ts index e14a765..56a7c80 100644 --- a/src/ts/@loafer/context/decorator/Pouch.ts +++ b/src/ts/@loafer/context/decorator/Pouch.ts @@ -6,7 +6,9 @@ import { import { Decorator, DecoratorHandler, - } from '@loafer/core/decorator'; +} from '@loafer/core/decorator'; + +import Annotation from '@loafer/core/annotation/Annotation'; import { Class, @@ -17,10 +19,11 @@ export interface PouchConfig { type?: ClassType; } -export class PouchAnnotation implements DecoratorHandler { +export class PouchAnnotation extends Annotation implements DecoratorHandler { private readonly Qualifier: PropertyType; private readonly Type: ClassType; public constructor(config: PouchConfig = {}) { + super(); this.Qualifier = config.qualifier; this.Type = config.type; } diff --git a/src/ts/@loafer/core/annotation/Annotation.ts b/src/ts/@loafer/core/annotation/Annotation.ts new file mode 100644 index 0000000..80a7d03 --- /dev/null +++ b/src/ts/@loafer/core/annotation/Annotation.ts @@ -0,0 +1,4 @@ +export abstract class Annotation { +} + +export default Annotation; diff --git a/src/ts/@loafer/core/annotation/index.ts b/src/ts/@loafer/core/annotation/index.ts new file mode 100644 index 0000000..ac90322 --- /dev/null +++ b/src/ts/@loafer/core/annotation/index.ts @@ -0,0 +1 @@ +export * from './Annotation'; diff --git a/src/ts/@loafer/core/decorator/Decorator.ts b/src/ts/@loafer/core/decorator/Decorator.ts index e97ea06..475b9a5 100644 --- a/src/ts/@loafer/core/decorator/Decorator.ts +++ b/src/ts/@loafer/core/decorator/Decorator.ts @@ -5,10 +5,11 @@ import { import * as ReflectConstants from '@loafer/core/constants/reflect'; import Reflection from '@loafer/core/reflect/Reflection'; import Class from '@loafer/core/reflect/Class'; +import Annotation from '@loafer/core/annotation/Annotation'; import DecoratorType from './DecoratorType'; export class Decorator { - public static create = (Annotation: Construtorable) => { + public static create = (Annotation: Construtorable) => { return (...handlerArgs: any[]) => { let annotation = new Annotation(...handlerArgs); diff --git a/src/ts/@loafer/core/env/ConfigurableEnvironment.ts b/src/ts/@loafer/core/env/ConfigurableEnvironment.ts new file mode 100644 index 0000000..a64c171 --- /dev/null +++ b/src/ts/@loafer/core/env/ConfigurableEnvironment.ts @@ -0,0 +1,11 @@ +import Environment from '@loafer/core/env/Environment'; + +export interface ConfigurableEnvironment extends Environment { + setActiveProfiles(...profiles: string[]): void; + addActiveProfiles(profile: string): void; + setDefaultProfiles(...profiles: string[]): void; + getSystemEnvironment(): Map; + getSystemProperties(): Map; +} + +export default Environment; diff --git a/src/ts/@loafer/core/env/ConfigurablePropertyResolver.ts b/src/ts/@loafer/core/env/ConfigurablePropertyResolver.ts new file mode 100644 index 0000000..6bfdac5 --- /dev/null +++ b/src/ts/@loafer/core/env/ConfigurablePropertyResolver.ts @@ -0,0 +1,6 @@ +import PropertyResolver from '@loafer/core/env/PropertyResolver'; + +export interface ConfigurablePropertyResolver extends PropertyResolver { +} + +export default ConfigurablePropertyResolver; diff --git a/src/ts/@loafer/core/env/Environment.ts b/src/ts/@loafer/core/env/Environment.ts new file mode 100644 index 0000000..059286e --- /dev/null +++ b/src/ts/@loafer/core/env/Environment.ts @@ -0,0 +1,9 @@ +import PropertyResolver from '@loafer/core/env/PropertyResolver'; + +export interface Environment extends PropertyResolver { + getActiveProfiles(): string[]; + getDefaultProfiles(): string[]; + acceptsProfiles(...profiles: string[]): boolean; +} + +export default Environment; diff --git a/src/ts/@loafer/core/env/EnvironmentCapable.ts b/src/ts/@loafer/core/env/EnvironmentCapable.ts new file mode 100644 index 0000000..045f804 --- /dev/null +++ b/src/ts/@loafer/core/env/EnvironmentCapable.ts @@ -0,0 +1,7 @@ +import Environment from '@loafer/core/env/Environment'; + +export interface EnvironmentCapable { + getEnvironment(): Environment; +} + +export default EnvironmentCapable; diff --git a/src/ts/@loafer/core/env/PropertyResolver.ts b/src/ts/@loafer/core/env/PropertyResolver.ts new file mode 100644 index 0000000..1e468c5 --- /dev/null +++ b/src/ts/@loafer/core/env/PropertyResolver.ts @@ -0,0 +1,6 @@ +export interface PropertyResolver { + containsProperty(key: string): boolean; + getProperty(key: string, defaultValue?: string): string; +} + +export default PropertyResolver; diff --git a/src/ts/@loafer/pouches/decorator/Inject.ts b/src/ts/@loafer/pouches/decorator/Inject.ts index 7220265..c9f4441 100644 --- a/src/ts/@loafer/pouches/decorator/Inject.ts +++ b/src/ts/@loafer/pouches/decorator/Inject.ts @@ -8,6 +8,8 @@ import { DecoratorHandler, } from '@loafer/core/decorator'; +import Annotation from '@loafer/core/annotation/Annotation'; + import { Class, } from '@loafer/core/reflect'; @@ -18,12 +20,13 @@ export interface InjectConfig { type?: ClassType; } -export class InjectAnnotation implements DecoratorHandler { +export class InjectAnnotation extends Annotation implements DecoratorHandler { private readonly Qualifier: PropertyType; private readonly Required: boolean; private readonly Type: ClassType; public constructor(config: InjectConfig = {}) { + super(); this.Qualifier = config.qualifier; this.Required = config.required; this.Type = config.type; diff --git a/src/ts/@loafer/pouches/decorator/Injectable.ts b/src/ts/@loafer/pouches/decorator/Injectable.ts index 1d6c917..bd20245 100644 --- a/src/ts/@loafer/pouches/decorator/Injectable.ts +++ b/src/ts/@loafer/pouches/decorator/Injectable.ts @@ -7,14 +7,17 @@ import { DecoratorHandler, } from '@loafer/core/decorator'; +import Annotation from '@loafer/core/annotation/Annotation'; + import { Class, } from '@loafer/core/reflect'; -export class InjectableAnnotation implements DecoratorHandler { +export class InjectableAnnotation extends Annotation implements DecoratorHandler { private readonly Qualifier: PropertyType; public constructor(qualifier?: PropertyType) { + super(); this.Qualifier = qualifier; } public onClassDecorator = (clazz: Class, target: TFunction): TFunction | void => { diff --git a/src/ts/@loafer/pouches/decorator/PostConstruct.ts b/src/ts/@loafer/pouches/decorator/PostConstruct.ts index b9d4caf..3a25638 100644 --- a/src/ts/@loafer/pouches/decorator/PostConstruct.ts +++ b/src/ts/@loafer/pouches/decorator/PostConstruct.ts @@ -5,13 +5,15 @@ import { import { Decorator, DecoratorHandler, - } from '@loafer/core/decorator'; +} from '@loafer/core/decorator'; + +import Annotation from '@loafer/core/annotation/Annotation'; import { Class, } from '@loafer/core/reflect'; -export class PostConstructAnnotation implements DecoratorHandler { +export class PostConstructAnnotation extends Annotation implements DecoratorHandler { public onMethodDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void => { console.log('PostConstruct'); diff --git a/src/ts/@loafer/pouches/decorator/PreDestroy.ts b/src/ts/@loafer/pouches/decorator/PreDestroy.ts index 53aac7a..d3989c7 100644 --- a/src/ts/@loafer/pouches/decorator/PreDestroy.ts +++ b/src/ts/@loafer/pouches/decorator/PreDestroy.ts @@ -5,13 +5,15 @@ import { import { Decorator, DecoratorHandler, - } from '@loafer/core/decorator'; +} from '@loafer/core/decorator'; + +import Annotation from '@loafer/core/annotation/Annotation'; import { Class, } from '@loafer/core/reflect'; -export class PreDestroyAnnotation implements DecoratorHandler { +export class PreDestroyAnnotation extends Annotation implements DecoratorHandler { public onMethodDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void => { console.log('PreDestroy'); diff --git a/src/ts/@loafer/pouches/decorator/Scope.ts b/src/ts/@loafer/pouches/decorator/Scope.ts index ce3caa1..5cbfd3e 100644 --- a/src/ts/@loafer/pouches/decorator/Scope.ts +++ b/src/ts/@loafer/pouches/decorator/Scope.ts @@ -11,10 +11,13 @@ import { Class, } from '@loafer/core/reflect'; -export class ScopeAnnotation implements DecoratorHandler { +import Annotation from '@loafer/core/annotation/Annotation'; + +export class ScopeAnnotation extends Annotation implements DecoratorHandler { private readonly Qualifier: PropertyType; public constructor(qualifier?: PropertyType) { + super(); this.Qualifier = qualifier; } public onClassDecorator = (clazz: Class, target: TFunction): TFunction | void => { diff --git a/src/ts/@loafer/pouches/decorator/Value.ts b/src/ts/@loafer/pouches/decorator/Value.ts index 831d258..19f314c 100644 --- a/src/ts/@loafer/pouches/decorator/Value.ts +++ b/src/ts/@loafer/pouches/decorator/Value.ts @@ -6,16 +6,19 @@ import { import { Decorator, DecoratorHandler, - } from '@loafer/core/decorator'; +} from '@loafer/core/decorator'; + +import Annotation from '@loafer/core/annotation/Annotation'; import { Class, } from '@loafer/core/reflect'; -export class ValueAnnotation implements DecoratorHandler { +export class ValueAnnotation extends Annotation implements DecoratorHandler { private readonly Value: PropertyType; public constructor(value: PropertyType) { + super(); this.Value = value; } diff --git a/src/ts/@loafer/pouches/factory/HierarchicalPouchFactory.ts b/src/ts/@loafer/pouches/factory/HierarchicalPouchFactory.ts new file mode 100644 index 0000000..20d810c --- /dev/null +++ b/src/ts/@loafer/pouches/factory/HierarchicalPouchFactory.ts @@ -0,0 +1,7 @@ +import PouchFactory from '@loafer/pouches/factory/PouchFactory'; + +export interface HierarchicalPouchFactory extends PouchFactory { + getParentBeanFactory(): PouchFactory; +} + +export default HierarchicalPouchFactory; diff --git a/src/ts/@loafer/pouches/factory/ListablePouchFactory.ts b/src/ts/@loafer/pouches/factory/ListablePouchFactory.ts new file mode 100644 index 0000000..5e9b2f6 --- /dev/null +++ b/src/ts/@loafer/pouches/factory/ListablePouchFactory.ts @@ -0,0 +1,9 @@ +import PouchFactory from '@loafer/pouches/factory/PouchFactory'; + +export interface ListablePouchFactory extends PouchFactory { + containsPouchDefinition(pouchName: string): boolean; + getPouchDefinitionCount(): number; + getPouchDefinitionNames(): string[]; +} + +export default ListablePouchFactory; diff --git a/src/ts/@loafer/pouches/factory/PouchFactory.ts b/src/ts/@loafer/pouches/factory/PouchFactory.ts index a5a77ff..d6abbbf 100644 --- a/src/ts/@loafer/pouches/factory/PouchFactory.ts +++ b/src/ts/@loafer/pouches/factory/PouchFactory.ts @@ -3,22 +3,30 @@ import { PropertyType, } from '@loafer/core/constants/types'; +import { + Class, +} from '@loafer/core/reflect'; + interface PouchFactory { /** - * @param qualifier is identity of pouch - * @param clazz is type of pouch (if clazz is not specified, set the undefined) + * @param name is identity of pouch + * @param type is type of pouch (if type is not specified, set the undefined) * @param args are argument of target constructor * @returns an instance of pouch */ - getPouch(qualifier: PropertyType, clazz: ClassType, ...args: any[]): any; + getPouch(name: PropertyType, type: ClassType, ...args: any[]): any; /** - * @param clazz is type of pouch + * @param type is type of pouch * @param qualifier is identity of pouch (if qualifier is not specified, set the undefined) * @param args are argument of target constructor * @returns an instance of pouch */ - getPouchByClass(clazz: ClassType, qualifier: PropertyType, ...args: any[]): any; + getPouchByType(type: ClassType, ...args: any[]): any; + containsPouch(name: string): boolean; + isSingleton(name: string): boolean; + isTransient(name: string): boolean; + getClass(name: string): Class; } export default PouchFactory; diff --git a/src/ts/@loafer/pouches/factory/config/ConfigurableListablePouchFactory.ts b/src/ts/@loafer/pouches/factory/config/ConfigurableListablePouchFactory.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/ts/@loafer/pouches/factory/config/InjectCapablePouchFactory.ts b/src/ts/@loafer/pouches/factory/config/InjectCapablePouchFactory.ts new file mode 100644 index 0000000..f9e9e34 --- /dev/null +++ b/src/ts/@loafer/pouches/factory/config/InjectCapablePouchFactory.ts @@ -0,0 +1,20 @@ +import { + ClassType, + PropertyType, +} from '@loafer/core/constants/types'; +import PouchFactory from '@loafer/pouches/factory/PouchFactory'; + +export interface InjectCapablePouchFactory extends PouchFactory { + createPouch(type: ClassType, injectMode?: number, dependencyCheck?: boolean): any; + injectPouch(existingPouch: any): void; + configureBean(existingBean: any, pouchName: PropertyType): any; + inject(type: ClassType, injectMode: number, dependencyCheck: boolean): any; + injectPouchProperties(existingPouch: any, injectMode: number, dependencyCheck: boolean): void; + applyPouchPropertyValues(existingPouch: any, pouchName: PropertyType): void; + initializePouch?(existingPouch: any, pouchName: PropertyType): any; + applyPouchPostProcessorsBeforeInitialization?(existingPouch: any, pouchName: PropertyType): any; + applyPouchPostProcessorsAfterInitialization?(existingPouch: any, pouchName: PropertyType): any; + destroyPouch(existingPouch: any): void; +} + +export default InjectCapablePouchFactory;