/** * Attributes definition live in the BeanProp object while attribute * values live in the DOMBinding objects. */ public void createAttribute(String dtdName, String name, int type, String[] values, String defValue) { AttrProp ap = new AttrProp(this.dtdName, dtdName, name, type, values, defValue); this.attributes.add(ap); if (DDLogFlags.debug) { TraceLogger.put(TraceLogger.DEBUG, TraceLogger.SVC_DD, DDLogFlags.DBG_BLD, 5, DDLogFlags.CREATEATTR, this.beanName + ": " + ap.toString()); } }
public void addExtraDataCurLink(Object data) { //System.out.println("** addExtraDataCurLink: data="+data+" curParentGroup.name="+((curParentGroup == null) ? "curParentGroup null" : curParentGroup.name)); if (curElementType == Common.ATTLIST) { //System.out.println("curElementType == Common.ATTLIST, curAttr="+curAttr); if (curAttr != null) curAttr.addExtraData(data); } else { //System.out.println("lastChild="+curParentGroup.getLastChild()); if (curParentGroup != null && curParentGroup.getLastChild() != null) { curParentGroup.getLastChild().extraData.add(data); } } }
/** * Called each time a character | is found. */ public void character(char c) { //System.out.println("character: c="+c+" curParentGroup="+curParentGroup); if (this.curElementType == Common.ELEMENT) { if (c == '|') curParentGroup.setSequence(Common.SEQUENCE_OR); } else if (this.curElementType == Common.ATTLIST) { if (c == '|') { this.curAttr.checkEnum(); } } }
String name; if (directChild) name = Common.convertName(attr.getName()); else name = Common.convertName(propertyName+"_"+attr.getName()); if (usedNames.containsKey(name)) { int uniqNum = 2; while (usedNames.containsKey(name = baseName + uniqNum)) uniqNum++; attr.setName(name); config.messageOut.println(Common.getMessage("RenamedProperty_msg", baseName, name, propertyName)); String javaType = attr.getJavaType(); int type; if (javaType == null) { List extraData = attr.getExtraData(); String namespace = attr.getNamespace(); bc.addProperty(name, attr.getDtdName(), namespace, null, null, javaType, 0, attr.getInstance(), groupInstance, type, null, Common.constName(name), attr.getDefaultValue(), directChild, extraData, false)
if (ap.isFixed() && (ap.defaultValue == null || !ap.defaultValue.equals(value))) throw new IllegalStateException(Common. getMessage("CannotChangeFIXEDAttribute_msg")); if (ap.isEnum() && (value != null)) { String[] values = ap.getValues(); boolean found = false; for (int i=0; i<values.length; i++) { throw new IllegalArgumentException(Common. getMessage("ValueDoesNotMatchEnumValues_msg", value, ap.enumsToString())); Object oldValue = b.getAttributeValue(this, ap.getDtdName()); b.setAttributeValue(this, ap.getDtdName(), normalizedAttrValue(value));
if (this.curAttr.isComplete()) throw new DocDefParser.MissingEndOfEltException(curAttr.getPropertyName()); this.curAttr.setDefaultValue(defaultValue); this.curAttr.addValue(attrName, attrNamespace); if (externalType) curAttr.setJavaType(typeName);
void genAttribute(String name, AttrProp attr) { String constName = Common.constName(attr.getDtdName()); gen("this.createAttribute("); if (name != null) gen(name, ", "); gen("\"", attr.getDtdName(), "\", "); gen("\"", attr.getName(), "\", "); cr(); gentab(4); gencr(attr.typeAsString(), ","); gentab(4); String[] values = attr.getValues(); if (values.length > 0) { gencr("new String[] {"); for (int k=0; k<values.length; k++) { if (k>0) gencr(","); gentab(5); gen("\"", values[k], "\""); } cr(); gentab(4); gen("}, "); } else gen("null, "); String value = attr.getDefaultValue(); if (value != null) gen("\"", value, "\")"); else gen("null)"); eol(); }
if (value.charAt(0) == '"') { // NOI18N if (valueLen == 1) failed(Common.getMessage("TooLittleDeclaration_msg", value)); value = value.substring(1, value.length()-1); } else if (value.charAt(0) == '\'') { // NOI18N if (valueLen == 1) failed(Common.getMessage("TooLittleDeclaration_msg", value)); value = value.substring(1, value.length()-1); case NEED_TYPE: this.type = this.stringToInt(value, kinds, kindValues); this.state = NEED_OPTION; if (this.type == -1) this.failed(Common.getMessage("UnknownType_msg", value)); break; case NEED_ENUM: break; case NEED_OPTION: int opt = this.stringToInt(value, options, optionValues); if (opt != -1) { this.type |= opt; break; case DONE: this.failed(Common.getMessage("TooMuchDeclaration_msg"));
public void validate() { // Called at the end of the element parsing if (this.state != DONE) this.failed(Common.getMessage("BadAttributeDecl_msg")); }
protected int dumpAttributes(GraphNode elt, StringBuffer str, String indent, int lineCount) { AttrProp[] attrList = elt.getAttributes(); for (int i = 0; i < attrList.length; i++) { AttrProp attr = attrList[i]; str.append(indent + "[attr: " + attr + "]"); if (!attr.getExtraData().isEmpty()) { str.append(" \t"); str.append(attr.getExtraData().toString()); } str.append("\n"); ++lineCount; } if (false && elt.getExtension() != null) lineCount = dumpAttributes(elt.getExtension(), str, indent, lineCount); return lineCount; }
/** * Get the attribute value */ public String getAttributeValue(int index, String name) { String ret = null; AttrProp ap = this.getAttrProp(name); if (!Common.isArray(this.type)) { // Value not set for single type property - return null if ((index > 0) || (this.bindingsSize() == 0)) return null; } DOMBinding b = (DOMBinding)this.bindings.get(index); if (b != null) ret = b.getAttributeValue(this, ap.getDtdName()); if (DDLogFlags.debug) { TraceLogger.put(TraceLogger.DEBUG, TraceLogger.SVC_DD, DDLogFlags.DBG_BLD, 10, DDLogFlags.GETATTR, this.beanName + "[" + index + "]." + ap.getDtdName() + ": " + ret + " " + ((b==null)?"<no binding>":("B("+b.hashCode()+")"))+ " BP(" + this.hashCode() + ")"); } return ret; }
curAttr = new AttrProp(typeName); node.addAttribute(curAttr);
public void checkEnum() { // Called when a | is found if (this.enumMode == 0) this.failed(Common.getMessage("UseCharORWithEnum_msg")); }
/** * When the bean tree is built from an XML document and an attribute * not defined in the DTD is found, the attribute is dynamically added * to the list of defined attribute with the TRANSIENT status. */ public void createTransientAttribute(String dtdName) { // Add the attribute only if we don't know about it AttrProp ap = this.getAttrProp(dtdName, true); if (ap != null) return; ap = new AttrProp(this.dtdName, dtdName, Common.convertName(dtdName), AttrProp.CDATA | AttrProp.IMPLIED | AttrProp.TRANSIENT, null, null); this.attributes.add(ap); if (DDLogFlags.debug) { TraceLogger.put(TraceLogger.DEBUG, TraceLogger.SVC_DD, DDLogFlags.DBG_BLD, 5, DDLogFlags.CREATEATTR, this.beanName + ": " + ap.toString()); } }
public void setEnum(boolean enume) { enumMode += (enume?1:-1); if (enumMode == 1) { if (this.values == null) this.values = new ArrayList(); this.type = ENUM; this.state = NEED_ENUM; } else if (enumMode == 0) { this.state = NEED_OPTION; } else this.failed(Common.getMessage("WrongEnumDecl_msg")); }
public void addExtraDataCurLink(Object[] data) { //System.out.println("** addExtraDataCurLink: data="+data+" curParentGroup.name="+((curParentGroup == null) ? "curParentGroup null" : curParentGroup.name)); if (curElementType == Common.ATTLIST) { //System.out.println("curElementType == Common.ATTLIST, curAttr="+curAttr); if (curAttr != null && data != null) for (int i=0; i < data.length; i++) curAttr.addExtraData(data[i]); } else { //System.out.println("lastChild="+curParentGroup.getLastChild()); if (curParentGroup != null && curParentGroup.getLastChild() != null) { if (data != null) for (int i=0; i < data.length; i++) curParentGroup.getLastChild().extraData.add(data[i]); } } }