Example usage for org.apache.commons.beanutils BeanMap entryIterator

List of usage examples for org.apache.commons.beanutils BeanMap entryIterator

Introduction

In this page you can find the example usage for org.apache.commons.beanutils BeanMap entryIterator.

Prototype

public Iterator entryIterator() 

Source Link

Document

Convenience method for getting an iterator over the entries.

Usage

From source file:com.datatorrent.stram.codec.LogicalPlanSerializer.java

public static PropertiesConfiguration convertToProperties(LogicalPlan dag) {
    PropertiesConfiguration props = new PropertiesConfiguration();
    Collection<OperatorMeta> allOperators = dag.getAllOperators();

    for (OperatorMeta operatorMeta : allOperators) {
        String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorMeta.getName();
        Operator operator = operatorMeta.getOperator();
        props.setProperty(operatorKey + "." + LogicalPlanConfiguration.OPERATOR_CLASSNAME,
                operator.getClass().getName());
        BeanMap operatorProperties = LogicalPlanConfiguration.getObjectProperties(operator);
        @SuppressWarnings("rawtypes")
        Iterator entryIterator = operatorProperties.entryIterator();
        while (entryIterator.hasNext()) {
            try {
                @SuppressWarnings("unchecked")
                Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryIterator.next();
                if (!entry.getKey().equals("class") && !entry.getKey().equals("name")
                        && entry.getValue() != null) {
                    props.setProperty(operatorKey + "." + entry.getKey(), entry.getValue());
                }//www .j a va2 s. c om
            } catch (Exception ex) {
                LOG.warn("Error trying to get a property of operator {}", operatorMeta.getName(), ex);
            }
        }
    }
    Collection<StreamMeta> allStreams = dag.getAllStreams();

    for (StreamMeta streamMeta : allStreams) {
        String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamMeta.getName();
        OutputPortMeta source = streamMeta.getSource();
        List<InputPortMeta> sinks = streamMeta.getSinks();
        props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE,
                source.getOperatorMeta().getName() + "." + source.getPortName());
        String sinksValue = "";
        for (InputPortMeta sink : sinks) {
            if (!sinksValue.isEmpty()) {
                sinksValue += ",";
            }
            sinksValue += sink.getOperatorWrapper().getName() + "." + sink.getPortName();
        }
        props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
        if (streamMeta.getLocality() != null) {
            props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY,
                    streamMeta.getLocality().name());
        }
    }

    // TBD: Attributes

    return props;
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

private Map<String, Object> getPropertiesAsMap(@QueryParam("propertyName") String propertyName,
        BeanMap operatorProperties) {
    Map<String, Object> m = new HashMap<String, Object>();
    @SuppressWarnings("rawtypes")
    Iterator entryIterator = operatorProperties.entryIterator();
    while (entryIterator.hasNext()) {
        try {// w  ww  . ja  v a2s. c  o  m
            @SuppressWarnings("unchecked")
            Entry<String, Object> entry = (Entry<String, Object>) entryIterator.next();
            if (propertyName == null) {
                m.put(entry.getKey(), entry.getValue());
            } else if (propertyName.equals(entry.getKey())) {
                m.put(entry.getKey(), entry.getValue());
                break;
            }
        } catch (Exception ex) {
            LOG.warn("Caught exception", ex);
        }
    }
    return m;
}

From source file:org.pentaho.big.data.impl.cluster.NamedClusterImpl.java

public String toXmlForEmbed(String rootTag) {
    BeanMap m = new BeanMap(this);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document doc = null;/*from   www. j  ava  2 s  .co  m*/
    try {
        builder = dbf.newDocumentBuilder();
        doc = builder.newDocument();
        Element rootNode = doc.createElement(rootTag);
        doc.appendChild(rootNode);
        Iterator<Map.Entry<Object, Object>> i = m.entryIterator();
        while (i.hasNext()) {
            Map.Entry<Object, Object> entry = i.next();
            String elementName = (String) entry.getKey();
            if (!"class".equals(elementName) && !"parentVariableSpace".equals(elementName)) {
                String value = "";
                String type = "String";
                Object o = entry.getValue();
                if (o != null) {
                    if (o instanceof Long) {
                        value = Long.toString((Long) o);
                    } else if (o instanceof Boolean) {
                        value = Boolean.toString((Boolean) o);
                    } else {
                        try {
                            value = (String) entry.getValue();
                            if (elementName.toLowerCase().contains("password")) {
                                value = passwordEncoder.encode(value);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                rootNode.appendChild(createChildElement(doc, elementName, type, value));
            }
        }
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);
        String s = writer.toString();
        // Remove header from the XML
        s = s.substring(s.indexOf(">") + 1);
        return s;
    } catch (ParserConfigurationException | TransformerException e1) {
        LOGGER.error("Could not parse embedded cluster xml" + e1.toString());
        return "";
    }
}