Java Code Examples for com.google.api.client.util.Types#newInstance()
The following examples show how to use
com.google.api.client.util.Types#newInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiKindFeedParser.java From google-api-java-client with Apache License 2.0 | 6 votes |
/** Sets the entry classes to use when parsing. */ public void setEntryClasses(Class<?>... entryClasses) { int numEntries = entryClasses.length; HashMap<String, Class<?>> kindToEntryClassMap = this.kindToEntryClassMap; for (int i = 0; i < numEntries; i++) { Class<?> entryClass = entryClasses[i]; ClassInfo typeInfo = ClassInfo.of(entryClass); Field field = typeInfo.getField("@gd:kind"); if (field == null) { throw new IllegalArgumentException("missing @gd:kind field for " + entryClass.getName()); } Object entry = Types.newInstance(entryClass); String kind = (String) FieldInfo.getFieldValue(field, entry); if (kind == null) { throw new IllegalArgumentException( "missing value for @gd:kind field in " + entryClass.getName()); } kindToEntryClassMap.put(kind, entryClass); } }
Example 2
Source File: XmlObjectParser.java From google-http-java-client with Apache License 2.0 | 5 votes |
private Object readObject(XmlPullParser parser, Type dataType) throws XmlPullParserException, IOException { Preconditions.checkArgument(dataType instanceof Class<?>, "dataType has to be of Class<?>"); Object result = Types.newInstance((Class<?>) dataType); Xml.parseElement(parser, result, namespaceDictionary, null); return result; }
Example 3
Source File: AbstractAtomFeedParser.java From google-http-java-client with Apache License 2.0 | 5 votes |
/** * Parse the feed and return a new parsed instance of the feed type. This method can be skipped if * all you want are the items. * * @throws IOException I/O exception * @throws XmlPullParserException XML pull parser exception */ public T parseFeed() throws IOException, XmlPullParserException { boolean close = true; try { this.feedParsed = true; T result = Types.newInstance(feedClass); Xml.parseElement(parser, result, namespaceDictionary, Atom.StopAtAtomEntry.INSTANCE); close = false; return result; } finally { if (close) { close(); } } }
Example 4
Source File: UrlEncodedParser.java From google-http-java-client with Apache License 2.0 | 5 votes |
public Object parseAndClose(Reader reader, Type dataType) throws IOException { Preconditions.checkArgument( dataType instanceof Class<?>, "dataType has to be of type Class<?>"); Object newInstance = Types.newInstance((Class<?>) dataType); parse(new BufferedReader(reader), newInstance); return newInstance; }
Example 5
Source File: MultiKindFeedParser.java From google-api-java-client with Apache License 2.0 | 5 votes |
@Override protected Object parseEntryInternal() throws IOException, XmlPullParserException { XmlPullParser parser = getParser(); String kind = parser.getAttributeValue(GoogleAtom.GD_NAMESPACE, "kind"); Class<?> entryClass = this.kindToEntryClassMap.get(kind); if (entryClass == null) { throw new IllegalArgumentException("unrecognized kind: " + kind); } Object result = Types.newInstance(entryClass); Xml.parseElement(parser, result, getNamespaceDictionary(), null); return result; }
Example 6
Source File: LinkHeaderParser.java From android-oauth-client with Apache License 2.0 | 5 votes |
@Override public Object parseAndClose(Reader reader, Type dataType) throws IOException { Preconditions.checkArgument( dataType instanceof Class<?>, "dataType has to be of type Class<?>"); Object newInstance = Types.newInstance((Class<?>) dataType); parse(new BufferedReader(reader), newInstance); return newInstance; }
Example 7
Source File: AtomFeedParser.java From google-http-java-client with Apache License 2.0 | 4 votes |
@Override protected Object parseEntryInternal() throws IOException, XmlPullParserException { E result = Types.newInstance(entryClass); Xml.parseElement(getParser(), result, getNamespaceDictionary(), null); return result; }