/** * Gets a reference to the Class or Class/Context provided by this AbstractReferenceManufacturer. * The reference will be a reference to the object identified by the given key. * * @param key The key used to identify the object to which the returned CDOMReference will refer. * @return A CDOMReference that refers to the object identified by the given key * @throws IllegalArgumentException if the given key is null or empty */ @Override public CDOMSingleRef<T> getReference(String key) { /* * TODO This is incorrect, but a hack for now :) * * Mainly this throws around IllegalArgumentException in order to catch * bad parsing issues (design flaws in the code). Not sure if we want to * continue that long term? Once tokens are truly tested this may not be * necessary or desirable. */ if (key == null) { throw new IllegalArgumentException("Cannot request a reference to null identifier"); } if (key.length() == 0) { throw new IllegalArgumentException("Cannot request a reference to an empty identifier"); } /* * Items thrown below this point are for protection from coding errors * in LST files, not part of the public interface of this method */ try { Integer.parseInt(key); throw new IllegalArgumentException("A number cannot be a valid single item: " + key); } catch (NumberFormatException nfe) { // ok } if (key.contains("=")) { throw new IllegalArgumentException( "= cannot be a in valid single item (perhaps something like TYPE= " + "is not supported in this token?): " + key); } if (key.equalsIgnoreCase("ANY")) { throw new IllegalArgumentException( "Any cannot be a valid single item (not supported in this token?)"); } if (key.equalsIgnoreCase("ALL")) { throw new IllegalArgumentException( "All cannot be a valid single item (not supported in this token?)"); } if (key.contains(":")) { throw new IllegalArgumentException( ": cannot exist in a valid single item (did you try to use a " + "PRE where it is not supported?) " + key); } if (key.equalsIgnoreCase("%LIST")) { throw new IllegalArgumentException( "%LIST cannot be a valid single item (not supported in this token?)"); } WeakReference<CDOMSingleRef<T>> wr = referenced.get(key); if (wr != null) { CDOMSingleRef<T> ref = wr.get(); if (ref != null) { return ref; } } CDOMSingleRef<T> ref; if (isResolved) { T current = active.get(key); if (current == null) { throw new IllegalArgumentException( key + " is not valid post-resolution " + "because it was never constructed"); } ref = CDOMDirectSingleRef.getRef(current); } else { CDOMSingleRef<T> lr = factory.getReference(key); referenced.put(key, new WeakReference<CDOMSingleRef<T>>(lr)); ref = lr; } return ref; }
@Override public Indirect<T> convertIndirect(String key) { return factory.getReference(key); }