Permalink
Browse files

Added API, CLI, basic impl and Vaadin GUI

  • Loading branch information...
1 parent d36062a commit 919f529d91a4d74f51dbe6778b3000c0f366bcf3 @njbartlett njbartlett committed Sep 1, 2011
Showing with 2,041 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +7 −0 org.example.auction.basic.test/.classpath
  3. +23 −0 org.example.auction.basic.test/.project
  4. +12 −0 org.example.auction.basic.test/.settings/org.eclipse.jdt.core.prefs
  5. +9 −0 org.example.auction.basic.test/base-test.bndrun
  6. +19 −0 org.example.auction.basic.test/bnd.bnd
  7. +4 −0 org.example.auction.basic.test/build.xml
  8. +2 −0 org.example.auction.basic.test/example.csv
  9. +77 −0 org.example.auction.basic.test/src/org/example/tests/ExampleTest.java
  10. +12 −0 org.example.auction.basic.test/test1.bndrun
  11. +5 −0 org.example.auction.basic.test/test2.bndrun
  12. +8 −0 org.example.auction.basic/.classpath
  13. +23 −0 org.example.auction.basic/.project
  14. +12 −0 org.example.auction.basic/.settings/org.eclipse.jdt.core.prefs
  15. +24 −0 org.example.auction.basic/bnd.bnd
  16. +4 −0 org.example.auction.basic/build.xml
  17. BIN org.example.auction.basic/commons-csv-20070730.jar
  18. +2 −0 org.example.auction.basic/example.csv
  19. +1 −0 org.example.auction.basic/example2.csv
  20. +1 −0 org.example.auction.basic/load/org.example.auction.cli.AuctionCommand.cfg
  21. +59 −0 org.example.auction.basic/src/org/example/auction/basic/ExampleComponent.java
  22. +18 −0 org.example.auction.basic/test/org/example/auction/basic/ExampleComponentTest.java
  23. +8 −0 org.example.auction.cli/.classpath
  24. +23 −0 org.example.auction.cli/.project
  25. +12 −0 org.example.auction.cli/.settings/org.eclipse.jdt.core.prefs
  26. +14 −0 org.example.auction.cli/bnd.bnd
  27. +4 −0 org.example.auction.cli/build.xml
  28. +76 −0 org.example.auction.cli/src/org/example/auction/cli/AuctionCommand.java
  29. +10 −0 org.example.auction.cli/test/org/example/ExampleComponentTest.java
  30. +8 −0 org.example.auction.gui/.classpath
  31. +23 −0 org.example.auction.gui/.project
  32. +81 −0 org.example.auction.gui/.settings/org.eclipse.jdt.core.prefs
  33. +7 −0 org.example.auction.gui/app.bnd
  34. +28 −0 org.example.auction.gui/bnd.bnd
  35. +4 −0 org.example.auction.gui/build.xml
  36. +2 −0 org.example.auction.gui/buy.bnd
  37. +2 −0 org.example.auction.gui/example.csv
  38. +1 −0 org.example.auction.gui/example2.csv
  39. BIN org.example.auction.gui/images/banner.png
  40. BIN org.example.auction.gui/images/welcome.jpg
  41. +2 −0 org.example.auction.gui/sell.bnd
  42. BIN org.example.auction.gui/src/org/.DS_Store
  43. BIN org.example.auction.gui/src/org/example/.DS_Store
  44. BIN org.example.auction.gui/src/org/example/auction/.DS_Store
  45. +171 −0 org.example.auction.gui/src/org/example/auction/ui/buy/BuyPanel.java
  46. +132 −0 org.example.auction.gui/src/org/example/auction/ui/sell/SellButton.java
  47. +9 −0 org.example.auction.gui/src/org/example/trader/gui/api/UriFragmentHandler.java
  48. +6 −0 org.example.auction.gui/src/org/example/trader/gui/api/UriFragmentService.java
  49. +1 −0 org.example.auction.gui/src/org/example/trader/gui/api/packageinfo
  50. +133 −0 org.example.auction.gui/src/org/example/trader/gui/app/TraderApplication.java
  51. +14 −0 org.example.auction.gui/src/org/example/trader/gui/app/WelcomePanel.java
  52. +100 −0 org.example.auction.gui/src/org/example/trader/gui/tradetab/AuctionListPanel.java
  53. +37 −0 org.example.auction.gui/src/org/example/trader/gui/tradetab/CountColumnGenerator.java
  54. +212 −0 org.example.auction.gui/src/org/example/trader/gui/tradetab/TradeTab.java
  55. BIN org.example.auction.gui/src/org/example/utils/.DS_Store
  56. +97 −0 org.example.auction.gui/src/org/example/utils/gui/DynamicContainer.java
  57. +68 −0 org.example.auction.gui/src/org/example/utils/types/Pair.java
  58. +80 −0 org.example.auction.gui/src/org/example/utils/types/Triple.java
  59. BIN org.example.auction.gui/theme/buttons/add.png
  60. +42 −0 org.example.auction.gui/theme/styles.css
  61. +8 −0 org.example.auction/.classpath
  62. +23 −0 org.example.auction/.project
  63. +12 −0 org.example.auction/.settings/org.eclipse.jdt.core.prefs
  64. +1 −0 org.example.auction/api.bnd
  65. +11 −0 org.example.auction/bnd.bnd
  66. +4 −0 org.example.auction/build.xml
  67. BIN org.example.auction/src/org/.DS_Store
  68. BIN org.example.auction/src/org/example/.DS_Store
  69. BIN org.example.auction/src/org/example/auction/.DS_Store
  70. +24 −0 org.example.auction/src/org/example/auction/AuctionItem.java
  71. +30 −0 org.example.auction/src/org/example/auction/AuctionService.java
  72. +20 −0 org.example.auction/src/org/example/auction/Bid.java
  73. +12 −0 org.example.auction/src/org/example/auction/InvalidBidException.java
  74. +1 −0 org.example.auction/src/org/example/auction/packageinfo
  75. +72 −0 org.example.auction/src/org/example/auction/utils/impl/AuctionItemImpl.java
  76. +45 −0 org.example.auction/src/org/example/auction/utils/impl/AuctionServiceImpl.java
  77. +44 −0 org.example.auction/src/org/example/auction/utils/impl/BidImpl.java
