if (prop.isImmutable() && conf.get(prop.getName()) != null) { throw new UnacceptableConfiguration("The property " + prop + " cannot be overridden : immutable " + "property"); // The instance configuration tries to override an immutable property. if (prop.isMandatory() && prop.getValue() == null && conf.get(prop.getName()) == null) { throw new UnacceptableConfiguration("The mandatory property " + prop.getName() + " is missing"); // The property must be set.
/** * Creates the description object for the configuration handler description. * @param handler the configuration handler. * @param props the list of properties. * @param pid the managed service pid or <code>null</code> if not set. */ public ConfigurationHandlerDescription(ConfigurationHandler handler, List/*<Property>*/ props, String pid) { super(handler); m_conf = handler; m_properties = new PropertyDescription[props.size()]; for (int i = 0; i < props.size(); i++) { m_properties[i] = new PropertyDescription((Property) props.get(i)); } m_pid = pid; }
/** * Computes the default service properties to publish : * factory.name, service.pid, component.providedServiceSpecification, component.properties, component.description, factory.State. * * @return : the dictionary of properties to publish. */ public Dictionary<String, Object> getPropertiesToPublish() { Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("factory.name", m_factory.getName()); props.put(Constants.SERVICE_PID, m_factory.getName()); // Service PID is required for the integration in the configuration admin. // Add the version if set String v = getVersion(); if (v != null) { props.put(Factory.FACTORY_VERSION_PROPERTY, v); } props.put("component.providedServiceSpecifications", m_providedServiceSpecification); props.put("component.properties", m_properties); props.put("component.description", this); // add every immutable property for (PropertyDescription m_property : m_properties) { if (m_property.isImmutable() && m_property.getValue() != null) { props.put(m_property.getName(), m_property.getObjectValue(m_factory.getBundleContext())); } } // Add factory state props.put("factory.state", m_factory.getState()); return props; }
/** * Gets a property by name. * @param name the property name * @return the property description with the given name, {@code null} if there is no property with the given name. * @since 1.11.0 */ public PropertyDescription getPropertyByName(String name) { for (PropertyDescription desc :m_properties) { if (name.equals(desc.getName())) { return desc; } } return null; }
PropertyDescription pd = new PropertyDescription(name, type, value, immutable); desc.addProperty(pd); pd.setMandatory();
/** * Gets a property by name. * @param name the property name * @return the property description with the given name, {@code null} if there is no property with the given name. * @since 1.11.0 */ public PropertyDescription getPropertyByName(String name) { for (PropertyDescription desc :m_properties) { if (name.equals(desc.getName())) { return desc; } } return null; }
PropertyDescription pd = new PropertyDescription(name, type, value, immutable); desc.addProperty(pd); pd.setMandatory();
if (prop.isImmutable() && conf.get(prop.getName()) != null) { throw new UnacceptableConfiguration("The property " + prop + " cannot be overridden : immutable " + "property"); // The instance configuration tries to override an immutable property. if (prop.isMandatory() && prop.getValue() == null && conf.get(prop.getName()) == null) { throw new UnacceptableConfiguration("The mandatory property " + prop.getName() + " is missing"); // The property must be set.
/** * Computes the default service properties to publish : * factory.name, service.pid, component.providedServiceSpecification, component.properties, component.description, factory.State. * * @return : the dictionary of properties to publish. */ public Dictionary<String, Object> getPropertiesToPublish() { Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("factory.name", m_factory.getName()); props.put(Constants.SERVICE_PID, m_factory.getName()); // Service PID is required for the integration in the configuration admin. // Add the version if set String v = getVersion(); if (v != null) { props.put(Factory.FACTORY_VERSION_PROPERTY, v); } props.put("component.providedServiceSpecifications", m_providedServiceSpecification); props.put("component.properties", m_properties); props.put("component.description", this); // add every immutable property for (PropertyDescription m_property : m_properties) { if (m_property.isImmutable() && m_property.getValue() != null) { props.put(m_property.getName(), m_property.getObjectValue(m_factory.getBundleContext())); } } // Add factory state props.put("factory.state", m_factory.getState()); return props; }
/** * Does the factory support the given property ? This method check if the property is contained in the given property description array. * @param name : name of the property * @param props : list of property description * @return true if the factory support this property */ private boolean containsProperty(String name, org.apache.felix.ipojo.architecture.PropertyDescription[] props) { for (int i = 0; props != null && i < props.length; i++) { if (props[i].getName().equalsIgnoreCase(name)) { return true; } } if (name.equalsIgnoreCase("name")) { return true; } // Skip the name property return false; }
pd = new PropertyDescription(name, type, null, false); // Cannot be immutable if we have no value. } else { pd = new PropertyDescription(name, type, value, immutable); pd.setMandatory();
/** * Creates the description object for the configuration handler description. * @param handler the configuration handler. * @param props the list of properties. * @param pid the managed service pid or <code>null</code> if not set. */ public ConfigurationHandlerDescription(ConfigurationHandler handler, List/*<Property>*/ props, String pid) { super(handler); m_conf = handler; m_properties = new PropertyDescription[props.size()]; for (int i = 0; i < props.size(); i++) { m_properties[i] = new PropertyDescription((Property) props.get(i)); } m_pid = pid; }
prop.addAttribute(new Attribute("name", m_properties[i].getName())); prop.addAttribute(new Attribute("type", m_properties[i].getType())); if (m_properties[i].isMandatory() && m_properties[i].getValue() == null) { prop.addAttribute(new Attribute("value", "REQUIRED")); } else { prop.addAttribute(new Attribute("value", m_properties[i].getValue()));
/** * Adds a configuration properties to the component type. * * @param pd : the property to add */ public void addProperty(PropertyDescription pd) { //NOPMD remove the instance name of the 'name' property. String name = pd.getName(); // Check if the property is not already in the array for (int i = 0; i < m_properties.length; i++) { PropertyDescription desc = m_properties[i]; if (desc.getName().equals(name)) { return; } } PropertyDescription[] newProps = new PropertyDescription[m_properties.length + 1]; System.arraycopy(m_properties, 0, newProps, 0, m_properties.length); newProps[m_properties.length] = pd; m_properties = newProps; }
pd = new PropertyDescription(name, type, null, false); // Cannot be immutable if we have no value. } else { pd = new PropertyDescription(name, type, value, immutable); pd.setMandatory();
/** * Adds a String property in the component type. * * @param name : property name. * @param value : property value. * @param immutable : the property is immutable. */ public void addProperty(String name, String value, boolean immutable) { addProperty(new PropertyDescription(name, String.class.getName(), value, immutable)); }
prop.addAttribute(new Attribute("name", m_properties[i].getName())); prop.addAttribute(new Attribute("type", m_properties[i].getType())); if (m_properties[i].isMandatory() && m_properties[i].getValue() == null) { prop.addAttribute(new Attribute("value", "REQUIRED")); } else { prop.addAttribute(new Attribute("value", m_properties[i].getValue()));
/** * Adds a configuration properties to the component type. * * @param pd : the property to add */ public void addProperty(PropertyDescription pd) { //NOPMD remove the instance name of the 'name' property. String name = pd.getName(); // Check if the property is not already in the array for (int i = 0; i < m_properties.length; i++) { PropertyDescription desc = m_properties[i]; if (desc.getName().equals(name)) { return; } } PropertyDescription[] newProps = new PropertyDescription[m_properties.length + 1]; System.arraycopy(m_properties, 0, newProps, 0, m_properties.length); newProps[m_properties.length] = pd; m_properties = newProps; }