This commit is contained in:
crusader 2017-08-07 16:22:48 +09:00
parent 04fa16b60d
commit 05f949fd3a
113 changed files with 65 additions and 2533 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.DS_Store
.idea/
node_modules/
dist/
@ -6,4 +7,4 @@ dist/
.idea
yarn.lock
.yarnclean
npm-debug.log
npm-debug.log

View File

@ -1,31 +0,0 @@
import AnnotationConfigApplicationContext from '@loafer/context/annotation/AnnotationConfigApplicationContext';
import ApplicationStater from '@loafer/application/ApplicationStater';
class Application {
// private appContext: AppContext;
private appClass: Class<any>;
// private appInstance: ApplicationStater;
public constructor(clazz: Class<any>) {
this.appClass = clazz;
}
public run(): void {
let context: AnnotationConfigApplicationContext = new AnnotationConfigApplicationContext();
context.register(AppConfig.prototype);
context.refresh();
context.getPouch('entitlement');
}
public static run(clazz: Class<any>): void {
new Application(clazz).run();
}
}
export class AppConfig {
}
export default Application;

View File

@ -1,5 +0,0 @@
export interface ApplicationStater {
run(): void;
}
export default ApplicationStater;

View File

@ -1,21 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import {
ConfigurationAnnotation,
} from '@loafer/context/decorator/Configuration';
export class ApplicationConfigurationAnnotation extends ConfigurationAnnotation {
public constructor(qualifier?: QualifierName) {
super(qualifier);
}
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
console.log('ApplicationConfiguration');
}
}
export const ApplicationConfiguration = Decorator.create(ApplicationConfigurationAnnotation);
export default ApplicationConfiguration;

View File

@ -1,18 +0,0 @@
// 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';
// export interface ApplicationContext extends EnvironmentCapable, ListablePouchFactory, HierarchicalPouchFactory {
// getId?(): Identity<T>;
// getApplicationName(): string;
// getDisplayName(): string;
// getParent?(): ApplicationContext;
// getInjectCapablePouchFactory(): InjectCapablePouchFactory;
// }
// export default ApplicationContext;

View File

@ -1,11 +0,0 @@
// import {
// Identity<T>,
// } 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 {
// }
// export default ConfigurableApplicationContext;

View File

@ -1,7 +0,0 @@
export interface Lifecycle {
start(): void;
stop(): void;
isRunning(): boolean;
}
export default Lifecycle;

View File

@ -1,110 +0,0 @@
import {
Assert,
} from '@loafer/core/util';
import {
Annotation,
} from '@loafer/core/annotation';
import {
PouchDefinitionRegistry,
} from '@loafer/pouches/factory/support';
import {
AnnotatedGenericPouchDefinition,
} from '@loafer/pouches/factory/annotation';
import GenericApplicationContext from '@loafer/context/support/GenericApplicationContext';
export class AnnotatedPouchDefinitionReader {
private readonly registry: PouchDefinitionRegistry;
private pouchNameGenerator: PouchNameGenerator = new AnnotationPouchNameGenerator();
private scopeMetadataResolver: ScopeMetadataResolver = new AnnotationScopeMetadataResolver();
private conditionEvaluator: ConditionEvaluator;
public constructor(registry: PouchDefinitionRegistry, environment?: Environment) {
if (undefined === environment) {
environment = this.getOrCreateEnvironment(registry);
}
Assert.notNull(registry, 'PouchDefinitionRegistry must not be null');
Assert.notNull(environment, 'Environment must not be null');
this.registry = registry;
this.conditionEvaluator = new ConditionEvaluator(registry, environment, null);
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
}
/**
* Register one or more annotated classes to be processed.
* <p>Calls to {@code register} are idempotent; adding the same
* annotated class more than once has no additional effect.
* @param annotatedClasses one or more annotated classes,
* e.g. {@link Configuration @Configuration} classes
*/
public register(...annotatedClasses: Class<any>[]): void {
annotatedClasses.forEach(annotatedClass => {
this.registerPouch(annotatedClass);
});
}
/**
* Register a pouch from the given pouch class, deriving its metadata from
* class-declared annotations.
* @param annotatedClass the class of the pouch
*/
public registerPouch(annotatedClass: Class<any>): void {
this.doRegisterPouch(annotatedClass, null, null, null);
}
/**
* Register a pouch from the given pouch class, deriving its metadata from
* class-declared annotations.
* @param annotatedClass the class of the pouch
* @param instanceSupplier a callback for creating an instance of the pouch
* (may be {@code null})
* @param name an explicit name for the pouch
* @param qualifiers specific qualifier annotations to consider, if any,
* in addition to qualifiers at the pouch class level
* @param definitionCustomizers one or more callbacks for customizing the
* factory's {@link PouchDefinition}, e.g. setting a lazy-init or primary flag
* @since 5.0
*/
public doRegisterPouch<T>(annotatedClass: Class<T>, instanceSupplier: Supplier<T>, name: PouchName,
qualifiers: Class<Annotation>[], ...definitionCustomizers: PouchDefinitionCustomizer[]): void {
let abd: AnnotatedGenericPouchDefinition = new AnnotatedGenericPouchDefinition(annotatedClass);
if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
return;
}
abd.setInstanceSupplier(instanceSupplier);
let scopeMetadata: ScopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
abd.setScope(scopeMetadata.getScopeName());
let pouchName: PouchName = (name != null ? name : this.pouchNameGenerator.generatePouchName(abd, this.registry));
AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
if (qualifiers != null) {
qualifiers.forEach((qualifier, index) => {
if (Primary.class === qualifier) {
abd.setPrimary(true);
}
else if (Lazy.class === qualifier) {
abd.setLazyInit(true);
}
else {
abd.addQualifier(new AutowireCandidateQualifier(qualifier));
}
});
}
definitionCustomizers.forEach((customizer) => {
customizer.customize(abd);
});
let definitionHolder: PouchDefinitionHolder = new PouchDefinitionHolder(abd, pouchName);
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
PouchDefinitionReaderUtils.registerPouchDefinition(definitionHolder, this.registry);
}
}
export default AnnotatedPouchDefinitionReader;

View File

@ -1,17 +0,0 @@
import {
Assert,
} from '@loafer/core/util';
import GenericApplicationContext from '@loafer/context/support/GenericApplicationContext';
import AnnotatedPouchDefinitionReader from '@loafer/context/annotation/AnnotatedPouchDefinitionReader';
export class AnnotationConfigApplicationContext extends GenericApplicationContext {
private readonly reader: AnnotatedPouchDefinitionReader;
public register(...annotatedClasses: Class<any>[]): void {
Assert.notEmpty(annotatedClasses, 'At least one annotated class must be specified');
this.reader.register(annotatedClasses);
}
}
export default AnnotationConfigApplicationContext;

View File

@ -1,21 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import {
InjectableAnnotation,
} from '@loafer/pouches/decorator/Injectable';
export class ConfigurationAnnotation extends InjectableAnnotation {
public constructor(qualifier?: QualifierName) {
super(qualifier);
}
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
console.log('Configuration');
}
}
export const Configuration = Decorator.create(ConfigurationAnnotation);
export default Configuration;

View File

@ -1,29 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export interface PouchConfig {
qualifier?: QualifierName;
type?: Class<any>;
}
export class PouchAnnotation extends Annotation {
private readonly Qualifier: QualifierName;
private readonly Type: Class<any>;
public constructor(config: PouchConfig = {}) {
super();
this.Qualifier = config.qualifier;
this.Type = config.type;
}
public onMethodDecorator = <T>(target: Object, propertyKey: Identity<T>,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
console.log('Pouch');
}
}
export const Pouch = Decorator.create(PouchAnnotation);
export default Pouch;

View File

@ -1,5 +0,0 @@
export abstract class AbstractApplicationContext {
}
export default AbstractApplicationContext;

View File

@ -1,10 +0,0 @@
import AbstractApplicationContext from '@loafer/context/support/AbstractApplicationContext';
import PouchDefinitionRegistry from '@loafer/pouches/factory/support/PouchDefinitionRegistry';
export class GenericApplicationContext extends AbstractApplicationContext implements PouchDefinitionRegistry {
}
export default GenericApplicationContext;

View File

