@Override public synchronized void removeContribution(NegotiationDescriptor contrib) { removeContribution(contrib, true); }
@Override public void activate(ComponentContext context) { super.activate(context); pageReg = new PageRegistry(); flavorReg = new FlavorRegistry(); negReg = new NegotiationRegistry(); }
@Override public String negotiate(String target, Object context) { String res = null; NegotiationDescriptor negd = negReg.getNegotiation(target); if (negd != null) { List<NegotiatorDescriptor> nds = negd.getNegotiators(); for (NegotiatorDescriptor nd : nds) { Class<Negotiator> ndc = nd.getNegotiatorClass(); try { Negotiator neg = ndc.newInstance(); neg.setProperties(nd.getProperties()); res = neg.getResult(target, context); if (res != null) { break; } } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException(e); } } } return res; }
NegotiationDescriptor neg = (NegotiationDescriptor) contribution; log.info(String.format("Register negotiation for '%s'", neg.getTarget())); negReg.addContribution(neg); log.info(String.format("Done registering negotiation for '%s'", neg.getTarget())); } else {
@Override public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { if (contribution instanceof FlavorDescriptor) { FlavorDescriptor flavor = (FlavorDescriptor) contribution; flavorReg.removeContribution(flavor); } else if (contribution instanceof Resource) { Resource resource = (Resource) contribution; unregisterResource(resource); } else if (contribution instanceof SimpleStyle) { SimpleStyle style = (SimpleStyle) contribution; unregisterResource(getResourceFromStyle(style)); } else if (contribution instanceof PageDescriptor) { PageDescriptor page = (PageDescriptor) contribution; if (page.hasResources()) { WebResourceManager wrm = Framework.getService(WebResourceManager.class); wrm.unregisterResourceBundle(page.getComputedResourceBundle()); } pageReg.removeContribution(page); } else if (contribution instanceof NegotiationDescriptor) { NegotiationDescriptor neg = (NegotiationDescriptor) contribution; negReg.removeContribution(neg); } else { log.error(String.format( "Unknown contribution to the theme " + "styling service, extension point '%s': '%s", extensionPoint, contribution)); } }