Author: jbonofre Date: Thu Nov 17 16:18:11 2011 New Revision: 1203239 URL: http://svn.apache.org/viewvc?rev=1203239&view=rev Log: Add console configuration model and digester
Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/KalumetConsole.java incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/Property.java Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/KalumetConsole.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/KalumetConsole.java?rev=1203239&view=auto ============================================================================== --- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/KalumetConsole.java (added) +++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/KalumetConsole.java Thu Nov 17 16:18:11 2011 @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 org.apache.kalumet.console.configuration.model; + +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.digester.Digester; + +/** + * Represents the <code>kalumet-console</code> root tag of the + * Kalumet Console configuration. + */ +public class KalumetConsole { + + private LinkedList properties; + + public KalumetConsole() { + this.properties = new LinkedList(); + } + + /** + * Add a new property. + * + * @param property the <code>Property</code> to add. + */ + public void addProperty(Property property) throws Exception { + if(this.getProperty(property.getName()) != null) { + throw new IllegalArgumentException("The property name " + property.getName() + " already exists in the console configuration"); + } + this.properties.add(property); + } + + /** + * Return the property list. + * + * @return the <code>Property</code> list. + */ + public List getProperties() { + return this.properties; + } + + /** + * Return the property identified by a given name. + * + * @param name the property name. + * @return the <code>Property</code> found or null if no <code>Property</code> found. + */ + public Property getProperty(String name) { + for(Iterator propertyIterator = this.getProperties().iterator(); propertyIterator.hasNext();) { + Property property = (Property) propertyIterator.next(); + if(property.getName().equals(name)) { + return property; + } + } + return null; + } + + /** + * Digest the Kalumet Console configuration. + * + * @param path the Kalumet Console location. + * @return the Kalumet Console configuration object. + */ + public static KalumetConsole digeste(String path) throws Exception { + KalumetConsole kalumetConsole = null; + try { + Digester digester = new Digester(); + digester.setValidating(false); + digester.addObjectCreate("kalumet-console", "org.apache.kalumet.console.configuration.model.KalumetConsole"); + + digester.addObjectCreate("kalumet-console/property", "org.apahce.kalumet.console.configuration.model.Property"); + digester.addSetProperties("kalumet-console/property"); + + digester.addSetNext("kalumet-console/property", "addProperty", "org.apache.kalumet.console.configuration.model.Property"); + + kalumetConsole = (KalumetConsole) digester.parse(path); + } catch (Exception e) { + throw new IOException("Can't read the Kalumet Console configuration", e); + } + return kalumetConsole; + } + +} Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/Property.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/Property.java?rev=1203239&view=auto ============================================================================== --- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/Property.java (added) +++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/model/Property.java Thu Nov 17 16:18:11 2011 @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 org.apache.kalumet.console.configuration.model; + +/** + * Represents the <code>property</code> tag in the WebAutoDeploy-config.xml + * configuration file. + */ +public class Property { + + private String name; + private String value; + + public Property() { + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + +}