Path: blob/master/src/java.desktop/share/classes/com/sun/beans/decoder/VarElementHandler.java
41171 views
/*1* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package com.sun.beans.decoder;2526/**27* This class is intended to handle <var> element.28* This element retrieves the value of specified variable.29* For example:<pre>30* <var id="id1" idref="id2"/></pre>31* is equivalent to {@code id1 = id2} in Java code.32* <p>The following attributes are supported:33* <dl>34* <dt>idref35* <dd>the identifier to refer to the variable36* <dt>id37* <dd>the identifier of the variable that is intended to store the result38* </dl>39*40* @since 1.741*42* @author Sergey A. Malenkov43*/44final class VarElementHandler extends ElementHandler {45private ValueObject value;4647/**48* Parses attributes of the element.49* The following attributes are supported:50* <dl>51* <dt>idref52* <dd>the identifier to refer to the variable53* <dt>id54* <dd>the identifier of the variable that is intended to store the result55* </dl>56*57* @param name the attribute name58* @param value the attribute value59*/60@Override61public void addAttribute(String name, String value) {62if (name.equals("idref")) { // NON-NLS: the attribute name63this.value = ValueObjectImpl.create(getVariable(value));64} else {65super.addAttribute(name, value);66}67}6869/**70* Returns the value of this element.71*72* @return the value of this element73*/74@Override75protected ValueObject getValueObject() {76if (this.value == null) {77throw new IllegalArgumentException("Variable name is not set");78}79return this.value;80}81}828384