Java Code Examples for javax.xml.stream.XMLStreamReader

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project com.cedarsoft.serialization, under directory /samples/demo1/src/test/java/com/cedarsoft/serialization/demo1/.

Source file: MoneyTest.java

  24 
vote

private static Money deserialize(@Nonnull InputStream serialized) throws XMLStreamException {
  XMLInputFactory factory=XMLInputFactory.newInstance();
  XMLStreamReader reader=factory.createXMLStreamReader(serialized);
  reader.nextTag();
  reader.nextTag();
  reader.next();
  double amount=Double.parseDouble(reader.getText());
  return new Money(amount);
}
 

Example 2

From project data-access, under directory /src/org/pentaho/platform/dataaccess/client/.

Source file: ConnectionServiceClient.java

  22 
vote

protected Object[] getResponseObjects(Object[] types,Element rootNode) throws XMLStreamException, AxisFault {
  ByteArrayInputStream in=new ByteArrayInputStream(rootNode.asXML().getBytes());
  XMLStreamReader parser=XMLInputFactory.newInstance().createXMLStreamReader(in);
  StAXOMBuilder builder=new StAXOMBuilder(parser);
  OMElement omElement=builder.getDocumentElement();
  OMElement bodyElement=omElement.getFirstElement();
  OMElement responseElement=bodyElement.getFirstElement();
  return BeanUtil.deserialize(responseElement,types,this);
}
 

Example 3

From project EasySOA, under directory /easysoa-proxy/easysoa-proxy-intents/easysoa-proxy-intents-cxfMonitoringIntent/src/main/java/org/talend/esb/sam/agent/eventproducer/.

Source file: MessageToEventMapper.java

  22 
vote

private BindingOperationInfo getOperationFromContent(Message message){
  BindingOperationInfo boi=null;
  XMLStreamReader xmlReader=message.getContent(XMLStreamReader.class);
  if (null != xmlReader) {
    QName qName=xmlReader.getName();
    boi=ServiceModelUtil.getOperation(message.getExchange(),qName);
  }
  return boi;
}
 

Example 4

From project geronimo-jaspi, under directory /geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/.

Source file: JaspiXmlUtil.java

  22 
vote

public static <T>T load(Reader in,Class<T> clazz) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
  XMLStreamReader xmlStream=XMLINPUT_FACTORY.createXMLStreamReader(in);
  try {
    return load(xmlStream,clazz);
  }
  finally {
    xmlStream.close();
  }
}
 

Example 5

From project gravitext, under directory /gravitext-xmlprod/src/main/java/com/gravitext/xml/jruby/.

Source file: XMLHelper.java

  22 
vote

@JRubyMethod(name="stax_parse_string",meta=true,required=2,argTypes={RubyString.class,StAXConsumer.class}) public static IRubyObject staxParse(ThreadContext tc,IRubyObject klazz,IRubyObject input,IRubyObject csmr) throws FactoryConfigurationError, XMLStreamException {
  ByteBuffer in=IOUtils.toByteBuffer(input.convertToString());
  StreamSource source=new StreamSource(Streams.inputStream(in));
  XMLStreamReader staxReader=StAXUtils.staxReader(source);
  StAXConsumer consumer=null;
  if (csmr.isNil()) {
    consumer=new StAXConsumer();
  }
 else {
    consumer=(StAXConsumer)csmr.toJava(StAXConsumer.class);
  }
  Element element=consumer.readDocument(staxReader);
  return Java.getInstance(tc.getRuntime(),element);
}
 

Example 6

From project Jenkins-Repository, under directory /repository-hpi/src/main/java/com/nirima/jenkins/webdav/impl/methods/.

Source file: MethodBase.java

  22 
vote

protected XMLStreamReader getDocument() throws MethodException, XmlSerializerException, IOException {
  s_logger.info("Request length = " + m_request.getContentLength());
  if (m_request.getContentLength() == 0) {
    return null;
  }
  Reader r=m_request.getReader();
  XMLStreamReader xpp=XmlSerializerFactory.createXMLStreamReader(r);
  return xpp;
}
 

Example 7

From project jmeter-sla-report, under directory /src/java/org/apache/jmeter/extra/report/sla/.

Source file: JMeterReportParser.java

  22 
vote

