From: Steve L. <st...@us...> - 2005-11-25 17:18:52
|
Update of /cvsroot/smartfrog/core/components/deployapi/src/org/smartfrog/services/deployapi/binding/xmlbeans In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26525/components/deployapi/src/org/smartfrog/services/deployapi/binding/xmlbeans Added Files: Axis2Beans.java BeanUtils.java EndpointBinding.java package.html Log Message: purging nearly all xmlbeans support, the build is broken. integrating with the new CDL tests. --- NEW FILE: package.html --- <html> <head>beans</head> <body> this package contains nothing but bean related stuff. As beans are no longer needed, this stuff is surpus and should be excluded from builds that dont contain the xmlbean classes </body> </html> --- NEW FILE: Axis2Beans.java --- /** (C) Copyright 2005 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.services.deployapi.binding.xmlbeans; import org.apache.axis2.client.StreamWrapper; import org.apache.axis2.om.OMAbstractFactory; import org.apache.axis2.om.OMElement; import org.apache.axis2.om.OMFactory; import org.apache.axis2.om.OMXMLParserWrapper; import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; import org.smartfrog.services.deployapi.system.Utils; import org.smartfrog.services.deployapi.transport.faults.BaseException; import javax.xml.stream.XMLStreamReader; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; /** * Convert axis2 stuff into a an XMLBean * @deprecated */ public class Axis2Beans<T extends XmlObject> { /** * generation-time options */ private XmlOptions options; /** * Error when things are of the wrong type */ public static final String ERROR_WRONG_TYPE = "Cannot convert XML because it is of the incompatible type "; public Axis2Beans() { } public Axis2Beans(XmlOptions options) { this.options = options; } public XmlOptions getOptions() { return options; } public T convert(OMElement element) { XMLStreamReader reader = element.getXMLStreamReader(); try { XmlObject xmlObject = T.Factory.parse(reader); T t; try { t = (T) xmlObject; } catch (ClassCastException e) { throw new BaseException(ERROR_WRONG_TYPE + xmlObject); } return t; } catch (XmlException e) { throw new BaseException(e); } } /** * Convert a message to the body of the response. * * @param document * @return a converted file * @throws BaseException if there is trouble */ public OMElement convert(T document) { return convertIntermediateDoc(document); //return convertDirect(document); } /** * convert a doc * * @param document * @return the converted doc * @throws BaseException if there is trouble */ public static OMElement convertDocument(XmlObject document) { return convertIntermediateDoc(document); } /** * convert a doc * * @param document * @return the converted doc * @throws BaseException if there is trouble */ private static OMElement convertIntermediateDoc(XmlObject document) { try { StringWriter writer = new StringWriter(); XmlOptions writeOptions = new XmlOptions(); writeOptions.setSaveOuter(); writeOptions.setSaveUseOpenFrag(); document.save(writer, writeOptions); writer.close(); String textForm = writer.toString(); return Utils.loadAxiomFromString(textForm); } catch (IOException e) { throw new BaseException(e); } } /** * Convert a message to the body of the response. * * @param document * @return a converted file */ protected OMElement convertDirect(T document) { XmlOptions writeOptions = new XmlOptions(); //writeOptions.setSaveOuter(); writeOptions.setSaveUseOpenFrag(); XMLStreamReader reader = document.newXMLStreamReader(writeOptions); StreamWrapper streamWrapper = new StreamWrapper(reader); OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(getOMFactory(), streamWrapper); //get the root element (in this case the envelope) OMElement elt = builder.getDocumentElement(); elt.build(); return elt; } private OMXMLParserWrapper createBuilder(XMLStreamReader reader) { OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(getOMFactory(), reader); return builder; } private OMFactory getOMFactory() { return OMAbstractFactory.getOMFactory(); } public T loadBeansFromResource(String resource) throws XmlException, IOException { InputStream stream = loadResource(resource); return (T) T.Factory.parse(stream); } private InputStream loadResource(String resource) { InputStream stream = this.getClass().getClassLoader().getResourceAsStream(resource); if (stream == null) { throw new BaseException("Resource missing: " + resource); } return stream; } } --- NEW FILE: EndpointBinding.java --- /** (C) Copyright 2005 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.services.deployapi.binding.xmlbeans; import org.apache.axis2.AxisFault; import org.apache.axis2.om.OMElement; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; import org.smartfrog.services.deployapi.client.ApiCall; import org.smartfrog.services.deployapi.client.Endpointer; import org.smartfrog.services.deployapi.transport.faults.BaseException; import org.smartfrog.services.deployapi.binding.xmlbeans.Axis2Beans; import javax.xml.namespace.QName; import java.rmi.RemoteException; /** * One stop class to create both the in and out bindings for an endpoint. * created 20-Sep-2005 17:09:45 */ public abstract class EndpointBinding<Tin extends XmlObject,Tout extends XmlObject> { private Axis2Beans<Tin> in; private Axis2Beans<Tout> out; private QName operation; public EndpointBinding(XmlOptions inOptions, XmlOptions outOptions) { in = new Axis2Beans<Tin>(inOptions); out = new Axis2Beans<Tout>(outOptions); } public EndpointBinding() { this(null, null); } public QName getOperation() { return operation; } public void setOperation(QName operation) { this.operation = operation; } public void setOperation(String namespace, String localpart) { this.operation = new QName(namespace, localpart); } public Axis2Beans<Tin> getRequestBinding() { return in; } public Axis2Beans<Tout> getResponseBinding() { return out; } public Tin convertRequest(OMElement element) { return in.convert(element); } public OMElement convertRequest(Tin data) { return in.convert(data); } public Tout convertResponse(OMElement element) { return out.convert(element); } public OMElement convertResponse(Tout data) { return out.convert(data); } /** * create a request object * * @return a request */ public abstract Tin createRequest(); /** * create a request object * * @return a response */ public abstract Tout createResponse(); /** * Invoke the call in a blocking operation with our payload * * @param call * @param operation * @param data * @return the response * @throws AxisFault */ public Tout invokeBlocking(ApiCall call, String operation, Tin data) throws AxisFault { final OMElement toSend = convertRequest(data); OMElement omElement = call.invokeBlocking(operation, toSend); return convertResponse(omElement); } /** * Invoke the call in a blocking operation with our payload * * @param endpointer * @param data * @return the response * @throws AxisFault */ public Tout invokeBlocking(Endpointer endpointer, String operation, Tin data) throws RemoteException { ApiCall call = endpointer.createStub(operation); if(call.lookupOperation(operation)==null) { throw new BaseException("No operation "+operation+" on endpointer "+endpointer); } return invokeBlocking(call, operation, data); } public XmlOptions getInOptions() { return in.getOptions(); } public XmlOptions getOutOptions() { return out.getOptions(); } } --- NEW FILE: BeanUtils.java --- /** (C) Copyright 2005 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ package org.smartfrog.services.deployapi.binding.xmlbeans; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.addressing.ServiceName; import org.apache.axis2.addressing.AnyContentType; import org.smartfrog.services.deployapi.transport.faults.FaultRaiser; import org.w3c.dom.Node; import java.util.ArrayList; import nu.xom.Element; import nu.xom.converters.DOMConverter; /** * This is only for use with beans * created 25-Nov-2005 16:23:09 */ public class BeanUtils { /** * We are invalid. * * @param message * @throws org.smartfrog.services.deployapi.transport.faults.DeploymentException * * @returns true for use in conditional code * @deprecated */ public static boolean validate(XmlObject message) { ArrayList validationErrors = new ArrayList(); XmlOptions validationOptions = new XmlOptions(); validationOptions.setErrorListener(validationErrors); if (!message.validate(validationOptions)) { message.dump(); throw FaultRaiser.raiseBadArgumentFault("XML did not validate against the schema"); } return true; } /** * validate documents iff assertions are enabled * * @param message * @deprecated */ public static void maybeValidate(XmlObject message) { assert validate(message); } /** * Turn a bean (which must map to an element, unless you like runtime exceptions * @param bean to convert * @return the converted doc * @deprecated */ public static Element beanToXom(XmlObject bean) { Node dom = bean.getDomNode(); org.w3c.dom.Element elt=(org.w3c.dom.Element)dom; return DOMConverter.convert(elt); } public static EndpointReference Wsa2003ToEPR(EndpointReferenceType source) { AttributedURI addrURI = source.getAddress(); EndpointReference dest = new EndpointReference(addrURI.getStringValue()); if(source.isSetServiceName()) { ServiceNameType sourceServiceName = source.getServiceName(); ServiceName destServiceName=new ServiceName(sourceServiceName.getQNameValue(), sourceServiceName.getPortName()); dest.setServiceName(destServiceName); } if(source.isSetReferenceProperties()) { ReferencePropertiesType props = source.getReferenceProperties(); props.newCursor(); dest.getReferenceParameters(); AnyContentType content=new AnyContentType(); //TODO: reference properties are not currently supported } return dest; } public static EndpointReferenceType EPRToWsa2003(EndpointReference source) { EndpointReferenceType dest = EndpointReferenceType.Factory.newInstance(); dest.addNewAddress().setStringValue(source.getAddress()); ServiceName serviceName = source.getServiceName(); if(serviceName!=null) { ServiceNameType destServiceName = dest.addNewServiceName(); destServiceName.setPortName(serviceName.getEndpointName()); destServiceName.setQNameValue(serviceName.getName()); } //TODO: reference properties are not currently supported return dest; } public static EndpointReference Wsa2004ToEPR(org.ggf.xbeans.cddlm.wsrf.wsa2004.EndpointReferenceType source) { org.ggf.xbeans.cddlm.wsrf.wsa2004.AttributedURI addrURI = source.getAddress(); EndpointReference dest = new EndpointReference(addrURI.getStringValue()); org.ggf.xbeans.cddlm.wsrf.wsa2004.ReferencePropertiesType props = source.getReferenceProperties(); //TODO: reference properties are not currently supported return dest; } public static org.ggf.xbeans.cddlm.wsrf.wsa2004.EndpointReferenceType EPRToWsa2004(EndpointReference source) { org.ggf.xbeans.cddlm.wsrf.wsa2004.EndpointReferenceType dest = org.ggf.xbeans.cddlm.wsrf.wsa2004.EndpointReferenceType.Factory.newInstance(); dest.addNewAddress().setStringValue(source.getAddress()); //TODO: reference properties are not currently supported return dest; } /** * copy a source to a dest * @param source */ public static void copyInto(org.ggf.xbeans.cddlm.wsrf.wsa2004.EndpointReferenceType source, EndpointReferenceType dest) { org.ggf.xbeans.cddlm.wsrf.wsa2004.AttributedURI address = source.getAddress(); dest.addNewAddress().setStringValue(address.getStringValue()); AttributedQName portType = source.getPortType(); dest.addNewPortType().setQNameValue(portType.getQNameValue()); org.ggf.xbeans.cddlm.wsrf.wsa2004.ServiceNameType serviceName = source.getServiceName(); dest.addNewServiceName().setPortName(serviceName.getPortName()); org.ggf.xbeans.cddlm.wsrf.wsa2004.ReferencePropertiesType sourceProperties = source.getReferenceProperties(); ReferencePropertiesType destProperties = dest.addNewReferenceProperties(); //TODO } } |