-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.glassfish.javaeetutorial</groupId> | ||
<artifactId>osgi</artifactId> | ||
<version>7.0.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>catalog-commands</artifactId> | ||
<name>Sample catalog commands for gogo shell</name> | ||
<packaging>bundle</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.javaeetutorial</groupId> | ||
<artifactId>catalog-service</artifactId> | ||
<version>7.0.6-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>2.5.3</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>bundle</goal> | ||
</goals> | ||
<configuration> | ||
<instructions> | ||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> | ||
<Bundle-Version>${project.version}</Bundle-Version> | ||
<Export-Package>com.forest.osgi.command*</Export-Package> | ||
<Import-Package>*</Import-Package> | ||
<_dsannotations>*</_dsannotations> | ||
</instructions> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
53 changes: 53 additions & 0 deletions
53
osgi/catalog-commands/src/main/java/com/forest/osgi/command/ProductCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.forest.osgi.command; | ||
|
||
import java.util.List; | ||
|
||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
import com.forest.model.Product; | ||
import com.forest.usecase.catalog.ProductManager; | ||
|
||
@Component( | ||
immediate=true, | ||
service = Object.class, | ||
property = { | ||
"osgi.command.function=list", | ||
"osgi.command.function=add", | ||
"osgi.command.scope=product" | ||
}) | ||
public class ProductCommands { | ||
|
||
/* | ||
* As this is only simple DEMO we are going to only implement commands for | ||
* listing and adding products! | ||
*/ | ||
|
||
ProductManager productManager; | ||
|
||
@Reference | ||
void bindProductManager (ProductManager productManager) { | ||
this.productManager = productManager; | ||
} | ||
|
||
void unbindProductManager (ProductManager productManager) { | ||
this.productManager = null; | ||
} | ||
|
||
public void add(String name, String description, double price) { | ||
Product product = new Product(); | ||
product.setName(name); | ||
product.setPrice(price); | ||
product.setDescription(description); | ||
productManager.createProduct(product); | ||
System.out.println("Product saved!"); | ||
} | ||
|
||
public void list() { | ||
List<Product> products = productManager.getAll(); | ||
System.out.format("%-15s | %-10s | %-40s\n", "NAME", "PRICE", "DESCRIPTION"); | ||
for (Product product : products) { | ||
System.out.format("%-15s | %10.2f | %-40s\n", product.getName(), product.getPrice(), product.getDescription()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ | |
|
||
<modules> | ||
<module>catalog-service</module> | ||
<module>catalog-commands</module> | ||
</modules> | ||
</project> |