001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2006-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.tools.mocks;
019:
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.LinkedList;
023: import org.java.plugin.registry.PluginAttribute;
024:
025: /**
026: * @version $Id$
027: */
028: public class MockPluginAttribute extends
029: MockPluginElement<PluginAttribute> implements PluginAttribute {
030: private LinkedList<PluginAttribute> subAttributes = new LinkedList<PluginAttribute>();
031: private PluginAttribute super Attribute;
032: private String value;
033:
034: /**
035: * No-arguments constructor.
036: */
037: public MockPluginAttribute() {
038: // no-op
039: }
040:
041: /**
042: * @param id attribute ID
043: * @param aValue attribute value
044: */
045: public MockPluginAttribute(final String id, final String aValue) {
046: setId(id);
047: value = aValue;
048: }
049:
050: /**
051: * @see org.java.plugin.registry.PluginAttribute#getSubAttribute(
052: * java.lang.String)
053: */
054: public PluginAttribute getSubAttribute(final String id) {
055: for (PluginAttribute attr : subAttributes) {
056: if (attr.getId().equals(id)) {
057: return attr;
058: }
059: }
060: throw new IllegalArgumentException("unknown attribute ID " + id); //$NON-NLS-1$
061: }
062:
063: /**
064: * @see org.java.plugin.registry.PluginAttribute#getSubAttributes()
065: */
066: public Collection<PluginAttribute> getSubAttributes() {
067: return Collections.unmodifiableCollection(subAttributes);
068: }
069:
070: /**
071: * @see org.java.plugin.registry.PluginAttribute#getSubAttributes(
072: * java.lang.String)
073: */
074: public Collection<PluginAttribute> getSubAttributes(final String id) {
075: LinkedList<PluginAttribute> result = new LinkedList<PluginAttribute>();
076: for (PluginAttribute attr : subAttributes) {
077: if (attr.getId().equals(id)) {
078: result.add(attr);
079: }
080: }
081: return result;
082: }
083:
084: /**
085: * @param attribute sub-attribute to add
086: * @return this instance
087: */
088: public MockPluginAttribute addSubAttribute(
089: final PluginAttribute attribute) {
090: subAttributes.add(attribute);
091: return this ;
092: }
093:
094: /**
095: * @see org.java.plugin.registry.PluginAttribute#getSuperAttribute()
096: */
097: public PluginAttribute getSuperAttribute() {
098: return super Attribute;
099: }
100:
101: /**
102: * @param attribute the super attribute to set
103: * @return this instance
104: */
105: public MockPluginAttribute setSuperAttribute(
106: final PluginAttribute attribute) {
107: super Attribute = attribute;
108: return this ;
109: }
110:
111: /**
112: * @see org.java.plugin.registry.PluginAttribute#getValue()
113: */
114: public String getValue() {
115: return value;
116: }
117:
118: /**
119: * @param attributeValue the attribute value to set
120: * @return this instance
121: */
122: public MockPluginAttribute setValue(final String attributeValue) {
123: value = attributeValue;
124: return this;
125: }
126: }
|