@Override public Object construct(final WireContext wireContext) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("looking up " + type + " by type in environment"); } if (type != null) { final Environment environment = Environment.getCurrent(); if (environment == null) { throw new WireException("no environment to search an object of type " + type.getName()); } return environment.get(type); } return null; }
static ClassLoader resolveClassLoader(ClassLoader classLoader) { // 1) if the user provided a classloader through the API, use that one if (classLoader != null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("using provided classloader"); } return classLoader; } // 2) if the user provided a classloader through the environment, use that // one Environment environment = Environment.getCurrent(); if (environment != null) { classLoader = environment.getClassLoader(); if (classLoader != null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("using environment classloader"); } return classLoader; } } // 3) otherwise, use the current thread's context classloader if (LOG.isLoggable(Level.FINE)) { LOG.fine("using context classloader"); } return Thread.currentThread().getContextClassLoader(); }
public static <T> T getFromCurrent(Class<T> type) { return getFromCurrent(type, true); }
public Object construct(WireContext wireContext) { if (contextName == null) { return wireContext; } Environment environment = Environment.getCurrent(); if (environment == null) { String message = ExceptionManager.getInstance().getFullMessage("bp_CRD_1", contextName); throw new WireException(message); } return environment.getContext(contextName); }
public Object construct(WireContext wireContext) { return Environment.getCurrent(); } }
@Override @SuppressWarnings("unchecked") public List<T> execute(final Environment environment) throws Exception { final Session session = (Session) environment.get(this.sessionName); final Query query = session.createQuery(this.query); if (stringParameters != null) { for (final Map.Entry<String, String> stringParameter : stringParameters.entrySet()) { query.setString(stringParameter.getKey(), stringParameter.getValue()); } } query.setCacheable(true); final List<T> result = new ArrayList<T>(); result.addAll(query.list()); return result; } }
/** * after opening of a new environment succeeded, the environment must be * pushed in the stack of current environments. * */ protected static synchronized void pushEnvironment(Environment environment) { Environment current = currentEnvironment.get(); if (current != null) { getStack().push(current); } currentEnvironment.set(environment); }
private void closeEnvironment(Environment environment) { try { if(environment != null) { environment.close(); } } catch(Exception e) { if(LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Impossible to open environment: ", e); } } }
public void close() { if (LOG.isLoggable(Level.FINE)) { LOG.fine("closing " + this); } Environment popped = Environment.popEnvironment(); if (this != popped) { String message = ExceptionManager.getInstance().getFullMessage("bp_BE_1"); throw new BonitaRuntimeException(message); } }
public static String getUserId() { final String userId = getEnv().getUserId(); if (userId == null) { final String message = ExceptionManager.getInstance().getMessage("bs_SET_3"); throw new BonitaRuntimeException(message); } return userId; }
protected static Environment getEnv() { final Environment environment = Environment.getCurrent(); Misc.badStateIfNull(environment, "Environment is null!"); return environment; }
protected static <T> T getEnvClass(final Class<T> clazz) { final Environment environment = getEnv(); final T object = environment.get(clazz); if (object == null) { final String message = ExceptionManager.getInstance().getFullMessage("be_EET_1", clazz.getName()); throw new BonitaRuntimeException(message); } return object; }
Environment environment = Environment.getCurrent(); if (environment != null) { try { wireContext = (WireContext) environment.getContext(contextName); if (wireContext == null) { String message = ExceptionManager.getInstance().getFullMessage(
/** * after opening of a new environment succeeded, the environment must be * pushed in the stack of current environments. * */ protected static synchronized void pushEnvironment(Environment environment) { Environment current = currentEnvironment.get(); if (current != null) { getStack().push(current); } currentEnvironment.set(environment); }
public <T> T execute(Command<T> command) { Environment environment = environmentFactory.openEnvironment(); try { return next.execute(command); } finally { environment.close(); } }
@Override public Environment openEnvironment() { final PvmEnvironment environment = new PvmEnvironment(this); if (LOG.isLoggable(Level.FINE)) { LOG.fine("opening " + environment); } // set the classloader final ClassLoader classLoader = environmentFactoryCtxWireContext.getClassLoader(); if (classLoader != null) { environment.setClassLoader(classLoader); } // add the environment-factory context environment.addContext(environmentFactoryCtxWireContext); // add the environment block context final WireContext environmentContext = new WireContext(environmentCtxWireDefinition, Context.CONTEXTNAME_ENVIRONMENT, true); // add the environment block context to the environment environment.addContext(environmentContext); try { // finish the creation of the environment wire context environmentContext.create(); } catch (final RuntimeException e) { // On exception, pop environment Environment.popEnvironment(); throw e; } // if all went well, return the created environment return environment; }
public boolean matches(String name, Object value) { boolean matches = false; Environment environment = Environment.getCurrent(); if (environment != null) { SessionFactory sessionFactory = null; if (hibernateSessionFactoryName != null) { sessionFactory = (SessionFactory) environment .get(hibernateSessionFactoryName); } else { sessionFactory = environment.get(SessionFactory.class); } if (sessionFactory != null) { ClassMetadata classMetadata = sessionFactory.getClassMetadata(value .getClass()); matches = ((classMetadata != null) && (classMetadata .getIdentifierType().getClass() == getIdType())); } } else { if (LOG.isLoggable(Level.FINE)) { LOG.fine("no current environment so valueClass cannot be stored as an id-ref to a hibernate object"); } matches = false; } return matches; }
static ClassLoader resolveClassLoader(ClassLoader classLoader) { // 1) if the user provided a classloader through the API, use that one if (classLoader != null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("using provided classloader"); } return classLoader; } // 2) if the user provided a classloader through the environment, use that // one Environment environment = Environment.getCurrent(); if (environment != null) { classLoader = environment.getClassLoader(); if (classLoader != null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("using environment classloader"); } return classLoader; } } // 3) otherwise, use the current thread's context classloader if (LOG.isLoggable(Level.FINE)) { LOG.fine("using context classloader"); } return Thread.currentThread().getContextClassLoader(); }
public <T> T execute(Command<T> command) { Environment environment = Environment.getCurrent(); try { return command.execute(environment); } catch (RuntimeException e) { if (LOG.isLoggable(Level.SEVERE)) { LOG.severe("exception while executing command " + command + ": " + e.getMessage()); } throw e; } catch (Exception e) { if (LOG.isLoggable(Level.SEVERE)) { LOG.severe("exception while executing command " + command + ": " + e.getMessage()); } String message = ExceptionManager.getInstance().getFullMessage("bp_DCS_1 ", command); throw new BonitaRuntimeException(message, e, DefaultCommandService.class.getName()); } } }
private void handleException(final Environment environment, final Job job, final Throwable exception) { final Transaction transaction = environment.get(Transaction.class); final JobExceptionHandler handler = new JobExceptionHandler(job.getId(), exception, this.eventExecutor.getCommandService()); transaction.registerSynchronization(handler); if (exception instanceof RuntimeException) { throw (RuntimeException) exception; } throw new BonitaRuntimeException("Execution of job (" + job + ") failed: " + exception.getMessage(), exception); }