All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codename1.properties.PropertyXMLElement Maven / Gradle / Ivy

There is a newer version: 7.0.167
Show newest version
/*
 * Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Codename One designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *  
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * 
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Please contact Codename One through http://www.codenameone.com/ if you 
 * need additional information or have any questions.
 */

package com.codename1.properties;

import com.codename1.io.Util;
import com.codename1.xml.Element;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;

/**
 * An XML element mapping to a property
 *
 * @author shai
 */
class PropertyXMLElement extends Element {
    private PropertyIndex parent;
    private int index = -1;
    private PropertyXMLElement parentElement;
    
    PropertyXMLElement(PropertyIndex parent) {
        this.parent = parent;
    }

    PropertyXMLElement(PropertyXMLElement parentElement, PropertyIndex parent) {
        this.parent = parent;
        this.parentElement = parentElement;
    }
    
    @Override
    public void addChild(Element childElement) {
        throw new IllegalStateException();
    }

    @Override
    public boolean contains(Element element) {
        if (this==element) {
            return true;
        }
        Vector children = getChildren();
        if (children != null) {
            int i=0;
            while (i iterator() {
        final int num = getNumChildren();
        return new Iterator() {
            private int offset = 0;
          
            @Override
            public boolean hasNext() {
                return offset < num;
            }

            @Override
            public Element next() {
                offset++;
                return getChildAt(index);
            }
            
            @Override
            public void remove() {
            }
        };
    }

    @Override
    public void removeChildAt(int index) {
        throw new RuntimeException();
    }

    @Override
    public void replaceChild(Element oldChild, Element newChild) {
        throw new RuntimeException();
    }

    @Override
    protected void setAttribute(Object id, String value) {
        throw new RuntimeException();
    }

    @Override
    public int setAttribute(String attribute, String value) {
        PropertyBase pb = parent.get(attribute);
        if(parent.setSimpleObject(pb, value)) {
            return -1;
        } 
        return 1;
    }

    @Override
    protected void setChildren(Vector children) {
        throw new RuntimeException();
    }

    @Override
    protected void setParent(Element parent) {
    }

    @Override
    protected void setTagName(String name) {
    }

    @Override
    public void setText(String str) {
    }

    @Override
    protected void setTextElement(boolean textElement) {
    }

    @Override
    public String toString() {
        return toString("");
    }

    @Override
    public String toString(String spacing) {

        String str=spacing;
        str+="<"+getTagName();
        Hashtable attributes = getAttributes();
        if (attributes!=null) {
            for(Enumeration e=attributes.keys();e.hasMoreElements();) {
                String attrStr=(String)e.nextElement();
                String val=(String)attributes.get(attrStr);
                str+=" "+attrStr+"='"+val+"'";
            }
        }
        str+=">\n";
        Vector children = getChildren();
        if (children!=null) {
            for(int i=0;i\n";
        return str;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy