KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > impl > ItemConfiguration


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: ItemConfiguration.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.ac.impl;
21
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.avalon.framework.configuration.DefaultConfiguration;
25
26 /**
27  * Use this class to create configurations from {@link AbstractItem}s or
28  * to build {@link AbstractItem}s from configurations.
29  */

30 public class ItemConfiguration {
31     
32     /**
33      * Ctor.
34      */

35     public ItemConfiguration() {
36     }
37     
38     /**
39      * Saves the ID, name and description of the Manageable to the configuration.
40      * @param manageable A manageable.
41      * @param configuration A configuration.
42      */

43     public void save(AbstractItem manageable, DefaultConfiguration configuration) {
44         configuration.setAttribute(CLASS_ATTRIBUTE, manageable.getClass().getName());
45         configuration.setAttribute(ID_ATTRIBUTE, manageable.getId());
46
47         DefaultConfiguration child = null;
48
49         // add name node
50
child = new DefaultConfiguration(NAME);
51         child.setValue(manageable.getName());
52         configuration.addChild(child);
53
54         // add description node
55
child = new DefaultConfiguration(DESCRIPTION);
56         child.setValue(manageable.getDescription());
57         configuration.addChild(child);
58
59     }
60
61     public static final String JavaDoc NAME = "name";
62     public static final String JavaDoc DESCRIPTION = "description";
63     public static final String JavaDoc ID_ATTRIBUTE = "id";
64     public static final String JavaDoc CLASS_ATTRIBUTE = "class";
65
66     /**
67      * Configures a Manageable.
68      * @param manageable The manageable.
69      * @param configuration The configuration.
70      * @throws ConfigurationException when something went wrong.
71      */

72     public void configure(AbstractItem manageable, Configuration configuration) throws ConfigurationException {
73         manageable.setId(configuration.getAttribute(ID_ATTRIBUTE));
74         manageable.setName(configuration.getChild(NAME).getValue(""));
75         manageable.setDescription(configuration.getChild(DESCRIPTION).getValue(""));
76     }
77
78 }
79
Popular Tags