001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.common.util.metainf.service;
017
018import java.util.List;
019
020import org.kuali.common.util.Assert;
021import org.kuali.common.util.execute.Executable;
022import org.kuali.common.util.metainf.model.MetaInfContext;
023import org.kuali.common.util.metainf.model.ScanResult;
024
025public final class MetaInfExecutable implements Executable {
026
027        public static final boolean DEFAULT_SKIP = false;
028
029        private final boolean skip;
030        private final List<MetaInfContext> contexts;
031        private final MetaInfService service;
032
033        public MetaInfExecutable(List<MetaInfContext> contexts, MetaInfService service) {
034                this(contexts, service, DEFAULT_SKIP);
035        }
036
037        public MetaInfExecutable(List<MetaInfContext> contexts, MetaInfService service, boolean skip) {
038                Assert.noNulls(contexts, service);
039                this.skip = skip;
040                this.contexts = contexts;
041                this.service = service;
042        }
043
044        @Override
045        public void execute() {
046
047                if (skip) {
048                        return;
049                }
050
051                List<ScanResult> results = service.scan(contexts);
052                service.write(results);
053
054        }
055
056        public boolean isSkip() {
057                return skip;
058        }
059
060        public List<MetaInfContext> getContexts() {
061                return contexts;
062        }
063
064        public MetaInfService getService() {
065                return service;
066        }
067
068}