Skip to content

Commit 7ca7687

Browse files
committed
Began configuration model
1 parent 698548f commit 7ca7687

24 files changed

Lines changed: 830 additions & 8 deletions

‎api/pom.xml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
1313
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1414
<modelVersion>4.0.0</modelVersion>
15+
1516
<parent>
1617
<groupId>com.ocpsoft.rewrite</groupId>
1718
<artifactId>rewrite-parent</artifactId>
@@ -21,6 +22,4 @@
2122

2223
<artifactId>rewrite-api</artifactId>
2324

24-
<dependencies>
25-
</dependencies>
2625
</project>

‎api/src/main/java/com/ocpsoft/rewrite/RewriteContext.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ public interface RewriteContext
3131

3232
void put(String key, Object value);
3333

34-
void hasKey(String key);
34+
void containsKey(String key);
3535
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
import java.util.Arrays;
25+
import java.util.List;
26+
27+
import com.ocpsoft.rewrite.event.Rewrite;
28+
29+
/**
30+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
31+
*
32+
*/
33+
public class And implements Condition
34+
{
35+
private final List<Condition> conditions;
36+
37+
private And(final Condition... conditions)
38+
{
39+
this.conditions = Arrays.asList(conditions);
40+
}
41+
42+
public static And $(final Condition... conditions)
43+
{
44+
return new And(conditions);
45+
}
46+
47+
public boolean evaluate(final Rewrite event)
48+
{
49+
boolean result = true;
50+
for (Condition c : conditions) {
51+
if (!c.evaluate(event))
52+
{
53+
result = false;
54+
}
55+
}
56+
return result;
57+
}
58+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
import com.ocpsoft.rewrite.event.Rewrite;
25+
26+
/**
27+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
28+
*
29+
*/
30+
public interface Condition
31+
{
32+
boolean evaluate(Rewrite event);
33+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
/**
25+
* Abstract access to conditional primitives.
26+
*
27+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
28+
*
29+
*/
30+
public abstract class Conditions
31+
{
32+
public Not not(final Condition condition)
33+
{
34+
return Not.$(condition);
35+
}
36+
37+
public And and(final Condition... conditions)
38+
{
39+
return And.$(conditions);
40+
}
41+
42+
public Or or(final Condition... conditions)
43+
{
44+
return Or.$(conditions);
45+
}
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
/**
25+
* Base interface for all Rewrite configuration objects.
26+
*
27+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
28+
*/
29+
public interface Configuration
30+
{
31+
32+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
import java.util.ArrayList;
25+
import java.util.Collections;
26+
import java.util.List;
27+
28+
import com.ocpsoft.rewrite.pattern.WeightedComparator;
29+
import com.ocpsoft.rewrite.services.ServiceLoader;
30+
import com.ocpsoft.rewrite.util.Iterators;
31+
32+
/**
33+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
34+
*
35+
*/
36+
public class ConfigurationLoader
37+
{
38+
public List<Configuration> loadConfigurations()
39+
{
40+
@SuppressWarnings("unchecked")
41+
ServiceLoader<ConfigurationProvider> loader = ServiceLoader.load(ConfigurationProvider.class);
42+
List<ConfigurationProvider> providers = Iterators.asList(loader.iterator());
43+
44+
Collections.sort(providers, new WeightedComparator());
45+
46+
List<Configuration> configs = new ArrayList<Configuration>();
47+
for (ConfigurationProvider provider : providers) {
48+
configs.add(provider.getConfiguration());
49+
}
50+
51+
return configs;
52+
}
53+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
import com.ocpsoft.rewrite.pattern.Weighted;
25+
26+
/**
27+
* Provider configuration to the Rewrite runtime environment.
28+
*
29+
* Additional configuration providers my be specified by providing a service activator file containing the name of your
30+
* implementations:
31+
* <p>
32+
* <code> /META-INF/services/com.ocpsoft.rewrite.config.ConfigurationProvider<br>
33+
*
34+
* --------------<br>
35+
* com.example.ConfigurationProviderImpl</code>
36+
*
37+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
38+
*/
39+
public interface ConfigurationProvider extends Weighted
40+
{
41+
/**
42+
* Return the additional configuration.
43+
*/
44+
public Configuration getConfiguration();
45+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
import com.ocpsoft.rewrite.event.Rewrite;
25+
26+
/**
27+
* Condition that always returns false.
28+
*
29+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
30+
*
31+
*/
32+
public class False implements Condition
33+
{
34+
@Override
35+
public boolean evaluate(final Rewrite event)
36+
{
37+
return false;
38+
}
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.config;
23+
24+
import com.ocpsoft.rewrite.event.Rewrite;
25+
26+
/**
27+
* Evaluates all conditions.
28+
*
29+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
30+
*
31+
*/
32+
public class Not implements Condition
33+
{
34+
private final Condition condition;
35+
36+
private Not(final Condition condition)
37+
38+
{
39+
this.condition = condition;
40+
}
41+
42+
public static Not $(final Condition condition)
43+
{
44+
return new Not(condition);
45+
}
46+
47+
public boolean evaluate(final Rewrite event)
48+
{
49+
return condition.evaluate(event) != true;
50+
}
51+
}

0 commit comments

Comments
 (0)