@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; }
@Override public Object construct(final WireContext wireContext) { try { final InitialContext initialContext = new InitialContext(); return initialContext.lookup(jndiName); } catch (final NamingException e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_JD_1", jndiName); throw new WireException(message); } }
public Object construct(WireContext wireContext) { try { return new URL(text); } catch (Exception e) { String message = ExceptionManager.getInstance().getFullMessage("bp_UD_1", text); throw new WireException(message, e); } }
public Object construct(WireContext wireContext) { Session session = null; if (sessionName != null) { session = (Session) wireContext.get(sessionName); if (session == null) { throw new WireException("Could not find a session with name: " + sessionName); } } else { session = wireContext.get(Session.class); if (session == null) { throw new WireException("No object ob type Session found in environment"); } } return getDbSessionObject(session); }
@Override @SuppressWarnings("unchecked") public void initialize(final Object object, final WireContext wireContext) { final Collection<Object> collection = (Collection<Object>) object; try { if (valueDescriptors != null) { for (final Descriptor descriptor : valueDescriptors) { final Object element = wireContext.create(descriptor, true); if (LOG.isLoggable(Level.FINE)) { LOG.fine("adding element " + element + " to collection"); } collection.add(element); } } } catch (final WireException e) { throw e; } catch (final Exception e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_CollD_2", name != null ? name : className); throw new WireException(message, e); } }
/** * adds an object to this context, which means storing it in the cache. This doesn't have to be an object that is * defined by the {@link WireDefinition}. If an object is set under a certain objectName that also is associated with * a descriptor, the object provided in this set invocation will be delivered upon subsequent {@link #get(String)} * requests. * * @return previous value of the object with the name objectName in the {@link #cache} * @throws WireException * when the objectName is null */ @Override public synchronized Object set(final String objectName, final Object object) { if (objectName == null) { final String message = ExceptionManager.getInstance().getFullMessage("bp_WC_1"); throw new WireException(message); } if (cache == null) { cache = new HashMap<String, Object>(); } fireObjectEvent(Descriptor.EVENT_SET, objectName, object); return cache.put(objectName, object); }
@SuppressWarnings("unchecked") public void initialize(Object object, WireContext wireContext) { Map<Object, Object> map = (Map<Object, Object>) object; try { if (keyDescriptors != null) { for (int i = 0; i < keyDescriptors.size(); i++) { Descriptor keyDescriptor = keyDescriptors.get(i); Descriptor valueDescriptor = valueDescriptors.get(i); Object key = wireContext.create(keyDescriptor, true); Object value = wireContext.create(valueDescriptor, true); map.put(key, value); } } } catch (WireException e) { throw e; } catch (Exception e) { String message = ExceptionManager.getInstance().getFullMessage( "bp_MD_1", (name != null ? name : className)); throw new WireException(message, e); } }
throw new WireException(message, e);
/** * @throws WireException * if this operation is applied on an object which is not a resource * or if the specified transaction cannot be found. */ public void apply(Object target, WireContext wireContext) { if (!(target instanceof StandardResource)) { String message = ExceptionManager.getInstance().getFullMessage( "bp_EO_1", StandardResource.class.getName(), target, (target != null ? " (" + target.getClass().getName() + ")" : "")); throw new WireException(message); } Object object = null; if (transactionName != null) { object = wireContext.get(transactionName); } else { object = wireContext.get(Transaction.class); } if ((object == null) || (!(object instanceof StandardTransaction))) { String message = ExceptionManager.getInstance().getFullMessage( "bp_EO_2", StandardTransaction.class.getName(), (transactionName != null ? "'" + transactionName + "'" : "by type"), target); throw new WireException(message); } StandardTransaction standardTransaction = (StandardTransaction) object; if (LOG.isLoggable(Level.FINE)) { LOG.fine("enlisting resource " + target + " with transaction"); } standardTransaction.enlistResource((StandardResource) target); }
public void event(Object source, String eventName, Object info) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("invoking " + methodName + " on " + target + " for event " + eventName); } try { Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors); Class<?> clazz = target.getClass(); Method method = ReflectUtilDescriptor.findMethod(clazz, methodName, argDescriptors, args); if (method == null) { String message = ExceptionManager.getInstance().getFullMessage( "bp_MIL_1", ReflectUtilDescriptor.getSignature(methodName, argDescriptors, args), target); throw new WireException(message); } ReflectUtil.invoke(method, target, args); } catch (WireException e) { throw e; } catch (Exception e) { String message = ExceptionManager.getInstance().getFullMessage( "bp_MIL_2", methodName, e.getMessage()); throw new WireException(message, e); } } }
public void apply(Object target, WireContext wireContext) { try { Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors); Class<?> clazz = target.getClass(); Method method = ReflectUtilDescriptor.findMethod(clazz, methodName, argDescriptors, args); if (method == null) { String message = ExceptionManager.getInstance().getFullMessage( "bp_IO_1", ReflectUtilDescriptor.getSignature(methodName, argDescriptors, args)); throw new WireException(message); } ReflectUtil.invoke(method, target, args); } catch (WireException e) { throw e; } catch (Exception e) { String message = ExceptionManager.getInstance().getFullMessage( "bp_IO_2", methodName, e.getMessage()); throw new WireException(message, e); } }
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); }
/** * loads the class from the class loader of the specified WireContext. * * @throws WireException * if the class could not be loaded. */ public Object construct(WireContext wireContext) { ClassLoader classLoader = wireContext.getClassLoader(); try { return ReflectUtil.loadClass(classLoader, text); } catch (BonitaRuntimeException e) { Throwable cause = e.getCause(); String message = ExceptionManager.getInstance().getFullMessage( "bp_CD_1", text, cause.getMessage()); throw new WireException(message, cause); } }
final String message = ExceptionManager.getInstance().getFullMessage("bp_CollD_1", name != null ? name : className, e.getMessage()); throw new WireException(message, e);
public void apply(Object target, WireContext wireContext) { // create the value to assign to the property Object value = wireContext.create(descriptor, true); Method method = null; Class<?> clazz = target.getClass(); Object[] args = new Object[] { value }; method = ReflectUtilDescriptor.findMethod(clazz, setterName, null, args); if (method == null) { String message = ExceptionManager.getInstance().getFullMessage( "bp_PO_1", setterName, value); throw new WireException(message); } ReflectUtil.invoke(method, target, args); }
/** * Initializes the specified object. If auto-wiring was set to * <code>true</code>, auto-wiring is performed (see * {@link #autoWire(Object, WireContext)}). Fields and properties injections * are then performed. * */ public void initialize(Object object, WireContext wireContext) { try { // specified operations takes precedence over auto-wiring. // e.g. in case there is a collision between // a field or property injection and an autowired value, // the field or property injections should win. // That is why autowiring is done first if (isAutoWireEnabled) { autoWire(object, wireContext); } if (operations != null) { for (Operation operation : operations) { operation.apply(object, wireContext); } } } catch (Exception e) { String message = ExceptionManager.getInstance().getMessage( "bp_OD_9", (name != null ? name : className), e.getMessage()); throw new WireException(message, e); } }
@Override public void apply(final Object target, final WireContext wireContext) { if (target != null) { // Get field synchronized (this) { if (field == null) { final Class<?> clazz = target.getClass(); field = ReflectUtil.getField(clazz, fieldName); } } // Create value final Object value = wireContext.create(descriptor, true); // Set the field value try { ReflectUtil.set(field, target, value); } catch (final Exception e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_FO_1", fieldName, value); throw new WireException(message, e); } } }
@Override public Class<?> getType(final WireDefinition wireDefinition) { if (className != null) { try { return ReflectUtil.loadClass(wireDefinition.getClassLoader(), className); } catch (final BonitaRuntimeException e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_HCD_1", className, e.getMessage()); throw new WireException(message, e.getCause()); } } return Configuration.class; }
public Class<?> getType(WireDefinition wireDefinition) { if (className != null) { try { return ReflectUtil .loadClass(wireDefinition.getClassLoader(), className); } catch (BonitaRuntimeException e) { String message = ExceptionManager.getInstance().getFullMessage( "bp_OD_10", (name != null ? name : className), e.getMessage()); throw new WireException(message, e .getCause()); } } Descriptor descriptor = null; if (factoryDescriptor != null) { descriptor = factoryDescriptor; } else if (factoryObjectName != null) { descriptor = wireDefinition.getDescriptor(factoryObjectName); } if (descriptor != null) { Class<?> factoryClass = descriptor.getType(wireDefinition); if (factoryClass != null) { Method method = ReflectUtilDescriptor.findMethod(factoryClass, methodName, argDescriptors, null); if (method != null) { return method.getReturnType(); } } } return null; }
@Override public Object construct(final WireContext wireContext) { Configuration configuration = null; if (configurationName != null) { configuration = (Configuration) wireContext.get(configurationName); } else if (configurationDescriptor != null) { configuration = (Configuration) wireContext.create(configurationDescriptor, false); } else { configuration = wireContext.get(Configuration.class); } if (configuration == null) { final String message = ExceptionManager.getInstance().getFullMessage("bp_HSF_1"); throw new WireException(message); } SearchUtil.addSearchConfiguration(configuration); addInterceptor(configuration); final SessionFactory sessionFactory = configuration.buildSessionFactory(); wireContext.addListener(new SessionFactoryCloser(sessionFactory)); return sessionFactory; }