/** * Returns a view of the given metadata as a map. This method returns always a map using UML identifier * and containing all entries including the null ones because the {@code MetadataSource} implementation * assumes so. * * @param metadata the metadata object to view as a map. * @return a map view over the metadata object. * @throws ClassCastException if the metadata object does not implement a metadata interface * of the expected package. */ final Map<String,Object> asValueMap(final Object metadata) throws ClassCastException { return standard.asValueMap(metadata, null, NAME_POLICY, ValueExistencePolicy.ALL); }
/** * Returns the property names and expected types for the given class. */ final Map<String,Class<?>> getDefinition(final Class<?> type) { return standard.asTypeMap(type, KeyNamePolicy.UML_IDENTIFIER, TypeValuePolicy.ELEMENT_TYPE); }
/** * Returns a key for use in {@link #getAccessor(CacheKey, boolean)} for the given type. * The type may be an interface (typically a GeoAPI interface) or an implementation class. */ private CacheKey createCacheKey(Class<?> type) { final Class<?> implementation = getImplementation(type); if (implementation != null) { type = implementation; } return new CacheKey(type); }
if (dependency.isMetadata(key)) { accessors.putIfAbsent(key, dependency); return true; final Class<?> standardType = findInterface(key); if (standardType != null) { accessors.putIfAbsent(key, standardType);
interf = (Class<?>) value; } else if (value instanceof MetadataStandard) { interf = ((MetadataStandard) value).getInterface(key); } else if (key.isValid()) { interf = findInterface(key); if (interf != null) { accessors.putIfAbsent(key, interf); if (dependencies != null) { for (final MetadataStandard dependency : dependencies) { if (dependency.isMetadata(key)) { accessors.putIfAbsent(key, dependency); return dependency.getInterface(key);
/** * Returns a value of the "title" property of the given metadata object. * The title property is defined by {@link TitleProperty} annotation on the implementation class. * * @param metadata the metadata for which to get the title property, or {@code null}. * @return the title property value of the given metadata, or {@code null} if none. * * @see TitleProperty * @see ValueExistencePolicy#COMPACT */ final Object getTitle(final Object metadata) { if (metadata != null) { final Class<?> type = metadata.getClass(); final PropertyAccessor accessor = getAccessor(createCacheKey(type), false); if (accessor != null) { TitleProperty an = type.getAnnotation(TitleProperty.class); if (an != null || (an = accessor.implementation.getAnnotation(TitleProperty.class)) != null) { return accessor.get(accessor.indexOf(an.name(), false), metadata); } } } return null; }
final Map<String,?> properties, final int position) throws ParseException Class<? extends T> impl = standard.getImplementation(type); if (impl == null) { if (standard.isMetadata(type)) { throw new ParseException(Errors.format(Errors.Keys.UnknownType_1, type), position); final Map<String,Object> asMap = standard.asValueMap(metadata, null, KeyNamePolicy.UML_IDENTIFIER, ValueExistencePolicy.NON_EMPTY); try {
final Class<?> interfaceType = standard.getInterface(implementationType); final String table = getTableName(interfaceType); final Set<String> columns = getExistingColumns(table); if (!columns.contains(column)) { if (colTypes == null) { colTypes = standard.asTypeMap(implementationType, NAME_POLICY, TypeValuePolicy.ELEMENT_TYPE); colTables = standard.asTypeMap(implementationType, NAME_POLICY, TypeValuePolicy.DECLARING_INTERFACE); Class<?> rt = colTypes.get(column); final boolean isCodeList = CodeList.class.isAssignableFrom(rt); if (isCodeList || standard.isMetadata(rt)) { if (value != null && !standard.isMetadata(value.getClass())) { identifier = abbreviation(value.toString()); break; } else if (type.isEnum()) { value = ((Enum<?>) value).name(); } else if (standard.isMetadata(type)) { String dependency = proxy(value); if (dependency == null) { final Class<?> targetType = standard.getInterface(value.getClass()); FKey fkey = foreigners.get(column); if (fkey != null && !targetType.isAssignableFrom(fkey.tableType)) { } else { primaryKey = ID_COLUMN;
/** * Returns indices for all properties defined in the given metadata type. * The keys in the returned map are the same than the keys in the above {@linkplain #asNameMap name map}. * The values are arbitrary indices numbered from 0 inclusive to <var>n</var> exclusive, where <var>n</var> * is the number of properties declared in the given metadata type. * * <p>Property indices may be used as an alternative to property names by some applications doing their own storage. * Such index usages are fine for temporary storage during the Java Virtual Machine lifetime, but indices should not * be used in permanent storage. The indices are stable as long as the metadata implementation does not change, * but may change when the implementation is upgraded to a newer version.</p> * * @param type the interface or implementation class of a metadata. * @param keyPolicy determines the string representation of map keys. * @return indices of all properties defined by the given metadata type. * @throws ClassCastException if the specified interface or implementation class does * not extend or implement a metadata interface of the expected package. */ public Map<String,Integer> asIndexMap(Class<?> type, final KeyNamePolicy keyPolicy) throws ClassCastException { ensureNonNull("type", type); ensureNonNull("keyPolicy", keyPolicy); final Class<?> implementation = getImplementation(type); if (implementation != null) { type = implementation; } return new IndexMap(getAccessor(new CacheKey(type), true), keyPolicy); }
if (value != null) { if (cache == null) { final Class<?> impl = source.standard.getImplementation(type); if (impl == null) { return value; final Map<String, Object> map = source.standard.asValueMap(cache, type, KeyNamePolicy.METHOD_NAME, ValueExistencePolicy.ALL); synchronized (cache) { final Class<?> impl = source.standard.getImplementation(type); if (impl != null) { final Dependencies dependencies = impl.getMethod(method.getName()).getAnnotation(Dependencies.class);
/** * Returns {@code true} if nodes for values of the given type can be expanded with more children. * A return value of {@code false} means that values of the given type are leaves. */ final boolean isMetadata(final Class<?> type) { return table.standard.isMetadata(type); }
if (!standard.getInterface(source.getClass()).isInstance(target)) { return false; sourceMap = standard.asValueMap(source, null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
/** * Returns the SIS implementation for the given GeoAPI interface. * * @return {@inheritDoc} */ @Override protected <T> Class<? extends T> getImplementation(final Class<T> type) { assertTrue(type.getName(), standard.isMetadata(type)); final Class<? extends T> impl = standard.getImplementation(type); assertNotNull(type.getName(), impl); return impl; }
/** * Verifies the {@link TitleProperty} annotations. This method verifies that the property exist, * is a singleton, and is not another metadata object. The property should also be mandatory, * but this method does not verify that restriction since there is some exceptions. * * @since 0.8 */ @Test public void testTitlePropertyAnnotation() { for (final Class<?> type : types) { final Class<?> impl = standard.getImplementation(type); if (impl != null) { final TitleProperty an = impl.getAnnotation(TitleProperty.class); if (an != null) { final String name = an.name(); final String message = impl.getSimpleName() + '.' + name; final PropertyAccessor accessor = new PropertyAccessor(standard.getCitation(), type, impl, impl); // Property shall exist. final int index = accessor.indexOf(name, false); assertTrue(message, index >= 0); // Property can not be a metadata. final Class<?> elementType = accessor.type(index, TypeValuePolicy.ELEMENT_TYPE); assertFalse(message, standard.isMetadata(elementType)); // Property shall be a singleton. assertSame(message, elementType, accessor.type(index, TypeValuePolicy.PROPERTY_TYPE)); } } } }
if (value instanceof Class<?>) { assert type == findInterface(key) : key; } else if (key.isValid()) { type = findInterface(key); if (type == null) { if (dependencies != null) { for (final MetadataStandard dependency : dependencies) { final PropertyAccessor accessor = dependency.getAccessor(key, false); if (accessor != null) { return v; final Class<?> standardImpl = getImplementation(type); final PropertyAccessor accessor; if (SpecialCases.isSpecialCase(type)) {
/** * Returns the metadata interface implemented by this class. It should be one of the interfaces * defined in the {@linkplain #getStandard() metadata standard} implemented by this class. * * @return the standard interface implemented by this implementation class. * * @see MetadataStandard#getInterface(Class) */ public Class<?> getInterface() { // No need to sychronize, since this method does not depend on property values. return getStandard().getInterface(getClass()); }
/** * Tests {@link MetadataStandard#hashCode(Object)} using {@link HashSet} as the reference * implementation for computing hash code values. The hash code is defined as the sum of * hash code values of all non-empty properties, plus the hash code of the interface. */ @Test @DependsOnMethod("testValueMap") public void testHashCode() { standard = MetadataStandard.ISO_19115; final DefaultCitation instance = HardCodedCitations.EPSG; final Map<String,Object> map = standard.asValueMap(instance, null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY); assertFalse(map.isEmpty()); // Actually 'testValueMap()' job, but verified for safety. assertEquals("hashCode()", new HashSet<>(map.values()).hashCode() + Citation.class.hashCode(), standard.hashCode(instance)); }
} else { final Class<?> type = value.getClass(); if (standard.isMetadata(type)) { dependency = search(getTableName(standard.getInterface(type)), null, asValueMap(value), stmt, new SQLBuilder(helper)); if (dependency == null) {
/** * Replaces every properties in the specified metadata by their * {@linkplain ModifiableMetadata#unmodifiable() unmodifiable variant}. * * @throws ClassCastException if the specified implementation class do * not implements a metadata interface of the expected package. * * @see ModifiableMetadata#freeze() */ final void freeze(final Object metadata) throws ClassCastException { getAccessor(new CacheKey(metadata.getClass()), true).freeze(metadata); }
public void testDependenciesAnnotation() throws NoSuchMethodException { for (final Class<?> type : types) { final Class<?> impl = standard.getImplementation(type); if (impl != null) { Map<String,String> names = null; final String name = method.getName(); if (names == null) { names = standard.asNameMap(type, KeyNamePolicy.JAVABEANS_PROPERTY, KeyNamePolicy.METHOD_NAME);