/** This method looks for modifiers in attribute name (currently transient:). * * @param attrName original name of attribute * @param value original value - can be null * @return Object array with size 2. * If there are no modifiers in attribute name, then is returned Object array with * , where first is placed unchanged attribute name, and then uchanged value. * If there are modifiers in attribute name, then as attribute name is returned * stripped original attribute name (without modifiers) and ModifiedAttribute object, * that wraps original object and also contain modifiers. */ static Object[] translateInto(String attrName, Object value) { String newAttrName = attrName; Object newValue = value; ModifiedAttribute attr = null; for (int i = 0; i < fragments.length; i++) { String fragment = fragments[i]; int idx = newAttrName.indexOf(fragment); if (idx != -1) { /** fragment is cleared away */ newAttrName = newAttrName.substring(0, idx) + newAttrName.substring(idx + fragment.length()); if (attr == null) { newValue = attr = new ModifiedAttribute(value); } attr.modifier |= (1 << i); //set modifier } } return new Object[] { newAttrName, newValue }; }
Attr attr; String origAttrName = (String) attrName; Object[] keyValuePair = ModifiedAttribute.translateInto((String) attrName, null); attrName = (String) keyValuePair[0]; Object res = ((ModifiedAttribute) retVal).getValue(origAttrName);
newValue = attr = new ModifiedAttribute(value);
final void maybeAddSerValueComment(PrintWriter pw, String indent) { if (obj != null) { Object modifObj = null; if (obj instanceof ModifiedAttribute) { modifObj = ((Attr)((ModifiedAttribute)obj).getValue ()).getValue (); if (distinguishObject (modifObj) != Attr.isValid("SERIALVALUE")) //NOI18N return; } // Important for debugging to know what this stuff really is. // Note this comment is only written to disk when the attr is // first saved; after that successive saves will just know the // ser value and will not print the comment. So look at .nbattrs // immediately after setting something serialized. --jglick pw.print(indent); pw.print("<!-- "); // NOI18N String s = (modifObj != null) ? modifObj.toString():obj.toString(); if (s.indexOf("--") != -1) { // NOI18N // XML comment no-no. s = s.replace('-', '_'); // NOI18N } pw.print(s); pw.println(" -->"); // NOI18N } }
newValue = attr = new ModifiedAttribute(value);
final void maybeAddSerValueComment(PrintWriter pw, String indent) { if (obj != null) { Object modifObj = null; if (obj instanceof ModifiedAttribute) { modifObj = ((Attr)((ModifiedAttribute)obj).getValue ()).getValue (); if (distinguishObject (modifObj) != Attr.isValid("SERIALVALUE")) //NOI18N return; } // Important for debugging to know what this stuff really is. // Note this comment is only written to disk when the attr is // first saved; after that successive saves will just know the // ser value and will not print the comment. So look at .nbattrs // immediately after setting something serialized. --jglick pw.print(indent); pw.print("<!-- "); // NOI18N String s = (modifObj != null) ? modifObj.toString():obj.toString(); if (s.indexOf("--") != -1) { // NOI18N // XML comment no-no. s = s.replace('-', '_'); // NOI18N } pw.print(s); pw.println(" -->"); // NOI18N } }
private Object getAttribute (Object attrName, Object[] params) throws Exception { Attr attr; String origAttrName = (String)attrName; Object[] keyValuePair = ModifiedAttribute.translateInto((String)attrName,null); attrName = (String)keyValuePair[0]; synchronized (this) { attr = (Attr)map.get(attrName); } Object retVal = null; try { retVal = (attr == null)?attr : attr.get(params); } catch (Exception e) { ExternalUtil.annotate (e, "attrName = "+attrName); //NOI18N throw e; } if (retVal instanceof ModifiedAttribute) { Object res = ((ModifiedAttribute)retVal).getValue (origAttrName); if (res instanceof Attr) return ((Attr)res).get (params); else return res; } return retVal; }
private Object getAttribute (Object attrName, Object[] params) throws Exception { Attr attr; String origAttrName = (String)attrName; Object[] keyValuePair = ModifiedAttribute.translateInto((String)attrName,null); attrName = (String)keyValuePair[0]; synchronized (this) { attr = (Attr)map.get(attrName); } Object retVal = null; try { retVal = (attr == null)?attr : attr.get(params); } catch (Exception e) { ExternalUtil.annotate (e, "attrName = "+attrName); //NOI18N throw e; } if (retVal instanceof ModifiedAttribute) { Object res = ((ModifiedAttribute)retVal).getValue (origAttrName); if (res instanceof Attr) return ((Attr)res).get (params); else return res; } return retVal; }
static boolean isTransient (FileObject fo, String attrName) { return XMLMapAttr.ModifiedAttribute.isTransient (fo, attrName); }
final String getValueForPrint() { if (obj != null) { Attr modifAttr = null; if (obj instanceof ModifiedAttribute) modifAttr = (Attr)((ModifiedAttribute)obj).getValue (); return (modifAttr != null) ? encode(modifAttr.getValue ()) : encode(getValue ()); } return (value != null)?encode(value) : ""; // NOI18N }
/** ModifiedAttribute holds original value + modifiers. This method returns original value. * @return then returns original value */ Object getValue() { return getValue("");//NOI18N }
final String getKeyForPrint() { if (obj != null && obj instanceof ModifiedAttribute) { Attr modifAttr = (Attr)((ModifiedAttribute)obj).getValue (); int keyIdx = Attr.isValid ("SERIALVALUE");//NOI18N if (modifAttr != null) keyIdx = distinguishObject (modifAttr.getValue ()); String keyArray[] = getAttrTypes(); return keyArray[keyIdx]; } return getKey (); }
final String getAttrNameForPrint (String attrName) { if (obj != null && obj instanceof ModifiedAttribute) { Object[] retVal = ModifiedAttribute.revert(attrName,obj); return encode ((String)retVal[0]); } return encode (attrName); }
static boolean isTransient (FileObject fo, String attrName) { return XMLMapAttr.ModifiedAttribute.isTransient (fo, attrName); }
final String getValueForPrint() { if (obj != null) { Attr modifAttr = null; if (obj instanceof ModifiedAttribute) modifAttr = (Attr)((ModifiedAttribute)obj).getValue (); return (modifAttr != null) ? encode(modifAttr.getValue ()) : encode(getValue ()); } return (value != null)?encode(value) : ""; // NOI18N }
final String getAttrNameForPrint (String attrName) { if (obj != null && obj instanceof ModifiedAttribute) { Object[] retVal = ModifiedAttribute.revert(attrName,obj); return encode ((String)retVal[0]); } return encode (attrName); }
synchronized Object put(final Object p1, final Object p2, boolean decode) { if (p1 == null || !(p1 instanceof String)) return null; Object[] keyValuePair = ModifiedAttribute.translateInto((String) p1, p2); String key = (String) keyValuePair[0]; Object value = keyValuePair[1]; Object toStore = (value == null || value instanceof Attr) ? value : new Attr(value); if (decode) { key = Attr.decode((String) key).intern(); } return map.put(key, toStore); }
/** ModifiedAttribute holds original value + modifiers. This method returns original value. * @return then returns original value */ Object getValue() { return getValue("");//NOI18N }
final String getKeyForPrint() { if (obj != null && obj instanceof ModifiedAttribute) { Attr modifAttr = (Attr)((ModifiedAttribute)obj).getValue (); int keyIdx = Attr.isValid ("SERIALVALUE");//NOI18N if (modifAttr != null) keyIdx = distinguishObject (modifAttr.getValue ()); String keyArray[] = getAttrTypes(); return keyArray[keyIdx]; } return getKey (); }
synchronized Object put(final Object p1, final Object p2, boolean decode) { if (p1 == null || !(p1 instanceof String)) return null; Object[] keyValuePair = ModifiedAttribute.translateInto((String) p1, p2); String key = (String) keyValuePair[0]; Object value = keyValuePair[1]; Object toStore = (value == null || value instanceof Attr) ? value : new Attr(value); if (decode) { key = Attr.decode((String) key).intern(); } return map.put(key, toStore); }