private void parseInputAsXml(FileInputStream fis,XMLInputFactory factory) throws XMLStreamException {
  XMLStreamReader xmlStreamReader=null;
  try {
    xmlStreamReader=factory.createXMLStreamReader(fis);
    StaxParser parser=new StaxParser();
    parser.registerParser("sample",new SampleParser(model));
    parser.registerParser("httpSample",new SampleParser(model));
    parser.registerParser("assertionResult",new AssertionResultParser());
    parser.parseElement(xmlStreamReader);
  }
  finally {
    close(xmlStreamReader);
  }
}
 

Example 8

From project lilith, under directory /jul/jul-xml/src/test/java/de/huxhorn/lilith/jul/xml/.

Source file: LoggingEventReaderTest.java

  22 
vote

private LoggingEvent read(byte[] bytes) throws XMLStreamException, UnsupportedEncodingException {
  XMLInputFactory inputFactory=XMLInputFactory.newInstance();
  ByteArrayInputStream in=new ByteArrayInputStream(bytes);
  XMLStreamReader reader=inputFactory.createXMLStreamReader(new InputStreamReader(in,"utf-8"));
  return instance.read(reader);
}
 

Example 9

From project ODE-X, under directory /repo/src/main/java/org/apache/ode/repo/.

Source file: RepoFileTypeMap.java

  22 
vote

public String getContentType(InputStream contents){
  try {
    XMLStreamReader reader=XMLInputFactory.newInstance().createXMLStreamReader(contents);
    reader.nextTag();
    String ns=namespaceMappings.get(reader.getNamespaceURI());
    contents.close();
    return ns;
  }
 catch (  Exception e) {
    return null;
  }
}
 

Example 10

From project activemq-apollo, under directory /apollo-dto/src/main/java/org/apache/activemq/apollo/dto/.

Source file: XmlCodec.java

  21 
vote

static public <T>T decode(Class<T> clazz,InputStream is,Properties props,ValidationEventHandler validationHandler) throws IOException, XMLStreamException, JAXBException, SAXException {
  ClassLoader original=Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(ClassFinder.class_loader());
    if (is == null) {
      throw new IllegalArgumentException("input stream was null");
    }
    try {
      XMLStreamReader reader=factory.createXMLStreamReader(is);
      if (props != null) {
        reader=new PropertiesFilter(reader,props);
      }
      Unmarshaller unmarshaller=context().createUnmarshaller();
      if (validationHandler != null) {
        try {
          SchemaFactory sf=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          sf.setFeature("http://apache.org/xml/features/validation/schema-full-checking",false);
          Schema schema=sf.newSchema(XmlCodec.class.getResource("apollo.xsd"));
          unmarshaller.setSchema(schema);
          unmarshaller.setEventHandler(validationHandler);
        }
 catch (        Exception e) {
          System.err.println("Could not load schema: " + e.getMessage());
        }
      }
      return clazz.cast(unmarshaller.unmarshal(reader));
    }
  finally {
      is.close();
    }
  }
  finally {
    Thread.currentThread().setContextClassLoader(original);
  }
}
 

Example 11

From project apb, under directory /modules/apb-base/src/apb/utils/.

Source file: SchemaUtils.java

  21 
vote

private static void collectFiles(File file,XMLInputFactory inputFactory,Queue<File> pending){
  try {
    final URL doc=file.toURI().toURL();
    final InputStream is=buffered(doc.openStream());
    try {
      final XMLStreamReader sr=inputFactory.createXMLStreamReader(is);
      collectFiles(sr,doc,pending);
      sr.close();
    }
  finally {
      close(is);
    }
  }
 catch (  IOException e) {
    logException(e);
  }
catch (  XMLStreamException e) {
    logException(e);
  }
}
 

Example 12

From project arquillian-container-glassfish, under directory /glassfish-common/src/main/java/org/jboss/arquillian/container/glassfish/clientutils/.

Source file: GlassFishClientUtil.java

  21 
vote

/** 
 * Marshalling a Glassfish Mng API response XML document to a java Map object
 * @param XML document 
 * @return map containing the XML doc representation in java map format
 */
