This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major changes now. need to change lot of variable names and all
- Loading branch information
Showing
9 changed files
with
266 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package schema; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.regex.Pattern; | ||
import static schema.SConstant.separator; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
public class GetterImpl<Source> { | ||
public ArrayList<Method> methods; | ||
public Class ReturnType; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public void initialize(Class SourceClass, String name) throws NoSuchMethodException, SecurityException { | ||
String[] names= name.split(separator); | ||
ArrayList<Method> methodlist = new ArrayList<Method>(); | ||
for(String subName:names){ | ||
Method m = SourceClass.getMethod(getGetterName(subName)); | ||
SourceClass = m.getReturnType(); | ||
methodlist.add(m); | ||
} | ||
methods = methodlist; | ||
ReturnType = methodlist.get(methodlist.size()-1).getReturnType(); | ||
return; | ||
|
||
} | ||
|
||
public Object getReturnValue(Source source) throws NoSuchMethodException, SecurityException, IllegalAccessException, | ||
IllegalArgumentException, InvocationTargetException { | ||
Object obj = source; | ||
for(Method subMethod:methods){ | ||
obj = subMethod.invoke(obj); | ||
} | ||
return obj; | ||
} | ||
|
||
public static String getGetterName(String name){ | ||
return "get"+ StringUtils.capitalise(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package schema; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class SConstant { | ||
public final static String separator = Pattern.quote("."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package schema; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import static schema.SConstant.separator; | ||
|
||
public class SetterImpl<Dest> { | ||
public ArrayList<Method> methods; | ||
public String[] names; | ||
|
||
public void intialize(Class DestClass, String name) | ||
throws NoSuchFieldException, SecurityException, NoSuchMethodException { | ||
names = name.split(separator); | ||
Class finalClass = DestClass; | ||
methods = new ArrayList<Method>(); | ||
for (String subName : names) { | ||
String getterName = getGetterName(name); | ||
Method getterMethod = finalClass.getMethod(getterName); | ||
Method method = finalClass.getMethod(getSetterName(subName), getterMethod.getReturnType()); | ||
methods.add(method); | ||
finalClass = getterMethod.getReturnType(); | ||
} | ||
// Collections.reverse(methods); | ||
} | ||
|
||
public static String getSetterName(String name) { | ||
return "set" + StringUtils.capitalise(name); | ||
} | ||
|
||
public static String getGetterName(String name) { | ||
return "get" + StringUtils.capitalize(name); | ||
} | ||
|
||
public void setValue(Dest destObj, Object obj) throws NoSuchMethodException, SecurityException, | ||
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, | ||
InstantiationException { | ||
int count=0; | ||
Object innerObject=destObj; | ||
for(String name:names){ | ||
Method getterMethod = innerObject.getClass().getMethod(getGetterName(name)); | ||
Object innerObjectAttribute = getterMethod.invoke(innerObject); | ||
if (innerObjectAttribute == null || count == names.length-1) { | ||
Class type = innerObject.getClass().getMethod(getGetterName(name)).getReturnType(); | ||
if(count == names.length-1){ | ||
innerObjectAttribute = obj; | ||
}else{ | ||
innerObjectAttribute = type.newInstance(); | ||
} | ||
Method setterMethod = methods.get(count); | ||
setterMethod.invoke(innerObject, innerObjectAttribute); | ||
} | ||
innerObject = innerObjectAttribute; | ||
count++; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package schema.Complex; | ||
|
||
public class Bus{ | ||
private Tyre tyre; | ||
|
||
/** | ||
* @return the tyre | ||
*/ | ||
public Tyre getTyre() { | ||
return tyre; | ||
} | ||
|
||
/** | ||
* @param tyre the tyre to set | ||
*/ | ||
public void setTyre(Tyre tyre) { | ||
this.tyre = tyre; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package schema.Complex; | ||
|
||
public class Bus2{ | ||
private String name; | ||
|
||
/** | ||
* @return the name | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @param name the name to set | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package schema.Complex; | ||
public class Tyre{ | ||
private String name; | ||
|
||
/** | ||
* @return the name | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @param name the name to set | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
Oops, something went wrong.