public ObjectFactory<T> createObjectFactory(final Class<T> cls) { logger.trace("Entry {}", cls); //$NON-NLS-1$ if (cls == null) { throw new NullPointerException(Messages.getMessage("variableIsNull", "cls")); //$NON-NLS-1$ //$NON-NLS-2$ } if (ResourceMetadataCollector.isDynamicResource(cls)) { // default factory cannot create instance of DynamicResource throw new IllegalArgumentException(Messages .getMessage("cannotCreateDefaultFactoryForDR", String.valueOf(cls))); //$NON-NLS-1$ } ObjectFactory<T> ret = null; if (ApplicationMetadataCollector.isApplication(cls)) { // by default application subclasses are singletons ret = LifecycleManagerUtils.createSingletonObjectFactory(cls); } else if (ProviderMetadataCollector.isProvider(cls)) { // by default providers are singletons ret = LifecycleManagerUtils.createSingletonObjectFactory(cls); } else if (ResourceMetadataCollector.isStaticResource(cls)) { // by default resources are prototypes (created per request) ret = LifecycleManagerUtils.createPrototypeObjectFactory(cls); } if (ret != null) { logger.trace("Exit {}", ret); //$NON-NLS-1$ return ret; } else // unknown object, should never reach this code throw new IllegalArgumentException(Messages .getMessage("cannotCreateDefaultFactoryFor", String.valueOf(cls))); //$NON-NLS-1$ }
protected static <T> ClassMetadata collectClassMetadata(final Class<T> cls, boolean validateConstructor) { ClassMetadata classMetadata = null; if (ProviderMetadataCollector.isProvider(cls)) { classMetadata = ProviderMetadataCollector.collectMetadata(cls); } else if (ResourceMetadataCollector.isResource(cls)) { classMetadata = ResourceMetadataCollector.collectMetadata(cls); } else if (ApplicationMetadataCollector.isApplication(cls)) { classMetadata = ApplicationMetadataCollector.collectMetadata(cls); } else { throw new IllegalArgumentException(Messages.getMessage("cannotCreateFactoryForClass", cls)); //$NON-NLS-1$ } // validate that there is a valid constructor if needed if (validateConstructor && classMetadata.getConstructor().getConstructor() == null) { throw new IllegalStateException(Messages.getMessage("noValidConstructorFoundFor", cls //$NON-NLS-1$ .getCanonicalName())); } return classMetadata; }
public ObjectFactory<T> createObjectFactory(Class<T> cls) { if (cls == null) { return null; } if (JSR250LifecycleManagerUtils.hasJSR250AnnotatedMethod(cls)) { ObjectFactory<T> ret = null; if (ApplicationMetadataCollector.isApplication(cls)) { // by default application subclasses are singletons ret = JSR250LifecycleManagerUtils.createSingletonObjectFactory(cls); } else if (ProviderMetadataCollector.isProvider(cls)) { // by default providers are singletons ret = JSR250LifecycleManagerUtils.createSingletonObjectFactory(cls); } else if (ResourceMetadataCollector.isStaticResource(cls)) { // by default resources are prototypes (created per request) ret = JSR250LifecycleManagerUtils.createPrototypeObjectFactory(cls); } return ret; } // has no JSR250 annotations, do nothing return null; }