@ -1,8 +0,0 @@
export interface AliasRegistry {
registerAlias(name: PouchName, alias: PouchName): void;
removeAlias(alias: PouchName): void;
isAlias(name: PouchName): boolean;
getAliases(name: PouchName): PouchName[];
}
export default AliasRegistry;

View File

@ -1,5 +0,0 @@
export interface AttributeAccessor {
}
export default AttributeAccessor;

View File

@ -1,8 +0,0 @@
import {
AttributeAccessor,
} from '@loafer/core';
export abstract class AttributeAccessorSupport implements AttributeAccessor {
}
export default AttributeAccessorSupport;

View File

@ -1,10 +0,0 @@
import Executable from '@loafer/core/reflect/Executable';
import Parameter from '@loafer/core/reflect/Parameter';
import Method from '@loafer/core/reflect/Method';
import Constructor from '@loafer/core/reflect/Constructor';
import Annotation from '@loafer/core/annotation/Annotation';
export class MethodParameter {
}
export default MethodParameter;

View File

@ -1,11 +0,0 @@
import {
RuntimeException,
} from '@loafer/core/lang';
export class NestedRuntimeException extends RuntimeException {
public constructor(message?: string) {
super(message);
}
}
export default NestedRuntimeException;

View File

@ -1,7 +0,0 @@
import AliasRegistry from '@loafer/core/AliasRegistry';
export class SimpleAliasRegistry implements AliasRegistry {
}
export default SimpleAliasRegistry;

View File

@ -1,13 +0,0 @@
export interface Annotation {
onClassDecorator?: <TFunction extends Function>(target: TFunction) => TFunction | void;
onPropertyDecorator?: (target: Object, propertyKey: PropertyName) => void;
onMethodDecorator?: <T>(target: Object, propertyKey: PropertyName,
descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
onParameterDecorator?: (target: Object, propertyKey: PropertyName, parameterIndex: number) => void;
}
export abstract class Annotation {
}
export default Annotation;

View File

@ -1 +0,0 @@
export * from './Annotation';

View File

@ -1,6 +0,0 @@
export enum DecoratorType {
CLASS,
PROPERTY,
PARAMETER,
METHOD,
}

View File

@ -1,9 +0,0 @@
// used to access design time types
export const DESIGN_TYPE = 'design:type';
// used to access design time parameter types
export const DESIGN_PARAMTYPES = 'design:paramtypes';
// used to access design time return type
export const DESIGN_RETURNTYPE = 'design:returntype';
// used to access design time return type
export const REFLECT_META = 'loafer:reflectmeta';

View File

@ -1,88 +0,0 @@
import * as ReflectConstants from '@loafer/core/constants/reflect';
import Reflection from '@loafer/core/reflect/Reflection';
import Clazz from '@loafer/core/reflect/Clazz';
import Annotation from '@loafer/core/annotation/Annotation';
import DecoratorType from './DecoratorType';
export class Decorator {
public static create = (AnnotationType: Class<Annotation>) => {
return (...handlerArgs: any[]) => {
let annotation: Annotation = new AnnotationType(...handlerArgs);
return (...decoratorArgs: any[]) => {
let decoratorType: DecoratorType = Decorator._detectDecoratorType(name, annotation, decoratorArgs);
let type = typeof decoratorArgs[0] === 'function' ? decoratorArgs[0].prototype : decoratorArgs[0];
let reflection: Reflection = Reflect.getMetadata(ReflectConstants.REFLECT_META, type);
if (undefined === reflection) {
reflection = new Reflection(type);
Reflect.defineMetadata(ReflectConstants.REFLECT_META, reflection, type);
}
let clazz: Clazz = reflection.getClass();
switch(decoratorType) {
case DecoratorType.CLASS:
reflection.addClassAnnotation(annotation);
return annotation.onClassDecorator.call(annotation, clazz, decoratorArgs[0]);
case DecoratorType.PROPERTY:
reflection.addPropertyAnnotation(annotation, decoratorArgs[1]);
return annotation.onPropertyDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1]);
case DecoratorType.METHOD:
reflection.addMethodAnnotation(annotation, decoratorArgs[1]);
return annotation.onMethodDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
case DecoratorType.PARAMETER:
reflection.addParameterAnnotation(annotation, decoratorArgs[1], decoratorArgs[2]);
return annotation.onParameterDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
default:
}
};
};
}
public static get = (targetType: Class<any>) => {
let reflection: Reflection = Reflect.getMetadata(ReflectConstants.REFLECT_META, targetType);
if (undefined === reflection) {
return undefined;
}
return reflection.getClass();
}
private static _detectDecoratorType(name: string, annotation: any, args: any[]): DecoratorType {
let params = [];
for (let i = 0; i < args.length; i++) {
if (args[i]) {
params.push(args[i]);
}
}
const paramCount = params.length;
let decoratorType: DecoratorType;
if (1 === paramCount) {
if ('onClassDecorator' in annotation) {
throw new Error(`Cannot apply @${name} decorator on Class.`);
}
decoratorType = DecoratorType.CLASS;
} else if (2 === paramCount) {
if ('onPropertyDecorator' in annotation) {
throw new Error(`Cannot apply @${name} decorator on Property.`);
}
decoratorType = DecoratorType.PROPERTY;
} else if (3 === paramCount) {
if(typeof args[2] === 'number') {
if ('onParameterDecorator' in annotation) {
throw new Error(`Cannot apply @${name} decorator on Parameter.`);
}
decoratorType = DecoratorType.PARAMETER;
} else {
if ('onMethodDecorator' in annotation) {
throw new Error(`Cannot apply @${name} decorator on Method.`);
}
decoratorType = DecoratorType.METHOD;
}
} else {
throw new Error(`@${name} decorator is not valid here!`);
}
return decoratorType;
}
}

View File

@ -1,8 +0,0 @@
export enum DecoratorType {
CLASS = 'Clazz',
PROPERTY = 'Property',
METHOD = 'Method',
PARAMETER = 'Parameter',
}
export default DecoratorType;

View File

@ -1,2 +0,0 @@
export * from './Decorator';
export * from './DecoratorType';

View File

@ -1,6 +0,0 @@
import Environment from '@loafer/core/env/Environment';
export interface ConfigurableEnvironment extends Environment {
}
export default Environment;

View File

@ -1,6 +0,0 @@
import PropertyResolver from '@loafer/core/env/PropertyResolver';
export interface ConfigurablePropertyResolver extends PropertyResolver {
}
export default ConfigurablePropertyResolver;

View File

@ -1,6 +0,0 @@
import PropertyResolver from '@loafer/core/env/PropertyResolver';
export interface Environment extends PropertyResolver {
}
export default Environment;

View File

@ -1,6 +0,0 @@
import Environment from '@loafer/core/env/Environment';
export interface EnvironmentCapable {
}
export default EnvironmentCapable;

View File

@ -1,4 +0,0 @@
export interface PropertyResolver {
}
export default PropertyResolver;

View File

@ -1,6 +0,0 @@
export * from './AliasRegistry';
export * from './AttributeAccessor';
export * from './AttributeAccessorSupport';
export * from './NestedRuntimeException';
export * from './SimpleAliasRegistry';

View File

@ -1,11 +0,0 @@
import {
RuntimeException,
} from '@loafer/core/lang';
export class IllegalArgumentException extends RuntimeException {
public constructor(message?: string) {
super(message);
}
}
export default IllegalArgumentException;

View File

@ -1,11 +0,0 @@
import {
RuntimeException,
} from '@loafer/core/lang';
export class IllegalStateException extends RuntimeException {
public constructor(message?: string) {
super(message);
}
}
export default IllegalStateException;

View File

@ -1,7 +0,0 @@
export class RuntimeException extends Error {
public constructor(message?: string) {
super(message);
}
}
export default RuntimeException;

View File

@ -1,3 +0,0 @@
export * from './IllegalArgumentException';
export * from './IllegalStateException';
export * from './RuntimeException';

View File

@ -1,29 +0,0 @@
export abstract class AnnotatedElement {
private _annotationMap: Map<Class<any>, any>;
protected constructor() {
this._annotationMap = new Map();
}
public getDeclaredAnnotation(type: Class<any>): any {
return this._annotationMap.get(type);
}
public getDeclaredAnnotations(): IterableIterator<any> {
return this._annotationMap.values();
}
public addAnnotation(annotation: any): void {
const type: Class<any> = Object.getPrototypeOf(annotation);
this._annotationMap.set(type, annotation);
}
public hasAnnotation(type: Class<any>): boolean {
return this._annotationMap.has(type);
}
// public abstract getAnnotation(type: Class<any>): any;
// public abstract getAnnotations(): IterableIterator<any>;
}
export default AnnotatedElement;

View File

@ -1,70 +0,0 @@
import AnnotatedElement from './AnnotatedElement';
import Constructor from './Constructor';
import Property from './Property';
import Method from './Method';
export class Clazz extends AnnotatedElement {
private _type: Class<any>;
private _name: PropertyName;
private _constructor: Constructor;
private _properties: Map<PropertyName, Property>;
private _methodes: Map<PropertyName, Method>;
public constructor(type: Class<any>, parameterTypes: Class<any>[]) {
super();
this._type = type;
this._name = this._type.constructor.name;
this._constructor = new Constructor(parameterTypes);
this._properties = new Map();
this._methodes = new Map();
}
public get Type(): Class<any> {
return this._type;
}
public get Name(): PropertyName {
return this._name;
}
public get Constructor(): Constructor {
return this._constructor;
}
public addProperty(propertyKey: PropertyName, type: Class<any>): Property {
if (this._properties.has(propertyKey)) {
throw new Error(`Property[${propertyKey}:${type.constructor.name}] on Clazz[${this._name}] is exist already`);
}
let proerty = new Property(type, propertyKey);
this._properties.set(propertyKey, proerty);
return proerty;
}
public getProperty(propertyKey: PropertyName): Property {
return this._properties.get(propertyKey);
}
public hasProperty(propertyKey: PropertyName): boolean {
return this._properties.has(propertyKey);
}
public addMethod(propertyKey: PropertyName, parameterTypes: Class<any>[], returnType: Class<any>): Method {
if (this._methodes.has(propertyKey)) {
throw new Error(`Method[${propertyKey}:${returnType.constructor.name}] on Clazz[${this._name}] is exist already`);
}
let method = new Method(propertyKey, parameterTypes, returnType);
this._methodes.set(propertyKey, method);
return method;
}
public getMethod(propertyKey: PropertyName): Method {
return this._methodes.get(propertyKey);
}
public hasMethod(propertyKey: PropertyName): boolean {
return this._methodes.has(propertyKey);
}
}
export default Clazz;

View File

@ -1,10 +0,0 @@
import Executable from '@loafer/core/reflect/Executable';
export class Constructor extends Executable {
public constructor(parameterTypes: Class<any>[]) {
super(parameterTypes);
}
}
export default Constructor;

View File

@ -1,26 +0,0 @@
import AnnotatedElement from './AnnotatedElement';
import Parameter from '@loafer/core/reflect/Parameter';
export abstract class Executable extends AnnotatedElement {
protected _parameters: Parameter[];
public constructor(parameterTypes: Class<any>[]) {
super();
this._parameters = [];
parameterTypes.forEach((currentValue, index, array) => {
this._parameters.push(new Parameter(currentValue, index));
});
}
public get Parameters(): Parameter[] {
return this._parameters;
}
public getParameter(index: number): Parameter {
return this._parameters[index];
}
}
export default Executable;

View File

@ -1,27 +0,0 @@
import Executable from '@loafer/core/reflect/Executable';
export class Method extends Executable {
private _name: PropertyName;
private _returnType: Class<any>;
public constructor(name: PropertyName, parameterTypes: Class<any>[], returnType: Class<any>) {
super(parameterTypes);
this._name = name;
this._returnType = returnType;
}
public get Name(): PropertyName {
return this._name;
}
public get ReturnType(): Class<any> {
return this._returnType;
}
public set ReturnType(returnType: Class<any>) {
this._returnType = returnType;
}
}
export default Method;

View File

@ -1,25 +0,0 @@
import AnnotatedElement from './AnnotatedElement';
import Constructor from './Constructor';
export class Parameter extends AnnotatedElement {
private _type: Class<any>;
private _index: number;
public constructor(type: Class<any>, index: number) {
super();
this._type = type;
this._index = index;
}
public get Type(): Class<any> {
return this._type;
}
public get Index(): number {
return this._index;
}
}
export default Parameter;

View File

@ -1,24 +0,0 @@
import AnnotatedElement from './AnnotatedElement';
import Constructor from './Constructor';
export class Property extends AnnotatedElement {
private _type: Class<any>;
private _name: PropertyName;
public constructor(type: Class<any>, name: PropertyName) {
super();
this._type = type;
this._name = name;
}
public get Name(): PropertyName {
return this._name;
}
public get Type(): Class<any> {
return this._type;
}
}
export default Property;

View File

@ -1,101 +0,0 @@
import * as ReflectConstants from '@loafer/core/constants/reflect';
import AnnotatedElement from './AnnotatedElement';
import Clazz from './Clazz';
export class Reflection {
private _clazz: Clazz;
public constructor(type: Class<any>) {
let parameterTypes: any[] = Reflect.getMetadata(ReflectConstants.DESIGN_PARAMTYPES, type.constructor);
this._clazz = new Clazz(type, this.convertParamTypes(parameterTypes));
}
/**
* getClass
*/
public getClass(): Clazz {
return this._clazz;
}
public addClassAnnotation(annotation: any): void {
let parameterTypes: any[] = Reflect.getMetadata(ReflectConstants.DESIGN_PARAMTYPES, this._clazz.Type);
const {valid, name} = this.validateAnnotation(annotation, this._clazz);
if (!valid) {
throw new Error(`Cannot apply @${name} decorator multiple times on Class[${this._clazz.Name}].`);
}
this._clazz.addAnnotation(annotation);
}
public addPropertyAnnotation(annotation: any, propertyKey: PropertyName): void {
let propertyType: any = Reflect.getMetadata(ReflectConstants.DESIGN_TYPE, this._clazz.Type, propertyKey);
let property = this._clazz.getProperty(propertyKey);
if (undefined === property) {
property = this._clazz.addProperty(propertyKey, propertyType.prototype);
}
const {valid, name} = this.validateAnnotation(annotation, property);
if (!valid) {
throw new Error(`Cannot apply @${name} decorator multiple times on Property[${this._clazz.Name}:${propertyKey}].`);
}
property.addAnnotation(annotation);
}
public addMethodAnnotation(annotation: any, propertyKey: PropertyName): void {
let parameterTypes: any[] = Reflect.getMetadata(ReflectConstants.DESIGN_PARAMTYPES, this._clazz.Type, propertyKey);
let returnType: any = Reflect.getMetadata(ReflectConstants.DESIGN_RETURNTYPE, this._clazz.Type, propertyKey);
let method = this._clazz.getMethod(propertyKey);
if (undefined === method) {
method = this._clazz.addMethod(propertyKey, this.convertParamTypes(parameterTypes), returnType.prototype);
}
const {valid, name} = this.validateAnnotation(annotation, method);
if (!valid) {
throw new Error(`Cannot apply @${name} decorator multiple times on Method[${this._clazz.Name}:${propertyKey}].`);
}
method.addAnnotation(annotation);
}
public addParameterAnnotation(annotation: any, propertyKey: PropertyName, parameterIndex: number): void {
let parameterTypes: any[] = Reflect.getMetadata(ReflectConstants.DESIGN_PARAMTYPES, this._clazz.Type, propertyKey);
let returnType: any = Reflect.getMetadata(ReflectConstants.DESIGN_RETURNTYPE, this._clazz.Type, propertyKey);
let method = this._clazz.getMethod(propertyKey);
if (undefined === method) {
method = this._clazz.addMethod(propertyKey, this.convertParamTypes(parameterTypes), returnType.prototype);
}
let parameter = method.getParameter(parameterIndex);
const {valid, name} = this.validateAnnotation(annotation, parameter);
if (!valid) {
throw new Error(`Cannot apply @${name} decorator multiple times on Parameter[${this._clazz.Name}:${propertyKey}(${parameterIndex}})].`);
}
parameter.addAnnotation(annotation);
}
private validateAnnotation(annotation: any, element: AnnotatedElement): {valid: boolean, name: string} {
const annotationType: Class<any> = Object.getPrototypeOf(annotation);
const name: string = annotationType.constructor.name;
if (element.hasAnnotation(annotationType)) {
return {valid: false, name: name};
}
return {valid: true, name: name};
}
private convertParamTypes(parameterTypes: any[]): Class<any>[] {
let returnTypes: Class<any>[] = [];
parameterTypes.forEach((currentValue, index, array) => {
returnTypes.push(currentValue.prototype);
});
return returnTypes;
}
}
export default Reflection;

View File

@ -1,8 +0,0 @@
export * from './AnnotatedElement';
export * from './Clazz';
export * from './Constructor';
export * from './Executable';
export * from './Method';
export * from './Parameter';
export * from './Property';
export * from './Reflection';

View File

@ -1,4 +0,0 @@
export interface AnnotatedTypeMetadata {
}
export default AnnotatedTypeMetadata;

View File

@ -1,9 +0,0 @@
import {
AnnotatedTypeMetadata,
ClassMetadata,
} from '@loafer/core/type';
export interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata {
}
export default AnnotationMetadata;

View File

@ -1,4 +0,0 @@
export interface ClassMetadata {
}
export default ClassMetadata;

View File

@ -1,25 +0,0 @@
import {
AnnotationMetadata,
StandardClassMetadata,
} from '@loafer/core/type';
export class StandardAnnotationMetadata extends StandardClassMetadata implements AnnotationMetadata {
/**
* Create a new {@link StandardAnnotationMetadata} wrapper for the given Class,
* providing the option to return any nested annotations or annotation arrays in the
* form of {@link org.springframework.core.annotation.AnnotationAttributes} instead
* of actual {@link Annotation} instances.
* @param introspectedClass the Class to introspect
* @param nestedAnnotationsAsMap return nested annotations and annotation arrays as
* {@link org.springframework.core.annotation.AnnotationAttributes} for compatibility
* with ASM-based {@link AnnotationMetadata} implementations
* @since 3.1.1
*/
public constructor(introspectedClass: Class<any>, nestedAnnotationsAsMap: boolean) {
super(introspectedClass);
this.annotations = introspectedClass.getAnnotations();
this.nestedAnnotationsAsMap = nestedAnnotationsAsMap;
}
}
export default StandardAnnotationMetadata;

View File

@ -1,8 +0,0 @@
import {
ClassMetadata,
} from '@loafer/core/type';
export class StandardClassMetadata extends ClassMetadata {
}
export default StandardClassMetadata;

View File

@ -1,5 +0,0 @@
export * from './AnnotatedTypeMetadata';
export * from './AnnotationMetadata';
export * from './ClassMetadata';
export * from './StandardAnnotationMetadata';
export * from './StandardClassMetadata';

View File

@ -1,128 +0,0 @@
import {
IllegalStateException,
IllegalArgumentException,
} from '@loafer/core/lang';
import {
StringUtils,
} from '@loafer/core/util';
export abstract class Assert {
public static state(expression: boolean, message: string): void {
if (!expression) {
throw new IllegalStateException(message);
}
}
public static isTrue(expression: boolean, message: string): void {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
public static isNull(object: any, message: string): void {
if (object !== null) {
throw new IllegalArgumentException(message);
}
}
public static notNull(object: any, message: string): void {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
public static hasLength(text: string, message: string): void {
if (!StringUtils.hasLength(text)) {
throw new IllegalArgumentException(message);
}
}
public static hasText(text: string, message: string): void {
if (!StringUtils.hasText(text)) {
throw new IllegalArgumentException(message);
}
}
public static doesNotContain(textToSearch: string, substring: string, message: string): void {
if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) &&
textToSearch.includes(substring)) {
throw new IllegalArgumentException(message);
}
}
public static notEmpty(collection: any[] | Map<any, any> | Set<any>, message: string): void {
if (undefined === collection || null === collection) {
throw new IllegalArgumentException(message);
}
let valid = true;
if (collection instanceof Array) {
let array: any[] = collection;
if (0 === collection.length) {
valid = false;
}
} else if (collection instanceof Map) {
let map: Map<any, any> = collection;
if (0 === map.size) {
valid = false;
}
} else if (collection instanceof Set) {
let set: Set<any> = collection;
if (0 === set.size) {
valid = false;
}
} else {
valid = false;
}
if (!valid) {
throw new IllegalArgumentException(message);
}
}
public static noNullElements(array: any[], message: string): void {
if (array !== null) {
array.forEach(element => {
if (element === null) {
throw new IllegalArgumentException(message);
}
});
}
}
public static isInstanceOf(type: Class<any>, obj: any, message: string = ''): void {
Assert.notNull(type, 'Type to check against must not be null');
if (!(obj instanceof type.constructor)) {
Assert.instanceCheckFailed(type, obj, message);
}
}
private static instanceCheckFailed(type: Class<any>, obj: any, message: string): void {
let className = (obj !== undefined && obj !== null ? Object.getPrototypeOf(obj).constructor.name : 'null');
let result = '';
let defaultMessage = true;
if (StringUtils.hasLength(message)) {
if (Assert.endsWithSeparator(message)) {
result = message + ' ';
} else {
result = Assert.messageWithTypeName(message, className);
defaultMessage = false;
}
}
if (defaultMessage) {
result = result + (`Object of class [${className}] must be an instance of ${type}`);
}
throw new IllegalArgumentException(result);
}
private static endsWithSeparator(message: string): boolean {
return (message.endsWith(':') || message.endsWith(';') || message.endsWith(',') || message.endsWith('.'));
}
private static messageWithTypeName(message: string, typeName: string): string {
return message + (message.endsWith(' ') ? '' : ': ') + typeName;
}
}
export default Assert;

View File

@ -1,64 +0,0 @@
export abstract class ObjectUtils {
/**
* Determine if the given objects are equal, returning {@code true} if
* both are {@code null} or {@code false} if only one is {@code null}.
* <p>Compares arrays with {@code Arrays.equals}, performing an equality
* check based on the array elements rather than the array reference.
* @param o1 first Object to compare
* @param o2 second Object to compare
* @return whether the given objects are equal
* @see Object#equals(Object)
* @see java.util.Arrays#equals
*/
public static nullSafeEquals(o1: any, o2: any): boolean {
if (o1 === o2) {
return true;
}
if (o1 === undefined || o2 === undefined) {
return false;
}
if (o1 == null || o2 == null) {
return false;
}
if (Array.isArray(o1) && Array.isArray(o2)) {
return ObjectUtils.arrayEquals(o1, o2);
}
return false;
}
/**
* Compare the given arrays with {@code Arrays.equals}, performing an equality
* check based on the array elements rather than the array reference.
* @param o1 first array to compare
* @param o2 second array to compare
* @return whether the given objects are equal
* @see #nullSafeEquals(Object, Object)
* @see java.util.Arrays#equals
*/
private static arrayEquals(o1: any, o2: any): boolean {
if (!Array.isArray(o1) || !Array.isArray(o2)) {
return false;
}
if (o1 === o2) {
return true;
}
const arr1 = <Array<any>>o1;
const arr2 = <Array<any>>o2;
if (arr1.length !== arr2.length) {
return false;
}
arr1.forEach((value, index) => {
if (value !== arr2[index]) {
return false;
}
});
return true;
}
}
export default ObjectUtils;

View File

@ -1,223 +0,0 @@
import {
IllegalStateException,
IllegalArgumentException,
} from '@loafer/core/lang';
export abstract class StringUtils {
private static readonly FOLDER_SEPARATOR: string = '/';
private static readonly WINDOWS_FOLDER_SEPARATOR: string = '\\';
private static readonly TOP_PATH: string = '..';
private static readonly CURRENT_PATH: string = '.';
private static readonly EXTENSION_SEPARATOR: string = '.';
public static isEmpty(str: any): boolean {
return (undefined === str || null === str || '' === str);
}
public static hasLength(str: string): boolean {
return (undefined !== str && null !== str && str.length > 0);
}
public static hasText(str: string): boolean {
if (!StringUtils.hasLength(str)) {
return false;
}
return str.trim() !== '';
}
public static containsWhitespace(str: string): boolean {
if (!StringUtils.hasLength(str)) {
return false;
}
return str.replace(/^\s+|\s+$/gm, '').length === 0;
}
public static trimWhitespace(str: string): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return str.trim();
}
public static trimAllWhitespace(str: string): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return str.replace(/\s/g, '');
}
public static trimLeadingWhitespace(str: string): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return str.replace(/^\s+/gm, '');
}
public static trimTrailingWhitespace(str: string): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return str.replace(/^\s+$/gm, '');
}
public static trimLeadingCharacter(str: string, leadingCharacter: string): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return str.replace(new RegExp('^[' + leadingCharacter + ']+'), '');
}
public static trimTrailingCharacter(str: string, trailingCharacter: string): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return str.replace(new RegExp('[' + trailingCharacter + ']+$'), '');
}
public static startsWithIgnoreCase(str: string, prefix: string): boolean {
if (undefined === str || null === str || undefined === prefix || null === prefix) {
return false;
}
if (str.startsWith(prefix)) {
return true;
}
if (str.length < prefix.length) {
return false;
}
const lcStr = str.substring(0, prefix.length).toLowerCase();
const lcPrefix = prefix.toLowerCase();
return lcStr === lcPrefix;
}
public static endsWithIgnoreCase(str: string, suffix: string): boolean {
if (str == null || suffix == null) {
return false;
}
if (str.endsWith(suffix)) {
return true;
}
if (str.length < suffix.length) {
return false;
}
const lcStr = str.substring(str.length - suffix.length).toLowerCase();
const lcSuffix = suffix.toLowerCase();
return lcStr === lcSuffix;
}
public static substringMatch(str: string, index: number, substring: string): boolean {
return str.includes(substring);
}
public static countOccurrencesOf(str: string, sub: string): number {
if (!StringUtils.hasLength(str) || !StringUtils.hasLength(sub)) {
return 0;
}
return (str.match(new RegExp(sub, 'gi')) || []).length;
}
public static replace(inString: string, oldPattern: string, newPattern: string): string {
if (!StringUtils.hasLength(inString) || !StringUtils.hasLength(oldPattern) || newPattern == null) {
return inString;
}
return inString.replace(new RegExp(oldPattern, 'g'), newPattern);
}
public static delete(inString: string, pattern: string): string {
return StringUtils.replace(inString, pattern, '');
}
public static deleteAny(inString: string, charsToDelete: string): string {
if (!StringUtils.hasLength(inString) || !StringUtils.hasLength(charsToDelete)) {
return inString;
}
return inString.replace(new RegExp('^[' + charsToDelete + ']+'), '');
}
public static quote(str: string): string {
return (str !== null ? '\'' + str + '\'' : null);
}
public static quoteIfString(obj: any): any {
return (typeof obj === 'string' ? StringUtils.quote(obj) : obj);
}
public static unqualify(qualifiedName: string, separator: string = '.'): string {
return qualifiedName.substring(qualifiedName.lastIndexOf(separator) + 1);
}
public static capitalize(str: string): string {
return StringUtils.changeFirstCharacterCase(str, true);
}
public static uncapitalize(str: string): string {
return StringUtils.changeFirstCharacterCase(str, false);
}
private static changeFirstCharacterCase(str: string, capitalize: boolean): string {
if (!StringUtils.hasLength(str)) {
return str;
}
return capitalize ? str.charAt(0).toUpperCase() + str.slice(1) : str.charAt(0).toLowerCase() + str.slice(1);
}
public static getFilename(path: string): string {
if (path === null) {
return null;
}
return path.split(StringUtils.WINDOWS_FOLDER_SEPARATOR).pop().split(StringUtils.FOLDER_SEPARATOR).pop();
}
public static getFilenameExtension(path: string): string {
if (path == null) {
return null;
}
return StringUtils.getFilename(path).split(StringUtils.EXTENSION_SEPARATOR).pop();
}
public static stripFilenameExtension(path: string): string {
if (path == null) {
return null;
}
return path.replace(new RegExp('[' + StringUtils.EXTENSION_SEPARATOR + StringUtils.getFilenameExtension(path) + ']+$'), '');
}
public static applyRelativePath(path: string, relativePath: string): string {
let separatorIndex = path.lastIndexOf(StringUtils.FOLDER_SEPARATOR);
if (separatorIndex !== -1) {
let newPath = path.substring(0, separatorIndex);
if (!relativePath.startsWith(StringUtils.FOLDER_SEPARATOR)) {
newPath += StringUtils.FOLDER_SEPARATOR;
}
return newPath + relativePath;
} else {
return relativePath;
}
}
}
export default StringUtils;

View File

@ -1,6 +0,0 @@
export abstract class TypeUtils {
}
export default TypeUtils;

View File

@ -1,5 +0,0 @@
export * from './Assert';
export * from './ObjectUtils';
export * from './StringUtils';
export * from './TypeUtils';

View File

@ -1,7 +0,0 @@
declare type Class<T> = {new(...args: any[]): T};
declare type Interface = Object;
declare type Identity<T> = T | symbol;
declare type PropertyName = Identity<string>;
declare type QualifierName = Identity<string>;
declare type PouchName = Identity<string>;
declare type ValueName = Identity<string>;

View File

@ -1,20 +0,0 @@
export interface Mergeable {
/**
* Is merging enabled for this particular instance?
*/
isMergeEnabled(): boolean;
/**
* Merge the current value set with that of the supplied object.
* <p>The supplied object is considered the parent, and values in
* the callee's value set must override those of the supplied object.
* @param parent the object to merge with
* @return the result of the merge operation
* @throws IllegalArgumentException if the supplied parent is {@code null}
* @exception IllegalStateException if merging is not enabled for this instance
* (i.e. {@code mergeEnabled} equals {@code false}).
*/
merge(parent: any): any;
}
export default Mergeable;

View File

@ -1,14 +0,0 @@
import {
AttributeAccessorSupport,
} from '@loafer/core';
import {
PouchMetadataElement,
} from '@loafer/pouches';
export class PouchMetadataAttributeAccessor extends AttributeAccessorSupport implements PouchMetadataElement {
}
export default PouchMetadataAttributeAccessor;

View File

@ -1,4 +0,0 @@
export interface PouchMetadataElement {
}
export default PouchMetadataElement;

View File

@ -1,11 +0,0 @@
import {
NestedRuntimeException,
} from '@loafer/core';
export class PouchesException extends NestedRuntimeException {
public constructor(message?: string) {
super(message);
}
}
export default PouchesException;

View File

@ -1,4 +0,0 @@
export enum PouchScope {
SINGLETON = 'Singleton',
TRANSIENT = 'Transient',
}

View File

@ -1,40 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export interface InjectConfig {
qualifier?: QualifierName;
required?: boolean;
type?: Class<any>;
}
export class InjectAnnotation extends Annotation {
private readonly Qualifier: QualifierName;
private readonly Required: boolean;
private readonly Type: Class<any>;
public constructor(config: InjectConfig = {}) {
super();
this.Qualifier = config.qualifier;
this.Required = config.required;
this.Type = config.type;
}
public onPropertyDecorator = (target: Object, propertyKey: PropertyName): void => {
console.log('Inject');
}
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyName,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
console.log('Inject');
}
public onParameterDecorator = (target: Object, propertyKey: PropertyName, parameterIndex: number): void => {
console.log('Inject');
}
}
export const Inject = Decorator.create(InjectAnnotation);
export default Inject;

View File

@ -1,22 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export class InjectableAnnotation extends Annotation {
private readonly Qualifier: QualifierName;
public constructor(qualifier?: QualifierName) {
super();
this.Qualifier = qualifier;
}
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
console.log('Injectable');
}
}
export const Injectable = Decorator.create(InjectableAnnotation);
export default Injectable;

View File

@ -1,16 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export class PostConstructAnnotation extends Annotation {
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyName,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
console.log('PostConstruct');
}
}
export const PostConstruct = Decorator.create(PostConstructAnnotation);
export default PostConstruct;

View File

@ -1,16 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export class PreDestroyAnnotation extends Annotation {
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyName,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
console.log('PreDestroy');
}
}
export const PreDestroy = Decorator.create(PreDestroyAnnotation);
export default PreDestroy;

View File

@ -1,22 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export class ScopeAnnotation extends Annotation {
private readonly Qualifier: QualifierName;
public constructor(qualifier?: QualifierName) {
super();
this.Qualifier = qualifier;
}
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
console.log('Scope');
}
}
export const Scope = Decorator.create(ScopeAnnotation);
export default Scope;

View File

