-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
304 additions
and
6 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
62 changes: 62 additions & 0 deletions
62
corant-context/src/main/java/org/corant/context/qualifier/Bundle.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,62 @@ | ||
/* | ||
* Copyright (c) 2013-2018, Bingo.Chen (finesoft@gmail.com). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.corant.context.qualifier; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import javax.enterprise.util.AnnotationLiteral; | ||
import javax.enterprise.util.Nonbinding; | ||
import javax.inject.Qualifier; | ||
|
||
/** | ||
* corant-modules-bundle | ||
* | ||
* @author bingo 下午8:44:38 | ||
* | ||
*/ | ||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE}) | ||
public @interface Bundle { | ||
|
||
/** | ||
* The name of the bundle. | ||
*/ | ||
@Nonbinding | ||
String value(); | ||
|
||
class BundleLiteral extends AnnotationLiteral<Bundle> implements Bundle { | ||
|
||
private static final long serialVersionUID = -5766940942537035511L; | ||
|
||
final String value; | ||
|
||
public BundleLiteral(String value) { | ||
this.value = value; | ||
} | ||
|
||
public static BundleLiteral of(String value) { | ||
return new BundleLiteral(value); | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return value; | ||
} | ||
|
||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
corant-context/src/main/java/org/corant/context/service/ResourceBundleProvider.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,37 @@ | ||
/* | ||
* Copyright (c) 2013-2021, Bingo.Chen (finesoft@gmail.com). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.corant.context.service; | ||
|
||
import java.util.ResourceBundle; | ||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import org.corant.context.qualifier.Bundle; | ||
|
||
/** | ||
* corant-modules-bundle | ||
* | ||
* @author bingo 下午10:14:42 | ||
* | ||
*/ | ||
public class ResourceBundleProvider { | ||
|
||
@Produces | ||
@Dependent | ||
@Bundle("") | ||
ResourceBundle produce(final InjectionPoint injectionPoint) { | ||
final String bundleName = injectionPoint.getAnnotated().getAnnotation(Bundle.class).value(); | ||
return ResourceBundle.getBundle(bundleName); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
corant-modules/corant-modules-javafx/corant-modules-javafx-cdi/pom.xml
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,25 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.corant</groupId> | ||
<artifactId>corant-modules-javafx</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>corant-modules-javafx-cdi</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.corant</groupId> | ||
<artifactId>corant-context</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjfx</groupId> | ||
<artifactId>javafx-fxml</artifactId> | ||
</dependency> | ||
<!-- Standard JEE --> | ||
<dependency> | ||
<groupId>jakarta.enterprise</groupId> | ||
<artifactId>jakarta.enterprise.cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...es-javafx/corant-modules-javafx-cdi/src/main/java/org/corant/modules/javafx/cdi/FXML.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,38 @@ | ||
/* | ||
* Copyright (c) 2013-2021, Bingo.Chen (finesoft@gmail.com). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.corant.modules.javafx.cdi; | ||
|
||
import static org.corant.shared.util.Strings.EMPTY; | ||
import javax.enterprise.util.Nonbinding; | ||
|
||
/** | ||
* corant-modules-javafx-cdi | ||
* | ||
* @author bingo 下午11:26:29 | ||
* | ||
*/ | ||
public @interface FXML { | ||
|
||
/** | ||
* The name of the resources used to resolve resource key attribute values. | ||
*/ | ||
@Nonbinding | ||
String bundle(); | ||
|
||
/** | ||
* The URL used to resolve relative path attribute values. | ||
*/ | ||
@Nonbinding | ||
String url() default EMPTY; | ||
} |
45 changes: 45 additions & 0 deletions
45
...ant-modules-javafx-cdi/src/main/java/org/corant/modules/javafx/cdi/FXMLLoaderFactory.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,45 @@ | ||
/* | ||
* Copyright (c) 2013-2021, Bingo.Chen (finesoft@gmail.com). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.corant.modules.javafx.cdi; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.corant.shared.util.Conversions.toObject; | ||
import static org.corant.shared.util.Strings.isBlank; | ||
import java.net.URL; | ||
import java.util.ResourceBundle; | ||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import org.corant.context.Beans; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.fxml.JavaFXBuilderFactory; | ||
|
||
/** | ||
* corant-modules-javafx-cdi | ||
* | ||
* @author bingo 下午11:08:06 | ||
* | ||
*/ | ||
public class FXMLLoaderFactory { | ||
|
||
@Produces | ||
@Dependent | ||
public FXMLLoader produce(final InjectionPoint ip) { | ||
final FXML fxml = ip.getAnnotated().getAnnotation(FXML.class); | ||
final URL url = fxml == null || isBlank(fxml.url()) ? null : toObject(fxml.url(), URL.class); | ||
final ResourceBundle bundle = | ||
fxml == null || isBlank(fxml.bundle()) ? null : ResourceBundle.getBundle(fxml.bundle()); | ||
return new FXMLLoader(url, bundle, new JavaFXBuilderFactory(), Beans::resolve, UTF_8); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...x/corant-modules-javafx-cdi/src/main/java/org/corant/modules/javafx/cdi/package-info.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,20 @@ | ||
/* | ||
* Copyright (c) 2013-2021, Bingo.Chen (finesoft@gmail.com). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
/** | ||
* corant-modules-javafx-cdi | ||
* | ||
* @author bingo 下午11:06:37 | ||
* | ||
*/ | ||
package org.corant.modules.javafx.cdi; |
5 changes: 5 additions & 0 deletions
5
...les/corant-modules-javafx/corant-modules-javafx-cdi/src/main/resources/META-INF/beans.xml
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,5 @@ | ||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd" | ||
bean-discovery-mode="annotated"> | ||
</beans> |
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,13 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.corant</groupId> | ||
<artifactId>corant-modules</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>corant-modules-javafx</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>corant-modules-javafx-cdi</module> | ||
</modules> | ||
</project> |
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