@Nullable public static Configuration load(final InputStream is) throws IOException, JDOMException { try { final Document document = JDOMUtil.loadDocument(is); final ArrayList<Element> elements = new ArrayList<Element>(); final Element rootElement = document.getRootElement(); final Element state; if (rootElement.getName().equals(COMPONENT_NAME)) { state = rootElement; } else { elements.add(rootElement); //noinspection unchecked elements.addAll(rootElement.getChildren("component")); state = ContainerUtil.find( elements, new Condition<Element>() { public boolean value(final Element element) { return "component".equals(element.getName()) && COMPONENT_NAME.equals(element.getAttributeValue("name")); } }); } if (state != null) { final Configuration cfg = new Configuration(); cfg.loadState(state); return cfg; } return null; } finally { is.close(); } }
public boolean replaceInjections( List<? extends BaseInjection> newInjections, List<? extends BaseInjection> originalInjections, boolean forceLevel) { if (!forceLevel && !originalInjections.isEmpty()) { if (myParentConfiguration.replaceInjections( Collections.<BaseInjection>emptyList(), originalInjections, forceLevel)) { myParentConfiguration.replaceInjections( newInjections, Collections.<BaseInjection>emptyList(), forceLevel); return true; } } return super.replaceInjections(newInjections, originalInjections, forceLevel); }
private static List<BaseInjection> loadDefaultInjections() { final ArrayList<Configuration> cfgList = new ArrayList<Configuration>(); final THashSet<Object> visited = new THashSet<Object>(); for (LanguageInjectionConfigBean configBean : Extensions.getExtensions(LanguageInjectionSupport.CONFIG_EP_NAME)) { PluginDescriptor descriptor = configBean.getPluginDescriptor(); final ClassLoader loader = descriptor.getPluginClassLoader(); try { final Enumeration<URL> enumeration = loader.getResources(configBean.getConfigUrl()); if (enumeration == null || !enumeration.hasMoreElements()) { LOG.warn(descriptor.getPluginId() + ": " + configBean.getConfigUrl() + " was not found"); } else { while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); if (!visited.add(url.getFile())) continue; // for DEBUG mode try { cfgList.add(load(url.openStream())); } catch (Exception e) { LOG.warn(e); } } } } catch (Exception e) { LOG.warn(e); } } final ArrayList<BaseInjection> defaultInjections = new ArrayList<BaseInjection>(); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { for (Configuration cfg : cfgList) { final List<BaseInjection> imported = cfg.getInjections(supportId); defaultInjections.addAll(imported); } } return defaultInjections; }
@Override public void loadState(final Element element) { myAdvancedConfiguration.loadState(element); super.loadState(element); }
@Override public long getModificationCount() { return super.getModificationCount() + myParentConfiguration.getModificationCount(); }
@NotNull @Override public List<BaseInjection> getInjections(final String injectorId) { return ContainerUtil.concat( myParentConfiguration.getInjections(injectorId), getOwnInjections(injectorId)); }
@Override public List<BaseInjection> getDefaultInjections() { return myParentConfiguration.getDefaultInjections(); }
@Override public AdvancedConfiguration getAdvancedConfiguration() { return myParentConfiguration.getAdvancedConfiguration(); }