@Test public void testResponsibleParty() { final MetadataProxyFactory factory = new MetadataProxyFactory(); Map<String,Object> attributes = new HashMap<>(); assertNull(attributes.put("name", new SimpleCitation("Aristotle"))); final Party party = factory.create(Party.class, attributes); assertEquals("Aristotle", party.getName().toString()); attributes = new HashMap<>(); assertNull(attributes.put("party", Collections.singleton(party))); final Responsibility responsibility = factory.create(Responsibility.class, attributes); assertEquals("Aristotle", getSingleton(responsibility.getParties()).getName().toString()); attributes = new HashMap<>(); assertNull(attributes.put("contact", Collections.singleton(responsibility))); final Metadata md = factory.create(Metadata.class, attributes); assertEquals("Aristotle", getSingleton(getSingleton(md.getContacts()).getParties()).getName().toString()); assertTrue("Null value should have been replaced by empty collection.", md.getSpatialRepresentationInfo().isEmpty()); assertEquals("MD_Metadata{contact=[CI_Responsibility{party=[CI_Party{name=Aristotle}]}]}", md.toString()); }
public <T> T create(final Class<T> type, final Map<String,?> attributes) throws IllegalArgumentException { if (!type.isInterface() || !type.getName().startsWith("org.opengis.metadata.")) { throw new IllegalArgumentException("Illegal type: " + type); } Objects.requireNonNull(attributes); return type.cast(Proxy.newProxyInstance(MetadataProxyFactory.class.getClassLoader(), new Class<?>[] {type}, new MetadataHandler(type, attributes))); }
MetadataProxyFactory { public <T> T create(final Class<T> type, final Map<String,?> attributes) throws IllegalArgumentException { if (!type.isInterface() || !type.getName().startsWith("org.opengis.metadata.")) { throw new IllegalArgumentException("Illegal type: " + type); } Objects.requireNonNull(attributes); return type.cast(Proxy.newProxyInstance(MetadataProxyFactory.class.getClassLoader(), new Class<?>[] {type}, new MetadataHandler(type, attributes))); } }
MetadataProxyFactory { public <T> T create(final Class<T> type, final Map<String,?> attributes) throws IllegalArgumentException { if (!type.isInterface() || !type.getName().startsWith("org.opengis.metadata.")) { throw new IllegalArgumentException("Illegal type: " + type); } Objects.requireNonNull(attributes); return type.cast(Proxy.newProxyInstance(MetadataProxyFactory.class.getClassLoader(), new Class<?>[] {type}, new MetadataHandler(type, attributes))); } MetadataProxyFactory(); }
MetadataProxyFactory { public <T> T create(final Class<T> type, final Map<String,?> attributes) throws IllegalArgumentException { if (!type.isInterface() || !type.getName().startsWith("org.opengis.metadata.")) { throw new IllegalArgumentException("Illegal type: " + type); } Objects.requireNonNull(attributes); return type.cast(Proxy.newProxyInstance(MetadataProxyFactory.class.getClassLoader(), new Class<?>[] {type}, new MetadataHandler(type, attributes))); } MetadataProxyFactory(); T create(final Class<T> type, final Map<String,?> attributes); }
MetadataProxyFactory { public <T> T create(final Class<T> type, final Map<String,?> attributes) throws IllegalArgumentException { if (!type.isInterface() || !type.getName().startsWith("org.opengis.metadata.")) { throw new IllegalArgumentException("Illegal type: " + type); } Objects.requireNonNull(attributes); return type.cast(Proxy.newProxyInstance(MetadataProxyFactory.class.getClassLoader(), new Class<?>[] {type}, new MetadataHandler(type, attributes))); } MetadataProxyFactory(); T create(final Class<T> type, final Map<String,?> attributes);  }