[Yanel-commits] rev 21987 -
public/yanel/trunk/src/core/java/org/wyona/yanel/core
michi at wyona.com
michi at wyona.com
Mon Jan 22 11:35:02 CET 2007
Author: michi
Date: 2007-01-22 11:35:00 +0100 (Mon, 22 Jan 2007)
New Revision: 21987
Added:
public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java
Log:
resource config started
Added: public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java 2007-01-22 10:31:16 UTC (rev 21986)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java 2007-01-22 10:35:00 UTC (rev 21987)
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2007 Wyona
+ *
+ * Licensed 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.wyona.org/licenses/APACHE-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 org.wyona.yanel.core;
+
+import java.io.BufferedReader;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Category;
+
+/**
+ * Abstraction of a resource configuration.
+ */
+public class ResourceConfiguration {
+
+ private Category log = Category.getInstance(ResourceConfiguration.class);
+
+ protected Map properties;
+ protected String universalName;
+
+ /**
+ *
+ */
+ public ResourceConfiguration(Reader reader) throws Exception {
+ BufferedReader br = new BufferedReader(reader);
+
+ this.universalName = br.readLine();
+ this.properties = new HashMap();
+
+ String property;
+ while ((property = br.readLine()) != null) {
+ int colonIndex = property.indexOf(":");
+ if (colonIndex > 0 && !property.trim().startsWith("#")) {
+ String name = property.substring(0, colonIndex).trim();
+ String value = property.substring(colonIndex + 1).trim();
+ this.properties.put(name, value);
+ }
+ }
+ }
+
+ /**
+ * Create a resource from scratch
+ */
+ public ResourceConfiguration(String universalName, Map properties) {
+ if (properties == null) {
+ this.properties = new HashMap();
+ } else {
+ this.properties = properties;
+ }
+ this.universalName = universalName;
+ }
+
+ /**
+ * Get universal name of resource type
+ */
+ public String getUniversalName() {
+ return universalName;
+ }
+
+ /**
+ * @param key
+ * @return value for this key or null if no value exists for this key.
+ */
+ public String getProperty(String key) {
+ return (String)properties.get(key);
+ }
+
+ /**
+ * Check if property exists
+ */
+ public boolean containsKey(String key) {
+ return properties.containsKey(key);
+ }
+}
More information about the Yanel-commits
mailing list