From 73dbae8fff7d2c5f244b2bce9c448ac1654e5ce4 Mon Sep 17 00:00:00 2001 From: Dave Briccetti Date: Sun, 15 Jul 2018 14:05:19 -0700 Subject: [PATCH] =?UTF-8?q?Remove=20PrototypeFactoryDeprecated=20This=20cl?= =?UTF-8?q?ass=20is=20used=20to=20get=20values=20from=20a=20map,=20but=20n?= =?UTF-8?q?othing=20is=20ever=20put=20into=20the=20map.=20The=20one=20plac?= =?UTF-8?q?e=20it=E2=80=99s=20called=20to=20get=20a=20(null)=20value,=20in?= =?UTF-8?q?=20XFormParser.buildInstanceStructure,=20is=20not=20exercised?= =?UTF-8?q?=20by=20any=20current=20tests.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/javarosa/core/model/QuestionDef.java | 2 +- .../PrototypeFactoryDeprecated.java | 69 ------------------- .../org/javarosa/xform/parse/XFormParser.java | 13 +--- 3 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 src/main/java/org/javarosa/core/util/externalizable/PrototypeFactoryDeprecated.java diff --git a/src/main/java/org/javarosa/core/model/QuestionDef.java b/src/main/java/org/javarosa/core/model/QuestionDef.java index 4b70b4782..786232543 100644 --- a/src/main/java/org/javarosa/core/model/QuestionDef.java +++ b/src/main/java/org/javarosa/core/model/QuestionDef.java @@ -42,7 +42,7 @@ * filling out a form. * * QuestionDef requires that any IDataReferences that are used - * are contained in the FormDefRMS's PrototypeFactoryDeprecated in order + * are registered with PrototypeManager in order * to be properly deserialized. If they aren't, an exception * will be thrown at the time of deserialization. * diff --git a/src/main/java/org/javarosa/core/util/externalizable/PrototypeFactoryDeprecated.java b/src/main/java/org/javarosa/core/util/externalizable/PrototypeFactoryDeprecated.java deleted file mode 100644 index 4050c5db4..000000000 --- a/src/main/java/org/javarosa/core/util/externalizable/PrototypeFactoryDeprecated.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2009 JavaRosa - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.javarosa.core.util.externalizable; - -import org.javarosa.core.util.Map; - -/** - * The PrototypeFactory is a factory class for instantiating classes - * based on their class name. This class fills a hole created by J2ME's - * lack of reflection. - * - * The most common use of PrototypeFactories in JavaRoa is to instantiate - * objects in order to deserialize them from RMS. - * - * Note that due to the nature of instantiating classes dynamically, - * prototypes registered with this class must maintain a constructor with - * no arguments. - * - * @author Clayton Sims - * - */ -public class PrototypeFactoryDeprecated { - public Map prototypes = new Map(); - - /** - * Adds a new class to be able to retrieve instances of - * @param name The name of the prototype. Generally prototype.getClass().getName() - * @param prototype The class object to be used for instantiation. Should be a class - * with a constructor that takes 0 arguments. - */ - public void addNewPrototype(String name, Class prototype) { - prototypes.put(name, prototype); - } - - /** - * @param prototypeName The name of the prototype to be instantiated - * @return a new object of the type linked to the name given in this factory. Null - * if the name is not associated with any class in this factory. - * @throws IllegalAccessException If the empty constructor of the class given is not - * allowed to be accessed. - * @throws InstantiationException - */ - public Object getNewInstance(String prototypeName) { - if(prototypes.get(prototypeName) == null) { - return null; - } - try { - return ((Class)prototypes.get(prototypeName)).newInstance(); - } catch (InstantiationException e) { - throw new CannotCreateObjectException(prototypeName); - } catch (IllegalAccessException e) { - throw new CannotCreateObjectException(prototypeName); - } - } -} diff --git a/src/main/java/org/javarosa/xform/parse/XFormParser.java b/src/main/java/org/javarosa/xform/parse/XFormParser.java index c3ff25b62..3ae7d1a7a 100644 --- a/src/main/java/org/javarosa/xform/parse/XFormParser.java +++ b/src/main/java/org/javarosa/xform/parse/XFormParser.java @@ -90,7 +90,6 @@ import org.javarosa.core.util.CacheTable; import org.javarosa.core.util.StopWatch; import org.javarosa.core.util.externalizable.PrototypeFactory; -import org.javarosa.core.util.externalizable.PrototypeFactoryDeprecated; import org.javarosa.model.xform.XPathReference; import org.javarosa.xform.util.InterningKXmlParser; import org.javarosa.xform.util.XFormAnswerDataParser; @@ -149,7 +148,6 @@ public class XFormParser implements IXFormParserFunctions { private static HashMap topLevelHandlers; private static HashMap groupLevelHandlers; private static final Map typeMappings = TypeMappings.getMap(); - private static PrototypeFactoryDeprecated modelPrototypes; private static List submissionParsers; private Reader _reader; @@ -205,7 +203,6 @@ public static void setAnswerResolver(IAnswerResolver answerResolver) { private static void staticInit() { initProcessingRules(); - modelPrototypes = new PrototypeFactoryDeprecated(); submissionParsers = new ArrayList<>(1); referencedInstanceIds = new HashSet<>(); @@ -2020,14 +2017,8 @@ public static TreeElement buildInstanceStructure(Element node, TreeElement paren if (typeMappings.get(modelType) == null) { throw new XFormParseException("ModelType " + modelType + " is not recognized.", node); } - element = (TreeElement) modelPrototypes.getNewInstance(typeMappings.get(modelType).toString()); - if (element == null) { - element = new TreeElement(name, multiplicity); - logger.info("No model type prototype available for {}", modelType); - } else { - element.setName(name); - element.setMult(multiplicity); - } + element = new TreeElement(name, multiplicity); + logger.info("No model type prototype available for {}", modelType); } if (node.getNamespace() != null) { if (!node.getNamespace().equals(docnamespace)) {