Factory method with a resource.

@param aBaseResource
The base resource. May not be <code>null</code>.
@return <code>null</code> if the resource does not exist
505892
@Nullable
  public static DefaultEntityResolver createOnDemand (@Nonnull final IReadableResource aBaseResource)
  {
    final URL aURL = aBaseResource.getAsURL ();
    return aURL == null ? null : new DefaultEntityResolver (aURL);
  }
71552
@SuppressWarnings("unchecked")
    protected <T extends RepositoryResourceImpl> T createNewResource() {

        T result;
        if (null == getType()) {
            result = (T) createTestResource(getRepositoryConnection());
        } else {
            result = ResourceFactory.getInstance().createResource(getType(), getRepositoryConnection(), null);
        }
        return result;
    }
1060836
@Override
    public T addAsWebResource(String resourceName, String target) throws IllegalArgumentException {
        Validate.notNull(resourceName, "ResourceName should be specified");
        Validate.notNull(target, "Target should be specified");

        return addAsWebResource(new ClassLoaderAsset(resourceName), target);
    }
1018028
public static Resource create(@NotNull ResourceResolver resourceResolver, @NotNull ValueMap valueMap) {
    return create(resourceResolver, null, JcrConstants.NT_UNSTRUCTURED, valueMap);
  }
788775
@Nullable
    public static InputStream getResourceAsStream(@NotNull String resource) {
        final ClassLoader classLoader = FileUtils.class.getClassLoader();
        final InputStream inputStream = classLoader != null
                ? classLoader.getResourceAsStream(resource)
                : ClassLoader.getSystemResourceAsStream(resource);

        if (inputStream == null) {
            try {
                return new FileInputStream(resource);
            } catch (final FileNotFoundException e) {
                LOGGER.error("Unable to create an Input Stream for " + resource, e);
            }
        }
        return inputStream;
    }
178612
public static <T> void initSingletonEJBCDIProvider(AbstractResourceInfo resource, Message message, T resourceObject) {

        /*
         * Only @Provider will use logic here.
         * As EJB can only be default constructor, CDI can be default constructor or 1 param with @Inject constructor
         * And a provider must have 1 public constructor(default constructor or @Context params constructor)
         * then the intersection is only default constructor.
         * so if ConstructorProxies!=null means there are some other invalid constructors to EJB or CDI container
         */
        if ((!(resource instanceof ProviderInfo)) || (resource instanceof ApplicationInfo) || resource.getConstructorProxies() != null) {
            return;
        }

        ProviderInfo<T> pi = (ProviderInfo<T>) resource;

        /**
         * if this provider is inited which means it may be replaced by EJB or CDI bean or it may be invoked with @PostConstrcut
         */
        if (pi.isInit()) {
            return;
        }

        synchronized(pi) {
            if (pi.isInit()) {
                return;
            }
            Class clz = pi.getProvider().getClass();
            Bus bus = resource.getBus();

            if (bus != null) { // if bus is null, then we don't need to do injection on this provider
                List<JaxRsFactoryBeanCustomizer> beanCustomizers = (List<JaxRsFactoryBeanCustomizer>) bus.getProperty(JaxRsConstants.ENDPOINT_LIST_BEANCUSTOMIZER);
                Map<String, Object> beanCustomizerContexts = (Map<String, Object>) bus.getProperty(JaxRsConstants.ENDPOINT_BEANCUSTOMIZER_CONTEXTOBJ);

                if (beanCustomizers != null && !beanCustomizers.isEmpty() && beanCustomizerContexts != null) {

                    Object newProviderInstance = null;
                    for (JaxRsFactoryBeanCustomizer beanCustomizer : beanCustomizers) {
                        if (beanCustomizer.isCustomizableBean(clz, beanCustomizerContexts.get(Integer.toString(beanCustomizer.hashCode())))) {

                            newProviderInstance = beanCustomizer.onSingletonProviderInit(pi.getProvider(), beanCustomizerContexts.get(Integer.toString(beanCustomizer.hashCode())), message);

                            /**
                             * if newProviderInstance!= the original object, which means it is replaced to EJB or CDI, so just return
                             * no need call @PostConstruct
                             */
                            if (newProviderInstance != null) {
                                //call setProvider to set isInit==true
                                pi.setProvider(newProviderInstance);
                                pi.setIsInit(true);
                                return;
                            }
                        }
                    }
                }
                //No replacement happens which means this is a POJO, call @PostConstruct
                pi.setIsInit(true);
                Method postConstructMethod = ResourceUtils.findPostConstructMethod(clz);
                InjectionUtils.invokeLifeCycleMethod(pi.getProvider(), postConstructMethod);
            }
        }
    }
