From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- .../gui/tabs/outcome/form/OutcomeStructure.java | 84 +++++++++++----------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'source/com/c2kernel/gui/tabs/outcome/form/OutcomeStructure.java') diff --git a/source/com/c2kernel/gui/tabs/outcome/form/OutcomeStructure.java b/source/com/c2kernel/gui/tabs/outcome/form/OutcomeStructure.java index a535da6..aee09df 100644 --- a/source/com/c2kernel/gui/tabs/outcome/form/OutcomeStructure.java +++ b/source/com/c2kernel/gui/tabs/outcome/form/OutcomeStructure.java @@ -4,7 +4,6 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; -import java.util.Iterator; import javax.swing.ImageIcon; import javax.swing.JPanel; @@ -49,11 +48,11 @@ public abstract class OutcomeStructure extends JPanel { subStructure = new HashMap(); Logger.msg(8, "Creating " + model.getName() + " structure as " + this.getClass().getName().substring(this.getClass().getName().lastIndexOf('.') + 1)); - + String doc = extractHelp(model); if (doc.length() > 0) help = doc; } - + public boolean getReadOnly() { return readOnly; } @@ -69,21 +68,21 @@ public abstract class OutcomeStructure extends JPanel { public OutcomeStructure createStructure(ElementDecl model, boolean readOnly, HelpPane help) throws OutcomeException { XMLType elementType = model.getType(); ComplexType elementComplexType; - + if (model.getMaxOccurs() == 0) return null; - + // if more than one can occur - dimension - if (model.getMaxOccurs() > 1 - || model.getMaxOccurs() == Particle.UNBOUNDED - || model.getMinOccurs() == 0) + if (model.getMaxOccurs() > 1 + || model.getMaxOccurs() == Particle.UNBOUNDED + || model.getMinOccurs() == 0) return new Dimension(model, readOnly, help); - + // must have a type from now on if (elementType == null) throw new StructuralException("Element "+model.getName()+" is elementary yet has no type."); // simple types will be fields if (elementType instanceof SimpleType) return new Field(model, readOnly, help); - + // otherwise is a complex type try { elementComplexType = (ComplexType)elementType; @@ -91,10 +90,10 @@ public abstract class OutcomeStructure extends JPanel { catch (ClassCastException e) { throw new StructuralException("Unknown XMLType for element " + model.getName()); } - + //when no element children - field if (elementComplexType.getParticleCount() == 0) return new Field(model, readOnly, help); - + //everything else is a data record return new DataRecord(model, readOnly, help, deferChild); } @@ -113,11 +112,11 @@ public abstract class OutcomeStructure extends JPanel { enumerateElements((ComplexType)base); } - for (Enumeration elements = group.enumerate(); elements.hasMoreElements(); ) { + for (Enumeration elements = group.enumerate(); elements.hasMoreElements(); ) { Particle thisParticle = (Particle)elements.nextElement(); if (thisParticle instanceof Group) { Group thisGroup = (Group)thisParticle; - if (thisGroup instanceof ModelGroup) { + if (thisGroup instanceof ModelGroup) { // HACK: Castor strangeness - model groups don't seem to resolve their own references. If fixed, this will still work ModelGroup thisModel = (ModelGroup)thisGroup; if (thisModel.hasReference()) thisGroup = thisModel.getReference(); @@ -152,39 +151,39 @@ public abstract class OutcomeStructure extends JPanel { public Element getElement() { return myElement; } - - public String getName() { + + @Override + public String getName() { if (model == null) return null; return model.getName(); } - + public ElementDecl getModel() { return model; } - + public String getHelp() { return help; } - + public String validateStructure() { StringBuffer errors = new StringBuffer(); - for (Iterator iter = subStructure.values().iterator(); iter.hasNext();) { - OutcomeStructure element = (OutcomeStructure)iter.next(); + for (OutcomeStructure element : subStructure.values()) { errors.append(element.validateStructure()); } return errors.toString(); } - + public abstract Element initNew(Document parent); - + public static String extractHelp(Annotated model) { - Enumeration e = model.getAnnotations(); + Enumeration e = model.getAnnotations(); StringBuffer doc = new StringBuffer(); if (e.hasMoreElements()) { // look for HTML Annotation note = (Annotation)e.nextElement(); - for (Enumeration g = note.getDocumentation(); g.hasMoreElements();) { + for (Enumeration g = note.getDocumentation(); g.hasMoreElements();) { Documentation thisDoc = (Documentation)g.nextElement(); - for (Enumeration h = thisDoc.getObjects(); h.hasMoreElements();) { + for (Enumeration h = thisDoc.getObjects(); h.hasMoreElements();) { AnyNode node = (AnyNode)h.nextElement(); String line = node.toString(); if (line.length() == 0) @@ -193,21 +192,22 @@ public abstract class OutcomeStructure extends JPanel { doc.append(line).append("\n"); } } - } + } } - + return doc.toString(); } - - public abstract void grabFocus(); - public static Class getJavaClass(int typeCode) { + @Override + public abstract void grabFocus(); + + public static Class getJavaClass(int typeCode) { switch (typeCode) { - + // boolean case SimpleTypesFactory.BOOLEAN_TYPE: return Boolean.class; - + // integers case SimpleTypesFactory.INTEGER_TYPE: case SimpleTypesFactory.NON_POSITIVE_INTEGER_TYPE: @@ -216,7 +216,7 @@ public abstract class OutcomeStructure extends JPanel { case SimpleTypesFactory.POSITIVE_INTEGER_TYPE: case SimpleTypesFactory.INT_TYPE: case SimpleTypesFactory.UNSIGNED_INT_TYPE: - case SimpleTypesFactory.SHORT_TYPE: + case SimpleTypesFactory.SHORT_TYPE: case SimpleTypesFactory.UNSIGNED_SHORT_TYPE: case SimpleTypesFactory.LONG_TYPE: case SimpleTypesFactory.UNSIGNED_LONG_TYPE: @@ -228,19 +228,19 @@ public abstract class OutcomeStructure extends JPanel { case SimpleTypesFactory.DOUBLE_TYPE: case SimpleTypesFactory.DECIMAL_TYPE: return BigDecimal.class; - + // images case SimpleTypesFactory.BASE64BINARY_TYPE: case SimpleTypesFactory.HEXBINARY_TYPE: return ImageIcon.class; - - // everything else is a string for now + + // everything else is a string for now default: return String.class; } } - - public static Object getTypedValue(String value, Class type) { + + public static Object getTypedValue(String value, Class type) { try { if (type.equals(Boolean.class)) if (value == null || value.equals("")) @@ -250,7 +250,7 @@ public abstract class OutcomeStructure extends JPanel { else if (type.equals(BigInteger.class)) if (value == null || value.equals("")) return new BigInteger("0"); - else + else return new BigInteger(value); else if (type.equals(BigDecimal.class)) if (value == null || value.equals("")) @@ -262,10 +262,10 @@ public abstract class OutcomeStructure extends JPanel { } return value==null?"":value; } - + public static boolean isEmpty(Object value) { if (value == null) return true; - + if (value instanceof String) { if (((String)value).length() == 0) return true; } -- cgit v1.2.3