Skip to content

Commit

Permalink
Catalog OSGi shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
azzazzel committed Mar 15, 2015
1 parent 8c9cdf3 commit 731c61b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions osgi/catalog-commands/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
49 changes: 49 additions & 0 deletions osgi/catalog-commands/pom.xml
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>
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());
}
}
}
1 change: 1 addition & 0 deletions osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@

<modules>
<module>catalog-service</module>
<module>catalog-commands</module>
</modules>
</project>

0 comments on commit 731c61b

Please sign in to comment.