protected static SessionFactoryImplementor getSessionFactory(final String domain, final String sessionFactoryName) throws Exception { final SessionFactory sessionFactory = (SessionFactory) GlobalEnvironmentFactory.getEnvironmentFactory(domain).get( sessionFactoryName); if (sessionFactory instanceof SessionFactoryImplementor) { return (SessionFactoryImplementor) sessionFactory; } return null; }
/** * 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); }
@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; }
void initialize(final Object object, final Descriptor descriptor, final boolean isDelayable) { final InitializationType initializationType = getInitializationType(object, descriptor, isDelayable); if (initializationType == InitializationType.IMMEDIATE) { performInitialization(object, descriptor); } else if (initializationType == InitializationType.DELAYEBLE) { addPendingInitialization(object, descriptor); } else { final String objectName = descriptor.getName(); if (objectName != null) { set(objectName, object); } } }
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 get(String name, String[] searchOrder) { if (searchOrder == null) { searchOrder = getDefaultSearchOrder(); } for (int i = 0; i < searchOrder.length; i++) { Context context = contexts.get(searchOrder[i]); if (context.has(name)) { return context.get(name); } } return null; }
/** * 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); }
/** convenience method that wires the object for a given descriptor. */ public static Object create(final Descriptor descriptor) { final WireContext wireContext = new WireContext(); return wireContext.create(descriptor, false); }
public String getUserId() { // if the authenticated user was explicitely set if (userId != null) { // return that one return userId; } // if an Authentication was specified Authentication authentication = get(Authentication.class); if (authentication != null) { // let the authentication do the work return authentication.getUserId(); } return null; }
/** * Add or replace an entry in the environment to generate. * * @param name * name of the entry * @param classToUse * implementation * @return previous declaration for this name */ public String setApplicationEntry(final String name, final Class< ? > classToUse) { String xml = getObjectDecl(name, classToUse); return setApplicationEntry(name, xml); }
public EnvironmentNotFoundException(final String environmentSpecified) { super(getMessage(environmentSpecified)); this.environmentSpecified = environmentSpecified; }
public <T> T execute(Command<T> command) { Environment environment = environmentFactory.openEnvironment(); try { return next.execute(command); } finally { environment.close(); } }
@Override public Object get(final String key) { return environmentFactoryCtxWireContext.get(key); }
@Override public String toString() { final String objectName = initializable.getName(); return "PendingInitialization[" + (objectName != null ? objectName + "|" : "") + object + "]"; } }
public void setUndeployedPackageHandlerType(final Class< ? extends UndeployedPackageHandler>... undeployedPackageHandlerTypes) { this.undeployedPackageHandlerXml = "<chainer name='" + UndeployedPackageHandler.DEFAULT_KEY + "'>" + Misc.LINE_SEPARATOR; for (Class< ? extends UndeployedPackageHandler> undeployedPackageHandlerType : undeployedPackageHandlerTypes) { this.undeployedPackageHandlerXml += defaultIndent + getObjectDecl(undeployedPackageHandlerType) + Misc.LINE_SEPARATOR; } this.undeployedPackageHandlerXml += "</chainer>" + Misc.LINE_SEPARATOR; }
@Override public Set<String> keys() { return environmentFactoryCtxWireContext.keys(); }
@Override public void close() { environmentFactoryCtxWireContext.fire(WireContext.EVENT_CLOSE, null); }
InitializationType getInitializationType(final Object object, final Descriptor descriptor, final boolean isDelayable) { if (object == null) { return InitializationType.NONE; } if (isDelayable && descriptor.isDelayable()) { return InitializationType.DELAYEBLE; } return InitializationType.IMMEDIATE; }
/** * retrieves the object for the given objectName, ensuring it is constructed and initialized. * * @return the object found, or null if the object was not found. */ @Override public Object get(final String objectName) { return get(objectName, false); }