@ -1,26 +0,0 @@
import {
Decorator,
} from '@loafer/core/decorator';
import Annotation from '@loafer/core/annotation/Annotation';
export class ValueAnnotation extends Annotation {
private readonly Value: ValueName;
public constructor(value: ValueName) {
super();
this.Value = value;
}
public onPropertyDecorator = (target: Object, propertyKey: PropertyName): void => {
console.log('Value');
}
public onParameterDecorator = (target: Object, propertyKey: PropertyName, parameterIndex: number): void => {
console.log('Value');
}
}
export const Value = Decorator.create(ValueAnnotation);
export default Value;

View File

@ -1,4 +0,0 @@
export interface DisposablePouch {
}
export default DisposablePouch;

View File

@ -1,4 +0,0 @@
export interface FactoryPouch<T> {
}
export default FactoryPouch;

View File

@ -1,6 +0,0 @@
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
export interface HierarchicalPouchFactory extends PouchFactory {
}
export default HierarchicalPouchFactory;

View File

@ -1,6 +0,0 @@
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
export interface ListablePouchFactory extends PouchFactory {
}
export default ListablePouchFactory;

View File

@ -1,11 +0,0 @@
import {
PouchesException,
} from '@loafer/pouches';
export class NoSuchPouchDefinitionException extends PouchesException {
public constructor(message?: string) {
super(message);
}
}
export default NoSuchPouchDefinitionException;

View File

@ -1,4 +0,0 @@
export interface ObjectFactory<T> {
}
export default ObjectFactory;

View File

@ -1,7 +0,0 @@
export class PouchDefinitionStoreException extends Error {
public constructor(message?: string) {
super(message);
}
}
export default PouchDefinitionStoreException;

View File

@ -1,6 +0,0 @@
export interface PouchFactory {
}
export default PouchFactory;

View File

@ -1,26 +0,0 @@
import {
AnnotationMetadata,
} from '@loafer/core/type';
import {
GenericPouchDefinition,
} from '@loafer/pouches/factory/support';
import {
AnnotatedPouchDefinition,
} from '@loafer/pouches/factory/annotation';
export class AnnotatedGenericPouchDefinition extends GenericPouchDefinition implements AnnotatedPouchDefinition {
private readonly metadata: AnnotationMetadata;
public constructor(pouchClass: Class<any>) {
super();
this.PouchClass = pouchClass;
this.metadata = new StandardAnnotationMetadata(pouchClass, true);
}
}
export default AnnotatedGenericPouchDefinition;

View File

@ -1,11 +0,0 @@
import {
PouchDefinition,
} from '@loafer/pouches/factory/config';
export interface AnnotatedPouchDefinition extends PouchDefinition {
}
export default AnnotatedPouchDefinition;

View File

@ -1,2 +0,0 @@
export * from './AnnotatedPouchDefinition';
export * from './AnnotatedGenericPouchDefinition';

View File

@ -1,6 +0,0 @@
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
export interface ConfigurableListablePouchFactory {
}
export default ConfigurableListablePouchFactory;

View File

@ -1,12 +0,0 @@
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
import HierarchicalPouchFactory from '@loafer/pouches/factory/HierarchicalPouchFactory';
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
import SingletonPouchRegistry from '@loafer/pouches/factory/config/SingletonPouchRegistry';
import PouchExpressionResolver from '@loafer/pouches/factory/config/PouchExpressionResolver';
export interface ConfigurablePouchFactory extends HierarchicalPouchFactory, SingletonPouchRegistry {
}
export default ConfigurablePouchFactory;

View File

@ -1,170 +0,0 @@
import {
Assert,
ObjectUtils,
TypeUtils,
} from '@loafer/core/util';
import {
Mergeable,
PouchMetadataElement,
} from '@loafer/pouches';
import {
HierarchicalPouchFactory,
PouchFactory,
} from '@loafer/pouches/factory';
import {
PouchDefinition,
PouchExpressionResolver,
SingletonPouchRegistry,
} from '@loafer/pouches/factory/config';
export class ConstructorArgumentValues {
private readonly indexedArgumentValues: Map<number, ValueHolder> = new Map();
private readonly genericArgumentValues: ValueHolder[] = [];
/**
* Deep copy constructor.
* @param original the ConstructorArgumentValues to copy
*/
public constructor(original?: ConstructorArgumentValues) {
//
}
}
/**
* Holder for a constructor argument value, with an optional type
* attribute indicating the target type of the actual constructor argument.
*/
export class ValueHolder implements PouchMetadataElement {
private value: any;
private type: string;
private name: string;
private source: any;
private converted: boolean = false;
private convertedValue: any;
/**
* Create a new ValueHolder for the given value, type and name.
* @param value the argument value
* @param type the type of the constructor argument
* @param name the name of the constructor argument
*/
public constructor( value: any, type?: string, name?: string) {
this.value = value;
this.type = type;
this.name = name;
}
/**
* Set the value for the constructor argument.
* @see PropertyPlaceholderConfigurer
*/
public set Value(value: any) {
this.value = value;
}
/**
* Return the value for the constructor argument.
*/
public get Value(): any {
return this.value;
}
/**
* Set the type of the constructor argument.
*/
public set Type(type: string) {
this.type = type;
}
/**
* Return the type of the constructor argument.
*/
public get Type(): string {
return this.type;
}
/**
* Set the name of the constructor argument.
*/
public set Name(name: string) {
this.name = name;
}
/**
* Return the name of the constructor argument.
*/
public get Name(): string {
return this.name;
}
/**
* Set the configuration source {@code Object} for this metadata element.
* <p>The exact type of the object will depend on the configuration mechanism used.
*/
public set Source(source: any) {
this.source = source;
}
public get Source(): any {
return this.source;
}
/**
* Return whether this holder contains a converted value already ({@code true}),
* or whether the value still needs to be converted ({@code false}).
*/
public isConverted(): boolean {
return this.converted;
}
/**
* Set the converted value of the constructor argument,
* after processed type conversion.
*/
public set ConvertedValue(value: any) {
this.converted = (value != null);
this.convertedValue = value;
}
/**
* Return the converted value of the constructor argument,
* after processed type conversion.
*/
public get ConvertedValue(): any {
return this.convertedValue;
}
/**
* Determine whether the content of this ValueHolder is equal
* to the content of the given other ValueHolder.
* <p>Note that ValueHolder does not implement {@code equals}
* directly, to allow for multiple ValueHolder instances with the
* same content to reside in the same Set.
*/
private contentEquals(other: ValueHolder): boolean {
return (this === other ||
(ObjectUtils.nullSafeEquals(this.value, other.value) && ObjectUtils.nullSafeEquals(this.type, other.type)));
}
/**
* Create a copy of this ValueHolder: that is, an independent
* ValueHolder instance with the same contents.
*/
public copy(): ValueHolder {
let copy: ValueHolder = new ValueHolder(this.value, this.type, this.name);
copy.Source = this.Source;
return copy;
}
}
export default ConstructorArgumentValues;

View File

@ -1,6 +0,0 @@
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
export interface InjectCapablePouchFactory extends PouchFactory {
}
export default InjectCapablePouchFactory;

View File

