My favorites | Sign in
Project Home Wiki Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
Annotations  
Updated Sep 15, 2010 by denis.ha...@gmail.com

Annotated method

Annotations are used in Jibe framework in order to nominate Java or Groovy method for different tasks to perform. Once annotated, it obtains an identification key which is used to reference the method from different configuration files. Value of identification key depends on the existence and value attribute of @Controller annotation.

public class MyBean {
     @Remote("myRemoteMethod")   <- Identification is "myRemoteMethod"
     public void someMethod(Context context){
     }
}

@Controller("MyBean")
public class MyControllerBean {
     @Remote   <- Identification is "MyBean.someMethod"
     public void someMethod(Context context){
     }
}


@Controller
public class MyControllerBean {
     @Remote   <- Identification is "package.MyControllerBean.someMethod"
     public void someMethod(Context context){
     }
}

Each annotated method, in order to be bootstrapped has to be part of spring registered bean.

Cache

Using this annotation it is possible to cache on the client return value of annotated method. The following example is used to cache UI state saved in the user preferences

@Cache("uiState")
	public final String cacheUIState() {
		    String state = StringEscapeUtils
				      .escapeJavaScript(UserNode.createForCurrentUser().getPreferences().getUIState());
		    return String.format("\"%1$s\"", state);
	}

After client start up, the value returned from above method will be available on the client as jibe.Cache.uiState

Component

When method is annotated with @Component annotation it can be bound to a component in xml configuration. For example, component todoTasks is bound to TodoListBean.backingMethod

<component-def id="core.viewPort" replace="true">
    <xtype>viewport</xtype>
    <layout>absolute</layout>
    <items>
	    <component id="todoTasks" method="TodoListBean.backingMethod"> <-- Method binding
              <xtype>panel</xtype>
	      <pageX>20</pageX>
	      <pageY>20</pageY>
	      <width>300</width>
	      <height>300</height>
	      <html>Hello from Jibe component</html>
	</component>
     </items>
</component-def>

which is defined here in this class.

package org.jibeframework.todolist;

import org.jibeframework.core.annotation.Controller;
import org.jibeframework.core.annotation.Component;
import org.jibeframework.core.ui.ParamSet;

@Controller("TodoListBean")
public class TodoListBean {
	@Component
	public void backingMethod(ParamSet params) {
	    params.put("html", "Hello from backing method!!!");
	}
}

In that case, annotated method will be invoked during rendering and you will have the chance to alter component definition which will be sent to the client

ConditionEvaluator

Condition is a small expression language which is able to express logical expression and which is following JSON syntax. An example of a logical expression would be

condition="[{type:'cm:folder',group:'ADMIN'},{permission:'Write'}]"

As we can see this is a JSON array containing two JSON objects.The first JSON object has two properties and names of those properties are mapped to java annotated methods.

Bellow are examples of two of such methods. During evaluation proces appropriate java method is invoked and value of property is passed as conditionValue argument of the method

@ConditionEvaluator("type")
public final boolean evaluateTypeConditionKey(String conditionValue, Context context) {
	if (context.getNode() != null) {
		RepoNode node = (RepoNode) context.getNode();
		return node.isSubTypeOf(conditionValue);
	} else if (context.getNodes() != null) {
		for (Node node : context.getNodes()) {
			if (!((RepoNode) node).isSubTypeOf(conditionValue)) {
				return false;
			}
		}
		return true;
	}
	return false;
}
@ConditionEvaluator("group")
public final boolean evaluateGroupConditionKey(String conditionValue, Context context) {
	ServiceRegistry serviceRegistry = Services.getServiceRegistry();
	String user = serviceRegistry.getAuthenticationService().getCurrentUserName();
	boolean contains = ServiceRegistry.getAuthorityService().getContainingAuthorities(
					AuthorityType.GROUP, user, false).contains(conditionValue);
	return contains;
		
}

Finally we can read the above condition expression as

condition is true if currently selected node is of 'cm:folder' type and current user belongs to 'ADMIN' group or current user has 'Write' permission on the currently selected node

This logical expression does not make much sense, but will serve for illustration purposes. There are a lot of condition evaluators available and you can easily make your own condition evaluator using above example as template.

Evaluator Value Description
type Valid node type name Will evaluate as true if current node is type or subtype of value
aspect Valid aspect name Will evaluate as true if current node has value aspect
group Valid group name Will evaluate as true if current user is member of value group
permission Valid permission name Will evaluate as true if current user has permission on the currently selected node
param Expression paramName:paramValue Will evaluate as true if http request contains parameter paramName with value equals paramValue
initParam Expression paramName:paramValueWill evaluate as true if initial URI contains parameter paramName with value equals paramValue

ContextInitializer

DefaultValueProvider

As the name says, method annotated with this annotation will be used to provide a default value for the form field.

ParamHandler

Resolver

Resolver is a method annotated with @Resolver annotation. The method is invoked if a non existent property is accessed on the node. For example

@Resolver("downloadUrl")
public final String resolveDownloadUrl(Node node) {
	DocumentNode documentNode = (DocumentNode) node;
	return documentNode.getDownloadUrl();
}

will be invoked in order to return property value in case of

node.getProperty("downloadUrl");

ToObjectConverter

ToStringConverter

Powered by Google Project Hosting