killbill-uncached
Changes
catalog/pom.xml 6(+6 -0)
Details
diff --git a/api/src/main/java/com/ning/billing/catalog/api/ICatlogService.java b/api/src/main/java/com/ning/billing/catalog/api/ICatlogService.java
new file mode 100644
index 0000000..e8dca55
--- /dev/null
+++ b/api/src/main/java/com/ning/billing/catalog/api/ICatlogService.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog.api;
+
+import com.ning.billing.lifecycle.IService;
+
+public interface ICatlogService extends IService {
+
+ public abstract ICatalog getCatalog();
+
+}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/config/ICatalogConfig.java b/api/src/main/java/com/ning/billing/config/ICatalogConfig.java
new file mode 100644
index 0000000..88fbefb
--- /dev/null
+++ b/api/src/main/java/com/ning/billing/config/ICatalogConfig.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.config;
+
+import org.skife.config.Config;
+
+public interface ICatalogConfig extends IKillbillConfig {
+
+ @Config("killbill.catalog.uri")
+ String getCatalogURI();
+
+}
diff --git a/api/src/main/java/com/ning/billing/config/IKillbillConfig.java b/api/src/main/java/com/ning/billing/config/IKillbillConfig.java
index 51207fa..d08947f 100644
--- a/api/src/main/java/com/ning/billing/config/IKillbillConfig.java
+++ b/api/src/main/java/com/ning/billing/config/IKillbillConfig.java
@@ -16,6 +16,7 @@
package com.ning.billing.config;
+
public interface IKillbillConfig {
}
catalog/pom.xml 6(+6 -0)
diff --git a/catalog/pom.xml b/catalog/pom.xml
index bc477d7..1bc4a58 100644
--- a/catalog/pom.xml
+++ b/catalog/pom.xml
@@ -33,7 +33,13 @@
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
+
<build>
<plugins>
<plugin>
diff --git a/catalog/src/main/java/com/ning/billing/catalog/CatalogService.java b/catalog/src/main/java/com/ning/billing/catalog/CatalogService.java
new file mode 100644
index 0000000..38f07ce
--- /dev/null
+++ b/catalog/src/main/java/com/ning/billing/catalog/CatalogService.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog;
+
+import java.net.URI;
+
+import com.google.inject.Provider;
+import com.ning.billing.catalog.api.ICatalog;
+import com.ning.billing.catalog.api.ICatlogService;
+import com.ning.billing.catalog.io.CatalogLoader;
+import com.ning.billing.config.IBusinessConfig;
+import com.ning.billing.config.ICatalogConfig;
+import com.ning.billing.config.IKillbillConfig;
+import com.ning.billing.lifecycle.IService;
+
+
+public class CatalogService implements IService, Provider<ICatalog>, ICatlogService {
+
+ private static ICatalog catalog;
+
+ @Override
+ public void initialize(IBusinessConfig businessConfig,
+ IKillbillConfig killbillConfig) throws ServiceException {
+ if(killbillConfig instanceof ICatalogConfig) {
+ ICatalogConfig catalogConfig = (ICatalogConfig) killbillConfig;
+ try {
+ catalog = CatalogLoader.getCatalogFromURI(new URI(catalogConfig.getCatalogURI()));
+ } catch (Exception e) {
+ throw new ServiceException(e);
+ }
+ } else {
+ throw new ServiceException("Configuration does not include catalog configuration.");
+ }
+ }
+
+ @Override
+ public void start() throws ServiceException {
+ // Intentionally blank
+
+ }
+
+ @Override
+ public void stop() throws ServiceException {
+ // Intentionally blank
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.ning.billing.catalog.ICatlogService#getCatalog()
+ */
+ @Override
+ public ICatalog getCatalog() {
+ return catalog;
+ }
+
+
+ // Should be able to use bind(ICatalog.class).toProvider(CatalogService.class);
+ @Override
+ public ICatalog get() {
+ return catalog;
+ }
+}