public Map xmlToMap(String document){
  if (document == null) {
    return new HashMap();
  }
  InputStream input=null;
  Map map=null;
  try {
    XMLInputFactory factory=XMLInputFactory.newInstance();
    factory.setProperty(XMLInputFactory.IS_VALIDATING,false);
    input=new ByteArrayInputStream(document.trim().getBytes("UTF-8"));
    XMLStreamReader stream=factory.createXMLStreamReader(input);
    while (stream.hasNext()) {
      int currentEvent=stream.next();
      if (currentEvent == XMLStreamConstants.START_ELEMENT) {
        if ("map".equals(stream.getLocalName())) {
          map=resolveXmlMap(stream);
        }
      }
    }
  }
 catch (  Exception ex) {
    log.log(Level.SEVERE,null,ex);
    throw new RuntimeException(ex);
  }
 finally {
    try {
      input.close();
    }
 catch (    IOException ex) {
      log.log(Level.SEVERE,null,ex);
    }
  }
  return map;
}
 

Example 13

From project astyanax, under directory /src/main/java/com/netflix/astyanax/serializers/.

Source file: JaxbSerializer.java

  21 
vote

/** 
 * {@inheritDoc} 
 */
@Override public Object fromByteBuffer(ByteBuffer bytes){
  if (bytes == null || !bytes.hasRemaining()) {
    return null;
  }
  ByteArrayInputStream bais=new ByteArrayInputStream(bytes.array());
  try {
    XMLStreamReader reader=createStreamReader(bais);
    Object ret=unmarshaller.get().unmarshal(reader);
    reader.close();
    return ret;
  }
 catch (  JAXBException e) {
    throw new SerializationException("Jaxb exception occurred during deserialization.",e);
  }
catch (  XMLStreamException e) {
    throw new SerializationException("Exception reading XML stream.",e);
  }
}
 

Example 14

From project babel, under directory /src/babel/util/persistence/.

Source file: XMPPageReader.java

  21 
vote

public List<Page> readPages(String fileName) throws FileNotFoundException, XMLStreamException {
  LinkedList<Page> pages=new LinkedList<Page>();
  XMLInputFactory factory=XMLInputFactory.newInstance();
  XMLStreamReader reader=factory.createXMLStreamReader(new FileInputStream(fileName));
  Page curPage;
  while (true) {
    int event=reader.next();
    if (event == XMLStreamConstants.END_DOCUMENT) {
      reader.close();
      break;
    }
    if ((event == XMLStreamConstants.START_ELEMENT) && reader.getName().toString().equals("Page")) {
      (curPage=new Page(reader.getAttributeValue(0))).unpersist(reader);
      pages.add(curPage);
    }
  }
  return pages;
}
 

Example 15

From project book, under directory /src/main/java/com/tamingtext/tagrecommender/.

Source file: ExtractStackOverflowData.java

  21 
vote

