Created
December 16, 2013 20:12
-
-
Save thenixan/7993571 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class Attribute { | |
private final String mAttributeName; | |
private final Method mSetter; | |
public Attribute(String attributeName, Method setter) { | |
mAttributeName = attributeName; | |
mSetter = setter; | |
} | |
public void setValue(Object target, Object value) | |
throws InvocationTargetException, IllegalAccessException { | |
mSetter.invoke(target, value); | |
} | |
public String getName() { | |
return mAttributeName; | |
} | |
public static class CompoundAttribute extends Attribute { | |
private final SubParser mSubParser; | |
public CompoundAttribute(String attributeName, Method setter, SubParser subParser) { | |
super(attributeName, setter); | |
mSubParser = subParser; | |
} | |
@Override | |
public void setValue(Object target, Object value) | |
throws InvocationTargetException, IllegalAccessException { | |
super.setValue(target, mSubParser.parse(value)); | |
} | |
} | |
public interface SubParser { | |
public Object parse(Object jsonObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment