Skip to content

Commit

Permalink
Fix #190 Remove module .xml and use genrated source code injected with
Browse files Browse the repository at this point in the history
spi
  • Loading branch information
sbordes committed Mar 20, 2016
1 parent ce2af9b commit 6073bee
Show file tree
Hide file tree
Showing 32 changed files with 396 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.jrebirth.af.api.wave.annotation.OnWave;

/**
* The annotation <strong>Preload</strong>.
* The annotation <strong>Preload</strong> is used to force loading of the current class.
*
* In example it will create WaveType and register them to be managed using {@link OnWave} annotation.
*
* @author Sébastien Bordes
*/
@Target(ElementType.METHOD)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jrebirth.af.processor.annotation;
package org.jrebirth.af.api.module;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand All @@ -29,6 +29,6 @@
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
@Documented
public @interface WarmUp {
public @interface BootComponent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.jrebirth.af.api.module;

public interface ModuleStarter {

void start();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jrebirth.af.api.module;

import org.jrebirth.af.api.annotation.Preload;

@Preload
public interface Preloadable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jrebirth.af.processor.annotation;
package org.jrebirth.af.api.module;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jrebirth.af.processor.annotation;
package org.jrebirth.af.api.module;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jrebirth.af.processor.annotation;
package org.jrebirth.af.api.module;

// TODO: Auto-generated Javadoc
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Provides...
*/
package org.jrebirth.af.api.module;
3 changes: 3 additions & 0 deletions org.jrebirth.af/component/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
<accessrules>
<accessrule kind="accessible" pattern="javafx/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
Expand Down
2 changes: 0 additions & 2 deletions org.jrebirth.af/component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<artifactId>processor</artifactId>
<version>8.1.0-SNAPSHOT</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -48,7 +47,6 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<!-- <optional>true</optional> -->
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import javafx.scene.image.Image;

import org.jrebirth.af.api.component.behavior.Behavior;
import org.jrebirth.af.api.module.RegistrationPoint;
import org.jrebirth.af.component.behavior.dockable.data.Dockable;
import org.jrebirth.af.component.resources.ComponentImages;
import org.jrebirth.af.processor.annotation.RegistrationPoint;

@RegistrationPoint(exclusive = true)
public interface DockableBehavior extends Behavior<Dockable> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jrebirth.af.component.behavior.dockable.impl;

import org.jrebirth.af.api.module.Register;
import org.jrebirth.af.api.module.RegistrationPriority;
import org.jrebirth.af.component.behavior.dockable.DockableBehavior;
import org.jrebirth.af.component.behavior.dockable.data.Dockable;
import org.jrebirth.af.core.component.behavior.AbstractModelBehavior;
import org.jrebirth.af.processor.annotation.Register;
import org.jrebirth.af.processor.annotation.RegistrationPriority;

@Register(value = DockableBehavior.class, priority = RegistrationPriority.Normal)
public class DockableBehaviorImpl extends AbstractModelBehavior<Dockable> implements DockableBehavior {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jrebirth.af.component.behavior.swipable;

import org.jrebirth.af.api.component.behavior.Behavior;
import org.jrebirth.af.api.module.RegistrationPoint;
import org.jrebirth.af.component.behavior.swipable.data.Swipable;
import org.jrebirth.af.processor.annotation.RegistrationPoint;

@RegistrationPoint
public interface SwipableBehavior extends Behavior<Swipable> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import javafx.event.EventType;
import javafx.scene.input.SwipeEvent;

import org.jrebirth.af.api.module.Register;
import org.jrebirth.af.api.module.RegistrationPriority;
import org.jrebirth.af.api.ui.Model;
import org.jrebirth.af.component.behavior.swipable.SwipableBehavior;
import org.jrebirth.af.component.behavior.swipable.data.Swipable;
import org.jrebirth.af.core.component.behavior.AbstractModelBehavior;
import org.jrebirth.af.processor.annotation.Register;
import org.jrebirth.af.processor.annotation.RegistrationPriority;

@Register(value = SwipableBehavior.class, priority = RegistrationPriority.Normal)
public class SwipableBehaviorImpl extends AbstractModelBehavior<Swipable> implements SwipableBehavior {
Expand Down
7 changes: 0 additions & 7 deletions org.jrebirth.af/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jrebirth.af</groupId>
<artifactId>processor</artifactId>
<version>8.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!--
Dependency used at compile time to manage Java Webstart classpath scan
If this jar is not available the related code will not be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import java.lang.Thread.UncaughtExceptionHandler;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.ServiceLoader;

import javafx.application.Application;
import javafx.application.Preloader;
Expand All @@ -33,20 +33,16 @@
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Pair;

import org.jrebirth.af.api.application.Configuration;
import org.jrebirth.af.api.application.JRebirthApplication;
import org.jrebirth.af.api.application.Localized;
import org.jrebirth.af.api.command.Command;
import org.jrebirth.af.api.component.basic.Component;
import org.jrebirth.af.api.exception.CoreException;
import org.jrebirth.af.api.exception.JRebirthThreadException;
import org.jrebirth.af.api.log.JRLogger;
import org.jrebirth.af.api.module.ModuleStarter;
import org.jrebirth.af.api.resource.ResourceItem;
import org.jrebirth.af.api.resource.style.StyleSheetItem;
import org.jrebirth.af.api.service.Service;
import org.jrebirth.af.api.ui.Model;
import org.jrebirth.af.core.concurrent.AbstractJrbRunnable;
import org.jrebirth.af.core.concurrent.JRebirth;
import org.jrebirth.af.core.concurrent.JRebirthThread;
Expand All @@ -62,8 +58,6 @@
import org.jrebirth.af.core.resource.provided.parameter.ResourceParameters;
import org.jrebirth.af.core.resource.provided.parameter.StageParameters;
import org.jrebirth.af.core.util.ClassUtility;
import org.jrebirth.af.core.util.ClasspathUtility;
import org.jrebirth.af.modular.ModuleConfigFileParser;
import org.jrebirth.af.preloader.JRebirthPreloader;

import com.sun.javafx.application.LauncherImpl;
Expand Down Expand Up @@ -420,57 +414,64 @@ public void preloadResources() {
/**
* Preload Module.xml files.
*/
@SuppressWarnings("unchecked")
protected void preloadModules() {

if (CoreParameters.PARSE_MODULE_CONFIG_FILE.get() && hasModuleLibrary()) {

// Assemble the regex pattern
final Pattern filePattern = Pattern.compile(".*module\\.xml");

// Retrieve all resources from default classpath
final Collection<String> list = ClasspathUtility.getClasspathResources(filePattern);

// LOGGER.info(JRebirthMarkers.MODULE, "{} Module.xml file{} found.", list.size(), list.size() > 1 ? "s" : "");

for (final String moduleFile : list) {
final List<Pair<Class<?>, Class<?>>> pairList = ModuleConfigFileParser.getRegistrations(moduleFile);
for (final Pair<Class<?>, Class<?>> pair : pairList) {

final Class<? extends Component<?>> interfaceClass = (Class<? extends Component<?>>) pair.getKey();
final Class<? extends Component<?>> implClass = (Class<? extends Component<?>>) pair.getValue();

JRebirthThread.getThread().getFacade().getComponentFactory().register(interfaceClass, implClass);
}
for (final Class<?> componentClass : ModuleConfigFileParser.getWarmUp(moduleFile)) {
if (Command.class.isAssignableFrom(componentClass)) {
JRebirthThread.getThread().getFacade().getCommandFacade().retrieve((Class<Command>) componentClass);
} else if (Service.class.isAssignableFrom(componentClass)) {
JRebirthThread.getThread().getFacade().getServiceFacade().retrieve((Class<Service>) componentClass);
} else if (Model.class.isAssignableFrom(componentClass)) {
JRebirthThread.getThread().getFacade().getUiFacade().retrieve((Class<Model>) componentClass);
}
}
}
final ServiceLoader<ModuleStarter> loader = ServiceLoader.load(ModuleStarter.class);

final Iterator<ModuleStarter> iter = loader.iterator();
while (iter.hasNext()) {
final ModuleStarter ms = iter.next();
ms.start();
}
}

/**
* Check that org.jrebirth.af.modular.jar is accessible.
*
* @return true if org.jrebirth.af.modular.jar is accessible
*/
private boolean hasModuleLibrary() {
boolean hasModuleLibrary = true;
try {
Class.forName("org.jrebirth.af.modular.ModuleConfigFileParser");
} catch (final ClassNotFoundException e) {
hasModuleLibrary = false;
}
return hasModuleLibrary;
// if (CoreParameters.PARSE_MODULE_CONFIG_FILE.get() && hasModuleLibrary()) {
//
// // Assemble the regex pattern
// final Pattern filePattern = Pattern.compile(".*module\\.xml");
//
// // Retrieve all resources from default classpath
// final Collection<String> list = ClasspathUtility.getClasspathResources(filePattern);
//
// // LOGGER.info(JRebirthMarkers.MODULE, "{} Module.xml file{} found.", list.size(), list.size() > 1 ? "s" : "");
//
// for (final String moduleFile : list) {
// final List<Pair<Class<?>, Class<?>>> pairList = ModuleConfigFileParser.getRegistrations(moduleFile);
// for (final Pair<Class<?>, Class<?>> pair : pairList) {
//
// final Class<? extends Component<?>> interfaceClass = (Class<? extends Component<?>>) pair.getKey();
// final Class<? extends Component<?>> implClass = (Class<? extends Component<?>>) pair.getValue();
//
// JRebirthThread.getThread().getFacade().getComponentFactory().register(interfaceClass, implClass);
// }
// for (final Class<?> componentClass : ModuleConfigFileParser.getWarmUp(moduleFile)) {
// if (Command.class.isAssignableFrom(componentClass)) {
// JRebirthThread.getThread().getFacade().getCommandFacade().retrieve((Class<Command>) componentClass);
// } else if (Service.class.isAssignableFrom(componentClass)) {
// JRebirthThread.getThread().getFacade().getServiceFacade().retrieve((Class<Service>) componentClass);
// } else if (Model.class.isAssignableFrom(componentClass)) {
// JRebirthThread.getThread().getFacade().getUiFacade().retrieve((Class<Model>) componentClass);
// }
// }
// }
//
// }
}

// /**
// * Check that org.jrebirth.af.modular.jar is accessible.
// *
// * @return true if org.jrebirth.af.modular.jar is accessible
// */
// private boolean hasModuleLibrary() {
// boolean hasModuleLibrary = true;
// try {
// Class.forName("org.jrebirth.af.modular.ModuleConfigFileParser");
// } catch (final ClassNotFoundException e) {
// hasModuleLibrary = false;
// }
// return hasModuleLibrary;
// }

/**
* Return the list of Resources to load.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.jrebirth.af.core.module;

import org.jrebirth.af.api.command.Command;
import org.jrebirth.af.api.component.basic.Component;
import org.jrebirth.af.api.exception.CoreRuntimeException;
import org.jrebirth.af.api.facade.GlobalFacade;
import org.jrebirth.af.api.module.ModuleStarter;
import org.jrebirth.af.api.service.Service;
import org.jrebirth.af.api.ui.Model;
import org.jrebirth.af.core.concurrent.JRebirthThread;

public abstract class AbstractModuleStarter implements ModuleStarter {

protected void register(Class<? extends Component<?>> interfaceClass, Class<? extends Component<?>> implClass) {
getFacade().getComponentFactory().register(interfaceClass, implClass);
}

@SuppressWarnings("unchecked")
protected void bootComponent(Class<? extends Component<?>> componentClass) {

preloadClass(componentClass);

try {
if (Command.class.isAssignableFrom(componentClass)) {
getFacade().getCommandFacade().retrieve((Class<Command>) componentClass);
} else if (Service.class.isAssignableFrom(componentClass)) {
getFacade().getServiceFacade().retrieve((Class<Service>) componentClass);
} else if (Model.class.isAssignableFrom(componentClass)) {
getFacade().getUiFacade().retrieve((Class<Model>) componentClass);
}
} catch (final CoreRuntimeException e) {
e.printStackTrace();
}
}

/**
* TODO To complete.
*
* @param objectClass
*/
protected void preloadClass(Class<?> objectClass) {
try {
Class.forName(objectClass.getName());
} catch (final ClassNotFoundException e) {
e.printStackTrace();
}
}

/**
* TODO To complete.
*/
protected GlobalFacade getFacade() {
return JRebirthThread.getThread().getFacade();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* The class <strong>package-info</strong>.
* TODO To complete
*
* @author Sébastien Bordes
*/
package org.jrebirth.af.core.module;
1 change: 1 addition & 0 deletions org.jrebirth.af/dialog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<groupId>org.jrebirth.af</groupId>
<artifactId>processor</artifactId>
<version>8.1.0-SNAPSHOT</version>
<optional>true</optional>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit 6073bee

Please sign in to comment.