Tuesday, June 23, 2009

Weird Pain In Abdomen At Nite

More Reflection in Java Annotations

Reflection is a Java API which is very useful and is used by many Java frameworks like Spring, Struts or Trapestry, allowing access methods, attributes and see the behavior of a class during program execution.

Reflection can be used to create visual development environments, tools that serve for testing a component, debugging tools (aka debugging) or a framework to create and inject instances of objects properties from a configuration file

So this time I show a class that a colleague made some years ago that lets you create instances and / or access to properties (Via accessor methods) so thoughtful. This is a very useful tool as it allows properties of objects so that we can use it to order more generally beans without having to define a comparator for each bean depending on the property you want to compare, make a list of beans in a map or create lists of any of the properties of the bean.

 
/ * * GenericBean.java


* * Created on June 22, 2006, 09:32 PM


* * /

/ **
* * @ author JM

* / import
java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class GenericBean {
private Object o;
private Class beanClass;

/** Creates a new instance of GenericBean */
public GenericBean(String className) {
try {
beanClass = Class.forName(className);
Constructor c = beanClass.getConstructor();
o = c.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}

public GenericBean(Object instance) {
o = instance;
beanClass = o.getClass();
}

public Object get(String property) {
Object ret = null;
property = property.substring(0, 1).toUpperCase()
+ property.substring(1);
try {
String methodName = "get" + property;
Method method = beanClass.getMethod(methodName);
ret = method.invoke(o);
}
catch(Exception e) {
try {
String methodName = "is" + property;
Method method = beanClass.getMethod(methodName);
ret = method.invoke(o);
}
catch(Exception ex) {
e.printStackTrace();
}
}

return ret;
}

public void set(String property, Object value) {
property = property.substring(0, 1).toUpperCase()
+ Property.substring (1);

try {Method method = beanClass.getMethod ("set" + property, value
. GetClass ());
method.invoke (or value);
} catch (Exception e)
{e.printStackTrace ();}



} public Object getObject () {
return o;}


GetObjectClass public Class () {return
o.getClass ();
}}


Tomorrow write and to use this class, because the truth right now it's a little night lol and now I'm falling asleep. Just as an additional reminder, it is important to remember that use Reflection generates low virtual machine performance and often can not use optimizers are there in the JVM, such as in multiple calls to methods, etc ... tail recursion Greetings


Gus

Monday, June 15, 2009

Tattoo Of Footprint On Leg



Level: Intermediate

annotations in Java, are trademarks that are made part of the program, which have no direct effect on it but they are thoughtful in execution, ie can be used by a container at the time of implementation.


Annotations are a special type of switch and can be used with other modifiers such as public, static, private etc ... Say annotations are one way to implement an interface, without the kind you do directly. For example, you create a Dog class, and then you note to say that is an animal, in this way, in implementing the program using reflection is possible to know that any object of class Dog is an animal. Ie we are saying that dog is an animal and serves a similar function to an interface.

 
@ Animal

public class Dog {/ / Some good dog class method}





Define an annotation is very simple, it is the same way as an interface and puts a " @ "at the beginning of the word interface, and methods will contain elements of the annotation, and can only return primitive types, String and Enums.




 
@ interface Animal {public boolean
vertebrate ();}



With the notation presented above, we score some sort and define whether the animal that we are noting is vertebrate or invertebrate

 
@ Animal (vertebrate = true) public class Dog {


}



This will ensure the implementation of the program can tell if an object of class Dog is an animal, and what kind of animal, we can also specify that serves only the annotation to annotate classes, we can not have animal-like methods. To do this we scored our touchdown. Then our notation becomes:

 
package annotations;
import
java.lang.annotation.Retention;
java.lang.annotation.Target import, import
java.lang.annotation.ElementType;
import java.lang. annotation.RetentionPolicy;



@ Retention (RetentionPolicy.RUNTIME)
@ Target (ElementType.TYPE)
Animal {public @ interface

vertebrate boolean ();}





Thus we specify that the scoring only used to define types. Now how to use it in the execution:

 


package annotations;

import java.util.ArrayList;
import java.util.List;

public class Main {

@ SuppressWarnings ("unchecked") public
static void main (String [] args) {

/ / Create a List List
obj = new ArrayList ();

/ / add 2 Dogs
obj.add (new Dog ());
obj.add (new Dog ());

/ / add 1
obj.add String ("I am a String");

System.out.println ("Number of animals in the list:" + contarAnimales (obj));



} public static int contarAnimales (List o)
{if (o == null) return 0
;

else {System.out.println ("Starting to count");
int count = 0;
for (Object object: o) {
/ / System.out.println (object.getClass (). getAnnotation (Animal.class));
if (object.getClass (). isAnnotationPresent (Animal.class)) {
count + +;
}
}
return count;
}
}

}



Although the example is not the most orthodox, gives an example of what can make annotations, and how is the use frameworks such as JAXB or Spring 2.5 Annotated, which can make Autoalambrado, define driver, mapping request with annotations to avoid having to configure a dispatcher servlet great. Greetings

Thursday, June 4, 2009

Accidental Groping Clips

Recruitment Incentives Regarding the Social Security Contribution

Recruitment Incentives Regarding the Social Security Contribution

CONTRACT TYPE 250 (part-time permanent contract)
TYPE OF CONTRACT 150
CONTRACT TYPE 350
CONTRACT TYPE 109
TYPES OF CONTRACT 209 y 309
TYPES OF CONTRACT 130, 230, 330, 139 y 239
TYPES 410 and 510 CONTRACT (interim contract to full time and part respectively)

Manfrotto Tripod Manual

BASE IS CALCULATED AS REGULATOR OF IT.


How to calculate the base salary of IT when the sick leave begins in the same month he begins work activity?

be divided based on the month trading low by the number of days corresponding to that contribution. In the event that it is a new contract, although there may be a contribution basis in the same company, or another in the previous month, divide the base price of the new contract between days quoted it. If you give the fact that the medical leave the occurrence of the same day to start work activity, the base pension is calculated taking into account the salary the employee would receive during the month I had to start their working relationship.



When the worker is in a situation of temporary incapacity and during your contract is terminated, will continue to receive temporary disability benefits, an amount equal to unemployment benefits until the end of the disability. After discharge, the worker is in a legal situation of unemployment (if the termination of the employment relationship is considered as such, under Article 208 of the General Law of Social Security) and, if it meets the requirements, you can access the level of unemployment benefit contributivo.Cuando temporary disability resulting from common contingencies are deducted from the period of perception unemployment benefit, as time already consumed, which had remained in temporary disability from the date of termination of employment contract.


The trustee of unemployment benefits made contributions to Social Security, assuming the contribution payable to workers for the period that is discounted as consumers.



In the event of temporary disability resulting from occupational contingencies are not deducted from the period of collecting unemployment benefits over time would have been in the situation of temporary incapacity.