Skip to content

Commit

Permalink
GuicedEE v2 And Vertx Support Addition
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Jun 1, 2024
1 parent b487a49 commit 0cd2dfa
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 31 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.guicedee.services</groupId>
<artifactId>uadetector-core</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.guicedee.services</groupId>
<artifactId>uadetector-resources</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

</dependencies>

Expand Down
84 changes: 53 additions & 31 deletions src/main/java/com/jwebmp/core/base/ajax/AjaxResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
@SuppressWarnings("MissingClassJavaDoc")
@CallScope
public class AjaxResponse<J extends AjaxResponse<J>>
extends JavaScriptPart<J> {
extends JavaScriptPart<J>
{
/**
* Whether or not the response is a success or not
*/
Expand Down Expand Up @@ -67,35 +68,40 @@ public class AjaxResponse<J extends AjaxResponse<J>>

private Map<String, String> properties = new HashMap<>();

public Map<String, String> getProperties() {
public Map<String, String> getProperties()
{
return properties;
}

@JsonProperty("data")
private Map<String, Object> dataReturns = new HashMap<>();

public J addDataResponse(String listener, IJsonRepresentation<?> json) {
public J addDataResponse(String listener, IJsonRepresentation<?> json)
{
dataReturns.put(listener, json);
return (J) this;
}

public J addDataResponse(String listener, Map json) throws Exception {

public J addDataResponse(String listener, Map json) throws Exception
{
dataReturns.put(listener, json);
return (J) this;
}

public J addDataResponse(String listener, String result){

public J addDataResponse(String listener, String result)
{
dataReturns.put(listener, result);
return (J) this;
}

/**
* Sets the properties for this response
*
* @param properties
* @return
*/
public AjaxResponse<J> setProperties(Map<String, String> properties) {
public AjaxResponse<J> setProperties(Map<String, String> properties)
{
this.properties = properties;
return this;
}
Expand All @@ -108,14 +114,15 @@ public AjaxResponse<J> setProperties(Map<String, String> properties) {
@JsonProperty("features")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@SuppressWarnings("unused")
protected Set<String> getFeatureQueries() {
protected Set<String> getFeatureQueries()
{
Set<String> list = new LinkedHashSet<>();
getFeatures().forEach(feature ->
{
feature.preConfigure();
list.add(feature.renderJavascript()
.toString());
});
{
feature.preConfigure();
list.add(feature.renderJavascript()
.toString());
});
return list;
}

Expand All @@ -124,8 +131,10 @@ protected Set<String> getFeatureQueries() {
*
* @return
*/
public Set<IFeature<?, ?>> getFeatures() {
if (features == null) {
public Set<IFeature<?, ?>> getFeatures()
{
if (features == null)
{
features = new TreeSet<>();
}
return features;
Expand All @@ -136,7 +145,8 @@ protected Set<String> getFeatureQueries() {
*
* @param features
*/
public void setFeatures(Set<IFeature<?, ?>> features) {
public void setFeatures(Set<IFeature<?, ?>> features)
{
this.features = features;
}

Expand All @@ -145,7 +155,8 @@ public void setFeatures(Set<IFeature<?, ?>> features) {
*
* @return
*/
public boolean isSuccess() {
public boolean isSuccess()
{
return success;
}

Expand All @@ -154,7 +165,8 @@ public boolean isSuccess() {
*
* @param success
*/
public void setSuccess(boolean success) {
public void setSuccess(boolean success)
{
this.success = success;
}

Expand All @@ -165,7 +177,8 @@ public void setSuccess(boolean success) {
* @return J Always this
*/
@SuppressWarnings("unchecked")
public J addFeature(IFeature<?, ?> feature) {
public J addFeature(IFeature<?, ?> feature)
{
getFeatures().add(feature);
return (J) this;
}
Expand All @@ -176,8 +189,9 @@ public J addFeature(IFeature<?, ?> feature) {
* @param reaction
*/
@SuppressWarnings("unchecked")

public J addReaction(AjaxResponseReaction<?> reaction) {

public J addReaction(AjaxResponseReaction<?> reaction)
{
getReactions().add(reaction);
return (J) this;
}
Expand All @@ -187,8 +201,10 @@ public J addReaction(AjaxResponseReaction<?> reaction) {
*
* @return
*/
public Set<AjaxResponseReaction<?>> getReactions() {
if (reactions == null) {
public Set<AjaxResponseReaction<?>> getReactions()
{
if (reactions == null)
{
reactions = new LinkedHashSet<>();
}
return reactions;
Expand All @@ -199,8 +215,10 @@ public Set<AjaxResponseReaction<?>> getReactions() {
*
* @return
*/
public Map<String, String> getLocalStorage() {
if (localStorage == null) {
public Map<String, String> getLocalStorage()
{
if (localStorage == null)
{
localStorage = new HashMap<>();
}
return localStorage;
Expand All @@ -211,7 +229,8 @@ public Map<String, String> getLocalStorage() {
*
* @param localStorage
*/
public void setLocalStorage(Map<String, String> localStorage) {
public void setLocalStorage(Map<String, String> localStorage)
{
this.localStorage = localStorage;
}

Expand All @@ -220,8 +239,10 @@ public void setLocalStorage(Map<String, String> localStorage) {
*
* @return
*/
public Map<String, String> getSessionStorage() {
if (sessionStorage == null) {
public Map<String, String> getSessionStorage()
{
if (sessionStorage == null)
{
sessionStorage = new HashMap<>();
}
return sessionStorage;
Expand All @@ -232,7 +253,8 @@ public Map<String, String> getSessionStorage() {
*
* @param sessionStorage
*/
public void setSessionStorage(Map<String, String> sessionStorage) {
public void setSessionStorage(Map<String, String> sessionStorage)
{
this.sessionStorage = sessionStorage;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.jwebmp.core.client.implementations;

import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.guicedee.client.IGuiceContext;
import com.guicedee.guicedinjection.interfaces.IGuiceModule;

import com.guicedee.guicedservlets.servlets.services.scopes.CallScope;
import com.jwebmp.core.base.ajax.AjaxCall;
import com.jwebmp.core.base.ajax.AjaxResponse;
import com.jwebmp.interception.services.AjaxCallIntercepter;
import com.jwebmp.interception.services.DataCallIntercepter;
import com.jwebmp.interception.services.JWebMPInterceptionBinder;
import com.jwebmp.interception.services.SiteCallIntercepter;
import net.sf.uadetector.UserAgentStringParser;
import net.sf.uadetector.service.UADetectorServiceFactory;

import java.util.ServiceLoader;

@SuppressWarnings("unchecked")
public class JWebMPClientBinder extends AbstractModule implements IGuiceModule<JWebMPClientBinder>
{
private static final UserAgentStringParser userAgentParser = UADetectorServiceFactory.getResourceModuleParser();

@Override
protected void configure()
{
bind(UserAgentStringParser.class)
.toInstance(userAgentParser);


bind(AjaxResponse.class)
.in(CallScope.class);

bind(AjaxCall.class)
.in(CallScope.class);

bind(JWebMPInterceptionBinder.AjaxCallInterceptorKey)
.toProvider(() -> IGuiceContext
.instance()
.getLoader(AjaxCallIntercepter.class, ServiceLoader.load(AjaxCallIntercepter.class)))
.in(Singleton.class);

bind(JWebMPInterceptionBinder.DataCallInterceptorKey)
.toProvider(() -> IGuiceContext.instance()
.getLoader(DataCallIntercepter.class, ServiceLoader.load(DataCallIntercepter.class)))
.in(Singleton.class);

bind(JWebMPInterceptionBinder.SiteCallInterceptorKey)
.toProvider(() -> IGuiceContext.instance()
.getLoader(SiteCallIntercepter.class, ServiceLoader.load(SiteCallIntercepter.class)))
.in(Singleton.class);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.jwebmp.core.client.implementations;

import com.guicedee.guicedinjection.interfaces.IGuiceConfig;
import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator;

public class JWebMPClientConfiguration implements IGuiceConfigurator
{
@Override
public IGuiceConfig<?> configure(IGuiceConfig<?> config)
{
config = config.setClasspathScanning(true)
.setAllowPaths(true)
.setFieldInfo(true)
.setMethodInfo(true)
.setAnnotationScanning(true)
.setIgnoreClassVisibility(true)
.setIgnoreFieldVisibility(true)
.setIgnoreMethodVisibility(true);
return config;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Set;

@SuppressWarnings("Convert2Diamond")
public interface JWebMPInterceptionBinder
{
Key<Set<AjaxCallIntercepter>> AjaxCallInterceptorKey = Key.get(new TypeLiteral<Set<AjaxCallIntercepter>>() {});
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator;
import com.guicedee.guicedinjection.interfaces.IGuiceModule;
import com.jwebmp.core.client.implementations.JWebMPClientBinder;
import com.jwebmp.core.client.implementations.JWebMPClientConfiguration;

module com.jwebmp.client {
uses com.jwebmp.interception.services.AjaxCallIntercepter;
uses com.jwebmp.interception.services.DataCallIntercepter;
uses com.jwebmp.interception.services.SiteCallIntercepter;
exports com.jwebmp.core.base.ajax;
exports com.jwebmp.core.base.client;
exports com.jwebmp.core.base.html.attributes;
Expand Down Expand Up @@ -34,6 +42,11 @@

requires static lombok;
requires static org.apache.commons.lang3;
requires transitive net.sf.uadetector.core;
requires transitive net.sf.uadetector.resources;

provides IGuiceModule with JWebMPClientBinder;
provides IGuiceConfigurator with JWebMPClientConfiguration;

opens com.jwebmp.core.base.ajax to com.fasterxml.jackson.databind;
opens com.jwebmp.core.base.client to com.fasterxml.jackson.databind;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.jwebmp.core.client.implementations.JWebMPClientConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.jwebmp.core.client.implementations.JWebMPClientBinder

0 comments on commit 0cd2dfa

Please sign in to comment.