public void extract(){
  XMLInputFactory xif=XMLInputFactory.newInstance();
  XMLStreamReader reader=null;
  InputStream is=null;
  XMLOutputFactory xof=XMLOutputFactory.newInstance();
  XMLStreamWriter writer=null;
  OutputStream os=null;
  try {
    log.info("Reading data from " + inputFile);
    is=new FileInputStream(inputFile);
    reader=xif.createXMLStreamReader(is);
    os=new FileOutputStream(trainingOutputFile);
    writer=xof.createXMLStreamWriter(os);
    int trainingDataCount=extractXMLData(reader,writer,trainingDataSize);
    os.close();
    os=new FileOutputStream(testOutputFile);
    writer=xof.createXMLStreamWriter(os);
    int testDataCount=extractXMLData(reader,writer,testDataSize);
    os.close();
    log.info("Extracted " + trainingDataCount + " rows of training data");
    log.info("Extracted " + testDataCount + " rows of test data");
  }
 catch (  XMLStreamException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 16

From project ceylon-module-resolver, under directory /impl/src/main/java/com/redhat/ceylon/cmr/util/.

Source file: WS.java

  21 
vote

public static void getXML(String url,Param[] params,XMLHandler handler){
  try {
    if (params != null)     url+=toQueryString(params);
    URL endpoint=new URL(url);
    HttpURLConnection connection=(HttpURLConnection)endpoint.openConnection();
    connection.addRequestProperty("Accept","application/xml");
    connection.connect();
    try {
      if (connection.getResponseCode() == 200) {
        InputStream is=connection.getInputStream();
        try {
          XMLInputFactory factory=XMLInputFactory.newFactory();
          XMLStreamReader reader=factory.createXMLStreamReader(is);
          try {
            Parser p=new Parser(reader);
            handler.onOK(p);
          }
  finally {
            reader.close();
          }
        }
  finally {
          is.close();
        }
      }
    }
  finally {
      connection.disconnect();
    }
  }
 catch (  XMLStreamException x) {
    throw new RuntimeException(x);
  }
catch (  IOException x) {
    throw new RuntimeException(x);
  }
}
 

Example 17

From project ceylon-runtime, under directory /bootstrap/src/main/java/ceylon/modules/bootstrap/loader/.

Source file: ModuleXmlParser.java

  21 
vote

static List<String> parseResourcePaths(final InputStream source,ModuleIdentifier mi) throws ModuleLoadException {
  try {
    final XMLInputFactory inputFactory=INPUT_FACTORY;
    setIfSupported(inputFactory,XMLInputFactory.IS_VALIDATING,Boolean.FALSE);
    setIfSupported(inputFactory,XMLInputFactory.SUPPORT_DTD,Boolean.FALSE);
    final XMLStreamReader streamReader=inputFactory.createXMLStreamReader(source);
    try {
      List<String> resourcePaths=new ArrayList<String>();
      parseResourcePaths(streamReader,resourcePaths);
      return resourcePaths;
    }
  finally {
      safeClose(streamReader);
    }
  }
 catch (  XMLStreamException e) {
    throw new ModuleLoadException("Error reading resource paths: " + mi,e);
  }
 finally {
    safeClose(source);
  }
}
 

Example 18

From project chromattic, under directory /testgenerator/src/main/java/org/chromattic/testgenerator/.

Source file: TestSerializer.java

  21 
vote

public List<TestRef> getClassNames(InputStream is){
  List<TestRef> refs=new ArrayList<TestRef>();
  try {
    XMLInputFactory factory=XMLInputFactory.newInstance();
    XMLStreamReader reader=factory.createXMLStreamReader(is);
    TestRef currentTestRef=null;
    while (reader.hasNext()) {
      reader.next();
      if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
        String name=reader.getName().toString();
        if (name.equals("name")) {
          reader.next();
          currentTestRef=new TestRef(reader.getText());
          refs.add(currentTestRef);
        }
 else         if (name.equals("chromatticObject")) {
          reader.next();
          currentTestRef.getChromatticObject().add(reader.getText());
        }
      }
    }
    return refs;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}
 

Example 19

From project jboss-modules, under directory /src/main/java/org/jboss/modules/.

Source file: ModuleXmlParser.java

  21 
vote

static ModuleSpec parseModuleXml(final ResourceRootFactory factory,final String rootPath,InputStream source,final String moduleInfoFile,final ModuleIdentifier moduleIdentifier) throws ModuleLoadException {
  try {
    final XMLInputFactory inputFactory=INPUT_FACTORY;
    setIfSupported(inputFactory,XMLInputFactory.IS_VALIDATING,Boolean.FALSE);
    setIfSupported(inputFactory,XMLInputFactory.SUPPORT_DTD,Boolean.FALSE);
    final XMLStreamReader streamReader=inputFactory.createXMLStreamReader(source);
    try {
      return parseDocument(factory,rootPath,streamReader,moduleIdentifier);
    }
  finally {
      safeClose(streamReader);
    }
  }
 catch (  XMLStreamException e) {
    throw new ModuleLoadException("Error loading module from " + moduleInfoFile,e);
  }
}
 

Example 20

From project JRebirth, under directory /org.jrebirth/presentation/src/main/java/org/jrebirth/presentation/service/.

Source file: PresentationService.java

  21 
vote

/** 
 * {@inheritDoc}
 */
@Override public void ready() throws CoreException {
  super.ready();
  try {
    final JAXBContext jaxbContext=JAXBContext.newInstance("org.jrebirth.presentation.model");
    final Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    final InputStreamReader in=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_NAME + ".xml"),Charset.forName("UTF-8"));
    final XMLStreamReader xsr=XMLInputFactory.newInstance().createXMLStreamReader(in);
    this.presentation=Presentation.class.cast(JAXBElement.class.cast(unmarshaller.unmarshal(xsr)).getValue());
  }
 catch (  final JAXBException|XMLStreamException|FactoryConfigurationError e) {
    System.err.println("Impossible to open " + CONFIG_NAME + ".xml");
    e.printStackTrace();
    throw new CoreException("Xml file incorrectly parsed !",e);
  }
}
 

Example 21

From project litle-sdk-for-java, under directory /lib/apache-cxf-2.5.2/samples/aegis_standalone/src/main/java/org/apache/cxf/demo/aegis/commands/.

