From 6dc6b9d3c0ce97a14678b99e594a8400f4c2eb45 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 11 Jul 2014 12:17:50 +0200 Subject: [PATCH] Made SchemaDefinitionType really serializable. --- .../_public/types_3/SchemaDefinitionType.java | 402 +++++++++--------- 1 file changed, 193 insertions(+), 209 deletions(-) diff --git a/infra/prism/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/SchemaDefinitionType.java b/infra/prism/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/SchemaDefinitionType.java index ac13c67b914..d28430716c5 100644 --- a/infra/prism/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/SchemaDefinitionType.java +++ b/infra/prism/src/main/java/com/evolveum/prism/xml/ns/_public/types_3/SchemaDefinitionType.java @@ -74,217 +74,9 @@ public void setSchema(Element schema) { this.schema = schema; } - /** - * Gets the value of the any property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the any property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getAny().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link Element } - * - * - */ public List getAny() { if (any == null) { - any = new List() { - - @Override - public int size() { - if (schema == null) { - return 0; - } else { - return 1; - } - } - - @Override - public boolean isEmpty() { - return schema == null; - } - - @Override - public boolean contains(Object o) { - return o.equals(schema); - } - - @Override - public Iterator iterator() { - // Very lazy implementation: TODO: cleanup if needed - return new Iterator() { - private int index = 0; - - @Override - public boolean hasNext() { - return index == 0; - } - - @Override - public Element next() { - index++; - return schema; - } - - @Override - public void remove() { - schema = null; - } - }; - } - - @Override - public Object[] toArray() { - if (schema == null) { - return new Object[0]; - } else { - Object[] a = new Object[1]; - a[0] = schema; - return a; - } - } - - @Override - public T[] toArray(T[] a) { - return (T[]) toArray(); - } - - @Override - public boolean add(Element e) { - if (schema == null) { - schema = e; - return true; - } else { - throw new IllegalStateException("Cannot add more then one schema element"); - } - } - - @Override - public boolean remove(Object o) { - if (o.equals(schema)) { - schema = null; - return true; - } else { - return false; - } - } - - @Override - public boolean containsAll(Collection c) { - for (Object e: c) { - if (!contains(e)) { - return false; - } - } - return true; - } - - @Override - public boolean addAll(Collection c) { - boolean changed = false; - for (Element e: c) { - if (add(e)) { - changed = true; - } - } - return changed; - } - - @Override - public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public void clear() { - schema = null; - } - - @Override - public Element get(int index) { - if (index == 0) { - return schema; - } else { - return null; - } - } - - @Override - public Element set(int index, Element element) { - if (index == 0) { - schema = element; - return schema; - } else { - throw new IndexOutOfBoundsException(); - } - } - - @Override - public void add(int index, Element element) { - if (index == 0 && schema == null) { - schema = element; - } else { - throw new IndexOutOfBoundsException(); - } - } - - @Override - public Element remove(int index) { - if (index == 0) { - Element old = schema; - schema = null; - return old; - } else { - throw new IndexOutOfBoundsException(); - } - - } - - @Override - public int indexOf(Object o) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public int lastIndexOf(Object o) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public ListIterator listIterator() { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public ListIterator listIterator(int index) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - - @Override - public List subList(int fromIndex, int toIndex) { - throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); - } - }; + any = new CustomList(); } return this.any; } @@ -325,4 +117,196 @@ public SchemaDefinitionType clone() throws CloneNotSupportedException { } return clone; } + + class CustomList implements Serializable, List { + + @Override + public int size() { + if (schema == null) { + return 0; + } else { + return 1; + } + } + + @Override + public boolean isEmpty() { + return schema == null; + } + + @Override + public boolean contains(Object o) { + return o.equals(schema); + } + + @Override + public CustomIterator iterator() { + return new CustomIterator(); + } + + @Override + public Object[] toArray() { + if (schema == null) { + return new Object[0]; + } else { + Object[] a = new Object[1]; + a[0] = schema; + return a; + } + } + + @Override + public T[] toArray(T[] a) { + return (T[]) toArray(); + } + + @Override + public boolean add(Element e) { + if (schema == null) { + schema = e; + return true; + } else { + throw new IllegalStateException("Cannot add more then one schema element"); + } + } + + @Override + public boolean remove(Object o) { + if (o.equals(schema)) { + schema = null; + return true; + } else { + return false; + } + } + + @Override + public boolean containsAll(Collection c) { + for (Object e: c) { + if (!contains(e)) { + return false; + } + } + return true; + } + + @Override + public boolean addAll(Collection c) { + boolean changed = false; + for (Element e: c) { + if (add(e)) { + changed = true; + } + } + return changed; + } + + @Override + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public void clear() { + schema = null; + } + + @Override + public Element get(int index) { + if (index == 0) { + return schema; + } else { + return null; + } + } + + @Override + public Element set(int index, Element element) { + if (index == 0) { + schema = element; + return schema; + } else { + throw new IndexOutOfBoundsException(); + } + } + + @Override + public void add(int index, Element element) { + if (index == 0 && schema == null) { + schema = element; + } else { + throw new IndexOutOfBoundsException(); + } + } + + @Override + public Element remove(int index) { + if (index == 0) { + Element old = schema; + schema = null; + return old; + } else { + throw new IndexOutOfBoundsException(); + } + } + + @Override + public int indexOf(Object o) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public int lastIndexOf(Object o) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public ListIterator listIterator() { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public ListIterator listIterator(int index) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + @Override + public List subList(int fromIndex, int toIndex) { + throw new UnsupportedOperationException("Lazyness is one of the greatest virtues of a programmer"); + } + + } + + class CustomIterator implements Serializable, Iterator { + + // Very lazy implementation: TODO: cleanup if needed + + private int index = 0; + + @Override + public boolean hasNext() { + return index == 0; + } + + @Override + public Element next() { + index++; + return schema; + } + + @Override + public void remove() { + schema = null; + } + } }