View | Details | Raw Unified | Return to bug 36384
Collapse All | Expand All

(-)../log4j/src/main/java/org/apache/log4j/config/PropertySetter.java (-10 / +26 lines)
Lines 107-133 Link Here
107
  public
107
  public
108
  void setProperties(Properties properties, String prefix) {
108
  void setProperties(Properties properties, String prefix) {
109
    int len = prefix.length();
109
    int len = prefix.length();
110
    
110
111
    for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) {
111
    for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) {
112
      String key = (String) e.nextElement();
112
      String key = (String) e.nextElement();
113
      
113
      
114
      // handle only properties that start with the desired frefix.
114
      // handle only properties that start with the desired frefix.
115
      if (key.startsWith(prefix)) {
115
      if (key.startsWith(prefix)) {
116
116
117
	
117
118
	// ignore key if it contains dots after the prefix
118
	// ignore key if it contains dots after the prefix
119
        if (key.indexOf('.', len + 1) > 0) {
119
        if (key.indexOf('.', len + 1) > 0) {
120
	  //System.err.println("----------Ignoring---["+key
120
	  //System.err.println("----------Ignoring---["+key
121
	  //	     +"], prefix=["+prefix+"].");
121
	  //	     +"], prefix=["+prefix+"].");
122
	  continue;
122
	  continue;
123
	}
123
	}
124
        
124
125
	String value = OptionConverter.findAndSubst(key, properties);
125
	String value = OptionConverter.findAndSubst(key, properties);
126
        key = key.substring(len);
126
        key = key.substring(len);
127
        if ("layout".equals(key) && obj instanceof Appender) {
127
        if ("layout".equals(key) && obj instanceof Appender) {
128
          continue;
128
          continue;
129
        }        
129
        }        
130
        setProperty(key, value);
130
        Object valueObj = setProperty(key, value);
131
132
        // If the value object itself needs to be configured with properties, do it.
133
        LogLog.debug( "Settings properties for Object: " + valueObj + " with prefix: " + prefix + key);
134
        new PropertySetter( valueObj ).setProperties( properties, prefix + key +"." );
131
      }
135
      }
132
    }
136
    }
133
    activate();
137
    activate();
Lines 144-156 Link Here
144
     If it expects an int, then an attempt is made to convert 'value'
148
     If it expects an int, then an attempt is made to convert 'value'
145
     to an int using new Integer(value). If the setter expects a boolean,
149
     to an int using new Integer(value). If the setter expects a boolean,
146
     the conversion is by new Boolean(value).
150
     the conversion is by new Boolean(value).
147
     
151
152
   <p>In case the setter expects an Object of another class, the
153
   Setter will attemps to create a new new Object of this class using
154
   Reflection.
155
     
148
     @param name    name of the property
156
     @param name    name of the property
149
     @param value   String value of the property
157
     @param value   String value of the property
158
     @return the Object that was actually set as a value.
150
   */
159
   */
151
  public
160
  public
152
  void setProperty(String name, String value) {
161
  Object setProperty(String name, String value) {
153
    if (value == null) return;
162
    if (value == null) return null;
154
    
163
    
155
    name = Introspector.decapitalize(name);
164
    name = Introspector.decapitalize(name);
156
    PropertyDescriptor prop = getPropertyDescriptor(name);
165
    PropertyDescriptor prop = getPropertyDescriptor(name);
Lines 162-173 Link Here
162
		  obj.getClass().getName()+"." );
171
		  obj.getClass().getName()+"." );
163
    } else {
172
    } else {
164
      try {
173
      try {
165
        setProperty(prop, name, value);
174
        return setProperty(prop, name, value);
166
      } catch (PropertySetterException ex) {
175
      } catch (PropertySetterException ex) {
167
        LogLog.warn("Failed to set property [" + name +
176
        LogLog.warn("Failed to set property [" + name +
168
                    "] to value \"" + value + "\". ", ex.rootCause);
177
                    "] to value \"" + value + "\". ", ex.rootCause);
169
      }
178
      }
170
    }
179
    }
180
    return null;
171
  }
181
  }
172
  
182
  
173
  /** 
183
  /** 
Lines 176-185 Link Here
176
      @param prop A PropertyDescriptor describing the characteristics
186
      @param prop A PropertyDescriptor describing the characteristics
177
      of the property to set.
187
      of the property to set.
178
      @param name The named of the property to set.
188
      @param name The named of the property to set.
179
      @param value The value of the property.      
189
      @param value The value of the property.
190
      @return the actual java.lang.Object that was passed as a value
180
   */
191
   */
181
  public
192
  public
182
  void setProperty(PropertyDescriptor prop, String name, String value)
193
  Object setProperty(PropertyDescriptor prop, String name, String value)
183
    throws PropertySetterException {
194
    throws PropertySetterException {
184
    Method setter = prop.getWriteMethod();
195
    Method setter = prop.getWriteMethod();
185
    if (setter == null) {
196
    if (setter == null) {
Lines 207-212 Link Here
207
    } catch (Exception ex) {
218
    } catch (Exception ex) {
208
      throw new PropertySetterException(ex);
219
      throw new PropertySetterException(ex);
209
    }
220
    }
221
    return arg;
210
  }
222
  }
211
  
223
  
212
224
Lines 234-239 Link Here
234
      }
246
      }
235
    } else if (Priority.class.isAssignableFrom(type)) {
247
    } else if (Priority.class.isAssignableFrom(type)) {
236
      return OptionConverter.toLevel(v, (Level) Level.DEBUG);
248
      return OptionConverter.toLevel(v, (Level) Level.DEBUG);
249
    } else {
250
      // Maybe the argument is a class name, let try to find
251
      // the class and check if it 'isAssignableFrom(type)'
252
      return OptionConverter.instantiateByClassName( v, type, null);
237
    }
253
    }
238
    return null;
254
    return null;
239
  }
255
  }

Return to bug 36384