KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > metadata > ServiceElementValueMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.system.metadata;
23
24 import java.beans.PropertyEditor JavaDoc;
25 import java.beans.PropertyEditorManager JavaDoc;
26
27 import org.jboss.logging.Logger;
28 import org.jboss.util.StringPropertyReplacer;
29 import org.w3c.dom.Element JavaDoc;
30
31 /**
32  * ServiceElementValueMetaData.
33  *
34  * This class is based on the old ServiceConfigurator
35  *
36  * @author <a HREF="mailto:marc@jboss.org">Marc Fleury</a>
37  * @author <a HREF="mailto:hiram@jboss.org">Hiram Chirino</a>
38  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
39  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
40  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
41  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
42  * @version $Revision: 1.1 $
43  */

44 public class ServiceElementValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData
45 {
46    /** The log */
47    private static final Logger log = Logger.getLogger(ServiceElementValueMetaData.class);
48    
49    /** The element */
50    private Element JavaDoc element;
51
52    /**
53     * Create a new ServiceElementValueMetaData.
54     */

55    public ServiceElementValueMetaData()
56    {
57    }
58    
59    /**
60     * Create a new ServiceElementValueMetaData.
61     *
62     * @param element the element
63     */

64    public ServiceElementValueMetaData(Element JavaDoc element)
65    {
66       setElement(element);
67    }
68
69    /**
70     * Get the element.
71     *
72     * @return the element.
73     */

74    public Element JavaDoc getElement()
75    {
76       return element;
77    }
78
79    /**
80     * Set the element.
81     *
82     * @param element the element.
83     */

84    public void setElement(Element JavaDoc element)
85    {
86       if (element == null)
87          throw new IllegalArgumentException JavaDoc("Null element");
88       this.element = element;
89    }
90
91    public Object JavaDoc getValue(ServiceValueContext valueContext) throws Exception JavaDoc
92    {
93       // Replace any ${x} references in the element text
94
if (valueContext.isReplace())
95       {
96          PropertyEditor JavaDoc editor = PropertyEditorManager.findEditor(Element JavaDoc.class);
97          if (editor == null)
98             log.warn("Cannot perform property replace on Element");
99          else
100          {
101             editor.setValue(element);
102             String JavaDoc text = editor.getAsText();
103             text = StringPropertyReplacer.replaceProperties(text);
104             editor.setAsText(text);
105             return editor.getValue();
106          }
107       }
108
109       return element;
110    }
111 }
112
Popular Tags