public void addDescriptor(Descriptor descriptor) { if (descriptor != null) { String name = descriptor.getName(); if (useTypes) { Class<?> type = descriptor.getType(this); if (type != null) { if ((name == null) && (descriptor instanceof AbstractDescriptor)) { name = type.getName(); ((AbstractDescriptor) descriptor).setName(type.getName()); } if ((name != null) && ((descriptors == null) || (!descriptors.containsKey(name)))) { // add all superclasses and interfaces to map to this descriptor addDescriptorType(type, descriptor, name); } } } if ((name != null) && (!hasDescriptor(name))) { putDescriptor(name, descriptor); if (descriptor.isEagerInit()) { addEagerInitObjectName(name); } } } }
/** * when this {@link Context} is used in an {@link Environment}, it needs a name. */ public WireContext(final WireDefinition wireDefinition, final String name) { super(); this.wireDefinition = wireDefinition; this.name = name; classLoader = wireDefinition != null ? wireDefinition.getClassLoader() : null; create(); }
/** * creates a new object for the given objectName as defined in the {@link #wireDefinition}. * * @param isDelayable * indicates wether initialization is delayable. When isDelayable is set to false the returned object will be * constructed and initialized. When isDelayable is set to true, the returned object will be constructed, but * not necessarily initialized. */ protected Object create(final String objectName, final boolean isDelayable) { final Descriptor descriptor = wireDefinition.getDescriptor(objectName); return create(descriptor, isDelayable); }
/** * This method builds the WireDefinition from the DOM tree. This methods parses all child nodes of the documentElement * that correspond to a Descriptor definition. * * @param documentElement * the root element of the document * @param parse * Parse object that contains all information for the current parse operation. * @return an instance of WireDefinition containing the resulting WireDefinition. * @see Parser#parseDocumentElement(Element, Parse) */ @Override public Object parseDocumentElement(final Element documentElement, final Parse parse) { final List<Element> elements = XmlUtil.elements(documentElement); final WireDefinition wireDefinition = new WireDefinition(); wireDefinition.setClassLoader(classLoader); if (elements != null) { parse.pushObject(wireDefinition); try { for (final Element descriptorElement : elements) { parseElement(descriptorElement, parse, CATEGORY_DESCRIPTOR); } } finally { parse.popObject(); } } return wireDefinition; }
/** * Initializes all the eager objects defined in the {@link #wireDefinition}. */ void initializeEagerObjects() { if (wireDefinition != null) { final List<String> eagerInitObjectNames = wireDefinition.getEagerInitNames(); if (eagerInitObjectNames != null) { for (final String eagerInitObjectName : eagerInitObjectNames) { final Descriptor descriptor = wireDefinition.getDescriptor(eagerInitObjectName); if (descriptor.isEagerInit()) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("eagerly initializing " + eagerInitObjectName); } get(eagerInitObjectName, descriptor.isDelayable()); } } while (!hasObjectUnderConstruction() && !hasObjectUnderInitialization() && hasPendingInitializations()) { processPendingInitializations(); } } } }
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; }
Descriptor descriptor = wireDefinition.getDescriptor(objectName); subscribe(listener, descriptor); .getDescriptors().values()); for (Descriptor descriptor : descriptors) { subscribe(listener, descriptor);
@Override public PvmEnvironmentFactory parseDocument(final Document document, final Parse parse) { // Default parsing final PvmEnvironmentFactory defaultEnvironmentFactory = (PvmEnvironmentFactory) super.parseDocument(document, parse); // Add authentication descriptor to application block final ObjectDescriptor authenticationDescriptor = new ObjectDescriptor(); authenticationDescriptor.setClassName(Authentication.class.getName()); defaultEnvironmentFactory.getEnvironmentFactoryCtxWireContext().getWireDefinition().addDescriptor(authenticationDescriptor); return defaultEnvironmentFactory; }
/** * checks if the given objectName is defined, either by means of a descriptor or by an explicit * {@link #set(String, Object)}. */ @Override public boolean has(final String objectName) { return hasCached(objectName) || (wireDefinition != null ? wireDefinition.hasDescriptor(objectName) : false); }
/** * the list of object names defined in this context. This means the union of the object names that are defined in the * {@link #wireDefinition} and the objects that are just {@link #set(String, Object)}. If there are no keys, an empty * set will be returned. */ @Override public Set<String> keys() { final Set<String> keys = new HashSet<String>(); if (cache != null) { keys.addAll(cache.keySet()); } if (wireDefinition != null) { final Map<String, Descriptor> descriptors = wireDefinition.getDescriptors(); if (descriptors != null) { keys.addAll(descriptors.keySet()); } } return keys; }
void addDescriptorType(Class<?> type, Descriptor descriptor, String descriptorName) { if (type != null) { if (descriptorNames == null) { descriptorNames = new HashMap<Class<?>, String>(); } if (!descriptorNames.containsKey(type)) { descriptorNames.put(type, descriptorName); } addDescriptorType(type.getSuperclass(), descriptor, descriptorName); Class<?>[] interfaceTypes = type.getInterfaces(); if (interfaceTypes != null) { for (Class<?> interfaceType : interfaceTypes) { addDescriptorType(interfaceType, descriptor, descriptorName); } } } }
/** * searches for the first descriptor that defines an object of the given type. In case of multiple objects of the same * type, the first object that is declared of the given type will be found. Also super classes and interfaces are * taken into account. Not all descriptor types will be type sensitive, only: * * <pre> * | ObjectDescriptor | object | * | HibernatePersistenceServiceDescriptor | business-calendar | * | TransactionDescriptor | transaction | * | PropertiesDescriptor | properties | * | BusinessCalendarDescriptor | business-calendar | * </ul> * </pre> */ @Override @SuppressWarnings("unchecked") public <T> T get(final Class<T> type) { if (wireDefinition != null) { final String name = wireDefinition.getDescriptorName(type); if (name != null) { return (T) get(name); } } return null; }
wireDefinition.addDescriptor(descriptor);
if (wireDefinition.hasDescriptor(objectName)) {
/** fires a {@link WireObjectEventInfo}. */ protected void fireObjectEvent(final String eventName, final String objectName, final Object object) { WireObjectEventInfo wireEvent = null; // first fire the event on the descriptor for object specific listeners if (wireDefinition != null) { final Map<String, Descriptor> descriptors = wireDefinition.getDescriptors(); if (descriptors != null) { final Descriptor descriptor = descriptors.get(objectName); if (descriptor != null) { wireEvent = new WireObjectEventInfo(eventName, objectName, object); descriptor.fire(eventName, wireEvent); } } } // then fire the event on this wiring environment for global listeners if (listeners != null && wireEvent == null) { wireEvent = new WireObjectEventInfo(eventName, objectName, object); } fire(eventName, wireEvent); }
/** * allows for postponing the creation of this wire context. * * @param delayCreate * specifies if creation should be postponed till {@link #create()} is called explicitly. If delayCreate is * set to false, creation is done as part of the constructor. If delayCreate is set to true, the * {@link #create()} method needs to be called explicitly by the client after construction is complete. The * use case is creation of environment where the transactionName needs to be set and the scope needs to be * added to the environment before the creation of this wire scope is done. * @see PvmEnvironmentFactory#openEnvironment() */ public WireContext(final WireDefinition wireDefinition, final String name, final boolean delayCreate) { super(); this.wireDefinition = wireDefinition; this.name = name; classLoader = wireDefinition != null ? wireDefinition.getClassLoader() : null; if (!delayCreate) { create(); } }
@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; }