{ "info": { "author": "Ivan Korobkov", "author_email": "ivan.korobkov@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Code Generators", "Topic :: Software Development :: Compilers" ], "description": "Pdef Java\n=========\nJava code generator for [Pdef compiler](https://github.com/pdef/pdef)\nand Java implementation of descriptors, JSON format and HTTP RPC.\n\nRequirements\n------------\n- Java 6+.\n- Code generator: [Pdef compiler 1.2+](https://github.com/pdef/pdef), Python 2.6 or Python 3.3+.\n\nInstallation\n------------\n- Code generator:\n ```bash\n $ pip install pdef-java\n ```\n\n Or [download](https://github.com/pdef/pdef-java/releases) the release,\n unzip it and in the `generator` directory run:\n ```bash\n $ python setup.py install\n ```\n\n- Java package (maven):\n ```xml\n \n io.pdef\n pdef\n 1.2.0\n \n\n \n io.pdef\n pdef-servlet\n 1.2.0\n \n ```\n\nCode generation\n---------------\nPass a pdef package path or a url to the compiler:\n```bash\n$ pdefc generate-java https://raw.github.com/pdef/pdef/1.2/example/world.yaml \\\n --out target/generated-sources\n```\n\nThe generator uses absolute module names (`package.module`) as java package names.\nUse the `--module` argument to manually map pdef modules to java packages.\nAlso it is possible to add namespace class prefixes via the `--prefix` argument.\n```bash\n$ pdefc generate-java https://raw.github.com/pdef/pdef/1.2/example/world.yaml \\\n --prefix world:W \\\n --module world:com.mycompany.world \\\n --module world.space:com.mycompany.common \\\n --out target/generated-sources\n```\n\nMessages\n--------\nGenerated messages implement `equals`, `hashCode`, copy constructors, a `copy` method\nwhich returns a deep copy of a message, and merging methods. The messages are not thread-safe.\nThe examples are based on the [pdef example package](https://github.com/pdef/pdef/tree/1.1/example).\n\nMessages have a fluent interface.\n```java\nHuman human = new Human()\n .setId(1)\n .setName(\"John\")\n .setSex(Sex.MALE)\n .setContinent(ContinentName.ASIA)\n\nHuman copy0 = human.copy();\nHuman copy1 = new Human(human);\n\nassert human.equals(copy0);\nassert human.equals(copy1);\n```\n\nMessages support merging which deep copies set fields from a source message to destination one:\n```\nHuman human = new Human()\n .setId(1)\n .setName(\"John\")\n .setSex(Sex.MALE)\n .setContinent(ContinentName.ASIA)\n\nHuman another = new Human();\nanother.merge(human);\n\nassert another.getName().equals(human.getName());\n```\n\nMessages try to be null-safe and return default values for null fields.\nIf a null field is a collection or a message then it is initialized to an empty\nobject on the first access.\n```java\n// All getters return the default values when the fields are not present or null.\nHuman human = new Human();\nassert human.getId() == 0;\nassert human.getName().equals(\"\");\n\n// Special methods allow to check if the field is present.\nassert human.hasId() == false;\nassert human.hasName() == false;\n\n// Collection and message getters initialize null fields to empty objects.\nContinent continent = new Continent();\nassert continent.hasHumans() == false;\n\n// The collection is initialized to an empty one.\ncontinent.getHumans().add(human);\nassert continent.getHumans().equals(Arrays.asList(human));\nassert continent.hasHumans();\n\n// Clear fields.\ncontinent.clearName().clearHumans();\n```\n\nJSON Format\n-----------\nJSON serialization is based on the [Jackson parser](https://github.com/FasterXML/jackson-core)\n(not the data binding package):\n```java\n// To a JSON-compatible map.\nMap map = human.toMap();\n\n// To JSON string.\nString json = human.toJson();\n\n// To pretty-printed JSON string.\njson = human.toJson(true);\n\n// Write to an output stream.\nOutputStream stream = getOutput();\nhuman.toJson(stream, true); // indent=true/false.\n\n// Write to a print writer.\nPrintWriter writer = getWriter();\nhuman.toJson(writer, true);\n```\n\nParsing:\n```java\n// From a JSON compatible map (only JSON primitives and collections).\nMap map = new HashMap<>;\nmap.put(\"name\", \"John\");\nmap.put(\"birthday\", \"2012-01-01T01:12:33Z\");\nmap.put(\"sex\", \"male\");\n\nHuman human0 = Human.fromMap(map);\nassert human0.getName().equals(\"John\");\n\n// From a JSON-string:\nString json = getJson();\nHuman human1 = Human.fromJson(json);\n\n// Merging for parsing input streams and readers.\n```\n\nUse `JsonFormat` to read/write other pdef data types:\n```java\n// Convert an int to a JSON string.\nString json = JsonFormat.write(Descriptors.int32, 123);\n\n// Write a list of integers to an output stream.\nOutputStream output = getOutput();\nListDescriptor listDescriptor = Descriptors.list(Descriptors.int32);\nJsonFormat.write(output, listDescriptor, Arrays.asList(1, 2, 3));\n\n// Read a message from an input stream.\nInputStream input = getInput();\nHuman human = JsonFormat.read(Human.DESCRIPTOR, input);\n```\n\nHTTP RPC Client\n---------------\nClient and server implementations are thread-safe.\n\nCreate an HTTP RPC client based on the `HttpUrlConnection`.\n```java\nRpcClient client = new RpcClient(World.DESCRIPTOR, \"http://example.com/world/\");\nWorld world = client.proxy();\n\n// Execute a remote method.\nList humans = world.humans().all(10, 0); // limit=10, offset=0.\n\n// Execute a void remote method.\nworld.switchDayNight();\n```\n\nNull primitive results are automatically converted into default values.\n```java\n// It is null-safe to write:\nint result = calculator.sum(1, 2);\n```\n\nCreate an RPC client with a custom `RpcSession`:\n```\nRpcSession session = createCustomSession();\nRpcClient client = new RpcClient(World.DESCRIPTOR, session);\nWorld world = client.proxy();\n```\n\nFull client example:\n```\nRpcSession session = new HttpUrlConnectionRpcSession(\"http://example.com/world/\");\nRpcClient client = new RpcClient(World.DESCRIPTOR, session);\nInvoker invoker = client;\nWorld world = InvocationProxy.create(World.DESCRIPTOR, invoker);\n```\nTo add custom headers or other HTTP logic subclass `HttpUrlConnectionRpcSession`,\nor implement a custom `RpcSession`.\n\n\nHTTP RPC Server\n---------------\nCreate an HTTP RPC handler:\n```java\nWorld world = getWorldImplementation();\nRpcHandler handler = new RpcHandler(World.DESCRIPTOR, world);\nRpcServlet servlet = new RpcServlet(handler);\n// Pass the servlet to your servlet container,\n// or wrap in another servlet as a delegate.\n```\n\nUse a custom provider when you need to get a fresh service instance for each request:\n```java\nProvider provider = getWorldProvider();\nRpcHandler handler = new RpcHandler(World.DESCRIPTOR, provider);\n```\n\nPrimitive null arguments are automatically converted into the default values.\n```\nclass MyHumans implements Humans {\n public List all(int limit, int offset) {\n // Null limit and offset are set to 0.\n return null;\n }\n}\n```\n\nWrap an `RpcServlet` in another servlet as a delegate to add custom headers and custom HTTP\nlogic (authentication, rate-limiting, etc).\n\n`RpcHandler` takes a simple bean-like `RpcRequest` and returns an `RpcResult` which\nallows to use it with custom HTTP transports such as Netty.\n\n\nLicense and Copyright\n---------------------\nCopyright: 2013 Ivan Korobkov \n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at:\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/pdef/pdef-java", "keywords": null, "license": "Apache License 2.0", "maintainer": null, "maintainer_email": null, "name": "pdef-java", "package_url": "https://pypi.org/project/pdef-java/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pdef-java/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/pdef/pdef-java" }, "release_url": "https://pypi.org/project/pdef-java/1.2.0/", "requires_dist": null, "requires_python": null, "summary": "Pdef java generator", "version": "1.2.0" }, "last_serial": 996963, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "22c4bc5fd823a96285dae34f9babcd58", "sha256": "7d52b0e4a3aebcffd7b4488c469d44a3b140e61da335a28d7372aa271bbdcf33" }, "downloads": -1, "filename": "pdef-java-1.0.0.tar.gz", "has_sig": false, "md5_digest": "22c4bc5fd823a96285dae34f9babcd58", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13346, "upload_time": "2013-12-18T14:11:08", "url": "https://files.pythonhosted.org/packages/d1/50/1c7aae9edf829b59ea86c5c8e4b6cb17c5e3fd89e07e922ce66bca28b556/pdef-java-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "16b0793c77f2a66166c9b215cc019fee", "sha256": "b59f8a42721b94028363b611fde49ab3a24fb7921795db3fa4b9dd2519cdd393" }, "downloads": -1, "filename": "pdef-java-1.1.0.tar.gz", "has_sig": false, "md5_digest": "16b0793c77f2a66166c9b215cc019fee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13566, "upload_time": "2013-12-22T16:07:46", "url": "https://files.pythonhosted.org/packages/94/8c/590fc7ac7dd91e28b85dc0000cf49fa933917ac00100b2ce2b687c42880f/pdef-java-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "22599ce1a35cfbca3f692a643a077e26", "sha256": "61fc4f85bd396b077199e4319ea22e0b76198633564d783c9579d0dfaf2508e1" }, "downloads": -1, "filename": "pdef-java-1.1.1.tar.gz", "has_sig": false, "md5_digest": "22599ce1a35cfbca3f692a643a077e26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13591, "upload_time": "2014-01-14T11:39:14", "url": "https://files.pythonhosted.org/packages/c7/20/3d89bfa73bc0835d61415ec4e1978db25ca9d92a38341de3d3704bbec508/pdef-java-1.1.1.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "6b4694405113b4833260b337705b6a91", "sha256": "9ac9b689f2c7b75fddd5d3df30abf61214a025dc6cfa942490dd7d702bc453f2" }, "downloads": -1, "filename": "pdef-java-1.2.0.tar.gz", "has_sig": false, "md5_digest": "6b4694405113b4833260b337705b6a91", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13631, "upload_time": "2014-02-11T10:26:35", "url": "https://files.pythonhosted.org/packages/12/0c/cddb1581f2fced05fbb222bbfa3dd2c141a187b4b4dc96153b32888d92f2/pdef-java-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6b4694405113b4833260b337705b6a91", "sha256": "9ac9b689f2c7b75fddd5d3df30abf61214a025dc6cfa942490dd7d702bc453f2" }, "downloads": -1, "filename": "pdef-java-1.2.0.tar.gz", "has_sig": false, "md5_digest": "6b4694405113b4833260b337705b6a91", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13631, "upload_time": "2014-02-11T10:26:35", "url": "https://files.pythonhosted.org/packages/12/0c/cddb1581f2fced05fbb222bbfa3dd2c141a187b4b4dc96153b32888d92f2/pdef-java-1.2.0.tar.gz" } ] }