XML no longer implements Wrapper interface. Instead getXmlObject method

is added to access the implementation. In this way all functionality
of Java API in XmlObject is available to scripts if they need it.
This commit is contained in:
igor%mir2.org 2004-11-10 23:13:04 +00:00
Родитель f935a248be
Коммит d41bf7368b
3 изменённых файлов: 34 добавлений и 18 удалений

Просмотреть файл

@ -50,7 +50,7 @@ import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlOptions;
class XML extends XMLObjectImpl implements Wrapper class XML extends XMLObjectImpl
{ {
final static class XScriptAnnotation extends XmlBookmark final static class XScriptAnnotation extends XmlBookmark
{ {
@ -256,8 +256,6 @@ class XML extends XMLObjectImpl implements Wrapper
frag = ((XMLObjectImpl) inputObject).toXMLString(0); frag = ((XMLObjectImpl) inputObject).toXMLString(0);
} else { } else {
if (inputObject instanceof Wrapper) { if (inputObject instanceof Wrapper) {
// Note: the check has to be done after the check for
// XMLObjectImpl as XML also implements Wrapper
Object wrapped = ((Wrapper)inputObject).unwrap(); Object wrapped = ((Wrapper)inputObject).unwrap();
if (wrapped instanceof XmlObject) { if (wrapped instanceof XmlObject) {
return createFromXmlObject(lib, (XmlObject)wrapped); return createFromXmlObject(lib, (XmlObject)wrapped);
@ -3065,11 +3063,7 @@ todo need to handle namespace prefix not found in XML look for namespace type in
return null; return null;
} }
// XmlObject getXmlObject()
// Implementation of Wrapper
//
public Object unwrap()
{ {
XmlObject xo; XmlObject xo;
XmlCursor cursor = newCursor(); XmlCursor cursor = newCursor();
@ -3080,5 +3074,4 @@ todo need to handle namespace prefix not found in XML look for namespace type in
} }
return xo; return xo;
} }
} }

Просмотреть файл

@ -1563,6 +1563,15 @@ class XMLList extends XMLObjectImpl implements Function
} }
} }
org.apache.xmlbeans.XmlObject getXmlObject()
{
if (length() == 1) {
return getXmlFromAnnotation(0).getXmlObject();
} else {
throw ScriptRuntime.typeError("getXmlObject method works only on lists containing one item");
}
}
/** /**
* See ECMA 357, 11_2_2_1, Semantics, 3_e. * See ECMA 357, 11_2_2_1, Semantics, 3_e.
*/ */

Просмотреть файл

@ -131,6 +131,11 @@ abstract class XMLObjectImpl extends XMLObject
abstract String toXMLString(int indent); abstract String toXMLString(int indent);
abstract Object valueOf(); abstract Object valueOf();
/**
* Extension to access native implementation from scripts
*/
abstract org.apache.xmlbeans.XmlObject getXmlObject();
protected abstract Object jsConstructor(Context cx, boolean inNewExpr, protected abstract Object jsConstructor(Context cx, boolean inNewExpr,
Object[] args); Object[] args);
@ -373,12 +378,14 @@ abstract class XMLObjectImpl extends XMLObject
Id_toXMLString = 39, Id_toXMLString = 39,
Id_valueOf = 40, Id_valueOf = 40,
MAX_PROTOTYPE_ID = 40; Id_getXmlObject = 41,
MAX_PROTOTYPE_ID = 41;
protected int findPrototypeId(String s) protected int findPrototypeId(String s)
{ {
int id; int id;
// #generated# Last update: 2004-08-21 11:02:57 CEST // #generated# Last update: 2004-11-10 15:38:11 CET
L0: { id = 0; String X = null; int c; L0: { id = 0; String X = null; int c;
L: switch (s.length()) { L: switch (s.length()) {
case 4: c=s.charAt(0); case 4: c=s.charAt(0);
@ -421,15 +428,15 @@ abstract class XMLObjectImpl extends XMLObject
case 's': X="setChildren";id=Id_setChildren; break L; case 's': X="setChildren";id=Id_setChildren; break L;
case 't': X="toXMLString";id=Id_toXMLString; break L; case 't': X="toXMLString";id=Id_toXMLString; break L;
} break L; } break L;
case 12: c=s.charAt(0); case 12: switch (s.charAt(0)) {
if (c=='a') { X="addNamespace";id=Id_addNamespace; } case 'a': X="addNamespace";id=Id_addNamespace; break L;
else if (c=='p') { X="prependChild";id=Id_prependChild; } case 'g': X="getXmlObject";id=Id_getXmlObject; break L;
else if (c=='s') { case 'p': X="prependChild";id=Id_prependChild; break L;
c=s.charAt(3); case 's': c=s.charAt(3);
if (c=='L') { X="setLocalName";id=Id_setLocalName; } if (c=='L') { X="setLocalName";id=Id_setLocalName; }
else if (c=='N') { X="setNamespace";id=Id_setNamespace; } else if (c=='N') { X="setNamespace";id=Id_setNamespace; }
}
break L; break L;
} break L;
case 14: X="hasOwnProperty";id=Id_hasOwnProperty; break L; case 14: X="hasOwnProperty";id=Id_hasOwnProperty; break L;
case 15: X="removeNamespace";id=Id_removeNamespace; break L; case 15: X="removeNamespace";id=Id_removeNamespace; break L;
case 16: c=s.charAt(0); case 16: c=s.charAt(0);
@ -510,6 +517,8 @@ abstract class XMLObjectImpl extends XMLObject
case Id_toSource: arity=1; s="toSource"; break; case Id_toSource: arity=1; s="toSource"; break;
case Id_toXMLString: arity=1; s="toXMLString"; break; case Id_toXMLString: arity=1; s="toXMLString"; break;
case Id_valueOf: arity=0; s="valueOf"; break; case Id_valueOf: arity=0; s="valueOf"; break;
case Id_getXmlObject: arity=0; s="getXmlObject"; break;
default: throw new IllegalArgumentException(String.valueOf(id)); default: throw new IllegalArgumentException(String.valueOf(id));
} }
initPrototypeMethod(XMLOBJECT_TAG, id, s, arity); initPrototypeMethod(XMLOBJECT_TAG, id, s, arity);
@ -693,6 +702,11 @@ abstract class XMLObjectImpl extends XMLObject
} }
case Id_valueOf: case Id_valueOf:
return realThis.valueOf(); return realThis.valueOf();
case Id_getXmlObject: {
org.apache.xmlbeans.XmlObject xmlObject = realThis.getXmlObject();
return Context.javaToJS(xmlObject, scope);
}
} }
throw new IllegalArgumentException(String.valueOf(id)); throw new IllegalArgumentException(String.valueOf(id));
} }