Package com.sun.grid.jgdi.configuration.reflect

Examples of com.sun.grid.jgdi.configuration.reflect.PropertyDescriptor


        }
        return doUpdate(jgdi, obj, text);
    }

    private static <T extends GEObject> T doUpdate(JGDI jgdi, T obj, String text) {
        PropertyDescriptor pd;
        Object key;
        String line;
        if (obj == null) {
            throw new IllegalArgumentException("GEObject is NULL");
        }
View Full Code Here


        Object o;
        int maxLen = 0;
        String name, spaces;
        Object value;
        StringBuilder sb = new StringBuilder();
        PropertyDescriptor pd;
        List subNames = null, subValues = null;
        for (Iterator iter = getProperties(obj, propScope).iterator(); iter.hasNext();) {
            pd = (PropertyDescriptor) iter.next();
            subNames = getStretchedElementNames(obj, pd);
            if (subNames.size() > 0) {
                for (Iterator it = subNames.iterator(); it.hasNext();) {
                    maxLen = Math.max(maxLen, ((String) it.next()).length());
                }
            } else {
                name = EditorUtil.java2cName(obj, pd.getPropertyName());
                maxLen = Math.max(maxLen, name.length());
            }
        }

        for (Iterator iter = getProperties(obj, propScope).iterator(); iter.hasNext();) {
            pd = (PropertyDescriptor) iter.next();
            subNames = getStretchedElementNames(obj, pd);
            if (subNames.size() > 0) {
                subValues = getStretchedElementValues(obj, pd);
                if (subNames.size() != subValues.size()) {
                    throw new IllegalArgumentException("Unknown error: Expecting name x value lists of a same size! Got sizes " + subNames.size() + " and " + subValues.size());
                }
                for (int j = 0; j < subNames.size(); j++) {
                    name = (String) subNames.get(j);
                    value = (String) subValues.get(j);
                    sb.append(name);
                    for (int i = name.length(); i < maxLen; i++) {
                        sb.append(' ');
                    }
                    sb.append("    " + value + "\n");
                }
            } else {
                name = EditorUtil.java2cName(obj, pd.getPropertyName());
                value = EditorUtil.translateObjectToStringValue(pd.getPropertyName(), EditorUtil.getPropertyValue(obj, pd));
                if (obj instanceof Configuration && name.equals("hostname")) {
                    sb.append("#");
                    sb.append(value);
                    sb.append(":\n");
                } else {
View Full Code Here

        int maxLen = 0;
        String name, spaces;
        Object value;
        StringBuilder sb = new StringBuilder();
        List subNames = null, subValues = null;
        PropertyDescriptor pd = getProperty(obj, propScope, propName);
        if (pd == null) {
            throw new JGDIException("JGDI Error: Attribute \"" + propName + "\" does not exits in " + obj.getName());
        }
        subNames = getStretchedElementNames(obj, pd);
        if (subNames.size() > 0) {
            subValues = getStretchedElementValues(obj, pd);
            if (subNames.size() != subValues.size()) {
                throw new IllegalArgumentException("Unknown error: Expecting name x value lists of a same size! Got sizes " + subNames.size() + " and " + subValues.size());
            }
            for (int j = 0; j < subNames.size(); j++) {
                name = (String) subNames.get(j);
                value = (String) subValues.get(j);
                sb.append(name);
                for (int i = name.length(); i < maxLen; i++) {
                    sb.append(' ');
                }
                sb.append("    " + value + "\n");
            }
        } else {
            name = EditorUtil.java2cName(obj, pd.getPropertyName());
            value = EditorUtil.translateObjectToStringValue(pd.getPropertyName(), EditorUtil.getPropertyValue(obj, pd));
            sb.append(name);
            for (int i = name.length(); i < maxLen; i++) {
                sb.append(' ');
            }
            spaces = "    ";
View Full Code Here

    }

    static PropertyDescriptor getProperty(GEObject obj, int propScope, String name) {
        List<PropertyDescriptor> propList = new ArrayList<PropertyDescriptor>();
        ClassDescriptor cd = Util.getDescriptor(obj.getClass());
        PropertyDescriptor pd = cd.getProperty(EditorUtil.unifyClientNamesWithAttr(obj, name));
        if (pd == null) {
            return null;
        }
        if (EditorUtil.doNotDisplayAttr(obj, pd, propScope)) {
            return null;
View Full Code Here

     * Each line is also converted to the intermediate format.
     */
    static Map<Object, String> parsePlainText(GEObject obj, String text, String delimiter) throws IOException {
        String attr;
        String line;
        PropertyDescriptor pd;
        Map<Object, String> map = new HashMap<Object, String>();
        text = trimText(text);
        String[] lines = text.split("\n");
        for (int i = 0; i < lines.length; i++) {
            line = lines[i];
            attr = line.split(delimiter)[0];
            line = (line.length() == attr.length()) ? "" : line.substring(attr.length() + 1);
            if (line.length() == 0) {
                throw new IllegalArgumentException("Expected at least 2 tokens name and value got: \"" + attr + "\"");
            }
            attr = EditorUtil.c2javaName(obj, attr);
           
            //CONFIGURATION special case
            if (obj instanceof Configuration) {
                map.put(attr, line.trim());
                continue;
            }
           
            if ((pd = getPropertyDescriptor(obj, attr)) == null || pd.isReadOnly()) {
                String msg = AnnotatedCommand.getDefaultErrorMessage("QConfCommand", "UnknownAttribute", attr);
                int exitCode = AnnotatedCommand.getCustomExitCode("QConfCommand", "UnknownAttribute", "");
                throw new JGDIException(msg, exitCode);
            }
           
View Full Code Here

               
                ClassDescriptor realClassDescriptor = Util.getDescriptor(pd.getPropertyType());
               
                Object obj = realClassDescriptor.newInstance();
               
                PropertyDescriptor rpd = realClassDescriptor.getPropertyByCullFieldName(pd.getCullContentField());
               
                if (rpd instanceof SimplePropertyDescriptor) {
                    ((SimplePropertyDescriptor)rpd).setValue(obj, parse(value, rpd));
                    return obj;
                } else {
View Full Code Here

                }
                obj = cd.newInstance();
            }
           
            public CullHandler getHandler(String name, org.xml.sax.Attributes attributes) throws SAXException {
                PropertyDescriptor pd = cd.getProperty(name);
                if (pd == null) {
                    throw new SAXParseException("cull type " + cd.getCullName() + " has no property " + name, locator);
                } if (pd instanceof SimplePropertyDescriptor) {
                    if (pd.getPropertyType().isPrimitive() || pd.getPropertyType().equals(String.class)) {
                        return new SimplePropertyHandler(this, (SimplePropertyDescriptor)pd);
                    } else {
                        return new ObjectPropertyHandler(this, (SimplePropertyDescriptor)pd);
                    }
                } else if (pd instanceof ListPropertyDescriptor) {
                    return new ListPropertyHandler(this, (ListPropertyDescriptor)pd);
                } else if (pd instanceof MapPropertyDescriptor) {
                    return new MapPropertyHandler(this, (MapPropertyDescriptor)pd, attributes);
                } else if (pd instanceof MapListPropertyDescriptor) {
                    return new MapListPropertyHandler(this, (MapListPropertyDescriptor)pd, attributes);
                } else {
                    throw new SAXParseException("Unknown property type " + pd.getClass(), locator);
                }
            }
View Full Code Here

            ctx.p.print(NONE);
        } else {
            ctx.p.println();
            ctx.p.indent();
            for(int i = 0; i < cd.getPropertyCount(); i++) {
                PropertyDescriptor pd = cd.getProperty(i);
               
                if (!ctx.include(pd)) {
                    continue;
                }
                if (pd instanceof SimplePropertyDescriptor) {
                    write(obj, (SimplePropertyDescriptor)pd, ctx);
                } else if (pd instanceof ListPropertyDescriptor) {
                    write(obj, (ListPropertyDescriptor)pd, ctx);
                } else if (pd instanceof MapPropertyDescriptor) {
                    write(obj, (MapPropertyDescriptor)pd, ctx);
                } else if (pd instanceof MapListPropertyDescriptor) {
                    write(obj, (MapListPropertyDescriptor)pd, ctx);
                } else {
                    throw new IllegalStateException("Unknown property type " + pd.getClass());
                }
               
            }
            ctx.p.deindent();
        }
View Full Code Here

            name = name.substring(bracketIndex + 1, bracketCloseIndex);
        }
       
        if (propertyName != null) {
            ClassDescriptor descr = getDescriptor(root.getClass());
            PropertyDescriptor propDescr = descr.getProperty(propertyName);
            if (propDescr == null) {
                throw new IllegalArgumentException("Invalid Path: property " + propertyName + " in object " + root.getName() + " not found");
            } else if (!GEObject.class.isAssignableFrom(propDescr.getBeanClass())) {
                throw new IllegalArgumentException("Invalid Path: property " + propertyName + " in object " + root.getName() + " is not a GEObject");
            } else {
                GEObject child = null;
                if (propDescr instanceof SimplePropertyDescriptor) {
                    SimplePropertyDescriptor spd = (SimplePropertyDescriptor) propDescr;
                    child = (GEObject) spd.getValue(root);
                } else if (propDescr instanceof ListPropertyDescriptor) {
                    ListPropertyDescriptor lpd = (ListPropertyDescriptor) propDescr;
                    int propCount = lpd.getCount(root);
                    GEObject tmpChild = null;
                    for (int i = 0; i < propCount; i++) {
                        tmpChild = (GEObject) lpd.get(root, i);
                        if (tmpChild.getName().equals(name)) {
                            child = tmpChild;
                            break;
                        }
                    }
                } else {
                    throw new IllegalStateException("Unkonwn property descriptor " + propDescr.getClass().getName());
                }
                if (child == null) {
                    return null;
                } else if (rest != null) {
                    return findObject(rest, child);
View Full Code Here

            differences.add(new Difference(path, "obj1 and obj2 have not the same class"));
        } else {
            ClassDescriptor cd = getDescriptor(obj1.getClass());
           
            for (int i = 0; i < cd.getPropertyCount(); i++) {
                PropertyDescriptor pd = cd.getProperty(i);
                String propPath = path + pd.getPropertyName();
               
                if (pd instanceof SimplePropertyDescriptor) {
                   
                    SimplePropertyDescriptor spd = (SimplePropertyDescriptor) pd;
                   
View Full Code Here

TOP

Related Classes of com.sun.grid.jgdi.configuration.reflect.PropertyDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.