Source file: ReadZoo.java

  21 
vote

private void go() throws Exception {
  AegisContext context;
  context=new AegisContext();
  Set<Type> rootClasses=new HashSet<Type>();
  rootClasses.add(Zoo.class);
  context.setRootClasses(rootClasses);
  context.initialize();
  AegisReader<XMLStreamReader> reader=context.createXMLStreamReader();
  FileInputStream input=new FileInputStream(inputPathname);
  XMLStreamReader xmlReader=inputFactory.createXMLStreamReader(input);
  Zoo zoo=(Zoo)reader.read(xmlReader);
  System.out.println("Name " + zoo.getName());
  System.out.println("Founder " + zoo.getFounder());
  for (  Map.Entry<String,Animal> e : zoo.getAnimals().entrySet()) {
    System.out.println(e.getKey() + " -> " + e.getValue().getName());
  }
}
 

Example 22

From project medsavant, under directory /medsavant/MedSavantClient/src/org/ut/biolab/medsavant/plugin/.

Source file: PluginIndex.java

  21 
vote

public PluginIndex(URL url) throws IOException {
  urls=new HashMap<String,URL>();
  try {
    XMLStreamReader reader=XMLInputFactory.newInstance().createXMLStreamReader(ClientNetworkUtils.openStream(url));
    boolean done=false;
    String id=null;
    do {
switch (reader.next()) {
case XMLStreamConstants.START_ELEMENT:
        String elemName=reader.getLocalName();
      if (elemName.equals("leaf")) {
        id=reader.getAttributeValue(null,"id");
      }
 else       if (elemName.equals("url")) {
        if (id != null) {
          try {
            urls.put(id,new URL(reader.getElementText()));
          }
 catch (          MalformedURLException x) {
            LOG.warn(String.format("Unable to parse \"%s\" as a plugin URL.",reader.getElementText()));
          }
          id=null;
        }
      }
    break;
case XMLStreamConstants.END_DOCUMENT:
  reader.close();
done=true;
break;
}
}
 while (!done);
}
 catch (XMLStreamException x) {
throw new IOException("Unable to get version number from web-site.",x);
}
}
 

Example 23

From project nodebox, under directory /src/main/java/nodebox/node/.

Source file: NodeLibrary.java

  21 
vote

private static NodeLibrary load(String libraryName,File file,Reader r,NodeRepository nodeRepository) throws XMLStreamException {
  XMLInputFactory xmlInputFactory=XMLInputFactory.newInstance();
  XMLStreamReader reader=xmlInputFactory.createXMLStreamReader(r);
  NodeLibrary nodeLibrary=null;
  while (reader.hasNext()) {
    int eventType=reader.next();
    if (eventType == XMLStreamConstants.START_ELEMENT) {
      String tagName=reader.getLocalName();
      if (tagName.equals("ndbx")) {
        String formatVersion=reader.getAttributeValue(null,"formatVersion");
        if (formatVersion != null && !CURRENT_FORMAT_VERSION.equals(formatVersion)) {
          throw new OutdatedLibraryException(file,"File uses version " + formatVersion + ", current version is "+ CURRENT_FORMAT_VERSION+ ".");
        }
        String uuidString=reader.getAttributeValue(null,"uuid");
        UUID uuid=(uuidString == null) ? UUID.randomUUID() : UUID.fromString(uuidString);
        nodeLibrary=parseNDBX(libraryName,file,reader,nodeRepository,uuid);
      }
 else {
        throw new XMLStreamException("Only tag ndbx allowed, not " + tagName,reader.getLocation());
      }
    }
  }
  return nodeLibrary;
}
 

Example 24

From project openengsb-connector-promreport, under directory /src/main/java/org/openengsb/connector/promreport/internal/.

Source file: ProcessFileStore.java

  21 
vote

