/** 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); }
@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; }
@Override public Object parseDocument(final Document document, final Parse parse) { final Element documentElement = document.getDocumentElement(); // if the default environment factory was already set in the parse PvmEnvironmentFactory pvmEnvironmentFactory = (PvmEnvironmentFactory) parse.getDocumentObject(); if (pvmEnvironmentFactory == null) { pvmEnvironmentFactory = new PvmEnvironmentFactory(); parse.setDocumentObject(pvmEnvironmentFactory); } final WireDefinition environmentFactoryWireDefinition = getApplicationWireDefinition(documentElement, parse); final WireDefinition environmentWireDefinition = getBlockWireDefinition(documentElement, parse); // create the application wire context from the definition final WireContext environmentFactoryWireContext = new WireContext(environmentFactoryWireDefinition, Context.CONTEXTNAME_ENVIRONMENT_FACTORY); // propagate the parser classloader to the application context environmentFactoryWireContext.setClassLoader(classLoader); // configure the default environment factory pvmEnvironmentFactory.setEnvironmentFactoryCtxWireContext(environmentFactoryWireContext); pvmEnvironmentFactory.setEnvironmentCtxWireDefinition(environmentWireDefinition); parse.setDocumentObject(pvmEnvironmentFactory); return pvmEnvironmentFactory; }