twitter4jads.json.DataObjectFactory Maven / Gradle / Ivy
The newest version!
package twitter4jads.json;
import twitter4jads.internal.models4j.*;
import twitter4jads.internal.org.json.JSONArray;
import twitter4jads.internal.org.json.JSONException;
import twitter4jads.internal.org.json.JSONObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public final class DataObjectFactory {
private DataObjectFactory() {
throw new AssertionError("not intended to be instantiated.");
}
private static final Constructor statusConstructor;
private static final Constructor userConstructor;
private static final Constructor relationshipConstructor;
private static final Constructor placeConstructor;
private static final Constructor savedSearchConstructor;
private static final Constructor trendConstructor;
private static final Constructor trendsConstructor;
private static final Constructor IDsConstructor;
private static final Method rateLimitStatusConstructor;
private static final Constructor categoryConstructor;
private static final Constructor directMessageConstructor;
private static final Constructor locationConstructor;
private static final Constructor userListConstructor;
private static final Constructor relatedResultsConstructor;
private static final Constructor statusDeletionNoticeConstructor;
private static final Constructor accountTotalsConstructor;
private static final Constructor oembedConstructor;
static {
try {
statusConstructor =
(Constructor) Class.forName("twitter4jads.internal.json.StatusJSONImpl").getDeclaredConstructor(JSONObject.class);
statusConstructor.setAccessible(true);
userConstructor = (Constructor) Class.forName("twitter4jads.internal.json.UserJSONImpl").getDeclaredConstructor(JSONObject.class);
userConstructor.setAccessible(true);
relationshipConstructor = (Constructor) Class.forName("twitter4jads.internal.json.RelationshipJSONImpl")
.getDeclaredConstructor(JSONObject.class);
relationshipConstructor.setAccessible(true);
placeConstructor = (Constructor) Class.forName("twitter4jads.internal.json.PlaceJSONImpl").getDeclaredConstructor(JSONObject.class);
placeConstructor.setAccessible(true);
savedSearchConstructor =
(Constructor) Class.forName("twitter4jads.internal.json.SavedSearchJSONImpl").getDeclaredConstructor(JSONObject.class);
savedSearchConstructor.setAccessible(true);
trendConstructor = (Constructor) Class.forName("twitter4jads.internal.json.TrendJSONImpl").getDeclaredConstructor(JSONObject.class);
trendConstructor.setAccessible(true);
trendsConstructor = (Constructor) Class.forName("twitter4jads.internal.json.TrendsJSONImpl").getDeclaredConstructor(String.class);
trendsConstructor.setAccessible(true);
IDsConstructor = (Constructor) Class.forName("twitter4jads.internal.json.IDsJSONImpl").getDeclaredConstructor(String.class);
IDsConstructor.setAccessible(true);
rateLimitStatusConstructor =
Class.forName("twitter4jads.internal.json.RateLimitStatusJSONImpl").getDeclaredMethod("createRateLimitStatuses", JSONObject.class);
rateLimitStatusConstructor.setAccessible(true);
categoryConstructor =
(Constructor) Class.forName("twitter4jads.internal.json.CategoryJSONImpl").getDeclaredConstructor(JSONObject.class);
categoryConstructor.setAccessible(true);
directMessageConstructor = (Constructor) Class.forName("twitter4jads.internal.json.DirectMessageJSONImpl")
.getDeclaredConstructor(JSONObject.class);
directMessageConstructor.setAccessible(true);
locationConstructor =
(Constructor) Class.forName("twitter4jads.internal.json.LocationJSONImpl").getDeclaredConstructor(JSONObject.class);
locationConstructor.setAccessible(true);
userListConstructor =
(Constructor) Class.forName("twitter4jads.internal.json.UserListJSONImpl").getDeclaredConstructor(JSONObject.class);
userListConstructor.setAccessible(true);
relatedResultsConstructor = (Constructor) Class.forName("twitter4jads.internal.json.RelatedResultsJSONImpl")
.getDeclaredConstructor(JSONArray.class);
relatedResultsConstructor.setAccessible(true);
statusDeletionNoticeConstructor =
(Constructor) Class.forName("twitter4jads.StatusDeletionNoticeImpl").getDeclaredConstructor(JSONObject.class);
statusDeletionNoticeConstructor.setAccessible(true);
accountTotalsConstructor = (Constructor) Class.forName("twitter4jads.internal.json.AccountTotalsJSONImpl")
.getDeclaredConstructor(JSONObject.class);
accountTotalsConstructor.setAccessible(true);
oembedConstructor =
(Constructor) Class.forName("twitter4jads.internal.json.OEmbedJSONImpl").getDeclaredConstructor(JSONObject.class);
oembedConstructor.setAccessible(true);
} catch (NoSuchMethodException e) {
throw new ExceptionInInitializerError(e);
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final ThreadLocal