@ -1,124 +0,0 @@
import {
PouchScope,
} from '@loafer/pouches/constants/types';
export interface PouchDefinition {
/**
* The name of the parent definition of this pouch definition, if any.
*/
ParentName: PouchName;
/**
* The current pouch class name of this pouch definition.
* <p>Note that this does not have to be the actual class name used at runtime, in
* case of a child definition overriding/inheriting the class name from its parent.
* Also, this may just be the class that a factory method is called on, or it may
* even be empty in case of a factory pouch reference that a method is called on.
* Hence, do <i>not</i> consider this to be the definitive pouch type at runtime but
* rather only use it for parsing purposes at the individual pouch definition level.
* @see #getParentName()
* @see #getFactoryPouchName()
* @see #getFactoryMethodName()
*/
PouchClassName: string;
/**
* Override the target scope of this pouch, specifying a new scope name.
* @see #SCOPE_SINGLETON
* @see #SCOPE_PROTOTYPE
*/
Scope: string;
/**
* Whether this pouch should be lazily initialized.
* <p>If {@code false}, the pouch will get instantiated on startup by pouch
* factories that perform eager initialization of singletons.
*/
LazyInit: boolean;
/**
* The names of the pouchs that this pouch depends on being initialized.
* The pouch factory will guarantee that these pouchs get initialized first.
*/
DependsOn: PouchName[];
/**
* Whether this pouch is a candidate for getting autowired into some other pouch.
* <p>Note that this flag is designed to only affect type-based autowiring.
* It does not affect explicit references by name, which will get resolved even
* if the specified pouch is not marked as an autowire candidate. As a consequence,
* autowiring by name will nevertheless inject a pouch if the name matches.
*/
AutowireCandidate: boolean;
/**
* Whether this pouch is a primary autowire candidate.
* <p>If this value is {@code true} for exactly one pouch among multiple
* matching candidates, it will serve as a tie-breaker.
*/
Primary: boolean;
/**
* Specify the factory pouch to use, if any.
* This the name of the pouch to call the specified factory method on.
* @see #setFactoryMethodName
*/
FactoryPouchName: PouchName;
/**
* Specify a factory method, if any. This method will be invoked with
* constructor arguments, or with no arguments if none are specified.
* The method will be invoked on the specified factory pouch, if any,
* or otherwise as a static method on the local pouch class.
* @see #setFactoryPouchName
* @see #setPouchClassName
*/
FactoryMethodName: PropertyName;
/**
* Return the constructor argument values for this pouch.
* <p>The returned instance can be modified during pouch factory post-processing.
* @return the ConstructorArgumentValues object (never {@code null})
*/
getConstructorArgumentValues(): ConstructorArgumentValues;
/**
* Return the property values to be applied to a new instance of the pouch.
* <p>The returned instance can be modified during pouch factory post-processing.
* @return the MutablePropertyValues object (never {@code null})
*/
getPropertyValues(): MutablePropertyValues;
/**
* Return whether this a <b>Singleton</b>, with a single, shared instance
* returned on all calls.
* @see #SCOPE_SINGLETON
*/
isSingleton(): boolean;
/**
* Return whether this a <b>Prototype</b>, with an independent instance
* returned for each call.
* @see #SCOPE_PROTOTYPE
*/
isPrototype(): boolean;
/**
* Return whether this pouch is "abstract", that is, not meant to be instantiated.
*/
isAbstract(): boolean;
// Read-only attributes
/**
* Return a human-readable description of this pouch definition.
*/
getDescription(): string;
/**
* Return a description of the resource that this pouch definition
* came from (for the purpose of showing context in case of errors).
*/
getResourceDescription(): string;
/**
* Return the originating PouchDefinition, or {@code null} if none.
* Allows for retrieving the decorated pouch definition, if any.
* <p>Note that this method returns the immediate originator. Iterate through the
* originator chain to find the original PouchDefinition as defined by the user.
*/
getOriginatingPouchDefinition(): PouchDefinition;
}
export default PouchDefinition;

View File

@ -1,7 +0,0 @@
import ConfigurablePouchFactory from '@loafer/pouches/factory/config/ConfigurablePouchFactory';
import Scope from '@loafer/pouches/factory/config/Scope';
export class PouchExpressionContext {
}
export default PouchExpressionContext;

View File

@ -1,7 +0,0 @@
import PouchExpressionContext from '@loafer/pouches/factory/config/PouchExpressionContext';
export interface PouchExpressionResolver {
}
export default PouchExpressionResolver;

View File

@ -1,7 +0,0 @@
import ObjectFactory from '@loafer/pouches/factory/ObjectFactory';
export interface Scope {
}
export default Scope;

View File

@ -1,4 +0,0 @@
export interface SingletonPouchRegistry {
}
export default SingletonPouchRegistry;

View File

@ -1,8 +0,0 @@
export * from './ConfigurableListablePouchFactory';
export * from './ConfigurablePouchFactory';
export * from './InjectCapablePouchFactory';
export * from './PouchDefinition';
export * from './PouchExpressionContext';
export * from './PouchExpressionResolver';
export * from './Scope';
export * from './SingletonPouchRegistry';

View File

@ -1,93 +0,0 @@
// import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
// import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
// import DefaultSingletonPouchRegistry from '@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry';
// abstract class AbstractPouchFactory extends DefaultSingletonPouchRegistry implements PouchDefinitionRegistry {
// protected pouchDefinitionMap: Map<Identity<T>, Map<Class<any>, PouchDefinition>>;
// public constructor() {
// super();
// this.pouchDefinitionMap = new Map();
// }
// public registerPouchDefinition(pouchDefinition: PouchDefinition): void {
// let clazz = pouchDefinition.Clazz;
// // let qualifier = validateQualifier(clazz, pouchDefinition.Qualifier);
// // if (this.hasPouchDefinition(qualifier, clazz)) {
// // throw new Error(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is exist already`);
// // }
// // let map = this.pouchDefinitionMap.get(qualifier);
// // if (undefined === map) {
// // map = new Map();
// // this.pouchDefinitionMap.set(qualifier, map);
// // }
// // map.set(clazz, pouchDefinition);
// }
// public getPouchDefinition(qualifier: Identity<T>, clazz?: Class<any>): PouchDefinition {
// if (!this.pouchDefinitionMap.has(qualifier)) {
// return undefined;
// }
// let map = this.pouchDefinitionMap.get(qualifier);
// let count = map.size;
// let pouchDefinition: PouchDefinition;
// try {
// pouchDefinition = this._getDefinition(map, clazz);
// } catch(e) {
// console.log(`Type of Pouch Definition[${qualifier}] cannot be specified (count:${count})`);
// }
// return pouchDefinition;
// }
// public getPouchDefinitionByClass(clazz: Class<any>, qualifier?: Identity<T>): PouchDefinition {
// // const _qualifier = validateQualifier(clazz, qualifier);
// return this.getPouchDefinition(qualifier, clazz);
// }
// public hasPouchDefinition(qualifier: Identity<T>, clazz?: Class<any>): boolean {
// return undefined === this.getPouchDefinition(qualifier, clazz) ? false : true;
// }
// public hasPouchDefinitionByClass(clazz: Class<any>, qualifier?: Identity<T>): boolean {
// // const _qualifier = validateQualifier(clazz, qualifier);
// return this.hasPouchDefinition(qualifier, clazz);
// }
// public removePouchDefinition(qualifier: Identity<T>, clazz?: Class<any>): void {
// if (!this.hasPouchDefinition(qualifier, clazz)) {
// console.log(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is not exist`);
// return;
// }
// this.pouchDefinitionMap.get(qualifier).delete(clazz);
// if (0 === this.pouchDefinitionMap.get(qualifier).size) {
// this.pouchDefinitionMap.delete(qualifier);
// }
// }
// public removePouchDefinitionByClass(clazz: Class<any>, qualifier?: Identity<T>): void {
// // const _qualifier = validateQualifier(clazz, qualifier);
// // this.removePouchDefinition(_qualifier, clazz);
// }
// private _getDefinition(map: Map<Class<any>, PouchDefinition>, clazz?: Class<any>): PouchDefinition {
// if (undefined !== clazz) {
// return map.get(clazz);
// }
// const count = map.size;
// if (1 < count) {
// throw new Error('Type of Pouch Definition cannot be specified.');
// }
// for (let value of Array.from(map.values())) {
// return value;
// }
// }
// }
// export default AbstractPouchFactory;

View File

