/** * Adds the given property to this Configuration object. The property can be a * {@link PropertySimple simple property}, a {@link PropertyList list of properties} or a * {@link PropertyMap map of properties}. * * @param value the new property */ @Override public void put(Property value) { Map<String, Property> map = getMap(); if (value.getName()!=null) { map.put(value.getName().intern(),value); } else { map.put(value.getName(), value); } value.setConfiguration(this); }
@Override public String toString() { StringBuilder str = new StringBuilder(this.getClass().getName().substring( this.getClass().getName().lastIndexOf(".") + 1)); str.append("[id=").append(getId()); str.append(", name=").append(getName()); appendToStringInternals(str); // ask subclasses if they have anything else to add str.append(']'); return str.toString(); }
/** * Returns a map of all <i>direct</i> children of this Configuration that are of type {@link PropertyList}. The * returned map is keyed on the {@link PropertyList}'s names. * * @return map containing of all of the Configuration's direct {@link PropertyList} children */ @NotNull public Map<String, PropertyList> getListProperties() { Map<String, PropertyList> map = new LinkedHashMap<String, PropertyList>(); for (Property prop : this.getProperties()) { if (prop instanceof PropertyList) { map.put(prop.getName(), (PropertyList) prop); } } return map; }
/** * Returns a map of all <i>direct</i> children of this Configuration that are of type {@link PropertyMap}. The * returned map is keyed on the {@link PropertyMap}'s names. * * @return map containing of all of the Configuration's direct {@link PropertyMap} children */ @NotNull public Map<String, PropertyMap> getMapProperties() { Map<String, PropertyMap> map = new LinkedHashMap<String, PropertyMap>(); for (Property prop : this.getProperties()) { if (prop instanceof PropertyMap) { map.put(prop.getName(), (PropertyMap) prop); } } return map; }
/** * Returns a map of all <i>direct</i> children of this Configuration that are of type {@link PropertySimple}. The * returned map is keyed on the {@link PropertySimple}'s names. * * @return map containing of all of the Configuration's direct {@link PropertySimple} children */ @NotNull public Map<String, PropertySimple> getSimpleProperties() { Map<String, PropertySimple> map = new LinkedHashMap<String, PropertySimple>(); for (Property prop : this.getProperties()) { if (prop instanceof PropertySimple) { map.put(prop.getName(), (PropertySimple) prop); } } return map; }
/** * Put a child property into this map keyed on the given property's name. This method also sets the * {@link Property#setParentMap(PropertyMap) parent map} for the child property to make persistence work. * * @param property the property to add to this map. */ public void put(@NotNull Property property) { getMap().put(property.getName(), property); property.setParentMap(this); }
private static PropertyType conforms(Property p, PropertyDefinition d) { if (p == null) { return PropertyType.UNKNOWN; } if (!p.getName().equals(d.getName())) { return null; } if (p instanceof PropertySimple && d instanceof PropertyDefinitionSimple) { return PropertyType.SIMPLE; } else if (p instanceof PropertyList && d instanceof PropertyDefinitionList) { return PropertyType.LIST; } else if (p instanceof PropertyMap && d instanceof PropertyDefinitionMap) { return PropertyType.MAP; } else if (p instanceof PropertySimple && d instanceof PropertyDefinitionDynamic) { return PropertyType.DYNAMIC; } else { return null; } }
/** * Adds a child property to the end of this list. This method also sets the * {@link Property#setParentList(PropertyList) parent list} for the child property to make persistence work. * * @param property the property to add to this list */ public void add(@NotNull Property property) { if (this.memberPropertyName == null) { this.memberPropertyName = property.getName(); } if (!property.getName().equals(this.memberPropertyName)) { throw new IllegalStateException("All properties in a PropertyList (id=[" + getId() + "], name=[" + getName() + "]) must have the same name: [" + property.getName() + "] != [" + this.memberPropertyName + "]"); } getList().add(property); property.setParentList(this); }
private static void unmaskPropertyMap(AbstractPropertyMap propertyMap, PropertyMap unmaskedPropertyMap) { if (unmaskedPropertyMap == null) { // The map does not exist in the unmasked config, so no unmasking is possible. return; } Map<String, Property> memberProperties = propertyMap.getMap(); for (Property memberProperty : memberProperties.values()) { unmaskProperty(memberProperty.getName(), propertyMap, unmaskedPropertyMap); } }
private static String createPropertyExpressionFormat(String configurationExpressionString, PropertySimple propertySimple, Integer listIndex) { StringBuilder stringBuilder = new StringBuilder("#{"); stringBuilder.append(FacesExpressionUtility.unwrapExpressionString(configurationExpressionString)); LinkedList<Property> propertyHierarchy = ConfigurationUtility.getPropertyHierarchy(propertySimple); for (Property property : propertyHierarchy) { Property parentProperty = ConfigurationUtility.getParentProperty(property); stringBuilder.append("."); if (parentProperty == null || parentProperty instanceof PropertyMap) { // top-level or map member property stringBuilder.append("map['").append(property.getName()).append("']"); } else { // list member property stringBuilder.append("list[").append(listIndex).append("]"); } } stringBuilder.append("}"); return stringBuilder.toString(); }
/** * Unmask the values of all masked simple properties of type PASSWORD in the configuration. The configuration does not * need to be normalized; that is, properties defined by the configuration definition do not need to exist in the * configuration. * * @param configuration the configuration to be unmasked * @param unmaskedConfiguration the unmasked configuration that should be used as the reference to unmask the * configuration */ public static void unmaskConfiguration(@NotNull Configuration configuration, @NotNull Configuration unmaskedConfiguration) { Map<String, Property> memberProperties = configuration.getAllProperties(); for (Property memberProperty : memberProperties.values()) { unmaskProperty(memberProperty.getName(), configuration, unmaskedConfiguration); } }
/** * Allow users to see a preview of the stored configuration data without having to edit it. * A default implementation is already provided which will print the properties in alphabetical * order, one per line, each followed by a string representation of that property's data. */ public String previewConfiguration() { StringBuilder builder = new StringBuilder(); List<Property> properties = new ArrayList<Property>(alertParameters.getProperties()); Collections.sort(properties); // alpha sort by property name boolean first = true; for (Property next : properties) { if (first) { first = false; } else { builder.append(" | "); } builder.append(next.getName()); builder.append(": "); builder.append(printProperty(next)); } return builder.toString(); }
public static PropertyDefinition getPropertyDefinitionForProperty(Property property, ConfigurationDefinition configurationDefinition) { LinkedList<Property> propertyHierarchy = getPropertyHierarchy(property); Property topLevelProperty = propertyHierarchy.get(0); PropertyDefinition propertyDefinition = configurationDefinition.getPropertyDefinitions().get(topLevelProperty.getName()); for (int i = 1; i < propertyHierarchy.size(); i++) { Property subProperty = propertyHierarchy.get(i); if (propertyDefinition instanceof PropertyDefinitionMap) { propertyDefinition = ((PropertyDefinitionMap)propertyDefinition).get(subProperty.getName()); } else if (propertyDefinition instanceof PropertyDefinitionList) { propertyDefinition = ((PropertyDefinitionList)propertyDefinition).getMemberDefinition(); } } return propertyDefinition; }
private static void prettyPrintProperty(Property property, int indent) { if (property instanceof PropertyList) { for (int i = 0; i < indent; i++) { System.out.print("\t"); } System.out.println("List Property [" + property.getName() + "]"); for (Property p : ((PropertyList) property).getList()) { prettyPrintProperty(p, indent + 1); } } else if (property instanceof PropertyMap) { for (int i = 0; i < indent; i++) { System.out.print("\t"); } System.out.println("Map Property [" + property.getName() + "]"); for (Property p : ((PropertyMap) property).getMap().values()) { prettyPrintProperty(p, indent + 1); } } else if (property instanceof PropertySimple) { for (int i = 0; i < indent; i++) { System.out.print("\t"); } System.out.println(property.getName() + " = " + ((PropertySimple) property).getStringValue()); } } }
ConnectionStringAvailableProperties(ResourceContainer container, MeasurementManager measurementManager, Configuration deploymentConfiguration) { this.resourceContainer = container; this.measurementManager = measurementManager; this.pluginConfiguration = new HashMap<String, Property>(); for (Property p : container.getResource().getPluginConfiguration().getProperties()) { pluginConfiguration.put("pluginConfiguration." + p.getName(), p); } this.resourceConfiguration = new HashMap<String, Property>(); for (Property p : InventoryManager.getResourceConfiguration(container.getResource()) .getProperties()) { resourceConfiguration.put("resourceConfiguration." + p.getName(), p); } this.traits = new HashMap<String, String>(); for (MeasurementScheduleRequest r : container.getMeasurementSchedule()) { if (r.getDataType() == DataType.TRAIT) { traits.put("measurementTrait." + r.getName(), r.getName()); } } this.deploymentConfiguration = new HashMap<String, Property>(); for (Property p : deploymentConfiguration.getProperties()) { this.deploymentConfiguration.put("deploymentConfiguration." + p.getName(), p); } }
public static void addPropertyDisplayName(UIComponent parent, PropertyDefinition propertyDefinition, Property property, boolean configReadOnly) { String displayName = (propertyDefinition != null) ? propertyDefinition.getDisplayName() : property.getName(); FacesComponentUtility.addOutputText(parent, null, displayName, CssStyleClasses.PROPERTY_DISPLAY_NAME_TEXT); if (!configReadOnly && propertyDefinition != null && propertyDefinition.isRequired() && (propertyDefinition instanceof PropertyDefinitionSimple || propertyDefinition instanceof PropertyDefinitionDynamic) ) { // Print a required marker next to required simples. // Ignore the required field for maps and lists, as it is has no significance for them. FacesComponentUtility.addOutputText(parent, null, " * ", CssStyleClasses.REQUIRED_MARKER_TEXT); } }
@Override public Operation getBatchOperation() { CompositeOperation compositeOperation = new CompositeOperation(); if (hasDiscoveryGroupName()) { compositeOperation.addStep(new UndefineAttribute(address, STATIC_CONNECTORS_ATTRIBUTE)); compositeOperation.addStep(new WriteAttribute(address, DISCOVERY_GROUP_NAME, configuration .getSimpleValue(DISCOVERY_GROUP_NAME))); } else { compositeOperation.addStep(new UndefineAttribute(address, DISCOVERY_GROUP_NAME)); List<Property> propertyList = configuration.getList(STATIC_CONNECTORS_PROPERTY).getList(); List<String> staticConnectors = new ArrayList<String>(propertyList.size()); for (Property property : propertyList) { if (property instanceof PropertySimple) { PropertySimple propertySimple = (PropertySimple) property; staticConnectors.add(propertySimple.getStringValue()); } else { getLog().warn(property.getName() + " property has unexpected type: " + property.getClass()); } } compositeOperation.addStep(new WriteAttribute(address, STATIC_CONNECTORS_ATTRIBUTE, staticConnectors)); } return compositeOperation; } }
private void addPropertyMapSummaryDataCells(UIComponent parent, PropertyDefinitionMap listMemberMapPropertyDefinition, PropertyMap listMemberMapProperty) { for (PropertyDefinition summaryPropertyDefinition : listMemberMapPropertyDefinition .getSummaryPropertyDefinitions()) { Property mapMemberProperty = listMemberMapProperty.get(summaryPropertyDefinition.getName()); if (!(mapMemberProperty instanceof PropertySimple)) { throw new IllegalStateException("Property '" + mapMemberProperty.getName() + "' is defined as a map of simples but contains one or more non-simple members."); } PropertySimple mapMemberSimpleProperty = (PropertySimple) mapMemberProperty; FacesComponentUtility.addVerbatimText(parent, "<td class='" + PROPERTY_MAP_SUMMARY_DATA_CELL_STYLE_CLASS + "'>"); if (mapMemberSimpleProperty.getStringValue() == null) { FacesComponentUtility.addOutputText(parent, this.config, "not set", CssStyleClasses.REQUIRED_MARKER_TEXT); } else { FacesComponentUtility.addOutputText(parent, this.config, mapMemberSimpleProperty.getStringValue(), PROPERTY_MAP_SUMMARY_DATA_TEXT_STYLE_CLASS); } FacesComponentUtility.addVerbatimText(parent, "</td>\n"); } }