{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Using Reflection","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":false}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"using-reflection","__idx":0},"children":["Using Reflection"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Reflection is a feature in the Java programming language. It supports dynamic retrieval of information about classes and data structures by name, and allows for their manipulation within an executing Java program. This is handy for obtaining class information. But it is also possible to use reflection to create new objects and invoke a method of a specific name. This is what the ReflectionUtil class is used for in INTViewer."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Java reflection classes are found in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["java.lang.reflect"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ReflectionUtil class is found in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["com.interactive.intviewerapi.util"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Overloaded Methods"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"newInstance(String fullyQualifiedClassName)\nnewInstance(Class<?> klass)\nnewInstance(String fullyQualifiedClassName, Class[] paramKlasses, Object[] params)\nnewInstance(Class<?> klass, Class<?>[] paramKlasses, Object[] params)\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Exceptions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["All methods in the ReflectionUtil class throw the following exceptions:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example 1"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Found in the AbstractLayerFactory class (createLayer method)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["where m is an IMemento object and destWindow is an ILayeredWindow object"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"        ViewerLayer2D layer = null;\n        int layerId = m.getInteger(ViewerLayer2D.ID, ViewerLayerFactory.getInstance().createUniqueLayerId());\n        // get the class name for the layer to be restored from the session IMemento document\n        String layerClassName = m.getString(ViewerLayer2D.CLASS);\n        // store the class types for the parameter objects\n        Class<?>[] classParameters = {destWindow.getClass().getSuperclass(), Integer.TYPE};\n        // store the parameter objects\n        Object[] parameters = {destWindow, layerId};\n        // pass the parameter arrays to the \"layerClassName\" constructor\n        layer = (ViewerLayer2D) ReflectionUtil.newInstance(layerClassName, classParameters, parameters);\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The reflection allows all classes extending the AbstractLayerFactory to use the one createLayer method for session restore without the AbstractLayerFactory having to hard-code information about the subclasses."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example 2"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Found in the IData.Factory class"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["where dataM is an IMemento object"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"        String dataKlassName = null;\n        try {\n            // get the class name for the data to be restored from the IMemento document\n            dataKlassName = dataM.getString(IData.DATA_CLASS);\n            if (dataKlassName != null) {\n                realData = (IData) ReflectionUtil.newInstance(dataKlassName);\n            }\n        } catch (Exception e) {\n            throw new Exception(\"Failed to create data source for data class = \" + dataKlassName + \" : \" + e.getMessage());\n        }\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To use the IData Factory:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["where m is an IMemento object"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"              IData realData = IData.Factory.createNewInstance(m);\n"},"children":[]}]},"headings":[{"value":"Using Reflection","id":"using-reflection","depth":1}],"frontmatter":{"title":"Using Reflection","pageId":"other-useful-intviewer-apis/using-reflection","seo":{"title":"Using Reflection"}},"lastModified":"2026-10-22T14:32:05.579Z","pagePropGetterError":{"message":"","name":""}},"slug":"/solutions/intviewer/other-useful-intviewer-apis/using-reflection","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}