public void onAttach(Class<?> aContainerType, ReflectorFactory aReflector, ConverterRegistry aConverters) { if ((intermediate != null) && (converter == null)) converter = (Converter<?,R>)aConverters.getConverter(intermediate, type); Class<?> _attachTo = ReflectorFactory.maybeConvertToProxy((intermediate != null) ? intermediate : type); for (Content _c : content) _c.onAttach(_attachTo, reflector, aConverters); aReflector.prepare(aContainerType, name, _attachTo); }
@Override public Builder<?> moveDown(String aName) { throw new ParsingException("Nothing can be nested in property " + name + " - definition doesn't match document?"); }
public DocumentDefinition<Immutable> immutableRootTypes() { return new JsonDocumentDefinition<Immutable>(){{ converting(Interface.class).to(Immutable.class).using( new Converter<Interface, Immutable>(){ @Override public Immutable convert(Interface aFrom) { return new Immutable(aFrom.getFirst(), aFrom.getSecond()); } } ); mapping(Immutable.class).via(Interface.class).with( property("first"), property("second") ); }}; }
public DocumentDefinition<Immutable> intermediateRootTypeWithNoCommonHierarchy() { // a converter that can convert from Uncommon to Immutable // this could be written inline in the document definition, // and, with Java8 lambdas, could be quite succinct. final Converter<Uncommon, Immutable> uncommonToImmutable = new Converter<Uncommon, Immutable>() { public Immutable convert(Uncommon aFrom) { return new Immutable(aFrom.getFirst(), aFrom.getSecond()); } }; return new JsonDocumentDefinition<Immutable>(){{ converting(Uncommon.class).to(Immutable.class).using(uncommonToImmutable); mapping(Immutable.class).via(Uncommon.class).with( property("first"), property("second") ); }}; }
public <F,T> TypeSafeConverter<F,T> getConverter(Class<F> aFromType, Class<T> aToType) { for (TypeSafeConverter<?,?> _c : converters) { if ((_c.canConvertFrom(aFromType)) && (_c.canConvertTo(aToType))) { return (TypeSafeConverter<F,T>) _c; } } throw new RuntimeException("no converter registered that can convert from " + aFromType + " to " + aToType); }
public static <R> SAXLegacyDocumentReader<R> mappingOf(String aTagName, Class<R> aClass) { return new SAXLegacyDocumentReader<R>( aClass, new TagHandler<R>(aTagName, aClass) ); }
@Override public Name alias(final String aName, final String anAlias) { return new Name.Impl(aName, anAlias); }
@Override public void setValue(Context aContext, String aName, Object aValue) { aContext.push(aValue); }
public static <R> PullLegacyDocumentReader<R> mappingOf(Class<R> aClass) { return new PullLegacyDocumentReader<R>(aClass); }
@Override public boolean isTextNode() { try { return parser.getEventType() == XmlPullParser.TEXT; } catch (XmlPullParserException anExc) { throw new ParsingException(anExc); } }
public <F,T> TypeSafeConverter<F,T> getConverter(Class<F> aFromType, Class<T> aToType) { for (TypeSafeConverter<?,?> _c : converters) { if ((_c.canConvertFrom(aFromType)) && (_c.canConvertTo(aToType))) { return (TypeSafeConverter<F,T>) _c; } } throw new RuntimeException("No converter registered that can convert from " + aFromType + " to " + aToType); }
@Override public int next() { try { return parser.next(); } catch (Exception anExc) { throw new ParsingException(anExc); } }
@Override public boolean hasMoreTags() { try { return parser.getEventType() != XmlPullParser.END_DOCUMENT; } catch (XmlPullParserException anExc) { throw new ParsingException(anExc); } }
@Override public boolean isStartTag() { try { return parser.getEventType() == XmlPullParser.START_TAG; } catch (XmlPullParserException anExc) { throw new ParsingException(anExc); } }
@Override public <T> T newInstance(Class<T> aType) { try { if (aType.isInterface()) { return newDynamicProxy(aType); } else { return aType.newInstance(); } } catch (Exception anExc) { throw new ParsingException(anExc); } }
public PullLegacyDocumentReader(Class<T> aClass) { super(aClass); try { factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); } catch (XmlPullParserException anExc) { throw new ParsingException(anExc); } }