Search in sources :

Example 1 with AttributeConverter

use of com.ramussoft.common.attribute.AttributeConverter in project ramus by Vitaliy-Yakovchuk.

the class JournaledEngine method findElements.

@Override
public List<Element> findElements(long qualifierId, Attribute attribute, Object object) {
    AttributeConverter converter = pluginFactory.getAttributeConverter(attribute.getAttributeType());
    FindObject[] findObjects = converter.getFindObjects(object);
    if (findObjects != null)
        return deligate.getElements(qualifierId, attribute, findObjects);
    List<Attribute> list = new ArrayList<Attribute>(1);
    list.add(attribute);
    Hashtable<Element, Object[]> elements = getElements(getQualifier(qualifierId), list);
    ArrayList<Element> res = new ArrayList<Element>();
    Enumeration<Element> e = elements.keys();
    while (e.hasMoreElements()) {
        Element element = e.nextElement();
        if (objectEquals(object, elements.get(element)[0])) {
            res.add(element);
        }
    }
    Collections.sort(res, new Comparator<Element>() {

        @Override
        public int compare(Element o1, Element o2) {
            if (o1.getId() < o2.getId())
                return -1;
            if (o1.getId() > o2.getId())
                return 1;
            return 0;
        }
    });
    return res;
}
Also used : AttributeConverter(com.ramussoft.common.attribute.AttributeConverter) FindObject(com.ramussoft.common.attribute.FindObject) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList)

Example 2 with AttributeConverter

use of com.ramussoft.common.attribute.AttributeConverter in project ramus by Vitaliy-Yakovchuk.

the class AbstractJournaledEngine method setAttribute.

@Override
public void setAttribute(Element element, Attribute attribute, Object object) {
    if (element != null)
        if (missAttributes.get(attribute.getId()) == null) {
            missAttributes.put(attribute.getId(), Boolean.TRUE);
        } else
            return;
    try {
        AttributeConverter converter = pluginFactory.getAttributeConverter(attribute.getAttributeType());
        Object old = getAttribute(element, attribute);
        setPersistentAttribute(element, attribute, object, converter);
        String typeName = attribute.getAttributeType().toString();
        if (element != null && (typeName.equals("Core.Text") || typeName.equals("IDEF0.DFDSName"))) {
            Qualifier q = getQualifier(element.getQualifierId());
            if (q.getAttributeForName() == attribute.getId()) {
                if (object == null)
                    element.setName("");
                else
                    element.setName(object.toString());
            }
        }
        AttributeEvent event = new AttributeEvent(this, element, attribute, old, object);
        attributeChanged(event);
    } catch (Exception e) {
    }
    if (element != null)
        missAttributes.remove(attribute.getId());
}
Also used : AttributeConverter(com.ramussoft.common.attribute.AttributeConverter) Qualifier(com.ramussoft.common.Qualifier) AttributeEvent(com.ramussoft.common.event.AttributeEvent)

Aggregations

AttributeConverter (com.ramussoft.common.attribute.AttributeConverter)2 Attribute (com.ramussoft.common.Attribute)1 Element (com.ramussoft.common.Element)1 Qualifier (com.ramussoft.common.Qualifier)1 FindObject (com.ramussoft.common.attribute.FindObject)1 AttributeEvent (com.ramussoft.common.event.AttributeEvent)1 ArrayList (java.util.ArrayList)1