001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.repository.sequencer; 025 026 import java.util.Collection; 027 import java.util.Collections; 028 import java.util.LinkedHashSet; 029 import java.util.Map; 030 import java.util.Set; 031 import net.jcip.annotations.Immutable; 032 import org.jboss.dna.common.component.ComponentConfig; 033 034 /** 035 * @author Randall Hauch 036 */ 037 @Immutable 038 public class SequencerConfig extends ComponentConfig { 039 040 private final Set<SequencerPathExpression> pathExpressions; 041 042 public SequencerConfig( String name, 043 String description, 044 String classname, 045 String[] classpath, 046 String... pathExpressions ) { 047 this(name, description, System.currentTimeMillis(), null, classname, classpath, pathExpressions); 048 } 049 050 public SequencerConfig( String name, 051 String description, 052 Map<String, Object> properties, 053 String classname, 054 String[] classpath, 055 String... pathExpressions ) { 056 this(name, description, System.currentTimeMillis(), properties, classname, classpath, pathExpressions); 057 } 058 059 public SequencerConfig( String name, 060 String description, 061 long timestamp, 062 Map<String, Object> properties, 063 String classname, 064 String[] classpath, 065 String... pathExpressions ) { 066 super(name, description, timestamp, properties, classname, classpath); 067 this.pathExpressions = buildPathExpressionSet(pathExpressions); 068 } 069 070 /* package */static Set<SequencerPathExpression> buildPathExpressionSet( String... pathExpressions ) { 071 Set<SequencerPathExpression> result = null; 072 if (pathExpressions != null) { 073 result = new LinkedHashSet<SequencerPathExpression>(); 074 for (String pathExpression : pathExpressions) { 075 if (pathExpression == null) continue; 076 pathExpression = pathExpression.trim(); 077 if (pathExpression.length() == 0) continue; 078 result.add(SequencerPathExpression.compile(pathExpression)); 079 } 080 result = Collections.unmodifiableSet(result); 081 } else { 082 result = Collections.emptySet(); // already immutable 083 } 084 return result; 085 } 086 087 public Collection<SequencerPathExpression> getPathExpressions() { 088 return Collections.unmodifiableSet(this.pathExpressions); 089 } 090 091 public boolean hasChanged( SequencerConfig that ) { 092 if (super.hasChanged(that)) return true; 093 if (!this.getPathExpressions().equals(that.getPathExpressions())) return true; 094 return false; 095 } 096 097 }