{"id":15793953,"url":"https://github.com/cedric05/easy-wrapper","last_synced_at":"2025-03-31T19:25:32.093Z","repository":{"id":110364917,"uuid":"217842025","full_name":"cedric05/easy-wrapper","owner":"cedric05","description":"java wrapper class around class for loaded class from different classloader","archived":false,"fork":false,"pushed_at":"2019-10-27T11:49:26.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-05T23:21:46.795Z","etag":null,"topics":["classloader-hell","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cedric05.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-27T11:01:04.000Z","updated_at":"2019-10-27T11:53:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c8daa8f-9194-491b-a3d0-1bab68f0422e","html_url":"https://github.com/cedric05/easy-wrapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedric05%2Feasy-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedric05%2Feasy-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedric05%2Feasy-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedric05%2Feasy-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cedric05","download_url":"https://codeload.github.com/cedric05/easy-wrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246525047,"owners_count":20791663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classloader-hell","java"],"created_at":"2024-10-04T23:21:49.385Z","updated_at":"2025-03-31T19:25:32.067Z","avatar_url":"https://github.com/cedric05.png","language":"Java","readme":"\n# Wrapper\n\nHaving to load class from different classloaders and invoking methods involves is tough job.\n\nHere we are using java's proxyInvocationHandler to loosen up things\n\nIn this example, it uses a seperate interface with having all the methods which user wants to invoke from other classloader.\n\nNow that we have Object and Wrapper Interface, This example creates Proxy object wrapping around target class Object using java's.\n\nwhen ever user wants to invoke method, Invocation Handler observes that and calls actual method. This logic has been used in lot more projects like spring. but here it is being used to load/simplify invocation from different classloaders.\n\n\n# For Example\n code like this\n ```java\n        try {\n            Class recClass = urlClassLoader.loadClass(\"Rectangle\");\n            Object obj = recClass.newInstance();\n            Method setLengthMethod = recClass.getMethod(\"setLength\", int.class);\n            Method setBreadthMethod = recClass.getMethod(\"setBreadth\", int.class);\n            setLengthMethod.invoke(obj, 3);\n            setBreadthMethod.invoke(obj, 4);\n            Method getArea = recClass.getMethod(\"getArea\");\n            Method getLengthMethod = recClass.getMethod(\"getLength\");\n            Method getBreadthMethod = recClass.getMethod(\"getBreadth\");\n            int area = (int) getArea.invoke(obj);\n            System.out.printf(\"area of rectangle with length %s bread %s is %s\\n\", getLengthMethod.invoke(obj),\n                    getBreadthMethod.invoke(obj), area);\n        } catch (InstantiationException ex) {\n            System.err.println(\"Not able to create Instance of Class\");\n        } catch (IllegalAccessException ex) {\n            System.err.println(\"Not able to access Class\");\n        } catch (ClassNotFoundException ex) {\n            System.err.println(\"Not able to find Class\");\n        } catch (IllegalArgumentException e) {\n            System.err.println(\"Illegal state, Arguments passed are of different types\");\n        } catch (InvocationTargetException e) {\n            System.err.println(\"Not able to invoke Class\");\n        } catch (NoSuchMethodException e) {\n            System.err.println(\"Not able find method\");\n            e.printStackTrace();\n        } catch (SecurityException e) {\n            System.err.println(\"Not able to invoke method\");\n        }\n\n ```\n\ncould be **simplified** to \n\n```java\n        Class appClass = urlClassLoader.loadClass(\"Rectangle\");\n        Object obj = appClass.newInstance();\n        Wrapper wrap = wrap(obj);\n        wrap.setLength(3);\n        wrap.setBreadth(4);\n        wrap.getArea();\n        System.out.printf(\"area of rectangle with length %s bread %s is %s\\n\", wrap.getLength(), wrap.getBreadth(),\n                wrap.getArea());\n```\nwith a [Wrapper Interface](src/main/java/Wrapper.java)\n\n\n\nTo run\n``` bash\ngradle run\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedric05%2Feasy-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedric05%2Feasy-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedric05%2Feasy-wrapper/lists"}