blob: 199c8d39ba7e4fb1a4331d111b44faeec7a853fe [file] [log] [blame]
Simon Hunt41b943e2015-05-21 13:52:01 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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
18package org.onosproject.cord.gui.model;
19
Simon Hunt6c2555b2015-05-21 18:17:56 -070020import com.google.common.collect.ImmutableSet;
21
22import java.util.HashSet;
23import java.util.Set;
24
Simon Hunt41b943e2015-05-21 13:52:01 -070025/**
26 * Encapsulates a bundle, including current state.
27 */
28public class Bundle {
29 private final BundleDescriptor bundleDescriptor;
Simon Hunt6c2555b2015-05-21 18:17:56 -070030 private final Set<XosFunction> functions;
Simon Hunt41b943e2015-05-21 13:52:01 -070031
32 /**
33 * Constructs a new bundle instance.
34 *
35 * @param bundleDescriptor the descriptor
36 */
37 public Bundle(BundleDescriptor bundleDescriptor) {
38 this.bundleDescriptor = bundleDescriptor;
Simon Hunt6c2555b2015-05-21 18:17:56 -070039 this.functions = initFunctions();
Simon Hunt41b943e2015-05-21 13:52:01 -070040 }
41
42 /**
43 * Returns the bundle descriptor.
44 *
45 * @return the descriptor
46 */
47 public BundleDescriptor descriptor() {
48 return bundleDescriptor;
49 }
50
Simon Hunt6c2555b2015-05-21 18:17:56 -070051 /**
52 * Returns the set of function instances for this bundle.
53 *
54 * @return the functions
55 */
56 public Set<XosFunction> functions() {
57 return ImmutableSet.copyOf(functions);
58 }
59
60 /**
61 * Creates an initial set of function instances.
62 *
63 * @return initial function instances
64 */
65 private Set<XosFunction> initFunctions() {
66 Set<XosFunction> funcs = new HashSet<XosFunction>();
67 for (XosFunctionDescriptor xfd: bundleDescriptor.functions()) {
68 funcs.add(createFunction(xfd));
69 }
70 return funcs;
71 }
72
73 private XosFunction createFunction(XosFunctionDescriptor xfd) {
74 XosFunction func;
75 switch (xfd) {
76 case URL_FILTER:
77 func = new UrlFilterFunction(xfd);
78 break;
79
80 default:
81 func = new DefaultXosFunction(xfd);
82 break;
83 }
84 return func;
85 }
Simon Hunt41b943e2015-05-21 13:52:01 -070086}