-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JavaResourceGenerator, and refactor ResourceFactory to select the…
… most specialized resource type when performing generation
- Loading branch information
1 parent
9779b47
commit 4ed74e8
Showing
15 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
container-api/src/main/java/org/jboss/forge/container/util/Weighted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2012 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.container.util; | ||
|
||
/** | ||
* Defines a class as having a weight for ordering. | ||
* | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
public interface Weighted | ||
{ | ||
int DEFAULT = 0; | ||
int HIGH = 1000; | ||
int MEDIUM = 100; | ||
int LOW = -100; | ||
|
||
int priority(); | ||
} |
35 changes: 35 additions & 0 deletions
35
container-api/src/main/java/org/jboss/forge/container/util/WeightedComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2012 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.container.util; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* Compares {@link Weighted} objects. | ||
* | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
* | ||
*/ | ||
public class WeightedComparator implements Comparator<Weighted> | ||
{ | ||
public static final Comparator<Weighted> INSTANCE = new WeightedComparator(); | ||
|
||
private WeightedComparator() | ||
{ | ||
} | ||
|
||
@Override | ||
public int compare(final Weighted left, final Weighted right) | ||
{ | ||
if ((left == null) || (right == null)) | ||
{ | ||
return 0; | ||
} | ||
return ((Integer) left.priority()).compareTo(right.priority()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...-java/impl/src/main/java/org/jboss/forge/parser/java/resources/JavaResourceGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jboss.forge.parser.java.resources; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.forge.container.services.Exported; | ||
import org.jboss.forge.resource.Resource; | ||
import org.jboss.forge.resource.ResourceFactory; | ||
import org.jboss.forge.resource.ResourceGenerator; | ||
|
||
@Exported | ||
public class JavaResourceGenerator implements ResourceGenerator<JavaResource, File> | ||
{ | ||
@Override | ||
public boolean handles(Class<?> type, Object resource) | ||
{ | ||
if (resource instanceof File && ((File) resource).getName().endsWith(".java")) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T extends Resource<File>> T getResource(ResourceFactory factory, Class<JavaResource> type, File resource) | ||
{ | ||
return (T) new JavaResource(factory, resource); | ||
} | ||
|
||
@Override | ||
public <T extends Resource<File>> Class<?> getResourceType(Class<JavaResource> type, File resource) | ||
{ | ||
return JavaResource.class; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
resources/api/src/main/java/org/jboss/forge/resource/ResourceGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package org.jboss.forge.resource; | ||
|
||
|
||
public interface ResourceGenerator<RESOURCETYPE, UNDERLYINGTYPE> | ||
{ | ||
public boolean handles(Class<?> type, final Object resource); | ||
|
||
public <T extends Resource<UNDERLYINGTYPE>> T getResource(final ResourceFactory factory, Class<RESOURCETYPE> type, | ||
final UNDERLYINGTYPE resource); | ||
|
||
public <T extends Resource<UNDERLYINGTYPE>> Class<?> getResourceType(Class<RESOURCETYPE> type, final UNDERLYINGTYPE resource); | ||
public <T extends Resource<UNDERLYINGTYPE>> Class<?> getResourceType(Class<RESOURCETYPE> type, | ||
final UNDERLYINGTYPE resource); | ||
|
||
} |