blob: 2d05001283d60fad1d4d3181711aaad2760d49cc [file] [log] [blame]
Carsten Ziegeler73903902013-01-30 21:09:50 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.scrplugin.helper;
20
21import java.util.ArrayList;
22import java.util.Iterator;
23import java.util.List;
24
25public abstract class ComponentContainerUtil {
26
27 public static class ComponentContainerContainer {
28 public List<ComponentContainer> components;
29 public String className;
30 }
31
32 /**
33 * Split the list of components into separate lists depending
34 * on the configuration.
35 */
Carsten Ziegelere5fef1c2013-07-17 12:32:32 +000036 public static List<ComponentContainerContainer> split(final List<ComponentContainer> components) {
Carsten Ziegeler73903902013-01-30 21:09:50 +000037 final List<ComponentContainerContainer> result = new ArrayList<ComponentContainerContainer>();
38
Carsten Ziegelere5fef1c2013-07-17 12:32:32 +000039 while ( !components.isEmpty() ) {
40 // get the first component
41 final List<ComponentContainer> innerList = new ArrayList<ComponentContainer>();
42 final ComponentContainer component = components.remove(0);
43 innerList.add(component);
44 final int pos = component.getClassDescription().getDescribedClass().getName().indexOf('$');
45 final String baseClassName;
46 if ( pos == -1 ) {
47 baseClassName = component.getClassDescription().getDescribedClass().getName();
48 } else {
49 baseClassName = component.getClassDescription().getDescribedClass().getName().substring(0, pos);
Carsten Ziegeler73903902013-01-30 21:09:50 +000050 }
Carsten Ziegelere5fef1c2013-07-17 12:32:32 +000051 final String baseClassPrefix = baseClassName + '$';
52
53 // check for inner classes
54 final Iterator<ComponentContainer> i = components.iterator();
55 while ( i.hasNext() ) {
56 final ComponentContainer cc = i.next();
57 if ( cc.getClassDescription().getDescribedClass().getName().startsWith(baseClassPrefix) ) {
58 innerList.add(cc);
59 i.remove();
60 }
Carsten Ziegeler73903902013-01-30 21:09:50 +000061 }
Carsten Ziegelere5fef1c2013-07-17 12:32:32 +000062
63 final ComponentContainerContainer ccc = new ComponentContainerContainer();
64 ccc.components = innerList;
65 ccc.className = baseClassName;
66 result.add(ccc);
Carsten Ziegeler73903902013-01-30 21:09:50 +000067 }
68
69 return result;
70 }
71}