FilterList.java revision 9158825f9c41869689d6b1786d7c7aa8bdd524ce
1/*
2 * Copyright (C) 2013 The Android Open Source Project
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
17package com.android.server.firewall;
18
19import com.android.internal.util.XmlUtils;
20import org.xmlpull.v1.XmlPullParser;
21import org.xmlpull.v1.XmlPullParserException;
22
23import java.io.IOException;
24import java.util.ArrayList;
25
26abstract class FilterList implements Filter {
27    protected final ArrayList<Filter> children = new ArrayList<Filter>();
28
29    public FilterList readFromXml(XmlPullParser parser) throws IOException, XmlPullParserException {
30        int outerDepth = parser.getDepth();
31        while (XmlUtils.nextElementWithin(parser, outerDepth)) {
32            readChild(parser);
33        }
34        return this;
35    }
36
37    protected void readChild(XmlPullParser parser) throws IOException, XmlPullParserException {
38        Filter filter = IntentFirewall.parseFilter(parser);
39        children.add(filter);
40    }
41}
42