/** * Gets the object represented by the given identifier. Will return null if an object with the * given identifier is not present in this AbstractReferenceManufacturer. * * <p>Note that this is testing *object* presence. This will not return an object if a reference * for the given identifier has been requested; it will only return true if an object with the * given identifier has actually been constructed by or imported into this * AbstractReferenceManufacturer. * * @param key identifier of the object to be returned * @return The object stored in this AbstractReferenceManufacturer with the given identifier, or * null if this AbstractReferenceManufacturer does not contain an object with the given * identifier. */ @Override public T getObject(String key) { T po = active.get(key); if (po != null) { List<T> list = duplicates.getListFor(new CaseInsensitiveString(key)); if ((list != null) && !list.isEmpty()) { Logging.errorPrint( "Reference to Constructed " + factory.getReferenceDescription() + " " + key + " is ambiguous"); StringBuilder sb = new StringBuilder(1000); sb.append("Locations: "); sb.append(po.getSourceURI()); for (T dupe : list) { sb.append(", "); sb.append(dupe.getSourceURI()); } Logging.errorPrint(sb.toString()); } return po; } return null; }
private boolean resolveGroupReferences() { for (T obj : getAllObjects()) { if (allRef != null) { allRef.addResolution(obj); } for (Map.Entry<FixedStringList, WeakReference<CDOMGroupRef<T>>> me : typeReferences.entrySet()) { CDOMGroupRef<T> trt = me.getValue().get(); if (trt != null) { boolean typeOkay = true; for (String type : me.getKey()) { if (!obj.isType(type)) { typeOkay = false; break; } } if (typeOkay) { trt.addResolution(obj); } } } } if (allRef != null && allRef.getObjectCount() == 0) { Logging.errorPrint( "Error: No " + factory.getReferenceDescription() + " objects were loaded but were referred to in the data"); fireUnconstuctedEvent(allRef); return false; } return true; }
private boolean validateDuplicates() { boolean returnGood = true; for (CaseInsensitiveString second : duplicates.getKeySet()) { List<T> list = duplicates.getListFor(second); T good = active.get(second.toString()); /* * CONSIDER Should get CDOMObject reference out of here :( */ if (good instanceof CDOMObject) { CDOMObject cdo = (CDOMObject) good; for (int i = 0; i < list.size(); i++) { T dupe = list.get(i); if (cdo.isCDOMEqual((CDOMObject) dupe)) { for (Iterator<WeakReference<T>> it = manufactured.iterator(); it.hasNext(); ) { WeakReference<T> wr = it.next(); T mfg = wr.get(); if (mfg == null) { it.remove(); } // Yes this is instance equality, not .equals else if (mfg == good) { forgetObject(good); break; } } } } } if (duplicates.containsListFor(second)) { Logging.errorPrint( "More than one " + factory.getReferenceDescription() + " with key/name " + good.getKeyName() + " was built"); List<T> dupes = duplicates.getListFor(second); StringBuilder sb = new StringBuilder(1000); sb.append("Sources: "); sb.append(good.isInternal() ? "<internal>" : good.getSourceURI()); for (T dupe : dupes) { sb.append(", ").append(dupe.isInternal() ? "<internal>" : dupe.getSourceURI()); if (!dupe.getKeyName().equals(good.getKeyName())) { Logging.errorPrint("Key case differed for " + dupe.getKeyName()); } } Logging.errorPrint(sb.toString()); returnGood = false; } } return returnGood; }
/** * Adds an object to the contents of this AbstractReferenceManufacturer. This is used in * conditions where this AbstractReferenceManufacturer was not used to construct the object. * * <p>Implementation Note: There are various situations where this "external construction" may * happen - the primary one being loading of "game mode" information like CDOMStat objects. * * @param item The object to be imported into this AbstractReferenceManufacturer * @param key The identifier of the object to be imported into this AbstractReferenceManufacturer * @throws IllegalArgumentException if the given object is not of the Class that this * AbstractReferenceManufacturer constructs and references */ @Override public void addObject(T item, String key) { if (!factory.isMember(item)) { throw new IllegalArgumentException( "Attempted to register a " + item.getClass().getName() + " in " + factory.getReferenceDescription()); } T current = active.get(key); if (current == null) { active.put(key, item); } else { duplicates.addToListFor(new CaseInsensitiveString(key), item); } }
/** * Resolves the references that have been requested from this AbstractReferenceManufacturer, using * the objects contained within this AbstractReferenceManufacturer. * * <p>This method guarantees that all references are resolved. * * <p>Note: Implementations of AbstractReferenceManufacturer may place limits on the number of * times resolveReferences() can be called. The reason for this is that some references may only * be resolved once, and the AbstractReferenceManufacturer is not required to maintain a list of * references that have been resolved and those which have not been resolved. */ @Override public boolean resolveReferences(UnconstructedValidator validator) { boolean resolutionSuccessful = resolvePrimitiveReferences(validator); resolutionSuccessful &= resolveGroupReferences(); for (WeakReference<CDOMGroupRef<T>> ref : typeReferences.values()) { CDOMGroupRef<T> trt = ref.get(); if (trt != null && trt.getObjectCount() == 0) { Logging.errorPrint( "Error: No " + factory.getReferenceDescription() + " objects of " + trt.getLSTformat(false) + " were loaded but were referred to in the data"); fireUnconstuctedEvent(trt); resolutionSuccessful = false; } } isResolved = true; return resolutionSuccessful; }
private boolean validateNames() { if (!Logging.isLoggable(Logging.LST_WARNING)) { return true; } for (String key : active.keySet()) { T value = active.get(key); if (value.isInternal()) { continue; } /* * http://wiki.pcgen.org/index.php?title=Data_LST_Standards * * Characters which should never be used in object names are Commas * (,), Pipes (|), Backslashes (\), Colons (:), Semicolons (;), * Periods (.), Brackets ([]), Percent (%), Asterisk (*) and Equals * (=). */ if (key.indexOf(',') != -1 && factory.getReferenceClass() != RollMethod.class) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a comma " + "(prohibited character in a key)"); } if (key.indexOf('|') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a pipe " + "(prohibited character in a key)"); } if (key.indexOf('\\') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a backslash " + "(prohibited character in a key)"); } if (key.indexOf(':') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a colon " + "(prohibited character in a key)"); } if (key.indexOf(';') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a semicolon " + "(prohibited character in a key)"); } // if (key.indexOf('.') != -1) // { // Logging.log(Logging.LST_WARNING, "Found " // + getReferenceDescription() + " with KEY: " + key // + " which contains a period " // + "(prohibited character in a key)"); // } if (key.indexOf('%') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a percent sign " + "(prohibited character in a key)"); } if (key.indexOf('*') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains an asterisk " + "(prohibited character in a key)"); } if (key.indexOf('=') != -1) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains an equals sign " + "(prohibited character in a key)"); } if ((key.indexOf('[') != -1) || (key.indexOf(']') != -1)) { Logging.log( Logging.LST_WARNING, "Found " + factory.getReferenceDescription() + " with KEY: " + key + " which contains a bracket " + "(prohibited character in a key)"); } } return true; }
@Override public String getReferenceDescription() { return factory.getReferenceDescription(); }