Skip to content

Commit

Permalink
Merge pull request #400 from gastaldi/FORGE-1651
Browse files Browse the repository at this point in the history
FORGE-1651: Created parser-json addon
  • Loading branch information
gastaldi committed Mar 8, 2014
2 parents a241e59 + ddb4a2b commit bcbb9af
Show file tree
Hide file tree
Showing 17 changed files with 652 additions and 0 deletions.
53 changes: 53 additions & 0 deletions parser-json/README.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
== parser-json
:idprefix: id_
This addon provides *standalone* functionality, and *exports services* for use in other addons.
It enables usage of JSR 353 - Java API for Json Processing in your addons

=== Depends on
[options="header"]
|===
|Addon |Exported |Optional
|resources
|yes
|yes

|simple
|yes
|no

|===

== Setup
This Addon requires the following installation steps.
=== Add configuration to pom.xml
To use this addon, you must add it as a dependency in the *pom.xml* of your `forge-addon` classified artifact:
(Make sure the dependency is put all the way to the left, and uses 3 spaces for indentation of GAV)
[source,xml]
----
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json</artifactId>
<classifier>forge-addon</classifier>
<version>${version}</version>
</dependency>
----
== Features
JsonResource for Json files::
Allows easy manipulation of json data
+
[source,java]
----
@Inject private ResourceFactory factory;
JsonResource resource = factory.createResource(new File("abc.json")).reify(JsonResource.class);
javax.json.JsonObject model = resource.getJsonObject();
....
JsonArray array = ...;
resource.setContents(array);
or
JsonObject obj = ...;
resource.setContents(obj);
----
67 changes: 67 additions & 0 deletions parser-json/addon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json-parent</artifactId>
<version>2.1.2-SNAPSHOT</version>
</parent>
<artifactId>parser-json</artifactId>
<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace.container</groupId>
<artifactId>simple</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>resources</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json-impl</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-dot</id>
<phase>prepare-package</phase>
<goals>
<goal>generate-dot</goal>
</goals>
<configuration>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>create-forge-addon</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>forge-addon</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package org.jboss.forge.addon.parser.json;
21 changes: 21 additions & 0 deletions parser-json/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json-parent</artifactId>
<version>2.1.2-SNAPSHOT</version>
</parent>
<artifactId>parser-json-api</artifactId>
<dependencies>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>resources</artifactId>
<classifier>forge-addon</classifier>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package org.jboss.forge.addon.parser.json;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.parser.json.resource;

import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonStructure;

import org.jboss.forge.addon.resource.FileResource;
import org.jboss.forge.addon.resource.Resource;

/**
* A {@link Resource} that represents a {@link JsonObject}
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface JsonResource extends FileResource<JsonResource>
{
/**
* Returns a JSON array or object that is represented in the input source
*
* Use this method if you are unsure of the json data format
*/
JsonStructure getJsonStructure();

/**
* Return the {@link JsonArray} representing the underlying Json data
*/
JsonArray getJsonArray();

/**
* Return the {@link JsonObject} representing the underlying Json data
*/
JsonObject getJsonObject();

/**
* Sets the content to this {@link JsonStructure} (could be an array or object)
*/
JsonResource setContents(JsonStructure structure);

}
2 changes: 2 additions & 0 deletions parser-json/api/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bean-discovery-mode="all" version="1.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"/>
27 changes: 27 additions & 0 deletions parser-json/impl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json-parent</artifactId>
<version>2.1.2-SNAPSHOT</version>
</parent>
<artifactId>parser-json-impl</artifactId>
<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace.container</groupId>
<artifactId>simple</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-json-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package org.jboss.forge.addon.parser.json;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jboss.forge.addon.parser.json.resource;

import java.io.File;

import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.resource.ResourceGenerator;
import org.jboss.forge.furnace.container.simple.Service;

public class JsonResourceGenerator implements ResourceGenerator<JsonResource, File>, Service
{
@Override
public boolean handles(Class<?> type, Object resource)
{
if (resource instanceof File && ((File) resource).getName().endsWith(".json"))
{
return true;
}
return false;
}

@Override
@SuppressWarnings("unchecked")
public <T extends Resource<File>> T getResource(ResourceFactory factory, Class<JsonResource> type, File resource)
{
return (T) new JsonResourceImpl(factory, resource);
}

@Override
public <T extends Resource<File>> Class<?> getResourceType(ResourceFactory factory, Class<JsonResource> type,
File resource)
{
return JsonResource.class;
}
}

0 comments on commit bcbb9af

Please sign in to comment.