001/*
002 * Copyright 2012 Atteo.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.atteo.moonshine.jetty.rewriterules;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import javax.xml.bind.annotation.XmlElement;
022import javax.xml.bind.annotation.XmlElementRef;
023import javax.xml.bind.annotation.XmlElementWrapper;
024import javax.xml.bind.annotation.XmlRootElement;
025
026import org.eclipse.jetty.rewrite.handler.Rule;
027import org.eclipse.jetty.rewrite.handler.VirtualHostRuleContainer;
028
029@XmlRootElement(name = "virtualHost")
030public class VirtualHostRuleConfig extends RuleConfig {
031    @XmlElementWrapper(name = "hosts")
032    @XmlElement(name = "host")
033    private String[] virtualHosts = new String[0];
034
035    @XmlElementWrapper(name = "rules")
036    @XmlElementRef
037    private List<RuleConfig> rules = new ArrayList<>();
038
039    @Override
040    public Rule getRule() {
041        VirtualHostRuleContainer ruleContainer = new VirtualHostRuleContainer();
042        for (RuleConfig rule : rules) {
043            ruleContainer.addRule(rule.getRule());
044        }
045        ruleContainer.setVirtualHosts(virtualHosts);
046        return ruleContainer;
047    }
048}