View Javadoc
1   /*
2    * Copyright (C) 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.codehaus.plexus.metadata.gleaner;
18  
19  import java.util.Collection;
20  import java.util.Map;
21  
22  import org.codehaus.plexus.component.repository.ComponentDescriptor;
23  import org.codehaus.plexus.configuration.PlexusConfiguration;
24  import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
25  
26  /**
27   * Support for component gleaner implementations.
28   *
29   * @version $Id$
30   */
31  public abstract class ComponentGleanerSupport
32  {
33      private static final String EMPTY_STRING = "";
34  
35      protected String filterEmptyAsNull(final String value) {
36          if (value == null) {
37              return null;
38          } else if (EMPTY_STRING.equals(value.trim())) {
39              return null;
40          } else {
41              return value;
42          }
43      }
44  
45      protected boolean isRequirementListType(final Class<?> type) {
46          // assert type != null;
47  
48          return Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type);
49      }
50  
51      protected void addChildConfiguration(final ComponentDescriptor<?> component, final PlexusConfiguration config) {
52          // assert component != null;
53          // assert config != null;
54  
55          if (!component.hasConfiguration()) {
56              component.setConfiguration(new XmlPlexusConfiguration("configuration"));
57          }
58  
59          component.getConfiguration().addChild(config);
60      }
61  
62      protected String deHump(final String string) {
63          // assert string != null;
64  
65          StringBuilder buff = new StringBuilder();
66  
67          for (int i = 0; i < string.length(); i++) {
68              if (i != 0 && Character.isUpperCase(string.charAt(i))) {
69                  buff.append('-');
70              }
71  
72              buff.append(string.charAt(i));
73          }
74  
75          return buff.toString().trim().toLowerCase();
76      }
77  }