BrightSide Workbench Full Report + Source Code
AbstractImplementation.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.abstracts;
19 
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.Map;
23 import org.turro.string.ObjectString;
24 import org.jdom.Element;
25 import org.turro.collections.KeyValueMap;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.elephant.context.IElement;
28 import org.turro.elephant.context.IImplementation;
29 
34 public abstract class AbstractImplementation implements IImplementation {
35 
36  protected IElement iel;
38  protected Element configuration;
39  protected Map attributes;
40 
43  attributes = new HashMap();
44  }
45 
46  @Override
47  public void setElement(IElement element) {
48  iel = element;
49  }
50 
51  @Override
53  this.constructor = constructor;
54  }
55 
56  @Override
57  public void setConfiguration(Element configuration) {
58  this.configuration = configuration;
59  Element el;
60  Iterator it = configuration.getChildren("attrib").iterator();
61  while(it.hasNext()) {
62  el = (Element) it.next();
63  attributes.put(el.getAttributeValue("name"), el.getAttributeValue("value"));
64  }
65  }
66 
67  private KeyValueMap _attributes;
68 
69  public KeyValueMap getAttributes() {
70  if(_attributes == null) {
71  _attributes = new KeyValueMap(attributes);
72  }
73  return _attributes;
74  }
75 
76  public Long getLongAttribute(String key) {
77  String value = (String) attributes.get(key);
78  return (Long) ObjectString.parseString(value, Long.class, true);
79  }
80 
81 }