alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.schema2beans;


import java.util.*;

/**
 *  This class hold the information about a property attribute.
 *
 *  This class is used by the TreeBuilder to build a representation of the
 *  attributes, by the BeanClass to convert these information into
 *  generated attribute code, and by the BeanProp class to hold at runtime
 *  the information about the attributes of a property.
 *
 */
public class AttrProp implements BaseAttribute {
    
    static public final int MASK_KIND 		= 0x00FF;
    static public final int CDATA 		= 0x0001;
    static public final int ENUM 		= 0x0002;
    static public final int NMTOKEN 		= 0x0003;
    static public final int ID 			= 0x0004;
    static public final int IDREF 		= 0x0005;
    static public final int IDREFS 		= 0x0006;
    static public final int ENTITY 		= 0x0007;
    static public final int ENTITIES 		= 0x0008;
    static public final int NOTATION 		= 0x0009;
    
    static final String[] kinds =
	new String[] {"CDATA", "ENUM", "NMTOKEN", "ID", "IDREF",	// NOI18N
		      "IDREFS", "ENTITY", "ENTITIES", "NOTATION"};	// NOI18N
    
    static final int[] kindValues =
	new int[] {CDATA, ENUM, NMTOKEN, ID, IDREF,
		   IDREFS, ENTITY, ENTITIES, NOTATION};
    
    static public final int MASK_OPTION 	= 0x0F00;
    static public final int REQUIRED 		= 0x0100;
    static public final int IMPLIED 		= 0x0200;
    static public final int FIXED 		= 0x0300;
    
    static public final int TRANSIENT		= 0x1000;
    
    static final String[] options =
        new String[] {"#REQUIRED", "#IMPLIED", "#FIXED"};	// NOI18N
    
    static final int[] optionValues = new int[] {REQUIRED, IMPLIED, FIXED};
    
    //	Property this attribure belongs to
    String		propertyName;
    
    //	Name of the attribute
    String 		name;
    
    //	Name of the attribute
    String 		dtdName;

    String 		namespace;
    
    //	Its type (CDATA, ID, ...)
    int			type;

    // Proposed java class for it.
    String javaType;
    
    //	Enum values if any (null if none)
    ArrayList		values;
    
    //	The default value of the attribute
    String		defaultValue;

    //
    //	The attribute content is populated only calling addValue()
    //	assuming it is built from a left to right parsing. This state
    //	is used to know which value is being added.
    //
    private int		state;
    
    private int 	enumMode;

    private List extraData;
    //private GraphNode sourceGraphNode;
    
    //	The state values when the attribute is populated
    private static final int NEED_NAME 		= 0;
    private static final int NEED_TYPE		= 1;
    private static final int NEED_ENUM		= 2;
    private static final int NEED_OPTION	= 3;
    private static final int NEED_DEFVAL	= 4;
    private static final int NEED_VALUE		= 5;
    private static final int DONE		= 6;
    
    public AttrProp() {
        this.values = null;
        this.state = NEED_NAME;
        this.type = 0;
        this.enumMode = 0;
    }
    
    public AttrProp(String propName) {
        this();
        this.propertyName = propName;
    }
    
    public AttrProp(String propName, String dtdName, String name, int type,
                    String[] values, String defValue) {
			
        this.dtdName = dtdName;
        this.name = name;
        this.propertyName = propName;
	
        if (values != null && values.length > 0) {
            this.values = new ArrayList();
            for (int i=0; i 0)
            return (String[])this.values.toArray(ret);
        else
            return ret;
    }

    public void setDefaultValue(String d) {
        defaultValue = d;
    }
    
    public String getDefaultValue() {
        return this.defaultValue;
    }
    
    public String getPropertyName() {
	return this.propertyName;
    }
    
    public String getName() {
        return this.name;
    }

    public void setName(String n) {
        name = n;
    }
    /*
    public void setSourceGraphNode(GraphNode node) {
        sourceGraphNode = node;
    }

    public GraphNode getSourceGraphNode() {
        return sourceGraphNode;
    }
    */
    
    public String getDtdName() {
        return this.dtdName;
    }

    public String getNamespace() {
        return this.namespace;
    }
    
    public String typeAsString() {
        String str = "AttrProp." +		// NOI18N
            intToString(this.type & MASK_KIND, kinds, kindValues);
	
        int opt = this.type & MASK_OPTION;
        if (opt != 0) {
            str += " | " + "AttrProp." +	// NOI18N
                intToString(opt, options, optionValues).substring(1);
        }
	
        return str;
    }
    
    String enumsToString() {
        String[] e = this.getValues();
        StringBuffer ret = new StringBuffer();
        for (int i=0; i
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.