Package com.volantis.mcs.build.themes.definitions

Examples of com.volantis.mcs.build.themes.definitions.Named


            addTypeDef(typeDef);

        } else if (name.equals("name")) {

            // Set the name of the containing named object.
            Named named = (Named) findObject(Named.class);
            named.setName(element.getText());

        } else if (name.equals("description")) {
            // Ignore description elements and their contents, they have no
            // effect on code generation.
        } else if (name.equals("initialValue")) {

            processInitialValue(element);

        } else if (name.equals("integerValue")) {
            String valStr = element.getText();
            try {
                int intVal = Integer.parseInt(valStr);
                IntegerValue value = definitionsFactory.createIntegerValue();
                value.setInteger(intVal);
                ValueContainer container =
                        (ValueContainer) findObject(ValueContainer.class);
                container.addValue(value);
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid number: '" + valStr + "'");
            }
        } else if (name.equals("lengthValue")) {
            String valStr = element.getText();
            try {
                int intVal = Integer.parseInt(valStr);
                LengthValue value = definitionsFactory.createLengthValue();
                value.setInteger(intVal);
                value.setUnits(element.getAttributeValue("units"));
                ValueContainer container =
                        (ValueContainer) findObject(ValueContainer.class);
                container.addValue(value);
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid number: '" + valStr + "'");
            }
        } else if (name.equals("angleValue")) {
            String valStr = element.getText();

            try {
                double doubleVal = Double.parseDouble(valStr);
                String units = element.getAttributeValue("units");
                ValueContainer container =
                        (ValueContainer) findObject(ValueContainer.class);
                AngleValue value = definitionsFactory.createAngleValue();
                value.setAngle(doubleVal);
                value.setUnits(units);
                container.addValue(value);
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid angle: '" + valStr + "'");
            }
        } else if (name.equals("stringValue")) {
            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            StringValue value = definitionsFactory.createStringValue();
            value.setString(element.getText());
            container.addValue(value);
        } else if (name.equals("colorValue")) {
            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            ColorValue value = definitionsFactory.createColorValue();
            value.setColorName(element.getText());
            container.addValue(value);
        } else if (name.equals("inheritValue")) {
            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            InheritValue value = definitionsFactory.createInheritValue();
            container.addValue(value);
        } else if (name.equals("percentageValue")) {
            String valStr = element.getText();
            try {
                double percentVal = Double.parseDouble(valStr);
                PercentageValue value =
                        definitionsFactory.createPercentageValue();
                value.setPercentage(percentVal);
                ValueContainer container =
                        (ValueContainer) findObject(ValueContainer.class);
                container.addValue(value);
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid percentage: '" + valStr + "'");
            }
        } else if (name.equals("timeValue")) {
            String valStr = element.getText();

            try {
                double doubleVal = Double.parseDouble(valStr);
                String units = element.getAttributeValue("units");
                ValueContainer container =
                        (ValueContainer) findObject(ValueContainer.class);
                TimeValue value = definitionsFactory.createTimeValue();
                value.setTime(doubleVal);
                value.setUnits(units);
                container.addValue(value);
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid time: '" + valStr + "'");
            }
        } else if (name.equals("pairValue")) {
            PairValueContainer pair = new PairValueContainer();

            pushObject(pair);
            processThemePropertyChildren(element);
            popObject();

            PairValue value = definitionsFactory.createPairValue();
            value.setFirst(pair.getFirst());
            value.setSecond(pair.getSecond());

            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            container.addValue(value);
        } else if (name.equals("listValue")) {
            ListValueContainer pair = new ListValueContainer();

            pushObject(pair);
            processThemePropertyChildren(element);
            popObject();

            ListValue value = definitionsFactory.createListValue();
            Value next = null;
            while((next = pair.getNext())!=null){
                value.setNext(next);
            }
           
            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            container.addValue(value);
        } else if (name.equals("frequencyValue")) {
            String valStr = element.getText();

            try {
                double doubleVal = Double.parseDouble(valStr);
                String units = element.getAttributeValue("units");
                ValueContainer container =
                        (ValueContainer) findObject(ValueContainer.class);
                FrequencyValue value = definitionsFactory.createFrequencyValue();
                value.setNumber(doubleVal);
                value.setUnits(units);
                container.addValue(value);
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid frequency: '" + valStr + "'");
            }
        } else if (name.equals("fractionValue")) {
            PairValueContainer pair = new PairValueContainer();

            pushObject(pair);
            processThemePropertyChildren(element);
            popObject();

            FractionValue value = definitionsFactory.createFractionValue();
            value.setNumerator(pair.getFirst());
            value.setDenominator(pair.getSecond());

            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            container.addValue(value);
        } else if (name.equals("keywordRef")) {

            // Resolve the keyword reference to the keyword (must come before)
            // and then create a representation.
            ValueContainer container =
                    (ValueContainer) findObject(ValueContainer.class);
            String keywordName = element.getText();

            // Get the keyword from the property's type.
            Property property = (Property) findObject(Property.class);
            Type type = property.getType();
            if (type != null) {
                KeywordSearchContainer keywordCont =
                        new KeywordSearchContainer();
                keywordCont.setKeywordName(keywordName);
                TypeVisitor keywordFinder = new AbstractTypeVisitor() {
                    public void visitKeywords(Keywords visitee, Object obj) {
                        KeywordSearchContainer ksc =
                                (KeywordSearchContainer) obj;
                        Keyword keyword =
                                visitee.getKeyword(ksc.getKeywordName());
                        if (keyword != null) {
                            ksc.setKeyword(keyword);
                        }
                    }

                    public void visitTypeRef(TypeRef visitee, Object obj) {
                        TypeDefinition td = getTypeDef(visitee.getReference());
                        if (td != null) {
                            Type t = td.getType();
                            if (t != null) {
                                t.accept(this, obj);
                            }
                        }
                    }
                };
                type.accept(keywordFinder, keywordCont);
                if (keywordCont.getKeyword() == null) {
                    System.out.println("Keyword " + keywordName
                                       + " not found in property "
                                       + property.getName());
                } else {
                    KeywordReference reference
                            = definitionsFactory.createKeywordReference();
                    reference.setKeyword(keywordCont.getKeyword());
                    container.addValue(reference);
                }
            } else {
                System.out.println(
                        "Property has no type: could not find keywords");
            }
        } else if (name.equals("themeDefinition")) {
            // Process all the children.
            processThemePropertyChildren(element);
        } else if (name.equals("choiceType")) {
            ChoiceType choiceType = definitionsFactory.createChoiceType();
            TypeList typeList = new TypeList();

            pushObject(choiceType);
            pushObject(typeList);
            processThemePropertyChildren(element);
            popObject();
            popObject();

            Iterator it = typeList.getList().iterator();
            while (it.hasNext()) {
                choiceType.addType((Type) it.next());
            }
            storeType(choiceType);
        } else if (name.equals("pairType")) {
            PairType pairType = definitionsFactory.createPairType();

            pushObject(pairType);
            processThemePropertyChildren(element);
            popObject();

            storeType(pairType);
        } else if (name.equals("fractionType")) {
            FractionType fractionType = definitionsFactory.createFractionType();

            pushObject(fractionType);
            processThemePropertyChildren(element);
            popObject();
            storeType(fractionType);
        } else if (name.equals("first")) {
            TypeList typeList = new TypeList();
            NameHolder nameHolder = new NameHolder();

            pushObject(typeList);
            pushObject(nameHolder);
            processThemePropertyChildren(element);
            popObject();
            popObject();

            if (!typeList.getList().isEmpty()) {
                PairType pair = (PairType) findObject(PairType.class);
                pair.setFirst((Type) typeList.getList().get(0));
            }
        } else if (name.equals("second")) {
            TypeList typeList = new TypeList();
            NameHolder nameHolder = new NameHolder();

            pushObject(typeList);
            pushObject(nameHolder);
            processThemePropertyChildren(element);
            popObject();
            popObject();

            if (!typeList.getList().isEmpty()) {
                PairType pair = (PairType) findObject(PairType.class);
                pair.setSecond((Type) typeList.getList().get(0));
            }
        } else if (name.equals("numerator")) {
            TypeList typeList = new TypeList();
            NameHolder nameHolder = new NameHolder();

            pushObject(typeList);
            pushObject(nameHolder);
            processThemePropertyChildren(element);
            popObject();
            popObject();

            if (!typeList.getList().isEmpty()) {
                FractionType fraction = (FractionType) findObject(FractionType.class);
                fraction.setNumerator((Type) typeList.getList().get(0));
            }
        } else if (name.equals("denominator")) {
            TypeList typeList = new TypeList();
            NameHolder nameHolder = new NameHolder();

            pushObject(typeList);
            pushObject(nameHolder);
            processThemePropertyChildren(element);
            popObject();
            popObject();

            if (!typeList.getList().isEmpty()) {
                FractionType fraction = (FractionType) findObject(FractionType.class);
                fraction.setDenominator((Type) typeList.getList().get(0));
            }
        }else if (name.equals("type")) {
            // Process the children in order to find the keyword definitions.
            processThemePropertyChildren(element);
        } else if (name.equals("typeRef")) {

            TypeRef typeRef = definitionsFactory.createTypeRef();
            typeRef.setReference(element.getText());
            Property property = (Property) findObject(Property.class);
            property.setType(typeRef);

        } else if (name.equals("keywords")) {

            Keywords keywords = definitionsFactory.createKeywords();

            pushObject(keywords);
            processThemePropertyChildren(element);
            popObject();

            storeType(keywords);

        } else if (name.equals("keyword")) {

            // Define a new keyword and add it into the containing set.
            Keyword keyword = definitionsFactory.createKeyword();

            pushObject(keyword);

            processThemePropertyChildren(element);

            popObject();

            Keywords keywords = (Keywords) findObject(Keywords.class);
            keywords.addKeyword(keyword);
        } else if (name.equals("inherited")) {
            Property prop = (Property) findObject(Property.class);
            prop.setInherited(
                    Boolean.valueOf(element.getText()).booleanValue());
            // These are named elements that we are deliberately ignoring for
            // the time being.
        } else if (name.equals("element") ||
                name.equals("media") ||
                name.equals("specifications") ||
                name.equals("integerType") ||
                name.equals("colorType") ||
                name.equals("percentageType") ||
                name.equals("lengthType") ||
                name.equals("uriType") ||
                name.equals("mcsComponentURIType") ||
                name.equals("appliesTo") ||
                name.equals("percentages") ||
                name.equals("stringType") ||
                name.equals("dependentType") ||
                name.equals("angleType") ||
                name.equals("functionType") ||
                name.equals("timeType") ||
                name.equals("numberType") ||
                name.equals("fractionType") ||
                name.equals("frequencyType") ||
                name.equals("emptyList") ||
                // From discussion with Paul Duffin, unorderedSetType is being
                // phased out, and can be safely ignored since it is only used
                // in one case, and there the initialValue falls outside the
                // unorderedSetType.
                name.equals("unorderedSetType") ||
                // Dependent values - such as color, text alignment etc. -
                // depend on some value outside of the scope of the property
                // definitions (such as the user agent or the writing
                // direction). A generic 'initial value' can not be
                // calculated for them.
                name.equals("dependentValue")) {
            // These are types which contain a single other type - lists and
            // ordered sets. Rather than creating a simple type that can contain
            // another type, they can be ignored, allowing the type tree to be
            // navigated without adding an additional (non-functional) layer.
        } else if (name.equals("listType") ||
                name.equals("orderedSetType")) {
            processThemePropertyChildren(element);
        } else if (name.equals("propertyRef")) {
            // This only works inside initialValue.
            PropertyReference reference = (PropertyReference)
                    findObject(PropertyReference.class);
            String propertyName = element.getText();
            if (reference == null) {
                System.out.println("Ignoring reference to property '" +
                                   propertyName + "'");
            } else {
                reference.setPropertyName(propertyName);
            }
        } else if (name.equals("computedRef")) {
            // This only works inside initialValue.
            ComputedReference reference = (ComputedReference)
                findObject(ComputedReference.class);
            if (reference == null) {
                System.out.println("Ignoring reference to computedRef");
            } else {

                Named propertyName = definitionsFactory.createProperty();
                pushObject(propertyName);
                Rules rules = definitionsFactory.createRules();
                pushObject(rules);
                processThemePropertyChildren(element);
                popObject();
                popObject();

                reference.setPropertyName(propertyName.getName());
                reference.setRules(rules.getRuleSet());
            }

        } else if (name.equals("rule")) {
View Full Code Here

TOP

Related Classes of com.volantis.mcs.build.themes.definitions.Named

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.