KNOX-1105 - Provide indication that topologies were generated from simple descriptors...
[knox.git] / gateway-server / src / main / java / org / apache / hadoop / gateway / topology / builder / BeanPropertyTopologyBuilder.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with this
4 * work for additional information regarding copyright ownership. The ASF
5 * licenses this file to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package org.apache.hadoop.gateway.topology.builder;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.hadoop.gateway.topology.Application;
23 import org.apache.hadoop.gateway.topology.Provider;
24 import org.apache.hadoop.gateway.topology.Service;
25 import org.apache.hadoop.gateway.topology.Topology;
26
27 public class BeanPropertyTopologyBuilder implements TopologyBuilder {
28
29 private String name;
30 private String defaultService;
31 private boolean isGenerated;
32 private List<Provider> providers;
33 private List<Service> services;
34 private List<Application> applications;
35
36 public BeanPropertyTopologyBuilder() {
37 providers = new ArrayList<Provider>();
38 services = new ArrayList<Service>();
39 applications = new ArrayList<Application>();
40 }
41
42 public BeanPropertyTopologyBuilder name(String name) {
43 this.name = name;
44 return this;
45 }
46
47 public String name() {
48 return name;
49 }
50
51 public BeanPropertyTopologyBuilder generated(String isGenerated) {
52 this.isGenerated = Boolean.valueOf(isGenerated);
53 return this;
54 }
55
56 public boolean isGenerated() {
57 return isGenerated;
58 }
59
60 public BeanPropertyTopologyBuilder defaultService(String defaultService) {
61 this.defaultService = defaultService;
62 return this;
63 }
64
65 public String defaultService() {
66 return defaultService;
67 }
68
69 public BeanPropertyTopologyBuilder addProvider(Provider provider) {
70 providers.add(provider);
71 return this;
72 }
73
74 public List<Provider> providers() {
75 return providers;
76 }
77
78 public BeanPropertyTopologyBuilder addService(Service service) {
79 services.add(service);
80 return this;
81 }
82
83 public List<Service> services() {
84 return services;
85 }
86
87 public BeanPropertyTopologyBuilder addApplication( Application application ) {
88 applications.add(application);
89 return this;
90 }
91
92 public List<Application> applications() {
93 return applications;
94 }
95
96 public Topology build() {
97 Topology topology = new Topology();
98 topology.setName(name);
99 topology.setDefaultServicePath(defaultService);
100 topology.setGenerated(isGenerated);
101
102 for (Provider provider : providers) {
103 topology.addProvider(provider);
104 }
105
106 for (Service service : services) {
107 topology.addService(service);
108 }
109
110 for (Application application : applications) {
111 topology.addApplication(application);
112 }
113
114 return topology;
115 }
116 }