public static RestxConfig parse(String origin, InputSupplier<InputStreamReader> readerSupplier) throws IOException { List<ConfigElement> elements = new ArrayList<>(); StringBuilder doc = new StringBuilder(); int lineCount = 0; for (String line : CharStreams.readLines(readerSupplier)) { lineCount++; if (line.startsWith("#")) { doc.append(line.substring(1).trim()).append("\n"); } else if (!line.trim().isEmpty()) { int index = line.indexOf('='); if (index == -1) { throw new IOException( "invalid config " + origin + " at line " + lineCount + ":" + " line does not contain the equals sign '='"); } String key = line.substring(0, index).trim(); String value = line.substring(index + 1).trim(); elements.add(ConfigElement.of(origin, doc.toString().trim(), key, value)); doc.setLength(0); } } return new StdRestxConfig(elements); }
@Override public Optional<String> getString(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } return Optional.of(element.getValue()); }
@Override public Optional<Boolean> getBoolean(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } return Optional.of(TRUE_VALUES.contains(element.getValue().toLowerCase(Locale.ENGLISH))); }
public Point getLocationOf(int idx) { ConfigElement vp_elt = (ConfigElement) getElement(idx); double x = ((Number) vp_elt.getProperty("origin", 0)).doubleValue() * mDesktopSize.getWidth(); double y = ((Number) vp_elt.getProperty("origin", 1)).doubleValue() * mDesktopSize.getHeight(); // Convert y from Juggler coords (bottom left is origin) double height = ((Number) vp_elt.getProperty("size", 1)).doubleValue() * mDesktopSize.getHeight(); y = mDesktopSize.getHeight() - y - height; return new Point((int) x, (int) y); }
private void createClusterManagerElement() { ConfigElementFactory factory = new ConfigElementFactory(mBroker.getRepository().getAllLatest()); ConfigElement cluster_manager = factory.create("Sample Cluster", "cluster_manager"); for (Enumeration e = mNodesListModel.elements(); e.hasMoreElements(); ) { cluster_manager.addProperty("cluster_node", (String) e.nextElement()); } cluster_manager.addProperty("plugin_path", "${VJ_BASE_DIR}/lib/gadgeteer/plugins/"); cluster_manager.addProperty("plugin", "RemoteInputManager"); cluster_manager.addProperty("plugin", "ApplicationDataManager"); mBroker.add(mContext, cluster_manager); }
/** * Removes the given configuration element to this configuration. * * @param elt The configuration element to remove. * @throws IllegalArgumentException if the element is not a part of this configuration */ public synchronized void removeElement(ConfigElement elt) throws IllegalArgumentException { if (!mElements.contains(elt)) { throw new IllegalArgumentException( "Element '" + elt.getName() + "' (type " + elt.getDefinition().getToken() + ") is not a part of this " + "configuration."); } mElements.remove(elt); }
@Override public Optional<Integer> getInt(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } try { return Optional.of(Integer.parseInt(element.getValue())); } catch (NumberFormatException e) { throw new RuntimeException( "can't access " + element + " as int" + " (parse exception " + e.getMessage() + ")"); } }
public ViewportPlacerModel(Dimension desktopSize, ConfigContext ctx, ConfigElement elt) { mDesktopSize = desktopSize; mContext = ctx; mDisplayElement = elt; mDisplayElement.addConfigElementListener(mChangeListener); Iterator i; for (i = elt.getPropertyValues("simulator_viewports").iterator(); i.hasNext(); ) { mViewports.add(i.next()); } for (i = elt.getPropertyValues("surface_viewports").iterator(); i.hasNext(); ) { mViewports.add(i.next()); } }
public void clopen(Object... settings) { config = getConfiguration(); if (mgmt != null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (settings != null && settings.length > 0) { Map<TestConfigOption, Object> options = validateConfigOptions(settings); TitanManagement gconf = null; ModifiableConfiguration lconf = new ModifiableConfiguration( GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.LOCAL); for (Map.Entry<TestConfigOption, Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { lconf.set(option.getKey().option, option.getValue(), option.getKey().umbrella); } else { if (gconf == null) gconf = graph.openManagement(); gconf.set( ConfigElement.getPath(option.getKey().option, option.getKey().umbrella), option.getValue()); } } if (gconf != null) gconf.commit(); lconf.close(); } if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
public void setSizeOf(int idx, Dimension size) { ConfigElement vp_elt = (ConfigElement) getElement(idx); double vp_width = (double) size.width / mDesktopSize.getWidth(); double vp_height = (double) size.height / mDesktopSize.getHeight(); if (vp_width > 1.0) { vp_width = 1.0; } if (vp_height > 1.0) { vp_height = 1.0; } vp_elt.setProperty("size", 0, new Double(vp_width), mContext); vp_elt.setProperty("size", 1, new Double(vp_height), mContext); }
private void mAddNodeBtn_actionPerformed(ActionEvent e) { String host_name = mHostnameField.getText().trim(); String element_name = "Node(" + host_name + ")"; java.util.List elts = mBroker.getElements(mContext); java.util.List matches = ConfigUtilities.getElementsWithDefinition(elts, element_name); if (!host_name.equals("") && matches.size() == 0) { // Create a cluster_node element for the node ConfigElementFactory factory = new ConfigElementFactory(mBroker.getRepository().getAllLatest()); ConfigElement element = factory.create(element_name, CLUSTER_NODE_TYPE); mBroker.add(mContext, element); element.setProperty("host_name", 0, host_name); element.setProperty("listen_port", 0, "7000"); } mHostnameField.setText(""); }
private StdRestxConfig(Iterable<ConfigElement> elements) { Map<String, ConfigElement> m = new LinkedHashMap<>(); for (ConfigElement element : elements) { ConfigElement curElement = m.get(element.getKey()); if (curElement == null) { m.put(element.getKey(), element); } else { if (isNullOrEmpty(curElement.getDoc()) && !isNullOrEmpty(element.getDoc())) { m.put(element.getKey(), curElement.withDoc(element.getDoc())); } } } this.elements = ImmutableMap.copyOf(m); }
public Dimension getSizeOf(int idx) { ConfigElement vp_elt = (ConfigElement) getElement(idx); double vp_width = ((Number) vp_elt.getProperty("size", 0)).doubleValue(); double vp_height = ((Number) vp_elt.getProperty("size", 1)).doubleValue(); if (vp_width > 1.0) { vp_width = 1.0; } if (vp_height > 1.0) { vp_height = 1.0; } double width = vp_width * mDesktopSize.getWidth(); double height = vp_height * mDesktopSize.getHeight(); return new Dimension((int) width, (int) height); }
public void setLocationOf(int idx, Point pt) { ConfigElement vp_elt = (ConfigElement) getElement(idx); // Convert y to Juggler coords (bottom left is origin) double height = ((Number) vp_elt.getProperty("size", 1)).doubleValue() * mDesktopSize.getHeight(); double y = mDesktopSize.height - pt.y - height; double vp_origin_x = (double) pt.x / mDesktopSize.getWidth(); double vp_origin_y = y / mDesktopSize.getHeight(); if (vp_origin_x < 0.0) { vp_origin_x = 0.0; } if (vp_origin_y < 0.0) { vp_origin_y = 0.0; } vp_elt.setProperty("origin", 0, new Double(vp_origin_x), mContext); vp_elt.setProperty("origin", 1, new Double(vp_origin_y), mContext); }
public void setState(boolean enb) { element.enabled = enb; setSelected(enb); props.setProperty(element.id, "" + enb); Configuration.getInstance().setChanged(true); }
ConfigElement processLine(String configfile, int lineno, CharBuffer buffer) throws ConfigParseException { char c; final StringBuilder processLineBuilder; final StringBuilder lineCommentBuilder; processLineBuilder = new StringBuilder(MAX_LINE_LENGTH); lineCommentBuilder = new StringBuilder(MAX_LINE_LENGTH); buffer.mark(); while (buffer.hasRemaining()) { final int position; position = buffer.position(); c = buffer.get(); // System.out.println(position + ": " + c); if (c == COMMENT_META) { if (position >= 1 && buffer.get(position - 1) == '\\') { /* Escaped semicolons aren't comments. */ } // NOPMD else if (buffer.remaining() >= 3 && buffer.get(position + 1) == COMMENT_TAG && buffer.get(position + 2) == COMMENT_TAG && buffer.get(position + 3) != COMMENT_TAG) { /* Meta-Comment start detected ";--" */ currentCommentLevel++; // System.out.println("Comment start, new level: " + currentCommentLevel); if (!inComment()) { commentBlock.append(";--"); buffer.position(position + 3); buffer.mark(); continue; } } else if (inComment() && position >= 2 && buffer.get(position - 1) == COMMENT_TAG && buffer.get(position - 2) == COMMENT_TAG) { /* Meta-Comment end detected */ currentCommentLevel--; if (!inComment()) { buffer.reset(); // int commentLength = (position + 1) - buffer.position(); // buffer.reset(); // for (int i = 0; i < commentLength; i++) // { // commentBlock.append(buffer.get()); // } commentBlock.append(c); // System.out.println("Comment end at " + position + ": '" + commentBlock.toString() + // "'"); buffer.position(position + 1); buffer.compact(); buffer.flip(); // System.out.println("Buffer compacted"); continue; } } else { if (!inComment()) { /* If ; is found, and we are not nested in a comment, we immediately stop all comment processing */ // System.out.println("Found ; while not in comment"); while (buffer.hasRemaining()) { lineCommentBuilder.append(buffer.get()); } break; } else { /* Found ';' while in comment */ } // NOPMD } } if (inComment()) { commentBlock.append(c); } else { // System.out.println("Added '" + c + "' to processLine"); processLineBuilder.append(c); } } String processLineString; String lineCommentString; ConfigElement configElement; processLineString = processLineBuilder.toString().trim(); lineCommentString = lineCommentBuilder.toString().trim(); // System.out.println("process line: '" + processLineString + "'"); if (processLineString.length() == 0) { if (lineCommentString.length() != 0) { commentBlock.append(";"); commentBlock.append(lineCommentString); } if (!inComment()) { commentBlock.append("\n"); } return null; } try { configElement = processTextLine(configfile, lineno, processLineString); } catch (ConfigParseException e) { // some parsing exceptions are treated as warnings by Asterisk, we mirror this behavior. if (WARNING_CLASSES.contains(e.getClass())) { warnings.add(e); return null; } else { throw e; } } if (lineCommentString.length() != 0) { configElement.setComment(lineCommentString); } if (commentBlock.length() != 0) { configElement.setPreComment(commentBlock.toString()); commentBlock.delete(0, commentBlock.length()); } return configElement; }