alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (Application.java)

This example Play Framework source code file (Application.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

application, classloader, configuration, file, inputstream, lib, library, play, play framework, t, url

The Application.java Play Framework example source code

/*
 * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 */
package play;

import java.io.*;
import java.util.*;
import java.net.*;

import play.libs.Scala;

/**
 * A Play application.
 * <p>
 * Application creation is handled by the framework engine.
 */
public class Application {
    
    private final play.api.Application application;
    
    public play.api.Application getWrappedApplication() {
      return application;
    }

    /**
     * Creates an application from a Scala Application value.
     */
    public Application(play.api.Application application) {
        this.application = application;
    }
    
    /**
     * Retrieves the application path.
     * <p>
     * @return the application path
     */
    public File path() {
        return application.path();
    }
    
    /**
     * Retrieves the application configuration/
     * <p>
     * @return the application path
     */
    public Configuration configuration() {
        return new Configuration(application.configuration());
    }
    
    /**
     * Retrieves the application classloader.
     * <p>
     * @return the application classloader
     */
    public ClassLoader classloader() {
        return application.classloader();
    }
    
    /**
     * Retrieves a file relative to the application root path.
     *
     * @param relativePath relative path of the file to fetch
     * @return a file instance - it is not guaranteed that the file exists
     */
    public File getFile(String relativePath) {
        return application.getFile(relativePath);
    }
    
    /**
     * Retrieves a resource from the classpath.
     *
     * @param relativePath relative path of the resource to fetch
     * @return URL to the resource (may be null)
     */
    public URL resource(String relativePath) {
        return Scala.orNull(application.resource(relativePath));
    }
    
    /**
     * Retrieves a resource stream from the classpath.
     *
     * @param relativePath relative path of the resource to fetch
     * @return InputStream to the resource (may be null)
     */
    public InputStream resourceAsStream(String relativePath) {
        return Scala.orNull(application.resourceAsStream(relativePath));
    }
    
    /**
     * Retrieve the plugin instance for the class.
     */
    public <T> T plugin(Class<T> pluginClass) {
        return Scala.orNull(application.plugin(pluginClass));
    }
    
    /**
     * Returns `true` if the application is `DEV` mode.
     */
    public boolean isDev() {
        return play.api.Play.isDev(application);
    }
    
    /**
     * Returns `true` if the application is `PROD` mode.
     */
    public boolean isProd() {
        return play.api.Play.isProd(application);
    }
    
    /**
     * Returns `true` if the application is `TEST` mode.
     */
    public boolean isTest() {
        return play.api.Play.isTest(application);
    }
    
}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework Application.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.