@Override public void initialize(Parameters params) throws ResourceInitializationException { super.initialize(params); try { model = Model.load(((ResourceReader) params.get(Constants.MODEL)).getReader()); } catch (IOException e) { throw new ResourceInitializationException("Failed to load SVM model.", e); } labelIndeces = new int[labels.size()]; labelIndeces = model.getLabels(); representer = (TextRepresenter) params.get(Constants.REPRESENTER); }
protected MMObjectNode getGroupOrUserNode(Parameters a) { MMObjectNode groupOrUser = getNode(a.getString(PARAMETER_GROUPORUSER)); if (groupOrUser == null) throw new IllegalArgumentException( "There is no node with id '" + a.get(PARAMETER_GROUPORUSER) + "'"); MMObjectBuilder parent = groupOrUser.getBuilder(); MMObjectBuilder userBuilder = Authenticate.getInstance().getUserProvider().getUserBuilder(); if (!(parent instanceof Groups || userBuilder.getClass().isInstance(parent))) { throw new IllegalArgumentException( "Node '" + a.get(PARAMETER_GROUPORUSER) + "' does not represent a group or a user"); } return groupOrUser; }
@Override public void render(Parameters blockParameters, Writer w, RenderHints hints) throws FrameworkException { log.debug("Error rendering " + blockParameters); switch (getType()) { case BODY: try { decorateIntro(hints, w, "error"); w.write("<h1>" + error.status); w.write(": "); CharTransformer escape = new Xml(Xml.ESCAPE); w.write(escape.transform(error.exception.getMessage())); w.write(" "); w.write(escape.transform(url)); w.write("</h1>"); w.write("<pre>"); HttpServletRequest request = blockParameters.get(Parameter.REQUEST); error.getErrorReport(w, request, escape); w.write("</pre>"); decorateOutro(hints, w); } catch (IOException eio) { throw new FrameworkException(eio.getMessage(), eio); } break; default: } }
/** * I think in the basic framework this method is never called explicitely, because processing is * done implicitly by the render */ @Override public void process( Processor processor, Parameters blockParameters, Parameters frameworkParameters) throws FrameworkException { HttpServletRequest request = frameworkParameters.get(Parameter.REQUEST); State state = State.getState(request); state.startBlock(frameworkParameters, null); setBlockParametersForProcess(state, blockParameters); processor.process(blockParameters); }
@Override public Block getRenderingBlock(Parameters frameworkParameters) { HttpServletRequest request = frameworkParameters.get(Parameter.REQUEST); State state = State.getState(request); if (state.isRendering()) { return state.getBlock(); } else { return null; } }
@SuppressWarnings("unchecked") @Override public <C> C setSettingValue(Setting<C> setting, Parameters parameters, C value) { if (parameters == null) throw new SecurityException("You should provide Cloud and request parameters"); boolean useSession = parameters.get(USE_REQ); if (useSession) { C ret = getSettingValue(setting, parameters); HttpServletRequest req = parameters.get(Parameter.REQUEST); req.getSession(true).setAttribute(getKey(setting), value); return ret; } else { Cloud cloud = parameters.get(Parameter.CLOUD); if (cloud.getUser().getRank() == org.mmbase.security.Rank.ADMIN) { saveSettingValue(setting, value); return (C) settingValues.put(setting, value); } else { throw new SecurityException("Permission denied"); } } }
public void majParams() { if (sharedForward) { throw new RuntimeException("Please not call majParams on a shared forward module"); } double[] vals = ((CPUMatrix) parameters).getValues(); int nb = input_size * output_size; // ArrayList<Parameter> pars=paramList.getParams(); for (int i = 0; i < nb; i++) { vals[i] = paramList.get(i).getVal(); // vals[i]=paramList[i].getVal(); } paramsChanged = false; }
/** Test default package versions. */ public static void testDefaultPackageVersion() throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setProperty("Bundle-Version", "1.2.3"); a.setProperty("Export-Package", "test.refer"); Jar jar = a.build(); Manifest m = jar.getManifest(); Parameters exports = Processor.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE), null); Map<String, String> attrs = exports.get("test.refer"); assertNotNull(attrs); assertEquals("1.2.3", attrs.get("version")); }
@SuppressWarnings("unchecked") @Override public <C> C getSettingValue(Setting<C> setting, Parameters parameters) { boolean useSession = parameters != null && parameters.get(USE_REQ); if (useSession) { HttpServletRequest req = parameters.get(Parameter.REQUEST); if (req != null) { Object v = req.getSession(true).getAttribute(getKey(setting)); if (v != null) { return setting.getDataType().cast(v, null, null); } } } if (settingValues.containsKey(setting)) { return (C) settingValues.get(setting); } else { C settingValue = loadSettingValue(setting); if (settingValue != null) { settingValues.put(setting, settingValue); return settingValue; } return setting.getDataType().getDefaultValue(); } }
public LambdaInfo getLambdaIfExists(AbstractInsnNode insnNode) { if (insnNode.getOpcode() == Opcodes.ALOAD) { int varIndex = ((VarInsnNode) insnNode).var; if (varIndex < parameters.totalSize()) { return parameters.get(varIndex).getLambda(); } } else if (insnNode instanceof FieldInsnNode) { FieldInsnNode fieldInsnNode = (FieldInsnNode) insnNode; if (fieldInsnNode.name.startsWith("$$$")) { return findCapturedField(fieldInsnNode, nodeRemapper).getLambda(); } } return null; }
/** * Tests if the implementation of the EventHandler (which is marked as a ConsumerType) causes the * import of the api package to use the consumer version policy. */ public static void testConsumerType() throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setPrivatePackage("test.versionpolicy.uses"); a.setExportPackage("test.versionpolicy.api"); a.setProperty("build", "123"); Jar jar = a.build(); assertTrue(a.check()); Manifest m = jar.getManifest(); m.write(System.err); Domain d = Domain.domain(m); Parameters parameters = d.getImportPackage(); Attrs attrs = parameters.get("test.versionpolicy.api"); assertNotNull(attrs); assertEquals("[1.2,2)", attrs.get("version")); }
/** * Test if the implementation of "AnnotatedProviderInterface", which is annotated with OSGi * R6 @ProviderType, causes import of the api package to use the provider version policy */ public static void testProviderTypeR6() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setPrivatePackage("test.versionpolicy.implemented.osgi"); b.setProperty("build", "123"); Jar jar = b.build(); assertTrue(b.check()); Manifest m = jar.getManifest(); m.write(System.err); Domain d = Domain.domain(m); Parameters params = d.getImportPackage(); Attrs attrs = params.get("test.version.annotations.osgi"); assertNotNull(attrs); assertEquals("[1.2,1.3)", attrs.get("version")); }
@Override public Node getUserNode(Parameters frameworkParameters) { Cloud cloud = frameworkParameters.get(Parameter.CLOUD); if (cloud == null) { return null; } else { try { int userNode = cloud.getCloudContext().getAuthentication().getNode(cloud.getUser()); if (cloud.hasNode(userNode)) { return cloud.getNode(userNode); } else { return null; } } catch (UnsupportedOperationException uoe) { // never mind return null; } } }
@Override public String getProcessUrl( String path, Map<String, ?> parameters, Parameters frameworkParameters, boolean escapeAmps) throws FrameworkException { HttpServletRequest request = BasicUrlConverter.getUserRequest(frameworkParameters.get(Parameter.REQUEST)); State state = State.getState(request); frameworkParameters.set(ACTION, state.getId()); Url url = urlConverter.getProcessUrl(path, parameters, frameworkParameters, escapeAmps); if (url == Url.NOT) { log.debug("Fall back url"); return fallbackConverter .getProcessUrl(path, parameters, frameworkParameters, escapeAmps) .getUrl(); } else { log.debug("Url converter url " + url); return url.getUrl(); } }
/** * Tests if the implementation of the EventAdmin (which is marked as a ProviderType) causes the * import of the api package to use the provider version policy. */ public static void testProviderType() throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setPrivatePackage("test.versionpolicy.implemented"); a.setExportPackage("test.versionpolicy.api"); a.setImportPackage("test.versionpolicy.api"); // what changed so this is // not automatically // added? a.setProperty("build", "123"); Jar jar = a.build(); assertTrue(a.check()); Manifest m = jar.getManifest(); m.write(System.err); Domain d = Domain.domain(m); Parameters parameters = d.getImportPackage(); Attrs attrs = parameters.get("test.versionpolicy.api"); assertNotNull(attrs); assertEquals("[1.2,1.3)", attrs.get("version")); }
/** Check implementation version policy. Uses the package test.versionpolicy.(uses|implemented) */ static void assertPolicy(String pack, String type) throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setProperty("Export-Package", "test.versionpolicy.api"); Jar jar = a.build(); Builder b = new Builder(); b.addClasspath(jar); b.addClasspath(new File("bin")); b.setProperty("-versionpolicy-impl", "IMPL"); b.setProperty("-versionpolicy-uses", "USES"); b.setProperty("Private-Package", pack); b.build(); Manifest m = b.getJar().getManifest(); m.write(System.err); Map<String, String> map = b.getImports().getByFQN("test.versionpolicy.api"); assertNotNull(map); // String s = map.get(Constants.IMPLEMENTED_DIRECTIVE); // assertEquals("true", s); Parameters mp = Processor.parseHeader(m.getMainAttributes().getValue("Import-Package"), null); assertEquals(type, mp.get("test.versionpolicy.api").get("version")); }
/** * Basic Framework implicitely also processes, i'm not sure if we should require any framework to * do that (perhaps we could say, that the render method must process, if that is necessary, and * not yet done). */ @Override public void render( Renderer renderer, Parameters blockParameters, Parameters frameworkParameters, Writer w, WindowState windowState) throws FrameworkException { ServletRequest request = frameworkParameters.get(Parameter.REQUEST); if (request == null) { throw new IllegalArgumentException("No request object given"); } State state = State.getState(request); if (state .isRendering()) { // mm:component used during rending of a component, that's fine, but use a // new State. state = new State(request); log.debug("Alreadying rendering, taking a new state for sub-block-rendering: " + state); } log.debug("Rendering " + renderer.getBlock() + " " + renderer); Object prevHints = request.getAttribute(RenderHints.KEY); try { request.setAttribute(COMPONENT_CLASS_KEY, getComponentClass()); request.setAttribute(COMPONENT_CURRENTUSER_KEY, getUserNode(frameworkParameters)); Renderer actualRenderer = state.startBlock(frameworkParameters, renderer); if (!actualRenderer.equals(renderer)) { Parameters newBlockParameters = actualRenderer.getBlock().createParameters(); newBlockParameters.setAllIfDefined(blockParameters); blockParameters = newBlockParameters; } state.setAction(request.getParameter(ACTION.getName())); if (state.needsProcess()) { log.service("Performing action on " + actualRenderer.getBlock()); Processor processor = actualRenderer.getBlock().getProcessor(); state.process(processor); log.service("Processing " + actualRenderer.getBlock() + " " + processor); setBlockParametersForProcess(state, blockParameters); processor.process(blockParameters); state.endProcess(); } state.render(actualRenderer); setBlockParametersForRender(state, blockParameters); RenderHints hints = new RenderHints( actualRenderer, windowState, state.getId(), getComponentClass(), RenderHints.Mode.NORMAL); request.setAttribute(RenderHints.KEY, hints); actualRenderer.render(blockParameters, w, hints); request.setAttribute("org.mmbase.framework.hints", hints); } catch (FrameworkException fe) { log.debug(fe); URI uri = renderer.getUri(); Renderer error = new ErrorRenderer( renderer.getType(), renderer.getBlock(), (uri != null) ? uri.toString() : null, 500, fe); RenderHints hints = new RenderHints( error, windowState, state.getId(), getComponentClass(), RenderHints.Mode.NORMAL); error.render(blockParameters, w, hints); } finally { request.setAttribute(RenderHints.KEY, prevHints); state.endBlock(); } }
@Override public void initialize(Parameters params) throws ResourceInitializationException { super.initialize(params); if (params.contains(Constants.REPRESENTER)) { representer = (TextRepresenter) params.get(Constants.REPRESENTER); } else { throw new ResourceInitializationException("No text representer specified."); } if (params.contains(Constants.FIND_BEST_PARAMETERS)) { findBestParameters = params.getBoolean(Constants.FIND_BEST_PARAMETERS); } else { gamma = 1.0 / (double) representer.getFeatures().size(); } if (params.contains(Constants.C)) { if (findBestParameters) { logger.warn("Finding best parameters. The specified C value will be ignored."); } else { c = params.getDouble(Constants.C); } } if (params.contains(Constants.WEIGHTS)) { // Parse weight specs weights = new TreeMap<Integer, Double>(); for (String piece : params.getString(Constants.WEIGHTS).split(",\\s*")) { String[] pair = piece.split(":"); if (pair.length != 2) { throw new ResourceInitializationException( "Invalid weight specs in " + params.getString(Constants.WEIGHTS)); } try { int i = Integer.parseInt(pair[0]); double w = Double.parseDouble(pair[1]); weights.put(i, w); } catch (Exception e) { throw new ResourceInitializationException( "Invalid weight specs in " + params.getString(Constants.WEIGHTS), e); } } } if (params.contains(Constants.GAMMA)) { if (findBestParameters) { logger.warn("Finding best parameters. The specified gamma value will be ignored."); } else { gamma = params.getDouble(Constants.GAMMA); } } if (params.contains(Constants.SAMPLE)) { if (findBestParameters) { sample = params.getDouble(Constants.SAMPLE); if (sample <= 0 || sample > 1) { throw new ResourceInitializationException("Invalid sample value " + sample); } } else { logger.warn( "Sample value valid for parameter optimization only. Provided sample value will be ignored."); } } if (params.contains(Constants.NUMBER_OF_THREADS)) { numberOfThreads = params.getInt(Constants.NUMBER_OF_THREADS); if (numberOfThreads < 1) { throw new ResourceInitializationException(Constants.NUMBER_OF_THREADS + " must be >= 1"); } } if (params.contains(Constants.TARGET_CLASS)) { targetClass = params.getString(Constants.TARGET_CLASS); logger.debug("Target Class: " + targetClass); } }