112 lines
2.8 KiB
Java
112 lines
2.8 KiB
Java
package org.gcube.smartgears.context.application;
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
import org.gcube.common.events.Hub;
|
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
|
import org.gcube.smartgears.context.Properties;
|
|
import org.gcube.smartgears.context.container.ContainerContext;
|
|
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
|
|
|
/**
|
|
* Default {@link ApplicationContext} implementation.
|
|
*
|
|
* @author Fabio Simeoni
|
|
*
|
|
*/
|
|
public class DefaultApplicationContext implements ApplicationContext {
|
|
|
|
private final ContainerContext container;
|
|
private final ServletContext sctx;
|
|
private final ApplicationConfiguration configuration;
|
|
private final ApplicationLifecycle lifecycle;
|
|
private final Properties properties;
|
|
private final Hub hub;
|
|
private final String id;
|
|
|
|
/**
|
|
* Crates an intance with mandatory parameters
|
|
* @param container the container context
|
|
* @param sctx the servlet context
|
|
* @param configuration the configuration
|
|
* @param hub the event hub
|
|
* @param lifecycle the lifecycle
|
|
* @param properties the properties
|
|
*/
|
|
public DefaultApplicationContext(String id,ContainerContext container,ServletContext sctx,ApplicationConfiguration configuration, Hub hub, ApplicationLifecycle lifecycle, Properties properties) {
|
|
this.id = id;
|
|
this.container=container;
|
|
this.sctx = sctx;
|
|
this.configuration=configuration;
|
|
this.hub=hub;
|
|
this.lifecycle = lifecycle;
|
|
this.properties=properties;
|
|
}
|
|
|
|
/**
|
|
* Creates an instance by copying the configuration of another.
|
|
* @param context the other instance
|
|
*/
|
|
public DefaultApplicationContext(ApplicationContext context) {
|
|
this(context.id(), context.container(),context.application(),context.configuration(),context.events(), context.lifecycle(), new Properties(context.properties()));
|
|
}
|
|
|
|
@Override
|
|
public ServletContext application() {
|
|
return sctx;
|
|
}
|
|
|
|
@Override
|
|
public ContainerContext container() {
|
|
return container;
|
|
}
|
|
|
|
@Override
|
|
public String name() { //little shortcut for ease of logging
|
|
return configuration.name();
|
|
}
|
|
|
|
@Override
|
|
public ApplicationConfiguration configuration() {
|
|
return configuration;
|
|
}
|
|
|
|
@Override
|
|
public ApplicationLifecycle lifecycle() {
|
|
return lifecycle;
|
|
}
|
|
|
|
@Override
|
|
public Hub events() {
|
|
return hub;
|
|
}
|
|
|
|
@Override
|
|
public PersistenceWriter persistence() {
|
|
return configuration.persistence();
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public Properties properties() {
|
|
return properties;
|
|
}
|
|
|
|
@Override
|
|
public String id() {
|
|
return id;
|
|
}
|
|
|
|
/**
|
|
* Returns the authorization provider.
|
|
* @return the AuhtorizationProvider
|
|
**/
|
|
public AuthorizationProvider authorizationProvider() {
|
|
return container().authorizationProvider();
|
|
}
|
|
|
|
}
|