From kalumet-commits-return-9-apmail-incubator-kalumet-commits-archive=incubator.apache.org@incubator.apache.org Sat Oct 22 13:10:45 2011 Return-Path: X-Original-To: apmail-incubator-kalumet-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-kalumet-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A3CB17FF2 for ; Sat, 22 Oct 2011 13:10:45 +0000 (UTC) Received: (qmail 18810 invoked by uid 500); 22 Oct 2011 13:10:45 -0000 Delivered-To: apmail-incubator-kalumet-commits-archive@incubator.apache.org Received: (qmail 18792 invoked by uid 500); 22 Oct 2011 13:10:45 -0000 Mailing-List: contact kalumet-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: kalumet-dev@incubator.apache.org Delivered-To: mailing list kalumet-commits@incubator.apache.org Received: (qmail 18785 invoked by uid 99); 22 Oct 2011 13:10:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Oct 2011 13:10:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Oct 2011 13:10:30 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 395EB2388AA9; Sat, 22 Oct 2011 13:10:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1187711 [4/5] - in /incubator/kalumet/trunk: ./ common/ common/src/ common/src/main/ common/src/main/java/ common/src/main/java/org/ common/src/main/java/org/apache/ common/src/main/java/org/apache/kalumet/ common/src/main/java/org/apache/... Date: Sat, 22 Oct 2011 13:10:04 -0000 To: kalumet-commits@incubator.apache.org From: jbonofre@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111022131007.395EB2388AA9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Kalumet.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Kalumet.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Kalumet.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Kalumet.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,765 @@ +/* + * 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.model; + +import java.io.FileOutputStream; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock; +import org.apache.kalumet.KalumetException; +import org.apache.kalumet.FileManipulator; + +import org.apache.commons.digester.Digester; +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.w3c.dom.Element; + +/** + * Represents the kalumet root tag in the main Kalumet DOM. + */ +public class Kalumet implements Serializable, Cloneable { + + private static final long serialVersionUID = -3237352886418250595L; + + private static WriterPreferenceReadWriteLock lock = new WriterPreferenceReadWriteLock(); + + private LinkedList properties; + private Security security; + private LinkedList agents; + private LinkedList environments; + + public Kalumet() { + this.properties = new LinkedList(); + this.security = new Security(); + this.agents = new LinkedList(); + this.environments = new LinkedList(); + } + + /** + * Adds a new Property in the Kalumet + * container. + * + * @param property the Property to add. + */ + public void addProperty(Property property) throws ModelObjectAlreadyExistsException { + if (this.getProperty(property.getName()) != null) { + throw new ModelObjectAlreadyExistsException("Property name already exists in Kalumet configuration."); + } + this.properties.add(property); + } + + /** + * Gets the Property list in the Kalumet + * container. + * + * @return the Property list. + */ + public List getProperties() { + return this.properties; + } + + /** + * Overwrites the Property list in the Kalumet + * container. + * + * @param properties the new Property list. + */ + public void setProperties(LinkedList properties) { + this.properties = properties; + } + + /** + * Get the Property identified by a given name in the + * Kalumet container. + * + * @param name the Property name. + * @return the found Property or null if no Property 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; + } + + /** + * Set the Security definition of the Kalumet + * container. + * + * @param security the Security definition. + */ + public void setSecurity(Security security) { + this.security = security; + } + + /** + * Get the Security definition of the Kalumet + * container. + * + * @return the Security definition. + */ + public Security getSecurity() { + return this.security; + } + + /** + * Add a new Agent in the Kalumet container. + * + * @param agent the Agent to add. + */ + public void addAgent(Agent agent) throws ModelObjectAlreadyExistsException { + if (this.getAgent(agent.getId()) != null) { + throw new ModelObjectAlreadyExistsException("Agent id already exists in Kalumet configuration."); + } + this.agents.add(agent); + } + + /** + * Overwrite the Agent list in the Kalumet + * container with a new list. + * + * @param agents the new Agent list. + */ + public void setAgents(LinkedList agents) { + this.agents = agents; + } + + /** + * Return the Agent list in the Kalumet + * container. + * + * @return the Agent list. + */ + public List getAgents() { + return this.agents; + } + + /** + * Get the Agent identified by a given id in the + * Kalumet container. + * + * @param id the Agent id. + * @return the found Agent or null if no Agent found. + */ + public Agent getAgent(String id) { + for (Iterator agentIterator = this.getAgents().iterator(); agentIterator.hasNext(); ) { + Agent agent = (Agent) agentIterator.next(); + if (agent.getId().equals(id)) { + return agent; + } + } + return null; + } + + /** + * Add a new Environment to the Kalumet + * container. + * + * @param environment the Environment to add. + */ + public void addEnvironment(Environment environment) throws ModelObjectAlreadyExistsException { + if (this.getEnvironment(environment.getName()) != null) { + throw new ModelObjectAlreadyExistsException("Environment name already exists in Kalumet configuration."); + } + this.environments.add(environment); + } + + /** + * Get the Environment list in the Kalumet + * container. + * + * @return the Environment list. + */ + public List getEnvironments() { + return this.environments; + } + + /** + * Overwrite the Environment list in the + * Kalumet container. + * + * @param environments the new Environment list. + */ + public void setEnvironments(LinkedList environments) { + this.environments = environments; + } + + /** + * Get the Environment identified by the given name in the + * Kalumet container. + * + * @param name the Environment name. + * @return the found Environment or null if no Environment found. + */ + public Environment getEnvironment(String name) { + for (Iterator environmentIterator = this.getEnvironments().iterator(); environmentIterator.hasNext();) { + Environment environment = (Environment) environmentIterator.next(); + if (environment.getName().equals(name)) { + return environment; + } + } + return null; + } + + /** + * Get the Environment map order by group. + * + * @return the groups/environments map. + */ + public Map getEnvironmentsByGroups() { + HashMap map = new HashMap(); + for (Iterator environmentIterator = environments.iterator(); environmentIterator.hasNext();) { + Environment current = (Environment) environmentIterator.next(); + if (!map.containsKey(current.getGroup())) { + map.put(current.getGroup(), new LinkedList()); + } + ((List) map.get(current.getGroup())).add(current); + } + return map; + } + + /** + * Get the Environment list for a given User id. + * + * @param userid the User id. + * @return the Environment list of the user. + */ + public List getUserEnvironments(String userid) { + LinkedList userEnvironments = new LinkedList(); + Security security = this.getSecurity(); + for (Iterator environmentIterator = this.getEnvironments().iterator(); environmentIterator.hasNext();) { + Environment environment = (Environment) environmentIterator.next(); + if (security.checkEnvironmentUserAccess(environment, userid, null)) { + userEnvironments.add(environment); + } + } + return userEnvironments; + } + + /** + * Get the Environment user map order by group. + * + * @param userid the User id. + * @return the groups/environments user map. + */ + public Map getUserEnvironmentsByGroups(String userid) { + HashMap map = new HashMap(); + for (Iterator userEnvironmentIterator = this.getUserEnvironments(userid).iterator(); userEnvironmentIterator.hasNext();) { + Environment environment = (Environment) userEnvironmentIterator.next(); + if (!map.containsKey(environment.getGroup())) { + map.put(environment.getGroup(), new LinkedList()); + } + ((List) map.get(environment.getGroup())).add(environment); + } + return map; + } + + /** + * Get the Environment list for a given Agent id. + * + * @param id the Agent id. + * @return the Environment list managed by the Agent. + */ + public List getEnvironmentsByAgent(String id) { + LinkedList list = new LinkedList(); + for (Iterator environmentIterator = this.getEnvironments().iterator(); environmentIterator.hasNext();) { + Environment current = (Environment) environmentIterator.next(); + if (current.getAgent().equals(id)) { + list.add(current); + } + } + return list; + } + + /** + * Digeste a given XML file and return the main kalumet root tag. + * + * @param path the Kalumet XML file to parse. + * @return the main Kalumet corresponding with the root tag. + */ + public static Kalumet digeste(String path) throws KalumetException { + if (!path.startsWith("http:") && !path.startsWith("HTTP:") && !path.startsWith("file:") && !path.startsWith("FILE:")) { + path = "file:" + path; + } + Kalumet kalumet = null; + try { + lock.readLock().acquire(); + + // init the digester with no validation on the XML file (no DTD) + Digester digester = new Digester(); + digester.setValidating(false); + + // kalumet tag rules + digester.addObjectCreate("kalumet", "org.apache.kalumet.model.Kalumet"); + digester.addSetProperties("kalumet"); + + // properties/property tag rules + digester.addObjectCreate("kalumet/properties/property", "org.apache.kalumet.model.Property"); + digester.addSetProperties("kalumet/properties/property"); + + // add property in the kalumet tag rule + digester.addSetNext("kalumet/properties/property", "addProperty", "org.apache.kalumet.model.Property"); + + // security tag rules + digester.addObjectCreate("kalumet/security", "org.apache.kalumet.model.Security"); + digester.addSetProperties("kalumet/security"); + + // user tag rules + digester.addObjectCreate("kalumet/security/users/user", "org.apache.kalumet.model.User"); + digester.addSetProperties("kalumet/security/users/user"); + + // add user to security tag rule + digester.addSetNext("kalumet/security/users/user", "addUser", "org.apache.kalumet.model.User"); + + // group tag rules + digester.addObjectCreate("kalumet/security/groups/group", "org.apache.kalumet.model.Group"); + digester.addSetProperties("kalumet/security/groups/group"); + + // user group tag rules + digester.addObjectCreate("kalumet/security/groups/group/users/user", "org.apache.kalumet.model.User"); + digester.addSetProperties("kalumet/security/groups/group/users/user"); + + // add user in group tag rule + digester.addSetNext("kalumet/security/groups/group/users/user", "addUser", "org.apache.kalumet.model.User"); + + // add group to security tag rule + digester.addSetNext("kalumet/security/groups/group", "addGroup", "org.apache.kalumet.model.Group"); + + // add security to kalumet tag rule + digester.addSetNext("kalumet/security", "setSecurity", "org.apache.kalumet.model.Security"); + + // agent tag rules + digester.addObjectCreate("kalumet/agents/agent", "org.apache.kalumet.model.Agent"); + digester.addSetProperties("kalumet/agents/agent"); + + // add agent to kalumet tag rule + digester.addSetNext("kalumet/agents/agent", "addAgent", "org.apache.kalumet.model.Agent"); + + // environment tag rules + digester.addObjectCreate("kalumet/environments/environment", "org.apache.kalumet.model.Environment"); + digester.addSetProperties("kalumet/environments/environment"); + + // variables tag rules + digester.addObjectCreate("kalumet/environments/environment/variables/variable", "org.apache.kalumet.model.Variable"); + digester.addSetProperties("kalumet/environments/environment/variables/variable"); + + // add variable to environment tag rule + digester.addSetNext("kalumet/environments/environment/variables/variable", "addVariable", "org.apache.kalumet.model.Variable"); + + // freefield tag rules + digester.addObjectCreate("kalumet/environments/environment/freefields/freefield", "org.apache.kalumet.model.FreeField"); + digester.addSetProperties("kalumet/environments/environment/freefields/freefield"); + // add freefield content + digester.addCallMethod("kalumet/environments/environment/freefields/freefield", "setContent", 0); + + // add freefield to environment tag rule + digester.addSetNext("kalumet/environments/environment/freefields/freefield", "addFreeField", "org.apache.kalumet.model.FreeField"); + + // access tag rules + digester.addObjectCreate("kalumet/environments/environment/accesses/access", "org.apache.kalumet.model.Access"); + digester.addSetProperties("kalumet/environments/environment/accesses/access"); + + // access properties rules + digester.addObjectCreate("kalumet/environments/environment/accesses/access/properties/property", "org.apache.kalumet.model.Property"); + digester.addSetProperties("kalumet/environments/environment/accesses/access/properties/property"); + + // add property in access tag rule + digester.addSetNext("kalumet/environments/environment/accesses/access/properties/property", "addProperty", "org.apache.kalumet.model.Property"); + + // add access to environment tag rule + digester.addSetNext("kalumet/environments/environment/accesses/access", "addAccess", "org.apache.kalumet.model.Access"); + + // environment notes and weblinks tag rules + digester.addCallMethod("kalumet/environments/environment/notes", "setNotes", 0); + digester.addCallMethod("kalumet/environments/environment/weblinks", "setWeblinks", 0); + + // applicationservers tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers", "org.apache.kalumet.model.ApplicationServers"); + digester.addSetProperties("kalumet/environments/environment/applicationservers"); + + // applicationserver tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver", "org.apache.kalumet.model.ApplicationServer"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver"); + + // applicationserver startupcommand and shutdowncommand tag rules + digester.addCallMethod("kalumet/environments/environment/applicationservers/applicationserver/startupcommand", "setStartupcommand", 0); + digester.addCallMethod("kalumet/environments/environment/applicationservers/applicationserver/shutdowncommand", "setShutdowncommand", 0); + + // connectionpool tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/connectionpools/connectionpool", "org.apache.kalumet.model.ConnectionPool"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/connectionpools/connectionpool"); + + // add connectionpool to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/connectionpools/connectionpool", "addConnectionPool", "org.apache.kalumet.model.ConnectionPool"); + + // datasource tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/datasources/datasource", "org.apache.kalumet.model.DataSource"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/datasources/datasource"); + + // add datasource to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/datasources/datasource", "addDataSource", "org.apache.kalumet.model.DataSource"); + + // jmsconnectionfactory tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/jmsconnectionfactories/jmsconnectionfactory", "org.apache.kalumet.model.JMSConnectionFactory"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/jmsconnectionfactories/jmsconnectionfactory"); + + // add jmsconnectionfactory to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/jmsconnectionfactories/jmsconnectionfactory", "addJMSConnectionFactory", "org.apache.kalumet.model.JMSConnectionFactory"); + + // jmsserver tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver", "org.apache.kalumet.model.JMSServer"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver"); + + // jmsqueue tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver/jmsqueues/jmsqueue", "org.apache.kalumet.model.JMSQueue"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver/jmsqueues/jmsqueue"); + + // add jmsqueue to jmsserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver/jmsqueues/jmsqueue", "addJMSQueue", "org.apache.kalumet.model.JMSQueue"); + + // jmstopic tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver/jmstopics/jmstopic", "org.apache.kalumet.model.JMSTopic"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver/jmstopics/jmstopic"); + + // add jmstopic to jmsserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver/jmstopics/jmstopic", "addJMSTopic", "org.apache.kalumet.model.JMSTopic"); + + // add jmsserver to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/jmsservers/jmsserver", "addJMSServer", "org.apache.kalumet.model.JMSServer"); + + // namespacebinding tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/namespacebindings/namespacebinding", "org.apache.kalumet.model.NameSpaceBinding"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/namespacebindings/namespacebinding"); + + // add namespacebinding to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/namespacebindings/namespacebinding", "addNameSpaceBinding", "org.apache.kalumet.model.NameSpaceBinding"); + + // sharedlibrary tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/sharedlibrairies/sharedlibrary", "org.apache.kalumet.model.SharedLibrary"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/sharedlibrairies/sharedlibrary"); + + // add sharedlibrary to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/sharedlibrairies/sharedlibrary", "addSharedLibrary", "org.apache.kalumet.model.SharedLibrary"); + + // application tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application", "org.apache.kalumet.model.Application"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application"); + + // archive tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/archives/archive", "org.apache.kalumet.model.Archive"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/archives/archive"); + + // add archive archive to application + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/archives/archive", "addArchive", "org.apache.kalumet.model.Archive"); + + // contentmanager tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/contentmanagers/contentmanager", "org.apache.kalumet.model.ContentManager"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/contentmanagers/contentmanager"); + + // contentmanager property tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/contentmanagers/contentmanager/properties/property", "org.apache.kalumet.model.Property"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/contentmanagers/contentmanager/properties/property"); + + // add property in contentmanager + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/contentmanagers/contentmanager/properties/property", "addProperty", "org.apache.kalumet.model.Property"); + + // add contentmanager to application + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/contentmanagers/contentmanager", "addContentManager", "org.apache.kalumet.model.ContentManager"); + + // configurationfile tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/configurationfiles/configurationfile", "org.apache.kalumet.model.ConfigurationFile"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/configurationfiles/configurationfile"); + + // mapping tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/configurationfiles/configurationfile/mappings/mapping", "org.apache.kalumet.model.Mapping"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/configurationfiles/configurationfile/mappings/mapping"); + + // add mapping to configurationfile + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/configurationfiles/configurationfile/mappings/mapping", "addMapping", "org.apache.kalumet.model.Mapping"); + + // add configurationfile to application + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/configurationfiles/configurationfile", "addConfigurationFile", + "org.apache.kalumet.model.ConfigurationFile"); + + // database tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database", "org.apache.kalumet.model.Database"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database"); + + // sqlscript tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database/sqlscripts/sqlscript", "org.apache.kalumet.model.SqlScript"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database/sqlscripts/sqlscript"); + + // sqlscript mapping tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database/sqlscripts/sqlscript/mappings/mapping", "org.apache.kalumet.model.Mapping"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database/sqlscripts/sqlscript/mappings/mapping"); + + // add mapping to sqlscript + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database/sqlscripts/sqlscript/mappings/mapping", "addMapping", + "org.apache.kalumet.model.Mapping"); + + // add sqlscript to database + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database/sqlscripts/sqlscript", "addSqlScript", "org.apache.kalumet.model.SqlScript"); + + // add database to application + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application/databases/database", "addDatabase", "org.apache.kalumet.model.Database"); + + // add application to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/applications/application", "addApplication", "org.apache.kalumet.model.Application"); + + // cache tag rules + digester.addObjectCreate("kalumet/environments/environment/applicationservers/applicationserver/caches/cache", "org.apache.kalumet.model.Cache"); + digester.addSetProperties("kalumet/environments/environment/applicationservers/applicationserver/caches/cache"); + + // add cache to applicationserver + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver/caches/cache", "addCache", "org.apache.kalumet.model.Cache"); + + // add applicationserver to applicationservers tag rule + digester.addSetNext("kalumet/environments/environment/applicationservers/applicationserver", "addApplicationServer", "org.apache.kalumet.model.ApplicationServer"); + + // add applicationservers to environment tag rule + digester.addSetNext("kalumet/environments/environment/applicationservers", "setApplicationServers", "org.apache.kalumet.model.ApplicationServers"); + + // logfile tag rules + digester.addObjectCreate("kalumet/environments/environment/logfiles/logfile", "org.apache.kalumet.model.LogFile"); + digester.addSetProperties("kalumet/environments/environment/logfiles/logfile"); + + // add logfile to environment tag rule + digester.addSetNext("kalumet/environments/environment/logfiles/logfile", "addLogFile", "org.apache.kalumet.model.LogFile"); + + // software tag rules + digester.addObjectCreate("kalumet/environments/environment/softwares/software", "org.apache.kalumet.model.Software"); + digester.addSetProperties("kalumet/environments/environment/softwares/software"); + + // software update plan command item + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/command", "org.apache.kalumet.model.Command"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/command"); + digester.addCallMethod("kalumet/environments/environment/softwares/software/updateplan/command", "setCommand", 0); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/command", "addCommand", "org.apache.kalumet.model.Command"); + + // software update plan location item + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/location", "org.apache.kalumet.model.Location"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/location"); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/location", "addLocation", "org.apache.kalumet.model.Location"); + + // software update plan configuration file item + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/configurationfile", "org.apache.kalumet.model.ConfigurationFile"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/configurationfile"); + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/configurationfile/mappings/mapping", "org.apache.kalumet.model.Mapping"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/configurationfile/mappings/mapping"); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/configurationfile/mappings/mapping", "addMapping", "org.apache.kalumet.model.Mapping"); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/configurationfile", "addConfigurationFile", "org.apache.kalumet.model.ConfigurationFile"); + + // software update plan database item + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/database", "org.apache.kalumet.model.Database"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/database"); + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/database/sqlscripts/sqlscript", "org.apache.kalumet.model.SqlScript"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/database/sqlscripts/sqlscript"); + digester.addObjectCreate("kalumet/environments/environment/softwares/software/updateplan/database/sqlscripts/sqlscript/mappings/mapping", "org.apache.kalumet.model.Mapping"); + digester.addSetProperties("kalumet/environments/environment/softwares/software/updateplan/database/sqlscripts/sqlscript/mappings/mapping"); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/database/sqlscripts/sqlscript/mappings/mapping", "addMapping", "org.apache.kalumet.model.Mapping"); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/database/sqlscripts/sqlscript", "addSqlScript", "org.apache.kalumet.model.SqlScript"); + digester.addSetNext("kalumet/environments/environment/softwares/software/updateplan/database", "addDatabase", "org.apache.kalumet.model.Database"); + + // add software to environment + digester.addSetNext("kalumet/environments/environment/softwares/software", "addSoftware", "org.apache.kalumet.model.Software"); + + // notifiers tag rules + digester.addObjectCreate("kalumet/environments/environment/notifiers", "org.apache.kalumet.model.Notifiers"); + digester.addSetProperties("kalumet/environments/environment/notifiers"); + + // email tag rules + digester.addObjectCreate("kalumet/environments/environment/notifiers/email", "org.apache.kalumet.model.Email"); + digester.addSetProperties("kalumet/environments/environment/notifiers/email"); + + // destination tag rules + digester.addObjectCreate("kalumet/environments/environment/notifiers/email/destinations/destination", "org.apache.kalumet.model.Destination"); + digester.addSetProperties("kalumet/environments/environment/notifiers/email/destinations/destination"); + + // add destination to email notifier + digester.addSetNext("kalumet/environments/environment/notifiers/email/destinations/destination", "addDestination", "org.apache.kalumet.model.Destination"); + + // add email to notifiers + digester.addSetNext("kalumet/environments/environment/notifiers/email", "addNotifier", "org.apache.kalumet.model.Email"); + + // add notifiers to environment + digester.addSetNext("kalumet/environments/environment/notifiers", "setNotifiers", "org.apache.kalumet.model.Notifiers"); + + // email publisher tag rules + digester.addObjectCreate("kalumet/environments/environment/publishers/email", "org.apache.kalumet.model.Email"); + digester.addSetProperties("kalumet/environments/environment/publishers/email"); + + // destination email publisher tag rules + digester.addObjectCreate("kalumet/environments/environment/publishers/email/destinations/destination", "org.apache.kalumet.model.Destination"); + digester.addSetProperties("kalumet/environments/environment/publishers/email/destinations/destination"); + + // add destination to email publisher + digester.addSetNext("kalumet/environments/environment/publishers/email/destinations/destination", "addDestination", "org.apache.kalumet.model.Destination"); + + // add email publisher to environment + digester.addSetNext("kalumet/environments/environment/publishers/email", "addPublisher", "org.apache.kalumet.model.Email"); + + // statistics tag rules + digester.addObjectCreate("kalumet/environments/environment/statistics", "org.apache.kalumet.model.Statistics"); + digester.addSetProperties("kalumet/environments/environment/statistics"); + + // add statistics to environment + digester.addSetNext("kalumet/environments/environment/statistics", "setStatistics", "org.apache.kalumet.model.Statistics"); + + // add environment to kalumet tag rule + digester.addSetNext("kalumet/environments/environment", "addEnvironment", "org.apache.kalumet.model.Environment"); + + // parse the XML file + kalumet = (Kalumet) digester.parse(path); + } + catch(Exception e) { + throw new KalumetException("Can't read Kalumet configuration.", e); + } finally { + lock.readLock().release(); + } + return kalumet; + } + + /** + * Transform the Kalumet POJO to a DOM Element. + * + * @param document the XML core document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "kalumet"); + // properties element + ElementImpl properties = new ElementImpl(document, "properties"); + // add property in properties container + for (Iterator propertyIterator = this.getProperties().iterator(); propertyIterator.hasNext();) { + Property property = (Property) propertyIterator.next(); + properties.appendChild(property.toDOMElement(document)); + } + // add properties in kalumet + element.appendChild(properties); + // add security in kalumet + element.appendChild(this.getSecurity().toDOMElement(document)); + // agents element + ElementImpl agents = new ElementImpl(document, "agents"); + // add agent in agents container + for (Iterator agentIterator = this.getAgents().iterator(); agentIterator.hasNext();) { + Agent agent = (Agent) agentIterator.next(); + agents.appendChild(agent.toDOMElement(document)); + } + // add agents in kalumet + element.appendChild(agents); + // environments element + ElementImpl environments = new ElementImpl(document, "environments"); + // add environment in environments container + for (Iterator environmentIterator = this.getEnvironments().iterator(); environmentIterator.hasNext();) { + Environment environment = (Environment) environmentIterator.next(); + environments.appendChild(environment.toDOMElement(document)); + } + // add environments in kalumet + element.appendChild(environments); + return element; + } + + /* + * (non-Javadoc) + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + Kalumet clone = new Kalumet(); + for (Iterator propertyIterator = this.properties.iterator(); propertyIterator.hasNext(); ) { + Property property = (Property)propertyIterator.next(); + clone.properties.add((Property)property.clone()); + } + clone.setSecurity((Security) this.getSecurity().clone()); + for (Iterator agentIterator = this.agents.iterator(); agentIterator.hasNext(); ) { + Agent agent = (Agent)agentIterator.next(); + clone.agents.add((Agent)agent.clone()); + } + for (Iterator environmentIterator = this.environments.iterator(); environmentIterator.hasNext(); ) { + Environment environment = (Environment)environmentIterator.next(); + clone.environments.add((Environment)environment.clone()); + } + return clone; + } + + /** + * Write a Kalumet XML file with the content of the in-memory + * configuration. + * + * @param path the path to the file to write. + * @param backup a flag indicated if a previous backup must be copied before writing. + */ + public synchronized void writeXMLFile(String path, boolean backup) throws KalumetException { + if (backup) { + this.backupXMLFile(path); + } + try { + lock.writeLock().acquire(); + OutputFormat format = new OutputFormat(); + format.setLineWidth(72); + format.setIndenting(true); + format.setIndent(3); + format.setEncoding("ISO-8859-1"); + if (path.startsWith("http:") || path.startsWith("http:")) { + throw new KalumetException("Can't write Kalumet XML file over a HTTP URL."); + } + if (path.startsWith("file:") || path.startsWith("FILE:")) { + path = path.substring(5); + } + XMLSerializer serializer = new XMLSerializer(new FileOutputStream(path), format); + serializer.serialize(this.toDOMElement(new CoreDocumentImpl(true))); + } + catch (Exception e) { + throw new KalumetException("Can't write Kalumet XML file.", e); + } finally { + lock.writeLock().release(); + } + } + + /** + * Write a Kalumet XML file with the content of the in-memory + * configuration. + * + * @param path the path to the file to write. + */ + public void writeXMLFile(String path) throws KalumetException { + this.writeXMLFile(path, false); + } + + /** + * Make a backup of the old Kalumet XML configuration to avoid file + * corruption (for example when disk full). + * + * @param path the path to the Kalumet XML file. + */ + public void backupXMLFile(String path) throws KalumetException { + FileManipulator fileManipulator = FileManipulator.getInstance(); + fileManipulator.copy(path, path + ".backup"); + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Location.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Location.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Location.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Location.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,129 @@ +/* + * 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.model; + +import java.io.Serializable; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * A location is a general wrapper for files and directories. + */ +public class Location implements Cloneable, Serializable, Comparable { + + private static final long serialVersionUID = 3632838715316673949L; + + private String name; + private boolean active; + private boolean blocker; + private String uri; + private String path; + private String agent; + + public Location() { } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isBlocker() { + return blocker; + } + + public void setBlocker(boolean blocker) { + this.blocker = blocker; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getPath() { + return path; + } + + public String getAgent() { + return agent; + } + + public void setAgent(String agent) { + this.agent = agent; + } + + public void setPath(String path) { + this.path = path; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + Location clone = new Location(); + clone.setActive(this.isActive()); + clone.setBlocker(this.isBlocker()); + clone.setName(this.getName()); + clone.setUri(this.getUri()); + clone.setPath(this.getPath()); + clone.setAgent(this.getAgent()); + return clone; + } + + /** + * Transform a location into a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + public Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "location"); + element.setAttribute("name", this.getName()); + element.setAttribute("active", new Boolean(this.isActive()).toString()); + element.setAttribute("blocker", new Boolean(this.isBlocker()).toString()); + element.setAttribute("uri", this.getUri()); + element.setAttribute("path", this.getPath()); + element.setAttribute("agent", this.getAgent()); + return element; + } + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object anotherLocation) { + return this.getName().compareTo(((Location)anotherLocation).getName()); + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/LogFile.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/LogFile.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/LogFile.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/LogFile.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,96 @@ +/* + * 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.model; + +import java.io.Serializable; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Define the access to a log file. + */ +public class LogFile implements Cloneable, Serializable, Comparable { + + private static final long serialVersionUID = -544824580684870083L; + + private String name; + private String path; + private String agent; + + public LogFile() {} + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getAgent() { + return agent; + } + + public void setAgent(String agent) { + this.agent = agent; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + LogFile logFile = new LogFile(); + logFile.setAgent(this.getAgent()); + logFile.setName(this.getName()); + logFile.setPath(this.getPath()); + return logFile; + } + + /** + * Transform a logfile into a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + public Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "logfile"); + element.setAttribute("name", this.getName()); + element.setAttribute("path", this.getPath()); + element.setAttribute("agent", this.getAgent()); + return element; + } + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object anotherLogFile) { + return this.getName().compareTo(((LogFile)anotherLogFile).getName()); + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Mapping.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Mapping.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Mapping.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Mapping.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,85 @@ +/* + * 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.model; + +import java.io.Serializable; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Represent the mapping tag in the Kalumet configuration DOM. + */ +public class Mapping implements Serializable, Cloneable, Comparable { + + private static final long serialVersionUID = 6313869273116904013L; + + private String key; + private String value; + + public Mapping() { } + + public String getKey() { + return this.key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + Mapping clone = new Mapping(); + clone.setKey(this.getKey()); + clone.setValue(this.getValue()); + return clone; + } + + /** + * Transform the Mapping POJO to a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "mapping"); + element.setAttribute("key", this.getKey()); + element.setAttribute("value", this.getValue()); + return element; + } + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object anotherMapping) { + return this.getKey().compareTo(((Mapping)anotherMapping).getKey()); + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/ModelObjectAlreadyExistsException.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/ModelObjectAlreadyExistsException.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/ModelObjectAlreadyExistsException.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/ModelObjectAlreadyExistsException.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,59 @@ +/* + * 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.model; + +import org.apache.kalumet.KalumetException; + +/** + * Exception class handler to manage when a model component already exists in + * the Kalumet configuration. + */ +public final class ModelObjectAlreadyExistsException extends KalumetException { + + private static final long serialVersionUID = -6461646659257275924L; + + /** + * Creates a ModelObjectAlreadyExistsException with an explanation message. + * + * @param message the explanation message. + */ + public ModelObjectAlreadyExistsException(String message) { + super(message); + } + + /** + * Creates a ModelObjectAlreadyExistsException with the underlying cause. + * + * @param cause the underlying cause. + */ + public ModelObjectAlreadyExistsException(Throwable cause) { + super(cause); + } + + /** + * Creates a ModelObjectAlreadyExistsException with an explanation message and the underlying cause. + * + * @param message the explanation message. + * @param cause the underlying cause. + */ + public ModelObjectAlreadyExistsException(String message, Throwable cause) { + super(message, cause); + } + +} Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/NameSpaceBinding.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/NameSpaceBinding.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/NameSpaceBinding.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/NameSpaceBinding.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,129 @@ +/* + * 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.model; + +import java.io.Serializable; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Represent the namespacebinding tag in the Kalumet configuration DOM. + */ +public class NameSpaceBinding implements Serializable, Cloneable, Comparable { + + private static final long serialVersionUID = -2336476111740231781L; + + private String name; + private String jndiname; + private String jndialias; + private String providerurl; + private boolean active; + private boolean blocker; + + public NameSpaceBinding() { } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getJndiname() { + return this.jndiname; + } + + public void setJndiname(String jndiname) { + this.jndiname = jndiname; + } + + public String getJndialias() { + return this.jndialias; + } + + public void setJndialias(String jndialias) { + this.jndialias = jndialias; + } + + public String getProviderurl() { + return this.providerurl; + } + + public void setProviderurl(String providerurl) { + this.providerurl = providerurl; + } + + public boolean isActive() { + return this.active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isBlocker() { + return this.blocker; + } + + public void setBlocker(boolean blocker) { + this.blocker = blocker; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + NameSpaceBinding clone = new NameSpaceBinding(); + clone.setName(this.getName()); + clone.setJndiname(this.getJndiname()); + clone.setJndialias(this.getJndialias()); + clone.setProviderurl(this.getProviderurl()); + clone.setActive(this.isActive()); + clone.setBlocker(this.isBlocker()); + return clone; + } + + /** + * Transform the NameSpaceBinding POJO to a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "namespacebinding"); + element.setAttribute("name", this.getName()); + element.setAttribute("jndiname", this.getJndiname()); + element.setAttribute("jndialias", this.getJndialias()); + element.setAttribute("providerurl", this.getProviderurl()); + element.setAttribute("active", new Boolean(this.isActive()).toString()); + element.setAttribute("blocker", new Boolean(this.isBlocker()).toString()); + return element; + } + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object anotherNameSpaceBinding) { + return this.getName().compareTo(((NameSpaceBinding)anotherNameSpaceBinding).getName()); + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Notifiers.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Notifiers.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Notifiers.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Notifiers.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,132 @@ +/* + * 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.model; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Represent the notifiers tag in the Kalumet configuration DOM. + */ +public class Notifiers implements Serializable, Cloneable { + + private static final long serialVersionUID = -5087839972754579270L; + + private int countdown; + private LinkedList notifiers; + + public Notifiers() { + this.notifiers = new LinkedList(); + } + + public int getCountdown() { + return this.countdown; + } + + public void setCountdown(int countdown) { + this.countdown = countdown; + } + + /** + * Add a new Email notifier in the Notifiers + * notifiers container. + * + * @param email the Email to add. + */ + public void addNotifier(Email email) throws ModelObjectAlreadyExistsException { + if (this.getNotifier(email.getMailhost()) != null) { + throw new ModelObjectAlreadyExistsException("Email notifier mailhost already exists in notifiers."); + } + this.notifiers.add(email); + } + + /** + * Get the Email notifier list in the Notifiers + * notifiers container. + * + * @return the Email notifier list. + */ + public List getNotifiers() { + return this.notifiers; + } + + /** + * Set the Email notifier list in the + * Notifiers notifiers container. + * + * @param notifiers the new Email notifier list. + */ + public void setNotifiers(LinkedList notifiers) { + this.notifiers = notifiers; + } + + /** + * Get the Email notifier identified by a given mail host in + * the Notifiers notifiers container. + * + * @param mailhost the Email notifier mail host. + * @return the Email found or null if not found. + */ + public Email getNotifier(String mailhost) { + for (Iterator notifierIterator = this.getNotifiers().iterator(); notifierIterator.hasNext();) { + Email email = (Email) notifierIterator.next(); + if (email.getMailhost().equals(mailhost)) { + return email; + } + } + return null; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + Notifiers clone = new Notifiers(); + clone.setCountdown(this.getCountdown()); + for(Iterator notifierIterator = this.notifiers.iterator(); notifierIterator.hasNext(); ) { + Email notifier = (Email)notifierIterator.next(); + clone.notifiers.add((Email)notifier.clone()); + } + return clone; + } + + /** + * Transform the Notifiers POJO to a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "notifiers"); + element.setAttribute("countdown", new Integer(this.getCountdown()).toString()); + // email notifier child nodes + for (Iterator notifierIterator = this.getNotifiers().iterator(); notifierIterator.hasNext();) { + Email email = (Email) notifierIterator.next(); + element.appendChild(email.toDOMElement(document)); + } + return element; + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Property.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Property.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Property.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Property.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,85 @@ +/* + * 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.model; + +import java.io.Serializable; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Represent a property tag in the Kalumet configuration DOM. + */ +public class Property implements Serializable, Cloneable, Comparable { + + private static final long serialVersionUID = -1044229953052391950L; + + private String name; + private String value; + + public Property() { } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setValue(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + Property clone = new Property(); + clone.setName(this.getName()); + clone.setValue(this.getValue()); + return clone; + } + + /** + * Transform the Property POJO to a DOM Element. + * + * @param document the DOM document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "property"); + element.setAttribute("name", this.getName()); + element.setAttribute("value", this.getValue()); + return element; + } + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object anotherProperty) { + return this.getName().compareTo(((Property)anotherProperty).getName()); + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Security.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Security.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Security.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/Security.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,277 @@ +/* + * 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.model; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.kalumet.KalumetException; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Represent the security tag in the Kalumet configuration DOM. + */ +public class Security implements Serializable, Cloneable { + + private static final long serialVersionUID = 1323976117053191122L; + + private LinkedList users; + private LinkedList groups; + + public Security() { + this.users = new LinkedList(); + this.groups = new LinkedList(); + } + + /** + * Add a new User in the Security container. + * + * @param user the User to add. + */ + public void addUser(User user) throws ModelObjectAlreadyExistsException { + if (this.getUser(user.getId()) != null) { + throw new ModelObjectAlreadyExistsException("User id already exists in the security user configuration."); + } + this.users.add(user); + } + + /** + * Get the User list in the Security + * container. + * + * @return the User list. + */ + public List getUsers() { + return this.users; + } + + /** + * Set the User list in the Security + * container. + * + * @param users the new User list. + */ + public void setUsers(LinkedList users) { + this.users = users; + } + + /** + * Get the User identified by a given id in the + * Security container. + * + * @param id the User id. + * @return the found User or null if not found. + */ + public User getUser(String id) { + for (Iterator userIterator = this.getUsers().iterator(); userIterator.hasNext();) { + User user = (User) userIterator.next(); + if (user.getId().equals(id)) { + return user; + } + } + return null; + } + + /** + * Identify a user. + * + * @param id the user id. + * @param password the user password (in clear). + * @return true if the user is identified, false else. + */ + public boolean identifyUser(String id, String password) throws KalumetException { + String encryptedPassword = User.md5PasswordCrypt(password); + User user = this.getUser(id); + if (user == null) { + return false; + } + if (!user.getPassword().equals(encryptedPassword)) { + return false; + } + return true; + } + + /** + * Add a new Group in the Security container. + * + * @param group the Group to add. + */ + public void addGroup(Group group) throws ModelObjectAlreadyExistsException { + if (this.getGroup(group.getId()) != null) { + throw new ModelObjectAlreadyExistsException("Group id already exists in security definition."); + } + this.groups.add(group); + } + + /** + * Get the Group list in the Security container. + * + * @return the Group list. + */ + public List getGroups() { + return this.groups; + } + + /** + * Set the Group list in the Security + * container. + * + * @param groups the new Grouplist. + */ + public void setGroups(LinkedList groups) { + this.groups = groups; + } + + /** + * Get a Group identified by a given id in the + * Security container. + * + * @param id the Group id. + * @return the found Group or null if not found. + */ + public Group getGroup(String id) { + for (Iterator groupIterator = this.getGroups().iterator(); groupIterator.hasNext();) { + Group group = (Group) groupIterator.next(); + if (group.getId().equals(id)) { + return group; + } + } + return null; + } + + /** + * Get all groups of a user. + * + * @param userid the user id. + * @return the user groups. + */ + public List getUserGroups(String userid) { + if (userid.equals("admin")) { + return this.getGroups(); + } + LinkedList userGroups = new LinkedList(); + for (Iterator groupIterator = this.getGroups().iterator(); groupIterator.hasNext();) { + Group group = (Group) groupIterator.next(); + if (group.getUser(userid) != null) { + userGroups.add(group); + } + } + return userGroups; + } + + /** + * Check user in group. + * + * @param userid the user id. + * @param groupid the group id. + * @return true if the user is a member of the group, false else. + */ + public boolean checkUserInGroup(String userid, String groupid) { + if (userid.equals("admin")) { + return true; + } + for (Iterator userGroupIterator = this.getUserGroups(userid).iterator(); userGroupIterator.hasNext();) { + Group group = (Group) userGroupIterator.next(); + if (group.getId().equals(groupid)) { + return true; + } + } + return false; + } + + /** + * Check if a user has an access to a given environment. + * + * @param environment the Environment. + * @param userid the User id. + * @param property the Access property. + * @return true if the user has access to the environment, false else. + */ + public boolean checkEnvironmentUserAccess(Environment environment, String userid, String property) { + if (this.checkUserInGroup(userid, "admin")) { + return true; + } + for (Iterator accessIterator = environment.getAccesses().iterator(); accessIterator.hasNext();) { + Access access = (Access) accessIterator.next(); + if (property == null) { + if (this.checkUserInGroup(userid, access.getGroup())) { + return true; + } + } else { + if (access.getProperty(property) != null && access.getProperty(property).getValue().equals("true")) { + if (this.checkUserInGroup(userid, access.getGroup())) { + return true; + } + } + } + } + return false; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + Security clone = new Security(); + for (Iterator userIterator = this.users.iterator(); userIterator.hasNext(); ) { + User user = (User)userIterator.next(); + clone.users.add((User)user.clone()); + } + for (Iterator groupIterator = this.groups.iterator(); groupIterator.hasNext(); ) { + Group group = (Group)groupIterator.next(); + clone.groups.add((Group)group.clone()); + } + return clone; + } + + /** + * Transform the Security POJO to a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "security"); + // users element + ElementImpl users = new ElementImpl(document, "users"); + // add user in the users container + for (Iterator userIterator = this.getUsers().iterator(); userIterator.hasNext();) { + User user = (User) userIterator.next(); + users.appendChild(user.toDOMElement(document)); + } + // add users in security + element.appendChild(users); + // groups element + ElementImpl groups = new ElementImpl(document, "groups"); + // add group in the groups container + for (Iterator groupIterator = this.getGroups().iterator(); groupIterator.hasNext();) { + Group group = (Group) groupIterator.next(); + groups.appendChild(group.toDOMElement(document)); + } + // add groups in security + element.appendChild(groups); + return element; + } + +} \ No newline at end of file Added: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/SharedLibrary.java URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/SharedLibrary.java?rev=1187711&view=auto ============================================================================== --- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/SharedLibrary.java (added) +++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/model/SharedLibrary.java Sat Oct 22 13:10:01 2011 @@ -0,0 +1,107 @@ +/* + * 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.model; + +import java.io.Serializable; + +import org.apache.xerces.dom.CoreDocumentImpl; +import org.apache.xerces.dom.ElementImpl; +import org.w3c.dom.Element; + +/** + * Represent the sharedlibrary tag in the Kalumet configuration DOM. + */ +public class SharedLibrary implements Serializable, Cloneable, Comparable { + + private static final long serialVersionUID = -16763008144930653L; + + private String name; + private String classpath; + private boolean active; + private boolean blocker; + + public SharedLibrary() { } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getClasspath() { + return this.classpath; + } + + public void setClasspath(String classpath) { + this.classpath = classpath; + } + + public boolean isActive() { + return this.active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isBlocker() { + return this.blocker; + } + + public void setBlocker(boolean blocker) { + this.blocker = blocker; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() throws CloneNotSupportedException { + SharedLibrary clone = new SharedLibrary(); + clone.setName(this.getName()); + clone.setClasspath(this.getClasspath()); + clone.setActive(this.isActive()); + clone.setBlocker(this.isBlocker()); + return clone; + } + + /** + * Transform the SharedLibrary POJO to a DOM element. + * + * @param document the DOM document. + * @return the DOM element. + */ + protected Element toDOMElement(CoreDocumentImpl document) { + ElementImpl element = new ElementImpl(document, "sharedlibrary"); + element.setAttribute("name", this.getName()); + element.setAttribute("classpath", this.getClasspath()); + element.setAttribute("active", new Boolean(this.isActive()).toString()); + element.setAttribute("blocker", new Boolean(this.isBlocker()).toString()); + return element; + } + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object anotherSharedLibrary) { + return this.getName().compareTo(((SharedLibrary)anotherSharedLibrary).getName()); + } + +} \ No newline at end of file