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 
17 package com.android.server.firewall;
18 
19 import com.android.internal.util.XmlUtils;
20 import org.xmlpull.v1.XmlPullParser;
21 import org.xmlpull.v1.XmlPullParserException;
22 
23 import java.io.IOException;
24 import java.util.ArrayList;
25 
26 abstract class FilterList implements Filter {
27     protected final ArrayList<Filter> children = new ArrayList<Filter>();
28 
readFromXml(XmlPullParser parser)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 
readChild(XmlPullParser parser)37     protected void readChild(XmlPullParser parser) throws IOException, XmlPullParserException {
38         Filter filter = IntentFirewall.parseFilter(parser);
39         children.add(filter);
40     }
41 }
42