extend spring web flow 2.3 - java

I'm working on a project with Spring Web Flow to manage some configurable flows.
My main question is: is it possible to extend the framework with custom classes and extend the spring-webflow-2.0.xsd?
We need to change the default behaviour of Spring Web Flow to achieve the following goals:
Extend the spring-webflow-2.0.xsd in order to add custom elements we need within the "states". And so, extend also the XmlFlowModelBuilder class in order to parse these new custom elements.
We need to be able to set a custom builder (like flow-builder inside flow-registry) which reads several XML resources, each one with its own id, like flow-location-pattern does. So we need a kind of mix between both ways to define a flow-registry. In addition, we would like to get those XML flow definition files from an external source (eg, with a service), and auto-rebuild the flowModels when some of those external XML changes.
Is it possible? We have found out that the flow-registry element creates a FlowRegistryFactoryBean, which has the main method calls. We would like to customize the class but this is not possible since it is a private class. We cannot even create a bean with this class.
So how could we make these customizations?

As in any other case of using the java library, you can extend and compose the classes from spring-webflow packages.

Related

How to create layers in an Android library without exposing internal classes to consumer of the library

I'm creating an android library and wanted to organize with layers it something like this.
PublicClassExposedToLibraryConsumer.java
logic.PublicFooLogicInterface1.java
logic.PackagePrivateFooLogicClass1.java
logic.PublicFooLogicInterface2.java
logic.PackagePrivateFooLogicClass2.java
domain.PublicFooDomainInterface1.java
domain.PackagePrivateFooDomainClass1.java
domain.PublicFooDomainInterface2.java
domain.PackagePrivateFooDomainClass2.java
repository.PublicFooRepoInterface1.java
repository.PackagePrivateFooRepoClass1.java
repository.PublicFooRepoInterface2.java
repository.PackagePrivateFooRepoClass2.java
1) I want a number of layers and I want to limit interaction between those layers by using interfaces.
2) I want to only expose PublicClassExposedToLibraryConsumer.java to the consumer of the library. They should not be able to access the other classes and interfaces.
Is this possible? From what I've read in order to make something accessible to something consuming the library it needs to be public and to hide something from the consumer of the library it needs to be not public. By my reading this means that you can't separate layers without exposing something and you can't hide internal classes without being forced to use a completely flat architecture. I find this very hard to believe, I have to be missing something.
You can try with annotations providing specific scope for your desired file to restrict to end-user of your library. Best way to do this in Android is using #RestrictTo support library annotation on class level.
Note : For Fields and Methods of particular entity can be scoped with access-modifiers like private, protected or package-protected etc. *(Just ignore if you already know that)
#RestrictTo : Denotes that the annotated element should only
be accessed from within a specific scope (as defined by
RestrictTo.Scope).

Add additinal functionality to existing methods

I have a web application in Servlets and JSP. Now i need to add some additional functionalities to a couple of service methods in it. Service methods those needs these changes are from different servlets.
Additional functionalities are as follows.
Validating status before its core function.
Notify respective users on successful completion of that process.
How can I inject these functionalities to existing code with minimum overhead?
I think AOP in spring can help here, but i cant use Spring in existing application for this feature.
Also tried to use decorator pattern, but i couldn't as each service class contains multiple methods, also there is no common interface for them.
Can someone let me know how to handle this change in a better way.
Also tried to use decorator pattern, but i couldn't as each service
class contains multiple methods, also there is no common interface for
them.
As you are stating that there is no common interface, you can use Adapter Pattern which is the best fit when you have problems with service interfaces. Basically, adapters help to interact with two services with no common interface. You can create an adapter (layer) which handle the additional functionalities (i.e., Validating status and Notify respective users, etc..) by invoking the existing services.
Below is the wikipedia definition for adapter pattern:
the adapter pattern is a software design pattern (also known as
Wrapper, an alternative naming shared with the Decorator pattern) that
allows the interface of an existing class to be used as another
interface. It is often used to make existing classes work with others
without modifying their source code.

Run method each time a specific annotation is used in a class

Say I have a class with a few fields all marked with a custom annotation. In my case it is #inject, because this is being used for dependency injection. How can I run a method in a separate class each time that annotation is used in my a class? In other words, each time a class is loaded the annotation runs a method that will collect the field data and in turn set the field.
I already have the entire system set up for collecting the resources, but I need some direction on how to actually run that code when the class with #inject annotation is loaded. Is this something that can be done by defining some sort of method in the annotation interface that performs the data collection?
My initial thought is to use a custom class loader, but I don't want to have to set the class loader when I use this jar in other projects. Is there a way to set a custom class loader programmatically for specific classes at runtime? I'm already doing a lot of pre-runtime reflection stuff and i'll already know which classes need to be loaded with a custom loader. Its just a matter of not knowing or if its even possible to set a custom loader on a class from within the code.
Can a classloader even be used to perform tasks such as pre-populating fields, or am I running off on a wrong tangent here? I just need a little direction on the most common way this type of thing is done (pre-populating class fields at runtime).
I was overthinking this problem. You cannot actually run code automatically prior to loading a class (unless its a servlet filter etc). In my situation the answer was to create an instance based on a specific class that already held the resource data I needed. Similar to how Google's Guice does it.
See this question for more insight: How does Guice Populate Annotated Fields
You can use injectors from Google Guice or Spring Framework.

Where to put business logic in Eclipse RCP program

I'm writing a small application in RCP to wrap around the business logic in another (non-RCP) simulation library. I can access and use the library fine from any of my plugins, but I don't know where I should put the instance of the Simulation library so that, say, one of the command handlers can make calls to it.
From reading the docs it sounds like I should be storing 'global' information like this in the workbench - but I still don't really understand how to do that.
Help?
First, the business layer (BL) can and should reside in its' own plugin. That will provide decent decoupling between the layers.
Second, you should carefully decide what the interface should be and which classes are exposed. Ideally, you should mostly expose interfaces and data objects.
Finally, decide how the "hand shake" works. E.g., how to obtain the initial interface to the BL. Since it is a Plugin, it could have an Activator which loads it. You could add a method in the activator which returns the BL interface.
If you are looking for something more decoupled, you could create an extension point or deploy the BL as an OSGi service, but that's a bit of an overkill for you need.
If I understand you correctly, I see two ways:
Store the instance in the model plug-in itself, using ‘SimulationFactory.getInstance(String myAppId)‘. The passed String is a constant in you app that is always used, when obtaining the reference.
Define a new class e.g. GlobalAccess in you app that is initilized with an instance of your model and has some getter (whether you use a single instance again or only provide public static methods is a matter of taste).
The seocond way is similar to some classes in eclipse like platfom or platformui, where you can obtain initial references and navigate through the workbench.
edit
i just found a tutorial that might help you:
Passing Data between Plug-ins

Do I need to create custom ClassLoaders to support new archives format?

I need to support loading classes from other types of archives(tar.gz,tar.bz2...) and custom types defined by third parties. Do I need to override the 'loadClass' method to achieve that? (Perhaps theres another extension point for doing this? I still want to benefit from all the security checks made by the default class loaders).
Unfortunately there's no standard class loader that delegates to a simple class name to byte[]/ByteBuffer interface. You'll need to either do your own class loader, save to an icky temporary file or, I believe, give URLClassLoader.newInstance a URL with a custom URLHandler.

Categories