private ProcessInstance readFrom(File processFile,String processInstanceId){
  BufferedInputStream fis=null;
  try {
    fis=new BufferedInputStream(new FileInputStream(processFile));
    XMLStreamReader xmlr=xmlif.createXMLStreamReader(fis);
    int eventType;
    while (xmlr.hasNext()) {
      eventType=xmlr.next();
      if (eventType == XMLStreamConstants.START_ELEMENT && xmlr.getLocalName().equals("ProcessInstance") && xmlr.getAttributeValue(null,"id").equals(processInstanceId)) {
        return (ProcessInstance)createUnmarshaller().unmarshal(xmlr);
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
 finally {
    IOUtils.closeQuietly(fis);
  }
  return null;
}
 

Example 25

From project pluto, under directory /pluto-container/src/main/java/org/apache/pluto/container/impl/.

Source file: PortletAppDescriptorServiceImpl.java

  21 
vote

/** 
 * Read the Web Application Deployment Descriptor.
 * @return WebAppDD instance representing the descriptor.
 * @throws java.io.IOException
 */
public PortletApplicationDefinition read(String name,String contextPath,InputStream in) throws IOException {
  if (in == null) {
    throw new IOException("Cannot read from a null InputStream");
  }
  final XMLInputFactory xmlInputFactory=getXmlInputFactory();
  final XMLStreamReader streamReader;
  try {
    streamReader=xmlInputFactory.createXMLStreamReader(in);
  }
 catch (  XMLStreamException e) {
    final IOException ioe=new IOException(e.getLocalizedMessage());
    ioe.initCause(e);
    throw ioe;
  }
  final XMLStreamReader delegatingStreamReader=new NamespaceOverridingStreamReaderDelegate(streamReader);
  final JAXBElement<?> app;
  try {
    final Unmarshaller unmarshaller=this.jaxbContext.createUnmarshaller();
    unmarshaller.setEventHandler(new DefaultValidationEventHandler());
    app=(JAXBElement<?>)unmarshaller.unmarshal(delegatingStreamReader);
  }
 catch (  JAXBException e) {
    final IOException ioe=new IOException(e.getMessage());
    ioe.initCause(e);
    throw ioe;
  }
  PortletApplicationDefinition pad=null;
  if (app.getValue() instanceof org.apache.pluto.container.om.portlet10.impl.PortletAppType) {
    pad=((org.apache.pluto.container.om.portlet10.impl.PortletAppType)app.getValue()).upgrade();
  }
 else {
    pad=(PortletApplicationDefinition)app.getValue();
  }
  pad.setName(name);
  pad.setContextPath(contextPath);
  return pad;
}
 

Example 26

From project qcadoo, under directory /qcadoo-model/src/main/java/com/qcadoo/model/internal/classconverter/.

Source file: ModelXmlToClassConverterImpl.java

  21 
vote

private Map<String,Class<?>> findExistingClasses(final InputStream stream) throws XMLStreamException {
  XMLStreamReader reader=XMLInputFactory.newInstance().createXMLStreamReader(stream);
  Map<String,Class<?>> existingClasses=new HashMap<String,Class<?>>();
  while (reader.hasNext() && reader.next() > 0) {
    if (isTagStarted(reader,TAG_MODEL)) {
      String pluginIdentifier=getPluginIdentifier(reader);
      String modelName=getStringAttribute(reader,L_NAME);
      String className=ClassNameUtils.getFullyQualifiedClassName(pluginIdentifier,modelName);
      try {
        existingClasses.put(className,classLoader.loadClass(className));
        LOG.info("Class " + className + " already exists, skipping");
      }
 catch (      ClassNotFoundException e) {
        LOG.info("Class " + className + " not found, will be generated");
      }
      break;
    }
  }
  reader.close();
  return existingClasses;
}
 

Example 27

From project agraph-java-client, under directory /src/com/franz/util/.

Source file: Closer.java

  19 
vote

/** 
 * Close an object immediately, will not be closed "later".
 */
public <Obj extends Object>Obj close(Obj o){
  if (o == null) {
    return null;
  }
 else   if (o instanceof Closeable) {
    return (Obj)close((Closeable)o);
  }
 else   if (o instanceof java.io.Closeable) {
    return (Obj)close((java.io.Closeable)o);
  }
 else   if (o instanceof CloseableIteration) {
    return (Obj)close((CloseableIteration)o);
  }
 else   if (o instanceof XMLStreamReader) {
    return (Obj)close((XMLStreamReader)o);
  }
 else   if (o instanceof MultiThreadedHttpConnectionManager) {
    return (Obj)close((MultiThreadedHttpConnectionManager)o);
  }
 else {
    return closeReflection(o);
  }
}
 

Example 28

From project amber, under directory /oauth-2.0/common/src/test/java/org/apache/amber/oauth2/common/.

Source file: OAuthUtilsTest.java

  19 
vote

@Test public void testBuildJSON() throws Exception {
  Map<String,Object> params=new HashMap<String,Object>();
  params.put(OAuthError.OAUTH_ERROR,OAuthError.TokenResponse.INVALID_REQUEST);
  String json=JSONUtils.buildJSON(params);
  JSONObject obj=new JSONObject(json);
  AbstractXMLStreamReader reader=new MappedXMLStreamReader(obj);
  assertEquals(XMLStreamReader.START_ELEMENT,reader.next());
  assertEquals(OAuthError.OAUTH_ERROR,reader.getName().getLocalPart());
  assertEquals(OAuthError.TokenResponse.INVALID_REQUEST,reader.getText());
  assertEquals(XMLStreamReader.CHARACTERS,reader.next());
  assertEquals(XMLStreamReader.END_ELEMENT,reader.next());
  assertEquals(XMLStreamReader.END_DOCUMENT,reader.next());
}
 

Example 29

From project caseconductor-platform, under directory /utest-webservice/utest-webservice-client/src/main/java/com/utest/webservice/client/rest/.

Source file: AegisEntityProvider.java

  19 
vote

@SuppressWarnings("unchecked") AegisUnmarshaller createUnmarshaller(){
  AegisDatabinding binding=new AegisDatabinding();
  DataReader reader=binding.createReader(XMLStreamReader.class);
  AegisUnmarshaller u=new AegisUnmarshaller(reader);
  return u;
}
 

Example 30

From project iudex_1, under directory /iudex-html/src/main/java/iudex/html/tree/.

Source file: HTMLStAXConsumer.java

  19 
vote

@Override @SuppressWarnings("unchecked") protected Element createElement(XMLStreamReader sr){
  HTMLTag tag=HTML.TAGS.get(sr.getLocalName());
  if (tag == null) {
    tag=new HTMLTag(sr.getLocalName(),namespace(sr),Collections.EMPTY_LIST,HTMLTag.Flag.BANNED);
  }
  Element element=new Element(tag);
  return element;
}
 

Example 31

From project jbosgi-repository, under directory /api/src/main/java/org/jboss/osgi/repository/.

Source file: RepositoryXMLReader.java

  19 
vote

private void readCapabilityElement(XMLStreamReader reader,XResourceBuilder builder) throws XMLStreamException {
  String namespace=reader.getAttributeValue(null,Attribute.NAMESPACE.toString());
  Map<String,Object> atts=new HashMap<String,Object>();
  Map<String,String> dirs=new HashMap<String,String>();
  readAttributesAndDirectives(reader,atts,dirs);
  try {
    builder.addCapability(namespace,atts,dirs);
  }
 catch (  RuntimeException ex) {
    throw MESSAGES.storageCannotReadResourceElement(ex,reader.getLocation());
  }
}
 

Example 32

From project mdk, under directory /io/xml-parsers/src/main/java/uk/ac/ebi/mdk/io/xml/uniprot/marshal/.

Source file: UniProtCrossreferenceMarshal.java

  19 
vote

@Override public void marshal(XMLStreamReader reader,ProteinProduct product) throws XMLStreamException {
  attributes.clear();
  int count=reader.getAttributeCount();
  for (int i=0; i < count; i++) {
    attributes.put(reader.getAttributeLocalName(i),reader.getAttributeValue(i));
  }
  String id=attributes.get("id");
  String type=attributes.get("type");
  if (factory.hasSynonym(type)) {
    Identifier identifier=factory.ofSynonym(type,id);
    if (include.isEmpty() || include.contains(identifier.getClass())) {
      product.addAnnotation(new CrossReference(identifier));
    }
 else {
      ignored.add(type);
    }
  }
 else {
    ignored.add(type);
  }
}
 

Example 33

From project onebusaway-nyc, under directory /onebusaway-nyc-transit-data-manager/onebusaway-nyc-tdm-adapters/src/main/java/org/onebusaway/nyc/transit_data_manager/adapters/input/readers/.

Source file: XMLBusDepotAssignsInputConverter.java

  19 
vote

private <T>T unmarshall(Class<T> docClass,XMLStreamReader inputReader) throws JAXBException {
  String packageName=docClass.getPackage().getName();
  JAXBContext jc=JAXBContext.newInstance(packageName);
  Unmarshaller u=jc.createUnmarshaller();
  JAXBElement<T> doc=(JAXBElement<T>)u.unmarshal(inputReader,docClass);
  return doc.getValue();
}