/** * Wraps the specified authority factories. If the specified collection contains more than one * element, then a chain of {@code FallbackAuthorityFactory} instances is created. The type is * inferred from the factories found in the collection. * * <p>Consider using <code>{@linkplain #create(Class, Collection) create}(type, factories) * </code> instead when the type is known at compile time. * * @param factories The factories to wrap, in iteration order. * @return The given factories as a chain of fallback factories. * @throws FactoryNotFoundException if the collection doesn't contains at least one element. * @since 2.4 */ public static AuthorityFactory create(final Collection<? extends AuthorityFactory> factories) throws FactoryNotFoundException { ensureNonNull("factories", factories); if (factories.isEmpty()) { throw new FactoryNotFoundException( Errors.format(ErrorKeys.FACTORY_NOT_FOUND_$1, AuthorityFactory.class)); } return create(false, interfaceMask(factories), factories.iterator()); }
/** Returns an arbitrary object from a code. */ @Override public IdentifiedObject createObject(final String code) throws FactoryException { try { return super.createObject(code); } catch (FactoryException exception) { notifyFailure("createObject", exception); try { return fallback.createObject(code); } catch (NoSuchAuthorityCodeException ignore) { throw exception; } } }
AuthorityFactory primary = factories.next(); if (factories.hasNext()) { AuthorityFactory fallback = create(true, interfaceMask, factories); while (fallback != primary) { // Paranoiac check if (!sameAuthorityCodes(fallback, primary)) { interfaceMask &= (interfaceMask(primary) | interfaceMask(fallback)); primary = create(interfaceMask, primary, fallback); } else {
/** * Invoked when a factory is requested for a specific version. This method should create a * factory for the exact version specified by the argument, or return {@code null} if no such * factory is available. In the later case, this class will fallback on the factory specified at * {@linkplain #URI_AuthorityFactory(AuthorityFactory, String, Citation) construction time}. * * @param version The version for the factory to create. * @return The factory, of {@code null} if there is none for the specified version. * @throws FactoryException if an error occurred while creating the factory. */ protected AuthorityFactory createVersionedFactory(final Version version) throws FactoryException { final Hints hints = new Hints(factory.getImplementationHints()); hints.put(Hints.VERSION, version); final List<AuthorityFactory> factories = Arrays.asList(new AuthorityFactory[] {new AllAuthoritiesFactory(hints), factory}); return FallbackAuthorityFactory.create(factories); }
assert (mask & ~(interfaceMask(primary) | interfaceMask(fallback))) == 0 : mask; final AuthorityFactory factory; break; case 0: factory = new FallbackAuthorityFactory(primary, fallback); break; default: assert (interfaceMask(factory) & ~mask) == 0 : mask; return factory;
/** Returns a mask that represent the implemented interfaces. */ private static int interfaceMask(final Collection<? extends AuthorityFactory> factories) { int mask = 0; for (final AuthorityFactory factory : factories) { mask |= interfaceMask(factory); } return mask; }
/** * Wraps a primary and a fallback authority factories. * * <p>This constructor is protected because subclasses must declare which of the {@link * DatumAuthorityFactory}, {@link CSAuthorityFactory}, {@link CRSAuthorityFactory} and {@link * CoordinateOperationAuthorityFactory} interfaces they choose to implement. * * @param primary The primary factory. * @param fallback The factory to use as a fallback if the primary factory failed. * @see #create */ protected FallbackAuthorityFactory( final AuthorityFactory primary, final AuthorityFactory fallback) { super(primary, fallback); ensureNonNull("fallback", fallback); this.fallback = (fallback instanceof AbstractAuthorityFactory) ? (AbstractAuthorityFactory) fallback : new AuthorityFactoryAdapter(fallback); }
/** * Creates a CRS chooser backed by the specified authority factory. * * @param authority The authority identifier (e.g. {@code "EPSG"}). * @throws FactoryRegistryException if no authority factory has been found. * @throws FactoryException if the factory can't provide CRS codes. * * @since 2.4 */ public AuthorityCodesComboBox(final String authority) throws FactoryRegistryException, FactoryException { // TODO: remove the cast when we will be allowed to compile for J2SE 1.5. this((CRSAuthorityFactory) FallbackAuthorityFactory.create(CRSAuthorityFactory.class, filter(ReferencingFactoryFinder.getCRSAuthorityFactories(null), authority))); }
/** * Returns {@code true} if the two specified factories can be used in a {@code * FallbackAuthorityFactory}. If this method returns {@code false}, then we should not create * instance of this class since it would be useless. */ static boolean chainable(final AuthorityFactory primary, final AuthorityFactory fallback) { return (interfaceMask(primary) & interfaceMask(fallback)) != 0; }
static List<CrsInfo> generateCRSList() { // todo - (mp/mz) this method takes time (2 sec.) try to speed up Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(hints); final List<CRSAuthorityFactory> filtered = new ArrayList<CRSAuthorityFactory>(); for (final CRSAuthorityFactory factory : factories) { if (Citations.identifierMatches(factory.getAuthority(), AUTHORITY)) { filtered.add(factory); } } CRSAuthorityFactory crsAuthorityFactory = FallbackAuthorityFactory.create(CRSAuthorityFactory.class, filtered); Set<String> codes = new HashSet<String>(); List<CrsInfo> crsList = new ArrayList<CrsInfo>(1024); retrieveCodes(codes, GeodeticCRS.class, crsAuthorityFactory); retrieveCodes(codes, ProjectedCRS.class, crsAuthorityFactory); for (String code : codes) { final String authCode = String.format("%s:%s", AUTHORITY, code); crsList.add(new CrsInfo(authCode, crsAuthorityFactory)); } codes.clear(); AutoCRSFactory autoCRSFactory = new AutoCRSFactory(); retrieveCodes(codes, ProjectedCRS.class, autoCRSFactory); for (String code : codes) { final String authCode = String.format("AUTO:%s", code); crsList.add(new AutoCrsInfo(authCode, autoCRSFactory)); } Collections.sort(crsList); return crsList; }
/** * Wraps the specified authority factories. If the specified collection contains more than one * element, then a chain of {@code FallbackAuthorityFactory} instances is created. * * @param <T> The interface to implement. * @param type The interface to implement. Should be one of {@link DatumAuthorityFactory}, * {@link CSAuthorityFactory}, {@link CRSAuthorityFactory} or {@link * CoordinateOperationAuthorityFactory}. * @param factories The factories to wrap, in iteration order. * @return The given factories as a chain of fallback factories. * @throws FactoryNotFoundException if the collection doesn't contains at least one element. * @throws ClassCastException if {@code type} is illegal. */ public static <T extends AuthorityFactory> T create( final Class<T> type, final Collection<T> factories) throws FactoryNotFoundException, ClassCastException { ensureNonNull("type", type); ensureNonNull("factories", factories); if (factories.isEmpty()) { throw new FactoryNotFoundException(Errors.format(ErrorKeys.FACTORY_NOT_FOUND_$1, type)); } return type.cast(create(false, interfaceMask(type), factories.iterator())); }
/** Returns a description for the object identified by the specified code. */ @Override public InternationalString getDescriptionText(final String code) throws FactoryException { try { return super.getDescriptionText(code); } catch (FactoryException exception) { notifyFailure("getDescriptionText", exception); try { return fallback.getDescriptionText(code); } catch (NoSuchAuthorityCodeException ignore) { throw exception; } } }
/** Returns a mask that represent the implemented interface. */ private static int interfaceMask(final AuthorityFactory factory) { return interfaceMask(factory.getClass()); }
static List<CrsInfo> generateCRSList() { // todo - (mp/mz) this method takes time (2 sec.) try to speed up Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(hints); final List<CRSAuthorityFactory> filtered = new ArrayList<CRSAuthorityFactory>(); for (final CRSAuthorityFactory factory : factories) { if (Citations.identifierMatches(factory.getAuthority(), AUTHORITY)) { filtered.add(factory); } } CRSAuthorityFactory crsAuthorityFactory = FallbackAuthorityFactory.create(CRSAuthorityFactory.class, filtered); Set<String> codes = new HashSet<String>(); List<CrsInfo> crsList = new ArrayList<CrsInfo>(1024); retrieveCodes(codes, GeodeticCRS.class, crsAuthorityFactory); retrieveCodes(codes, ProjectedCRS.class, crsAuthorityFactory); for (String code : codes) { final String authCode = String.format("%s:%s", AUTHORITY, code); crsList.add(new CrsInfo(authCode, crsAuthorityFactory)); } codes.clear(); AutoCRSFactory autoCRSFactory = new AutoCRSFactory(); retrieveCodes(codes, ProjectedCRS.class, autoCRSFactory); for (String code : codes) { final String authCode = String.format("AUTO:%s", code); crsList.add(new AutoCrsInfo(authCode, autoCRSFactory)); } Collections.sort(crsList); return crsList; }
/** * Creates a {@linkplain EngineeringCRS engineering coordinate reference system} from a code. * * @throws FactoryException if the object creation failed for all factories. */ @Override public EngineeringCRS createEngineeringCRS(final String code) throws FactoryException { try { return super.createEngineeringCRS(code); } catch (FactoryException exception) { notifyFailure("createEngineeringCRS", exception); try { return fallback.createEngineeringCRS(code); } catch (NoSuchAuthorityCodeException ignore) { throw exception; } } }
public JCRSList(){ String authority = "EPSG"; this.factory = FallbackAuthorityFactory.create(CRSAuthorityFactory.class, filter(ReferencingFactoryFinder.getCRSAuthorityFactories(null), authority));
/** * Returns an arbitrary {@linkplain CoordinateReferenceSystem coordinate reference system} from * a code. * * @throws FactoryException if the object creation failed for all factories. */ @Override public CoordinateReferenceSystem createCoordinateReferenceSystem(final String code) throws FactoryException { try { return super.createCoordinateReferenceSystem(code); } catch (FactoryException exception) { notifyFailure("createCoordinateReferenceSystem", exception); try { return fallback.createCoordinateReferenceSystem(code); } catch (NoSuchAuthorityCodeException ignore) { throw exception; } } }
/** * Returns a {@linkplain PrimeMeridian prime meridian} from a code. * * @throws FactoryException if the object creation failed for all factories. */ @Override public PrimeMeridian createPrimeMeridian(final String code) throws FactoryException { try { return super.createPrimeMeridian(code); } catch (FactoryException exception) { notifyFailure("createPrimeMeridian", exception); try { return fallback.createPrimeMeridian(code); } catch (NoSuchAuthorityCodeException ignore) { throw exception; } } }
/** * Returns an arbitrary {@linkplain CoordinateSystem coordinate system} from a code. * * @throws FactoryException if the object creation failed for all factories. */ @Override public CoordinateSystem createCoordinateSystem(final String code) throws FactoryException { try { return super.createCoordinateSystem(code); } catch (FactoryException exception) { notifyFailure("createCoordinateSystem", exception); try { return fallback.createCoordinateSystem(code); } catch (NoSuchAuthorityCodeException ignore) { throw exception; } } }