590928
@Override
    public T addAsResource(String resourceName, ArchivePath target, ClassLoader classLoader)
        throws IllegalArgumentException {
        Validate.notNull(resourceName, "ResourceName should be specified");
        Validate.notNull(target, "Target should be specified");
        Validate.notNull(classLoader, "ClassLoader should be specified");

        return addAsResource(new ClassLoaderAsset(resourceName, classLoader), target);
    }
292531
@Override
    public Object createResource(ResourceInfo info) throws Exception {
        ComponentMetaData cData = ComponentMetaDataAccessorImpl.getComponentMetaDataAccessor().getComponentMetaData();
        if (cData != null)
            applications.add(cData.getJ2EEName().getApplication());

        return cloudantSvc.createResource(
                                          (String) props.get("databaseName"),
                                          (Boolean) props.get("create"),
                                          info == null ? ResourceInfo.AUTH_APPLICATION : info.getAuth(),
                                          info == null ? null : info.getLoginPropertyList());
    }
675107
@Override
    public URL getResource(String name) {
        return name == null ? null : shadowedLoader.getResource(name);
    }
858762
static WebServiceRef createWebServiceRefFromResource(Resource resource, Class<?> typeClass, String jndiName) throws InjectionException {
        // notice we send in 'Service.class' for the 'value' attribute, this is
        // because only service type injections are possible with the @Resource
        // annotation, so we'll use the default value for the 'value' attribute.
        return new WebServiceRefSimulator(resource.mappedName(), jndiName, typeClass, Service.class, null, "");
    }
647474
protected void setDataSourceFactory(ServiceReference<ResourceFactory> ref) {
        if (TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_WAS.logp(Level.FINE, methodClassName, "setDataSourceFactory", "setting " + ref);
        }
        dataSourceFactoryRef.setReference(ref);
    }
956586
public DOMSource createDOMSource(DocumentSource src)
    {
        try
        {
            Constructor<? extends DOMSource> constr = getDOMSourceClass().getConstructor(DocumentSource.class);
            return constr.newInstance(src);
        } catch (Exception e) {
            log.warn("BoxFactory: Warning: could not create the DOMSource instance: " + e.getMessage());
            return null;
        }
    }
1224016
@Override
  public Source create() throws InitializationFailedException {
    Source source = null;
    try {
      source = sourceClass.newInstance();
    } catch (InstantiationException e) {
      LOG.fatal("Creating source failed, " + SOURCE_CLASS_CONFIG_KEY + ": " + sourceClass, e);
      System.exit(0);
    } catch (IllegalAccessException e) {
      LOG.fatal("Creating source failed, " + SOURCE_CLASS_CONFIG_KEY + ": " + sourceClass, e);
      System.exit(0);
    }
    LOG.info("Initializing source...");
    source.init(config);
    LOG.info("Initializing source... DONE.");
    return source;
  }
430543
public ResourceHandler build() {
        if (resourceProviderFactory == null) {
            throw new IllegalStateException("No resourceProviderFactory has been set");
        }
        return new ResourceHandler(resourceProviderFactory, pathToServeFrom, defaultFile, extensionToResourceType);
    }
103536
public static DataSource create(DataSource ds, Log log) {
        if (ds == null) {
            throw new IllegalArgumentException();
        }
        if (log == null) {
            log = LogFactory.getLog(LoggingDataSource.class);
        }
        if (!log.isDebugEnabled()) {
            return ds;
        }
        return new LoggingDataSource(log, ds);
    }
978684
private Builder getResource(EntityOperation operation)
            throws ServiceException {
        return getResource(operation.getUri()).type(operation.getContentType())
                .accept(operation.getAcceptType());
    }
1062408
public static <K, V> QueuedKeyedResourcePool<K, V> create(ResourceFactory<K, V> factory,
                                                              ResourcePoolConfig config) {
        return new QueuedKeyedResourcePool<K, V>(factory, config);
    }