List of usage examples for org.springframework.context.support AbstractApplicationContext addApplicationListener
@Override
public void addApplicationListener(ApplicationListener<?> listener)
From source file:com.brienwheeler.apps.main.ContextMain.java
private List<AbstractApplicationContext> findOrLaunchContext(String contextSpecList) { // check to see if we've already figured this out List<AbstractApplicationContext> resultingContexts = contextAliasMap.get(contextSpecList); if (resultingContexts != null) return resultingContexts; // circular dependency detection if (contextsResolving.contains(contextSpecList)) throw new ResourceMapError("circular dependency: " + contextSpecList); String originalContextSpecList = contextSpecList; contextsResolving.add(originalContextSpecList); try {/* w ww. j av a 2 s .co m*/ // create container for eventual results resultingContexts = new ArrayList<AbstractApplicationContext>(); // first check to see if it has a properties prefix and process/strip it from spec string // do this before looking for comma separated list below so that a comma-separated list // within the properties prefix gets handled correctly if (contextSpecList.startsWith(PROPSPEC_PREFIX)) { int specEnd = contextSpecList.indexOf(PROPSPEC_SUFFIX); if (specEnd == -1) throw new ResourceMapError("unterminated property spec in " + contextSpecList); String propertySpecList = contextSpecList.substring(PROPSPEC_PREFIX.length(), specEnd); contextSpecList = contextSpecList.substring(specEnd + PROPSPEC_SUFFIX.length()).trim(); loadPropertySpec(propertySpecList); } // if the list has more than one spec string, split then recurse for first spec and remaining spec list int comma = contextSpecList.indexOf(","); if (comma != -1) { String currentSpec = contextSpecList.substring(0, comma).trim(); resultingContexts.addAll(findOrLaunchContext(currentSpec)); String remainingSpecList = contextSpecList.substring(comma + 1).trim(); resultingContexts.addAll(findOrLaunchContext(remainingSpecList)); contextAliasMap.put(contextSpecList, resultingContexts); return resultingContexts; } // be robust against a properties spec with no context -- user might do something like this: // properties[props1],context1,properties[props2],context2 // in any case, an empty contextSpecList implies no further action if (contextSpecList.isEmpty()) { return resultingContexts; } // ok, contextSpecList has just one spec string in it. Possibly alias or location. // check context map and recurse if present if (contextMap != null) { String resolvedSpecList = contextMap.getProperty(contextSpecList); if (resolvedSpecList != null) { resultingContexts.addAll(findOrLaunchContext(resolvedSpecList)); contextAliasMap.put(contextSpecList, resultingContexts); return resultingContexts; } } // not an alias, must be a location at this point AbstractApplicationContext context = new SmartClassPathXmlApplicationContext(contextSpecList); synchronized (contextLaunchOrder) { // this allows a context to close itself during its startup (schematool does this) if (context.isActive()) contextLaunchOrder.add(context); context.addApplicationListener(this); } resultingContexts.add(context); contextAliasMap.put(contextSpecList, resultingContexts); return resultingContexts; } finally { contextsResolving.remove(originalContextSpecList); } }