@ -1,110 +0,0 @@
// import {
// PouchScope,
// } from '@loafer/pouches/constants/types';
// import PouchFactory from '@loafer/pouches/factory/PouchFactory';
// import AbstractPouchFactory from '@loafer/pouches/factory/implement/AbstractPouchFactory';
// import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
// import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
// class DefaultPouchFactory extends AbstractPouchFactory implements PouchFactory, PouchDefinitionRegistry {
// public constructor() {
// super();
// }
// public getPouch(qualifier: Identity<T>, clazz: Class<any>, ...args: any[]): any {
// let pouchDefinition = this._getPouchDefinition(qualifier, clazz);
// if (undefined === pouchDefinition) {
// throw new Error(`This class[${clazz.constructor.name}:${qualifier}] is not pouch.`);
// }
// return this._getPouch(pouchDefinition, ...args);
// }
// public getPouchByClass(clazz: Class<any>, qualifier: Identity<T>, ...args: any[]): any {
// // let _qualifier = validateQualifier(clazz, qualifier);
// // let pouchDefinition = this._getPouchDefinition(_qualifier, clazz);
// // if (undefined === pouchDefinition) {
// // throw new Error(`This class[${clazz.constructor.name}:${qualifier}] is not pouch.`);
// // }
// // return this._getPouch(pouchDefinition, ...args);
// }
// private _getPouchDefinition(qualifier: Identity<T>, clazz: Class<any>): PouchDefinition {
// let pouchDefinition = this.getPouchDefinition(qualifier, clazz);
// if (undefined === pouchDefinition) {
// // pouchDefinition = this._getInjectableDefinition(clazz);
// if (undefined !== pouchDefinition) {
// this.registerPouchDefinition(pouchDefinition);
// }
// }
// return pouchDefinition;
// }
// private _getPouch(pouchDefinition: PouchDefinition, ...args: any[]): any {
// let instance;
// if (pouchDefinition.isSingleton()) {
// instance = this.getSingleton(pouchDefinition.Qualifier, pouchDefinition.Clazz);
// if (undefined !== instance) {
// return instance;
// }
// }
// instance = Object.create(pouchDefinition.Clazz);
// instance.constructor.apply(instance, ...args);
// this._injectDependency(instance, pouchDefinition.Clazz);
// }
// private _injectDependency(instance: any, clazz: Class<any>): void {
// if (clazz.constructor === Object) {
// return;
// }
// // let injectDefinition: InjectDefinition = this._getInjectDefinition(clazz);
// // if (undefined !== injectDefinition) {
// // let injectors: Map<Identity<T>, InjectItem> = injectDefinition.injectors;
// // let propertyDescriptor: PropertyDescriptor;
// // injectors.forEach((injectItem, key, map) => {
// // propertyDescriptor = Object.getOwnPropertyDescriptor(clazz, key);
// // switch (injectItem.decoratorType) {
// // case DecoratorType.PROPERTY:
// // this._injectDependencyProperty(instance, clazz, key, propertyDescriptor, injectItem.propertyConfig);
// // break;
// // case DecoratorType.PARAMETER:
// // this._injectDependencyParameter(instance, propertyDescriptor, injectItem.parameterConfigMap);
// // break;
// // default:
// // break;
// // }
// // });
// // }
// // this._injectDependency(instance, Object.getPrototypeOf(clazz));
// }
// // private _injectDependencyProperty(instance: any, clazz: Class<any>, propertyKey: Identity<T>,
// // propertyDescriptor: PropertyDescriptor, injectConfig: InjectConfig): void {
// // let pouch = this.getPouchByClass(injectConfig.clazz, injectConfig.qualifier);
// // if (injectConfig.required && undefined === instance) {
// // throw new Error(`Pouch which used by [${clazz.constructor.name}.${propertyKey}] is not exist in the context.`);
// // }
// // instance[propertyKey] = pouch;
// // }
// // private _injectDependencyParameter(target: object, propertyDescriptor: PropertyDescriptor,
// // parameterConfigs: Map<number, InjectConfig>): void {
// // console.log('');
// // }
// // private _getInjectableDefinition(clazz: Class<any>): InjectableDefinition {
// // return Reflect.getMetadata(POUCH_INJECTABLE_DEFINITION, clazz);
// // }
// // private _getInjectDefinition(clazz: Class<any>): InjectDefinition {
// // return Reflect.getMetadata(POUCH_INJECT_DEFINITION, clazz);
// // }
// }
// export default DefaultPouchFactory;

View File

@ -1,73 +0,0 @@
import SingletonPouchRegistry from '@loafer/pouches/factory/config/SingletonPouchRegistry';
class DefaultSingletonPouchRegistry implements SingletonPouchRegistry {
protected singletonInstanceMap: Map<PouchName, Map<Class<any>, any>>;
protected constructor() {
this.singletonInstanceMap = new Map();
}
public registerSingleton(pouch: any, qualifier?: QualifierName): void {
let clazz: Class<any> = Object.getPrototypeOf(pouch);
// const _qualifier = validateQualifier(clazz, qualifier);
// if (this._hasSingleton(_qualifier, clazz)) {
// throw new Error(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is exist already`);
// }
// let map = this.singletonInstanceMap.get(_qualifier);
// if (undefined === map) {
// map = new Map();
// this.singletonInstanceMap.set(_qualifier, map);
// }
// map.set(clazz, pouch);
}
public getSingleton(qualifier: QualifierName, clazz?: Class<any>): any {
return this._getSingleton(qualifier, clazz);
}
public getSingletonByClass(clazz: Class<any>, qualifier?: QualifierName): any {
// const _qualifier = validateQualifier(clazz, qualifier);
return this._getSingleton(qualifier, clazz);
}
public hasSingleton(qualifier: QualifierName, clazz?: Class<any>): boolean {
return this._hasSingleton(qualifier, clazz);
}
public hasSingletonByClass(clazz: Class<any>, qualifier?: QualifierName): boolean {
// const _qualifier = validateQualifier(clazz, qualifier);
return this._hasSingleton(qualifier, clazz);
}
private _getSingleton<T>(qualifier: QualifierName, clazz?: Class<any>): T {
if (!this.singletonInstanceMap.has(qualifier)) {
return undefined;
}
let map = this.singletonInstanceMap.get(qualifier);
let instance;
try {
instance = this._getInstance(map, clazz);
} catch(e) {
throw new Error(`Type of Pouch[${qualifier}] cannot be specified(count is ${map.size}).`);
}
return instance;
}
private _hasSingleton(qualifier: QualifierName, clazz?: Class<any>): boolean {
return undefined === this._getSingleton(qualifier, clazz) ? false : true;
}
private _getInstance(map: Map<Class<any>, any>, clazz?: Class<any>): any {
if (undefined !== clazz) {
return map.get(clazz);
}
const count = map.size;
if (1 < count) {
throw new Error(`Type of Pouch cannot be specified(count is ${count}).`);
}
for (let value of Array.from(map.values())) {
return value;
}
}
}
export default DefaultSingletonPouchRegistry;

View File

@ -1,7 +0,0 @@
export * from './FactoryPouch';
export * from './HierarchicalPouchFactory';
export * from './ListablePouchFactory';
export * from './NoSuchPouchDefinitionException';
export * from './PouchDefinitionStoreException';
export * from './PouchFactory';

View File

@ -1,7 +0,0 @@
import AliasRegistry from '@loafer/core/AliasRegistry';
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
export abstract class AbstractInjectCapablePouchFactory implements AliasRegistry {
}
export default AbstractInjectCapablePouchFactory;

View File

@ -1,12 +0,0 @@
import {
PouchMetadataAttributeAccessor,
} from '@loafer/pouches';
import {
PouchDefinition,
} from '@loafer/pouches/factory/config';
export abstract class AbstractPouchDefinition extends PouchMetadataAttributeAccessor implements PouchDefinition {
}
export default AbstractPouchDefinition;

View File

@ -1,7 +0,0 @@
import AliasRegistry from '@loafer/core/AliasRegistry';
import FactoryPouchRegistrySupport from '@loafer/pouches/factory/support/FactoryPouchRegistrySupport';
export abstract class AbstractPouchFactory extends FactoryPouchRegistrySupport {
}
export default AbstractPouchFactory;

View File

@ -1,7 +0,0 @@
import AliasRegistry from '@loafer/core/AliasRegistry';
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
export class DefaultListablePouchFactory implements AliasRegistry {
}
export default DefaultListablePouchFactory;

View File

@ -1,10 +0,0 @@
import SimpleAliasRegistry from '@loafer/core/SimpleAliasRegistry';
import ObjectFactory from '@loafer/pouches/factory/ObjectFactory';
import DisposablePouch from '@loafer/pouches/factory/DisposablePouch';
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
import SingletonPouchRegistry from '@loafer/pouches/factory/config/SingletonPouchRegistry';
export class DefaultSingletonPouchRegistry extends SimpleAliasRegistry implements SingletonPouchRegistry {
}
export default DefaultSingletonPouchRegistry;

View File

@ -1,9 +0,0 @@
import AliasRegistry from '@loafer/core/AliasRegistry';
import FactoryPouch from '@loafer/pouches/factory/FactoryPouch';
import DefaultSingletonPouchRegistry from '@loafer/pouches/factory/support/DefaultSingletonPouchRegistry';
export abstract class FactoryPouchRegistrySupport extends DefaultSingletonPouchRegistry {
}
export default FactoryPouchRegistrySupport;

View File

@ -1,8 +0,0 @@
import {
AbstractPouchDefinition,
} from '@loafer/pouches/factory/support';
export class GenericPouchDefinition extends AbstractPouchDefinition {
}
export default GenericPouchDefinition;

Some files were not shown because too many files have changed in this diff Show More