private EndpointManagementService(TemplateManagementService templateManagementService) { this.templateManagementService = templateManagementService; this.modelFactory=RuntimeDelegate.getInstance().getModelFactory(); this.endpointRepository=RuntimeDelegate.getInstance().getEndpointRepository(); this.resourceRepository=RuntimeDelegate.getInstance().getResourceRepository(); this.listenerManager=ListenerManager.<EndpointLifecycleListener>newInstance(); }
private WriteSessionService(final TemplateManagementService templateManagementService, final EndpointManagementService endointManagementService) { this.templateManagementService = templateManagementService; this.endpointManagementService = endointManagementService; this.resourceRepository=RuntimeDelegate.getInstance().getResourceRepository(); this.transactionManager=RuntimeDelegate.getInstance().getTransactionManager(); }
private static RuntimeDelegate createRuntimeInstanceFromConfigurationFile() { RuntimeDelegate result=null; File configFile = getConfigurationFile(); if(configFile.canRead()) { InputStream is=null; try { is=new FileInputStream(configFile); Properties configProperties=new Properties(); configProperties.load(is); String delegateClassName=configProperties.getProperty(LDP4J_APPLICATION_SPI_PROPERTY); if(delegateClassName!=null) { result=createRuntimeInstanceForClassName(delegateClassName); } if(delegateClassName==null && LOGGER.isWarnEnabled()) { LOGGER.warn("Configuration file '"+configFile.getAbsolutePath()+"' does not define a delegate class name"); } } catch(FileNotFoundException e) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("Could not find runtime instance configuration file '"+configFile.getAbsolutePath()+"'",e); } } catch(IOException e) { if(LOGGER.isWarnEnabled()) { LOGGER.warn("Could not load runtime instance configuration file '"+configFile.getAbsolutePath()+"'",e); } } finally { closeQuietly(is, "Could not close configuration properties"); } } return result; }
private ApplicationContextOperationController() { this.transactionManager = RuntimeDelegate.getInstance().getTransactionManager(); }
private <T extends Resource> T publishResource(Class<? extends T> clazz, String templateId, Name<?> resourceName, String path) { Transaction transaction = RuntimeDelegate.getInstance().getTransactionManager().currentTransaction(); transaction.begin(); Resource newResource=this.modelFactory.createResource(this.tms.templateOfId(templateId),resourceName); T resource=clazz.cast(newResource); RuntimeDelegate.getInstance().getResourceRepository().add(resource); Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); transaction.commit(); return resource; }
DefaultApplicationContext(DefaultApplicationEngine engine) { this.engine=engine; this.resourceRepository=RuntimeDelegate.getInstance().getResourceRepository(); this.endpointRepository=RuntimeDelegate.getInstance().getEndpointRepository(); this.constraintReportRepository=RuntimeDelegate.getInstance().getConstraintReportRepository(); this.factory=DefaultPublicResourceFactory.newInstance(this); this.operationController=new ApplicationContextOperationController(); this.currentOperation=new ThreadLocal<DefaultApplicationOperation>(); }
private ApplicationLoader(Class<? extends Application<T>> appClass) { this.appClass=appClass; RuntimeDelegate instance = RuntimeDelegate.getInstance(); this.transactionManager=instance.getTransactionManager(); this.modelFactory=instance.getModelFactory(); ServiceRegistry serviceRegistry=ServiceRegistry.getInstance(); this.writeSessionService=serviceRegistry.getService(WriteSessionService.class); this.templateManagementService=serviceRegistry.getService(TemplateManagementService.class); }
private void setup(Application<T> application) throws ApplicationConfigurationException { BootstrapImpl<T> bootstrap= new BootstrapImpl<T>( this.configuration, templateManagementService()); this.lifecycleEnvironment=new DefaultLifecycleEnvironment(); EnvironmentImpl environment= new EnvironmentImpl( templateManagementService(), resourceFactory(), RuntimeDelegate.getInstance().getEndpointRepository(), RuntimeDelegate.getInstance().getResourceRepository(), lifecycleEnvironment ); try { application.setup(environment,bootstrap); bootstrap.configureTemplates(); environment.configureRootResources(); } catch (ApplicationSetupException e) { throw new ApplicationConfigurationException(e); } }
@Before public void setUp() throws Exception { ServiceRegistry.setInstance(null); RuntimeDelegate.setInstance(new InMemoryRuntimeDelegate()); this.templateManagementService = ServiceRegistry. getInstance(). getService(TemplateManagementService.class); this.templateManagementService. configure( Lists.<Class<?>>newArrayList(), Arrays.<ResourceHandler>asList(new PersonHandler())); this.modelFactory= RuntimeDelegate. getInstance(). getModelFactory(); this.writeSessionService= ServiceRegistry. getInstance(). getService(WriteSessionService.class); }
private final RuntimeDelegate runtimeDelegate() { if(this.runtimeDelegate!=null) { return this.runtimeDelegate; } else { return RuntimeDelegate.getInstance(); } }
private Endpoint endpoint(Resource resource) { EndpointRepository er = RuntimeDelegate.getInstance().getEndpointRepository(); Endpoint endpoint = er.endpointOfResource(resource.id()); return endpoint; }
@Before public void setUp() throws Exception { this.sut = ServiceRegistry. getInstance(). getService(ResourceControllerService.class); this.tms = ServiceRegistry. getInstance(). getService(TemplateManagementService.class); this.modelFactory= RuntimeDelegate. getInstance(). getModelFactory(); }
@After public void tearDown() throws Exception { RuntimeDelegate.setInstance(null); }
/** * Obtain a {@code RuntimeInstance} instance using the method described in * {@link #getInstance}. * * @return an instance of {@code RuntimeInstance}. */ private static RuntimeDelegate findDelegate() { try { RuntimeDelegate result=createRuntimeInstanceFromSPI(); if(result==null) { result=createRuntimeInstanceFromConfigurationFile(); } if(result==null) { String delegateClassName = System.getProperty(LDP4J_APPLICATION_SPI_PROPERTY); if(delegateClassName!=null) { result=createRuntimeInstanceForClassName(delegateClassName); } } if(result==null) { result=new DefaultRuntimeInstance(); } return result; } catch (Exception ex) { throw new IllegalStateException("Could not find runtime delegate",ex); } }
protected final ModelFactory modelFactory() { if(this.modelFactory==null) { this.modelFactory=runtimeDelegate().getModelFactory(); } return this.modelFactory; }
private void setRuntimeManager(RuntimeDelegate runtimeDelegate) { this.runtimeDelegate=checkNotNull(runtimeDelegate,"Resource factory cannot be null"); this.transactionManager=runtimeDelegate.getTransactionManager(); }
private Resource initialize(final String id, final String path) { final Transaction transaction= RuntimeDelegate. getInstance(). getTransactionManager(). currentTransaction(); transaction.begin(); try { this.uow = UnitOfWork.newCurrent(); final Resource resource= this.modelFactory.createResource( this.templateManagementService.templateOfId("personTemplate"), name(id)); final Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getResourceRepository().add(resource); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); UnitOfWork.setCurrent(null); transaction.commit(); return resource; } finally { if(transaction.isActive()) { transaction.rollback(); } } }
public <T> T transactional(Callable<T> callable) throws Exception { Transaction transaction = RuntimeDelegate.getInstance().getTransactionManager().currentTransaction(); transaction.begin(); try { return callable.call(); } catch(Exception e) { e.printStackTrace(); throw e; } finally { try { assertThat(transaction.isActive(),equalTo(false)); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); } } }
public ServiceRegistry() { this.services=MutableClassToInstanceMap.<Service>create(); this.builders=new LinkedHashMap<Class<?>, ServiceBuilder<?>>(); this.delegate=RuntimeDelegate.getInstance(); }
@AfterClass public static void tearDownAfter() throws Exception { RuntimeDelegate.setInstance(null); }