Refine search
public static Object unmarshall(JAXBContext c, XMLStreamReader reader) throws JAXBException { Unmarshaller u = c.createUnmarshaller(); try { u.setEventHandler(null); return u.unmarshal(reader); } finally { closeUnmarshaller(u); } }
private void processHandlerElement(Element el, List<Handler> chain) { try { JAXBContext ctx = getContextForPortComponentHandlerType(); PortComponentHandlerType pt = JAXBUtils.unmarshall(ctx, el, PortComponentHandlerType.class).getValue(); chain.addAll(buildHandlerChain(pt, classLoader)); } catch (JAXBException e) { throw new IllegalArgumentException("Could not unmarshal handler chain", e); } }
/** * Constructs a JAXBAssertionBuilder from the QName of the schema type * @param qn the schema type * @throws JAXBException * @throws ClassNotFoundException */ public JaxbAssertionBuilder(QName qn) throws JAXBException, ClassNotFoundException { this(JAXBUtils.namespaceURIToPackage(qn.getNamespaceURI()) + "." + JAXBUtils.nameToIdentifier(qn.getLocalPart(), JAXBUtils.IdentifierType.CLASS), qn); }
/** * Convert from EndpointReference to CXF internal 2005/08 EndpointReferenceType * * @param external the javax.xml.ws.EndpointReference * @return CXF internal 2005/08 EndpointReferenceType */ public static EndpointReferenceType convertToInternal(EndpointReference external) { if (external instanceof W3CEndpointReference) { Unmarshaller um = null; try { DocumentFragment frag = DOMUtils.getEmptyDocument().createDocumentFragment(); DOMResult result = new DOMResult(frag); external.writeTo(result); W3CDOMStreamReader reader = new W3CDOMStreamReader(frag); // CXF internal 2005/08 EndpointReferenceType should be // compatible with W3CEndpointReference //jaxContext = ContextUtils.getJAXBContext(); JAXBContext context = JAXBContext .newInstance(new Class[] {org.apache.cxf.ws.addressing.ObjectFactory.class}); um = context.createUnmarshaller(); return um.unmarshal(reader, EndpointReferenceType.class).getValue(); } catch (JAXBException e) { throw new IllegalArgumentException("Could not unmarshal EndpointReference", e); } finally { JAXBUtils.closeUnmarshaller(um); } } return null; }
private QName getTypeQName(Class<?> cls, String namespace) { QName qn = TYPE_MAP.get(cls); if (qn != null) { return qn; } XmlType xtype = cls.getAnnotation(XmlType.class); String tn = xtype == null ? "##default" : xtype.name(); String tns = xtype == null ? "##default" : xtype.namespace(); if ("##default".equals(tn)) { tn = java.beans.Introspector.decapitalize(cls.getSimpleName()); } if ("##default".equals(tns) || StringUtils.isEmpty(tns)) { tns = JAXBUtils.getPackageNamespace(cls); } if ("##default".equals(tns) || StringUtils.isEmpty(tns)) { tns = namespace; } return new QName(tns, tn); } private XmlSchemaType mapToSchemaType(Class<?> cls, String namespace) {
public W3CEndpointReference run() throws Exception { Unmarshaller unmarshaller = getJAXBContext().createUnmarshaller(); try { return (W3CEndpointReference)unmarshaller.unmarshal(writer.getDocument()); } finally { JAXBUtils.closeUnmarshaller(unmarshaller); } } });
Object obj = JAXBUtils.unmarshall(context, doc.getDocumentElement()); if (obj instanceof JAXBElement) { obj = ((JAXBElement)obj).getValue(); || h.getTypes().contains(new QName("", WSDiscoveryClient.SERVICE_QNAME.getLocalPart()))) { ByeType h = (ByeType)obj; if (h.getTypes().contains(WSDiscoveryClient.SERVICE_QNAME) || h.getTypes().contains(new QName("", WSDiscoveryClient.SERVICE_QNAME.getLocalPart()))) { e.printStackTrace(); } catch (XMLStreamException e1) {
String name = mpi.getName().getLocalPart(); Class<?> clz = mpi.getTypeClass(); Object obj = mpi.getProperty(ReflectionServiceFactoryBean.RAW_CLASS); av0.visit("name", name); if (Boolean.TRUE.equals(factory.isWrapperPartQualified(mpi))) { av0.visit("namespace", mpi.getConcreteName().getNamespaceURI()); String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode, fieldDescriptor == null ? null : "()" + fieldDescriptor, mv.visitEnd(); methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V", fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V", null);
public Object read(MessagePartInfo part, T reader) { boolean honorJaxbAnnotation = honorJAXBAnnotations(part); Annotation[] anns = null; if (honorJaxbAnnotation) { anns = getJAXBAnnotation(part); if (anns.length > 0) { // RpcLit will use the JAXB Bridge to unmarshall part message when it is // annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter // TODO:Cache the JAXBRIContext QName qname = new QName(null, part.getConcreteName().getLocalPart()); Object obj = JAXBEncoderDecoder.unmarshalWithBridge(qname, part.getTypeClass(), anns, databinding.getContextClasses(), reader, getAttachmentUnmarshaller()); onCompleteUnmarshalling(); return obj; } } Unmarshaller um = createUnmarshaller(); try { Object obj = JAXBEncoderDecoder.unmarshall(um, reader, part, unwrapJAXBElement); onCompleteUnmarshalling(); return obj; } finally { JAXBUtils.closeUnmarshaller(um); } }
Object elForRun = ReflectionInvokationHandler .createProxyWrapper(listener, JAXBUtils.getParamClass(compiler, "setErrorListener")); JAXBUtils.logGeneratedClassNames(LOG, codeModel); Object writer = JAXBUtils.createFileCodeWriter(src); codeModel.build(writer); } catch (Exception e) { context = JAXBContext.newInstance(new Class[0], contextProperties); } else { context = JAXBContext.newInstance(packageList, cl, contextProperties); + jbe.getMessage(), jbe);
@SuppressWarnings("unchecked") protected T getData(Element element) { Object obj = null; Unmarshaller um = getUnmarshaller(); try { obj = um.unmarshal(element); } catch (JAXBException ex) { LogUtils.log(LOG, Level.SEVERE, "UNMARSHAL_ELEMENT_EXC", ex); } finally { JAXBUtils.closeUnmarshaller(um); } if (obj instanceof JAXBElement<?>) { JAXBElement<?> el = (JAXBElement<?>)obj; obj = el.getValue(); } if (null != obj && LOG.isLoggable(Level.FINE)) { LOG.fine("Unmarshaled element into object of type: " + obj.getClass().getName() + " value: " + obj); } return (T)obj; }
public static JAXBContext createJaxbContext(Set<Class<?>> classes, Class<?>[] extraClass, Map<String, Object> contextProperties) { if (classes == null || classes.isEmpty()) { return null; } org.apache.cxf.common.jaxb.JAXBUtils.scanPackages(classes, extraClass, null); JAXBContext ctx; try { ctx = JAXBContext.newInstance(classes.toArray(new Class[0]), contextProperties); return ctx; } catch (JAXBException ex) { LOG.log(Level.SEVERE, "No JAXB context can be created", ex); } return null; }
try { marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); marshaller.setListener(databinding.getMarshallerListener()); databinding.applyEscapeHandler(!noEscape, eh -> JAXBUtils.setEscapeHandler(marshaller, eh)); Object mapper = JAXBUtils.setNamespaceMapper(nspref != null ? nspref : nsctxt, marshaller); if (nsctxt != null) { setContextualNamespaceDecls(mapper, nsctxt); throw new Fault(faultMessage, ex); throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
public Object[] getHeaders(QName name, JAXBContext context, boolean allRoles) { SOAPMessage msg = getMessage(); SOAPHeader header; try { header = msg.getSOAPPart().getEnvelope().getHeader(); if (header == null || !header.hasChildNodes()) { return new Object[0]; } List<Object> ret = new ArrayList<>(); Iterator<SOAPHeaderElement> it = CastUtils.cast(header.examineAllHeaderElements()); while (it.hasNext()) { SOAPHeaderElement she = it.next(); if ((allRoles || roles.contains(she.getActor())) && name.equals(she.getElementQName())) { ret.add(JAXBUtils.unmarshall(context, she)); } } return ret.toArray(new Object[0]); } catch (SOAPException | JAXBException e) { throw new WebServiceException(e); } }
private Plugin getPlugin(InputStream is) throws JAXBException { try { Document doc = StaxUtils.read(is); return JAXBUtils.unmarshall(jaxbContext, doc.getDocumentElement(), Plugin.class).getValue(); } catch (XMLStreamException xse) { throw new JAXBException(xse); } finally { try { is.close(); } catch (IOException e) { //ignore } } }
public static Object createFileCodeWriter(File f, String encoding) throws JAXBException { try { Class<?> cls; try { cls = Class.forName("com.sun.codemodel.writer.FileCodeWriter"); } catch (ClassNotFoundException e) { cls = Class.forName("com.sun.codemodel.internal.writer.FileCodeWriter", true, getXJCClassLoader()); } if (encoding != null) { try { return cls.getConstructor(File.class, String.class) .newInstance(f, encoding); } catch (Exception ex) { // try a single argument constructor } } return cls.getConstructor(File.class).newInstance(f); } catch (Exception ex) { throw new JAXBException(ex); } }
private static boolean addJaxbObjectFactory(JAXBException e1, Set<Class<?>> classes) { boolean added = false; java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream(); java.io.PrintStream pout = new java.io.PrintStream(bout); e1.printStackTrace(pout); String str = new String(bout.toByteArray()); Pattern pattern = Pattern.compile("(?<=There's\\sno\\sObjectFactory\\swith\\san\\s" + "@XmlElementDecl\\sfor\\sthe\\selement\\s\\{)\\S*(?=\\})"); java.util.regex.Matcher matcher = pattern.matcher(str); while (matcher.find()) { String pkgName = JAXBUtils.namespaceURIToPackage(matcher.group()); try { Class<?> clz = JAXBContextCache.class.getClassLoader() .loadClass(pkgName + "." + "ObjectFactory"); if (!classes.contains(clz)) { classes.add(clz); added = true; } } catch (ClassNotFoundException e) { // do nothing } } return added; }
public static SchemaCompiler createSchemaCompilerWithDefaultAllocator(Set<String> allocatorSet) { try { SchemaCompiler compiler = JAXBUtils.createSchemaCompiler(); Object allocator = ReflectionInvokationHandler .createProxyWrapper(new DefaultClassNameAllocator(allocatorSet), JAXBUtils.getParamClass(compiler, "setClassNameAllocator")); compiler.setClassNameAllocator(allocator); return compiler; } catch (JAXBException e1) { throw new IllegalStateException("Unable to create schema compiler", e1); } }
JAXBSchemaInitializer(ServiceInfo serviceInfo, SchemaCollection col, JAXBContext context, boolean q, String defaultNs) { super(serviceInfo); schemas = col; this.context = JAXBUtils.createJAXBContextProxy(context, serviceInfo.getXmlSchemaCollection(), defaultNs); this.qualifiedSchemas = q; }
private String getPackageNamespace(Class<?> cls) { String packageNs = JAXBUtils.getPackageNamespace(cls); return packageNs != null ? getNamespace(packageNs) : ""; }