View
@@ -0,0 +1,5 @@
+.metadata
+/cnf/cache/
+/*/generated/
+/*/bin/
+/*/bin_test/
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.example.auction.basic.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>bndtools.core.bndbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>bndtools.core.bndnature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Wed Aug 31 17:03:28 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,9 @@
+-runbundles:\
+ org.example.auction.basic.test;version=latest,\
+ org.mockito.mockito-all,\
+ org.example.auction.basic;version=latest,\
+ org.example.auction.api;version=latest,\
+ org.apache.felix.scr,\
+ osgi.cmpn,\
+ org.apache.felix.shell,\
+ org.apache.felix.shell.tui
@@ -0,0 +1,19 @@
+Test-Cases: ${classes;CONCRETE;EXTENDS;junit.framework.TestCase}
+Private-Package: org.example.tests
+-buildpath: osgi.core;version=[4.1','5),\
+ osgi.cmpn,\
+ junit.osgi,\
+ org.mockito.mockito-all,\
+ org.example.auction.api;version=latest
+-runvm: -ea
+-runfw: org.apache.felix.framework
+-runsystempackages: sun.reflect
+-runbundles:\
+ org.mockito.mockito-all,\
+ org.example.auction.basic;version=latest,\
+ org.example.auction.api;version=latest,\
+ org.apache.felix.scr,\
+ osgi.cmpn,\
+ org.apache.felix.shell,\
+ org.apache.felix.shell.tui
+
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="project" default="build">
+ <import file="../cnf/build.xml"/>
+</project>
@@ -0,0 +1,2 @@
+100,Widgets
+150,OSGi Book (second hand; barely read)
@@ -0,0 +1,77 @@
+package org.example.tests;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.example.auction.AuctionService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ExampleTest extends TestCase {
+
+ private final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+
+ public void testExample() throws Exception {
+ ServiceReference[] refs;
+
+ refs = context.getAllServiceReferences("org.example.auction.AuctionService", null);
+ assertNull(refs);
+
+ ServiceRegistration reg = context.registerService(Runnable.class.getName(), new Runnable() {
+ @Override
+ public void run() {
+ }
+ }, null);
+
+ refs = context.getAllServiceReferences("org.example.auction.AuctionService", null);
+ assertEquals(1, refs.length);
+
+ reg.unregister();
+ refs = context.getAllServiceReferences("org.example.auction.AuctionService", null);
+ assertNull(refs);
+
+
+ ServiceReference cfgAdmRef = context.getServiceReference(ConfigurationAdmin.class.getName());
+ ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(cfgAdmRef);
+ Configuration config = configAdmin.getConfiguration("org.example.auction.basic.ExampleComponent", null);
+ Properties props = new Properties();
+ props.put("fileName", "example2.csv");
+ config.update(props);
+
+ // sleeeeep
+
+ AuctionService auction = (AuctionService) context.getService(context.getServiceReference(AuctionService.class.getName()));
+ auction.listAuctionItems();
+ // ...
+
+ /*
+ assertNotNull(refs);
+ assertEquals(1, refs.length);
+
+ AuctionService auction = (AuctionService) context.getService(refs[0]);
+ assertEquals(2, auction.listAuctionItems().size());
+
+ Bundle bundle = findBundle("org.example.auction.basic");
+ bundle.stop();
+
+ refs = context.getAllServiceReferences("org.example.auction.AuctionService", null);
+ assertNull(refs);
+ */
+ }
+
+ private Bundle findBundle(String bsn) {
+ Bundle[] bundles = context.getBundles();
+ for (Bundle bundle : bundles) {
+ if (bsn.equals(bundle.getSymbolicName())) {
+ return bundle;
+ }
+ }
+ return null;
+ }
+}
@@ -0,0 +1,12 @@
+-runfw: org.apache.felix.framework
+-runvm: -ea
+-runsystempackages: sun.reflect
+-runbundles:\
+ org.example.auction.basic.test;version=latest,\
+ org.mockito.mockito-all,\
+ org.example.auction.basic;version=latest,\
+ org.example.auction.api;version=latest,\
+ org.apache.felix.scr,\
+ osgi.cmpn,\
+ org.apache.felix.shell,\
+ org.apache.felix.shell.tui
@@ -0,0 +1,5 @@
+-include: base-test.bndrun
+
+-runfw: org.eclipse.osgi
+-runvm: -ea
+-runsystempackages: sun.reflect
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="bin_test" path="test"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.example.auction.basic</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>bndtools.core.bndbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>bndtools.core.bndnature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Tue Aug 30 14:36:19 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,24 @@
+Private-Package: org.example.auction.basic,\
+ org.apache.commons.csv,\
+ org.example.auction.utils.impl,\
+ aQute.bnd.annotation.metatype
+-runfw: org.apache.felix.framework;version=3.2.2
+-runbundles: osgi.cmpn,\
+ org.apache.felix.scr,\
+ org.apache.felix.shell,\
+ org.apache.felix.shell.tui,\
+ org.example.auction.api;version=latest,\
+ org.example.auction.cli;version=latest,\
+ org.apache.felix.webconsole,\
+ org.apache.felix.http.jetty,\
+ org.apache.felix.log,\
+ org.apache.felix.fileinstall,\
+ org.apache.felix.configadmin,\
+ org.apache.felix.metatype
+Service-Component: *
+-buildpath: osgi.core,\
+ osgi.cmpn,\
+ biz.aQute.bnd.annotation,\
+ junit.osgi,\
+ org.example.auction;version=project,\
+ commons-csv-20070730.jar;version=file
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="project" default="build">
+ <import file="../cnf/build.xml"/>
+</project>
Binary file not shown.
@@ -0,0 +1,2 @@
+100,Widgets
+150,OSGi Book (second hand; barely read)
@@ -0,0 +1 @@
+15000,Gerd and Nils' Excellent Book
@@ -0,0 +1 @@
+target.auctionService=(client=chris)
@@ -0,0 +1,59 @@
+package org.example.auction.basic;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
+
+import org.apache.commons.csv.CSVParser;
+import org.example.auction.AuctionService;
+import org.example.auction.utils.impl.AuctionServiceImpl;
+
+import aQute.bnd.annotation.component.Activate;
+import aQute.bnd.annotation.component.Component;
+import aQute.bnd.annotation.component.ConfigurationPolicy;
+import aQute.bnd.annotation.component.Reference;
+import aQute.bnd.annotation.metatype.Configurable;
+import aQute.bnd.annotation.metatype.Meta;
+
+@Component(provide = AuctionService.class)
+public class ExampleComponent extends AuctionServiceImpl {
+
+ interface Config {
+ String label();
+ @Meta.AD(min = "100", max = "1000", description = "This is the timeout", deflt = "500")
+ int timeout();
+ File fileName();
+ FileType fileType();
+ }
+ enum FileType {
+ csv, xml;
+ }
+
+ @Activate
+ protected void activate(Map<String, Object> props) throws IOException {
+ System.out.println("Activated ExampleComponent");
+
+ Config config = Configurable.createConfigurable(Config.class, props);
+ File fileName = config.fileName();
+ if (fileName == null) fileName = new File("example.csv");
+ System.out.println("Configured filename: " + fileName);
+ FileReader reader = new FileReader(fileName);
+ CSVParser parser = new CSVParser(reader);
+
+ String[] line;
+ while ((line = parser.getLine()) != null) {
+ String priceStr = line[0];
+ String description = line[1];
+
+ addItem(description, new Date(), Long.parseLong(priceStr));
+ }
+ }
+
+ @Reference
+ public void setTask(Runnable task) {
+ System.out.println("Bound to a task");
+ }
+
+}
@@ -0,0 +1,18 @@
+package org.example.auction.basic;
+
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+public class ExampleComponentTest extends TestCase {
+
+ public void testExample() throws Exception {
+ ExampleComponent comp = new ExampleComponent();
+
+ HashMap<String, Object> config = new HashMap<String, Object>();
+ config.put("fileName", "example.csv");
+ comp.activate(config);
+
+ assertEquals(2, comp.listAuctionItems().size());
+ }
+}
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="bin_test" path="test"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.example.auction.cli</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>bndtools.core.bndbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>bndtools.core.bndnature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Tue Aug 30 15:48:05 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Oops, something went wrong.

0 comments on commit 919f529

Please sign in to comment.