use of java.util.LinkedHashMap in project camel by apache.
the class DefaultCamelContext method explainComponentJson.
public String explainComponentJson(String componentName, boolean includeAllOptions) {
try {
String json = getComponentParameterJsonSchema(componentName);
if (json == null) {
return null;
}
List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("componentProperties", json, true);
// selected rows to use for answer
Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
// insert values from component
Component component = getComponent(componentName);
Map<String, Object> options = new HashMap<String, Object>();
IntrospectionSupport.getProperties(component, options, null);
for (Map.Entry<String, Object> entry : options.entrySet()) {
String name = entry.getKey();
// skip unwanted options which is default inherited from DefaultComponent
if ("camelContext".equals(name) || "endpointClass".equals(name)) {
continue;
}
String value = "";
if (entry.getValue() != null) {
value = entry.getValue().toString();
}
value = URISupport.sanitizePath(value);
// find type and description from the json schema
String type = null;
String kind = null;
String group = null;
String label = null;
String required = null;
String javaType = null;
String deprecated = null;
String secret = null;
String defaultValue = null;
String description = null;
for (Map<String, String> row : rows) {
if (name.equals(row.get("name"))) {
type = row.get("type");
kind = row.get("kind");
group = row.get("group");
label = row.get("label");
required = row.get("required");
javaType = row.get("javaType");
deprecated = row.get("deprecated");
secret = row.get("secret");
defaultValue = row.get("defaultValue");
description = row.get("description");
break;
}
}
// add as selected row
selected.put(name, new String[] { name, kind, group, label, required, type, javaType, deprecated, secret, value, defaultValue, description });
}
// include other rows
for (Map<String, String> row : rows) {
String name = row.get("name");
String kind = row.get("kind");
String group = row.get("group");
String label = row.get("label");
String required = row.get("required");
String value = row.get("value");
String defaultValue = row.get("defaultValue");
String type = row.get("type");
String javaType = row.get("javaType");
String deprecated = row.get("deprecated");
String secret = row.get("secret");
value = URISupport.sanitizePath(value);
String description = row.get("description");
// always include path options
if (includeAllOptions) {
// add as selected row
if (!selected.containsKey(name)) {
selected.put(name, new String[] { name, kind, group, label, required, type, javaType, deprecated, secret, value, defaultValue, description });
}
}
}
json = ObjectHelper.before(json, " \"componentProperties\": {");
StringBuilder buffer = new StringBuilder(" \"componentProperties\": {");
boolean first = true;
for (String[] row : selected.values()) {
if (first) {
first = false;
} else {
buffer.append(",");
}
buffer.append("\n ");
String name = row[0];
String kind = row[1];
String group = row[2];
String label = row[3];
String required = row[4];
String type = row[5];
String javaType = row[6];
String deprecated = row[7];
String secret = row[8];
String value = row[9];
String defaultValue = row[10];
String description = row[11];
// add json of the option
buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
CollectionStringBuffer csb = new CollectionStringBuffer();
if (kind != null) {
csb.append("\"kind\": \"" + kind + "\"");
}
if (group != null) {
csb.append("\"group\": \"" + group + "\"");
}
if (label != null) {
csb.append("\"label\": \"" + label + "\"");
}
if (required != null) {
csb.append("\"required\": \"" + required + "\"");
}
if (type != null) {
csb.append("\"type\": \"" + type + "\"");
}
if (javaType != null) {
csb.append("\"javaType\": \"" + javaType + "\"");
}
if (deprecated != null) {
csb.append("\"deprecated\": \"" + deprecated + "\"");
}
if (secret != null) {
csb.append("\"secret\": \"" + secret + "\"");
}
if (value != null) {
csb.append("\"value\": \"" + value + "\"");
}
if (defaultValue != null) {
csb.append("\"defaultValue\": \"" + defaultValue + "\"");
}
if (description != null) {
csb.append("\"description\": \"" + description + "\"");
}
if (!csb.isEmpty()) {
buffer.append(csb.toString());
}
buffer.append(" }");
}
buffer.append("\n }\n}\n");
// insert the original first part of the json into the start of the buffer
buffer.insert(0, json);
return buffer.toString();
} catch (Exception e) {
// ignore and return empty response
return null;
}
}
use of java.util.LinkedHashMap in project camel by apache.
the class MBeanInfoAssembler method getMBeanInfo.
/**
* Gets the {@link ModelMBeanInfo} for the given managed bean
*
* @param defaultManagedBean the default managed bean
* @param customManagedBean an optional custom managed bean
* @param objectName the object name
* @return the model info, or <tt>null</tt> if not possible to create, for example due the managed bean is a proxy class
* @throws JMException is thrown if error creating the model info
*/
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
// skip proxy classes
if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
return null;
}
// maps and lists to contain information about attributes and operations
Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();
// extract details from default managed bean
if (defaultManagedBean != null) {
extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
}
// extract details from custom managed bean
if (customManagedBean != null) {
extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
extractMbeanOperations(customManagedBean, operations, mBeanOperations);
extractMbeanNotifications(customManagedBean, mBeanNotifications);
}
// create the ModelMBeanInfo
String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
LOG.trace("Created ModelMBeanInfo {}", info);
return info;
}
use of java.util.LinkedHashMap in project camel by apache.
the class CwComponentTest method setsMeticDimensions.
@Test
public void setsMeticDimensions() throws Exception {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
Map<String, String> dimensionsMap = new LinkedHashMap<String, String>();
dimensionsMap.put("keyOne", "valueOne");
dimensionsMap.put("keyTwo", "valueTwo");
exchange.getIn().setHeader(CwConstants.METRIC_DIMENSIONS, dimensionsMap);
}
});
ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
verify(cloudWatchClient).putMetricData(argument.capture());
List<Dimension> dimensions = argument.getValue().getMetricData().get(0).getDimensions();
Dimension dimension = dimensions.get(0);
assertThat(dimensions.size(), is(2));
assertEquals("keyOne", dimension.getName());
assertEquals("valueOne", dimension.getValue());
}
use of java.util.LinkedHashMap in project camel by apache.
the class ResultSetIterator method next.
@Override
public Map<String, Object> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
try {
Map<String, Object> row = new LinkedHashMap<String, Object>();
for (Column column : columns) {
if (useGetBytes && column instanceof BlobColumn) {
row.put(column.getName(), ((BlobColumn) column).getBytes(resultSet));
} else {
row.put(column.getName(), column.getValue(resultSet));
}
}
loadNext();
return row;
} catch (SQLException e) {
close();
throw new RuntimeCamelException("Cannot process result", e);
}
}
use of java.util.LinkedHashMap in project groovy by apache.
the class ASTTransformationCollectorCodeVisitor method visitAnnotations.
/**
* If the annotation is annotated with {@link GroovyASTTransformation}
* the annotation is added to <code>stageVisitors</code> at the appropriate processor visitor.
*
* @param node the node to process
*/
public void visitAnnotations(AnnotatedNode node) {
super.visitAnnotations(node);
Map<Integer, List<AnnotationNode>> existing = new TreeMap<Integer, List<AnnotationNode>>();
Map<Integer, List<AnnotationNode>> replacements = new LinkedHashMap<Integer, List<AnnotationNode>>();
Map<Integer, AnnotationCollectorMode> modes = new LinkedHashMap<Integer, AnnotationCollectorMode>();
int index = 0;
for (AnnotationNode annotation : node.getAnnotations()) {
findCollectedAnnotations(annotation, node, index, modes, existing, replacements);
index++;
}
for (Integer replacementIndex : replacements.keySet()) {
mergeCollectedAnnotations(modes.get(replacementIndex), existing, replacements.get(replacementIndex));
existing.put(replacementIndex, replacements.get(replacementIndex));
}
List<AnnotationNode> mergedList = new ArrayList<AnnotationNode>();
for (List<AnnotationNode> next : existing.values()) {
mergedList.addAll(next);
}
node.getAnnotations().clear();
node.getAnnotations().addAll(mergedList);
for (AnnotationNode annotation : node.getAnnotations()) {
Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode());
if (transformClassAnnotation == null) {
// skip if there is no such annotation
continue;
}
addTransformsToClassNode(annotation, transformClassAnnotation);
}
}
Aggregations