private void parseMongoDBStore(
      XMLExtendedStreamReader reader,
      LoadersConfigurationBuilder loadersBuilder,
      ClassLoader classLoader)
      throws XMLStreamException {
    MongoDBCacheStoreConfigurationBuilder builder =
        new MongoDBCacheStoreConfigurationBuilder(loadersBuilder);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CONNECTION:
          {
            this.parseConnection(reader, builder);
            break;
          }
        case AUTHENTICATION:
          {
            this.parseAuthentication(reader, builder);
            break;
          }
        case STORAGE:
          {
            this.parseStorage(reader, builder);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
    loadersBuilder.addStore(builder);
  }
 static ModelNode parseCustomLoadMetric(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode load = new ModelNode();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case CAPACITY:
         load.get(CAPACITY).set(value);
         break;
       case WEIGHT:
         load.get(WEIGHT).set(value);
         break;
       case CLASS:
         load.get(CLASS).set(value);
         break;
       default:
         unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case PROPERTY:
         final Property property = parseProperty(reader);
         load.get("property").add(property.getName(), property.getValue());
         break;
       default:
         unexpectedElement(reader);
     }
   }
   return load;
 }
  private void parseLocalCache(
      XMLExtendedStreamReader reader, ModelNode containerAddress, List<ModelNode> operations)
      throws XMLStreamException {

    // ModelNode for the cache add operation
    ModelNode cache = Util.getEmptyOperation(ModelDescriptionConstants.ADD, null);
    List<ModelNode> additionalConfigurationOperations = new ArrayList<ModelNode>();

    // set the cache mode to local
    // cache.get(ModelKeys.MODE).set(Configuration.CacheMode.LOCAL.name());

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      this.parseCacheAttribute(reader, i, attribute, value, cache);
    }

    if (!cache.hasDefined(ModelKeys.NAME)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME));
    }

    // update the cache address with the cache name
    addCacheNameToAddress(cache, containerAddress, ModelKeys.LOCAL_CACHE);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      this.parseCacheElement(reader, element, cache, additionalConfigurationOperations);
    }

    operations.add(cache);
    // add operations to create configuration resources
    for (ModelNode additionalOperation : additionalConfigurationOperations) {
      operations.add(additionalOperation);
    }
  }
  public static FilterMappingMetaData parse(XMLStreamReader reader) throws XMLStreamException {
    FilterMappingMetaData filterMapping = new FilterMappingMetaData();

    // Handle attributes
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final String value = reader.getAttributeValue(i);
      if (reader.getAttributeNamespace(i) != null) {
        continue;
      }
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case ID:
          {
            filterMapping.setId(value);
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case FILTER_NAME:
          filterMapping.setFilterName(getElementText(reader));
          break;
        case URL_PATTERN:
          List<String> urlPatterns = filterMapping.getUrlPatterns();
          if (urlPatterns == null) {
            urlPatterns = new ArrayList<String>();
            filterMapping.setUrlPatterns(urlPatterns);
          }
          urlPatterns.add(getElementText(reader));
          break;
        case SERVLET_NAME:
          List<String> servletNames = filterMapping.getServletNames();
          if (servletNames == null) {
            servletNames = new ArrayList<String>();
            filterMapping.setServletNames(servletNames);
          }
          servletNames.add(getElementText(reader));
          break;
        case DISPATCHER:
          List<DispatcherType> dispatchers = filterMapping.getDispatchers();
          if (dispatchers == null) {
            dispatchers = new ArrayList<DispatcherType>();
            filterMapping.setDispatchers(dispatchers);
          }
          dispatchers.add(DispatcherType.valueOf(getElementText(reader)));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return filterMapping;
  }
 private void parseOutboundConnections(
     final XMLExtendedStreamReader reader,
     final ModelNode address,
     final List<ModelNode> operations)
     throws XMLStreamException {
   // Handle nested elements.
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case REMOTE_OUTBOUND_CONNECTION:
         {
           this.parseRemoteOutboundConnection(reader, address, operations);
           break;
         }
       case LOCAL_OUTBOUND_CONNECTION:
         {
           this.parseLocalOutboundConnection(reader, address, operations);
           break;
         }
       case OUTBOUND_CONNECTION:
         {
           this.parseOutboundConnection(reader, address, operations);
           break;
         }
       default:
         {
           throw unexpectedElement(reader);
         }
     }
   }
 }
Ejemplo n.º 6
0
    ModelNode parseModulesElement(XMLExtendedStreamReader reader) throws XMLStreamException {

      // Handle attributes
      requireNoAttributes(reader);

      ModelNode modules = new ModelNode();

      // Handle elements
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case OSGI_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              if (element == Element.MODULE) {
                String identifier = null;
                String start = null;
                final int count = reader.getAttributeCount();
                for (int i = 0; i < count; i++) {
                  requireNoNamespaceAttribute(reader, i);
                  final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                  switch (attribute) {
                    case IDENTIFIER:
                      {
                        identifier = reader.getAttributeValue(i);
                        break;
                      }
                    case START:
                      {
                        start = reader.getAttributeValue(i);
                        break;
                      }
                    default:
                      throw unexpectedAttribute(reader, i);
                  }
                }
                if (identifier == null)
                  throw missingRequired(reader, Collections.singleton(Attribute.IDENTIFIER));
                if (modules.has(identifier))
                  throw new XMLStreamException(
                      element.getLocalName() + " already declared", reader.getLocation());

                ModelNode module = new ModelNode();
                if (start != null) {
                  module.get(START).set(start);
                }
                modules.get(identifier).set(module);

                requireNoContent(reader);
              } else {
                throw unexpectedElement(reader);
              }
              break;
            }
          default:
            throw unexpectedElement(reader);
        }
      }

      return modules;
    }
  private void parseReplicatedCache(XMLExtendedStreamReader reader, ModelNode cache)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      this.parseClusteredCacheAttribute(
          reader, i, attribute, value, cache, Configuration.CacheMode.REPL_SYNC);
    }

    if (!cache.hasDefined(ModelKeys.NAME)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME));
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case STATE_TRANSFER:
          {
            this.parseStateTransfer(reader, cache.get(ModelKeys.STATE_TRANSFER).setEmptyObject());
            break;
          }
        default:
          {
            this.parseCacheElement(reader, element, cache);
          }
      }
    }
  }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader,
   *     Object)
   */
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations)
      throws XMLStreamException {

    PathAddress subsystemAddress = PathAddress.pathAddress(InfinispanExtension.SUBSYSTEM_PATH);
    ModelNode subsystem = Util.createAddOperation(subsystemAddress);

    // command to add the subsystem
    operations.add(subsystem);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CACHE_CONTAINER:
          {
            parseContainer(reader, subsystemAddress, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
Ejemplo n.º 9
0
    /** {@inheritDoc} */
    @Override
    public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list)
        throws XMLStreamException {
      ModelNode subsystemAdd = null;

      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
          case JPA:
            {
              subsystemAdd = parseJPA(reader);
              break;
            }
          default:
            {
              throw ParseUtils.unexpectedElement(reader);
            }
        }
      }
      if (subsystemAdd == null) {
        throw ParseUtils.missingRequiredElement(
            reader, Collections.singleton(Element.JPA.getLocalName()));
      }
      list.add(subsystemAdd);
    }
 static ModelNode parseModClusterConfig(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode config = new ModelNode();
   // Parse the attributes.
   parsePropConf(reader, config);
   // Parse the elements
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case SIMPLE_LOAD_PROVIDER:
         final ModelNode load = parseSimpleLoadProvider(reader);
         config.get(SIMPLE_LOAD_PROVIDER).set(load);
         break;
       case DYNAMIC_LOAD_PROVIDER:
         final ModelNode dynload = parseDynamicLoadProvider(reader);
         config.get(DYNAMIC_LOAD_PROVIDER).set(dynload);
         break;
       case SSL:
         final ModelNode ssl = parseSSL(reader);
         config.get(SSL).set(ssl);
         break;
       default:
         unexpectedElement(reader);
     }
   }
   return config;
 }
Ejemplo n.º 11
0
 public static VDBMetaData unmarshell(InputStream content) throws XMLStreamException {
   XMLInputFactory inputFactory = XMLType.getXmlInputFactory();
   XMLStreamReader reader = inputFactory.createXMLStreamReader(content);
   try {
     // elements
     while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
       Element element = Element.forName(reader.getLocalName());
       switch (element) {
         case VDB:
           VDBMetaData vdb = new VDBMetaData();
           Properties props = getAttributes(reader);
           vdb.setName(props.getProperty(Element.NAME.getLocalName()));
           vdb.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName())));
           parseVDB(reader, vdb);
           return vdb;
         default:
           throw new XMLStreamException(
               AdminPlugin.Util.gs(
                   "unexpected_element1", reader.getName(), Element.VDB.getLocalName()),
               reader.getLocation());
       }
     }
   } finally {
     try {
       content.close();
     } catch (IOException e) {
       Logger.getLogger(VDBMetadataParser.class.getName())
           .log(Level.FINE, "Exception closing vdb stream", e);
     }
   }
   return null;
 }
Ejemplo n.º 12
0
    @Override
    public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list)
        throws XMLStreamException {

      final ModelNode address = new ModelNode();
      address.add(SUBSYSTEM, SUBSYSTEM_NAME);
      address.protect();

      final ModelNode subsystem = new ModelNode();
      subsystem.get(OP).set(ADD);
      subsystem.get(OP_ADDR).set(address);
      list.add(subsystem);

      // Handle elements
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case THREADS_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              switch (element) {
                case BOUNDED_QUEUE_THREAD_POOL:
                  {
                    parseBoundedQueueThreadPool(reader, address, list);
                    break;
                  }
                case THREAD_FACTORY:
                  {
                    // Add connector updates
                    parseThreadFactory(reader, address, list);
                    break;
                  }
                case QUEUELESS_THREAD_POOL:
                  {
                    parseQueuelessThreadPool(reader, address, list);
                    break;
                  }
                case SCHEDULED_THREAD_POOL:
                  {
                    parseScheduledThreadPool(reader, address, list);
                    break;
                  }
                case UNBOUNDED_QUEUE_THREAD_POOL:
                  {
                    parseUnboundedQueueThreadPool(reader, address, list);
                    break;
                  }
                default:
                  {
                    throw unexpectedElement(reader);
                  }
              }
              break;
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
      }
    }
  public static ContainerListenerMetaData parse(XMLStreamReader reader) throws XMLStreamException {
    ContainerListenerMetaData containerListener = new ContainerListenerMetaData();

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CLASS_NAME:
          containerListener.setListenerClass(getElementText(reader));
          break;
        case MODULE:
          containerListener.setModule(getElementText(reader));
          break;
        case LISTENER_TYPE:
          containerListener.setListenerType(ContainerListenerType.valueOf(getElementText(reader)));
          break;
        case PARAM:
          List<ParamValueMetaData> params = containerListener.getParams();
          if (params == null) {
            params = new ArrayList<ParamValueMetaData>();
            containerListener.setParams(params);
          }
          params.add(ParamValueMetaDataParser.parse(reader));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return containerListener;
  }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader,
   *     java.lang.Object)
   */
  @Override
  public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations)
      throws XMLStreamException {

    ModelNode subsystemAddress = new ModelNode();
    subsystemAddress.add(ModelDescriptionConstants.SUBSYSTEM, InfinispanExtension.SUBSYSTEM_NAME);
    subsystemAddress.protect();

    ModelNode subsystem = Util.getEmptyOperation(ModelDescriptionConstants.ADD, subsystemAddress);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      ParseUtils.requireNoNamespaceAttribute(reader, i);
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case DEFAULT_CACHE_CONTAINER:
          {
            subsystem.get(ModelKeys.DEFAULT_CACHE_CONTAINER).set(value);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    if (!subsystem.hasDefined(ModelKeys.DEFAULT_CACHE_CONTAINER)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.DEFAULT_CACHE_CONTAINER));
    }

    // command to add the subsystem
    operations.add(subsystem);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      switch (Namespace.forUri(reader.getNamespaceURI())) {
        case INFINISPAN_1_0:
        case INFINISPAN_1_1:
          {
            Element element = Element.forName(reader.getLocalName());
            switch (element) {
              case CACHE_CONTAINER:
                {
                  parseContainer(reader, subsystemAddress, operations);
                  break;
                }
              default:
                {
                  throw ParseUtils.unexpectedElement(reader);
                }
            }
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  public static HttpHandlerMetaData parse(XMLStreamReader reader, PropertyReplacer propertyReplacer)
      throws XMLStreamException {
    HttpHandlerMetaData valve = new HttpHandlerMetaData();

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CLASS_NAME:
          valve.setHandlerClass(getElementText(reader, propertyReplacer));
          break;
        case MODULE:
          valve.setModule(getElementText(reader, propertyReplacer));
          break;
        case PARAM:
          List<ParamValueMetaData> params = valve.getParams();
          if (params == null) {
            params = new ArrayList<ParamValueMetaData>();
            valve.setParams(params);
          }
          params.add(ParamValueMetaDataParser.parse(reader, propertyReplacer));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return valve;
  }
Ejemplo n.º 16
0
  private static void parseModel(XMLStreamReader reader, ModelMetaData model)
      throws XMLStreamException {
    Properties props = getAttributes(reader);
    model.setName(props.getProperty(Element.NAME.getLocalName()));
    model.setModelType(props.getProperty(Element.TYPE.getLocalName(), "PHYSICAL"));
    model.setVisible(
        Boolean.parseBoolean(props.getProperty(Element.VISIBLE.getLocalName(), "true")));
    model.setPath(props.getProperty(Element.PATH.getLocalName()));

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case DESCRIPTION:
          model.setDescription(reader.getElementText());
          break;
        case PROPERTY:
          parseProperty(reader, model);
          break;
        case SOURCE:
          Properties sourceProps = getAttributes(reader);
          String name = sourceProps.getProperty(Element.NAME.getLocalName());
          String translatorName =
              sourceProps.getProperty(Element.SOURCE_TRANSLATOR_NAME_ATTR.getLocalName());
          String connectionName =
              sourceProps.getProperty(Element.SOURCE_CONNECTION_JNDI_NAME_ATTR.getLocalName());
          model.addSourceMapping(name, translatorName, connectionName);
          ignoreTillEnd(reader);
          break;
        case VALIDATION_ERROR:
          Properties validationProps = getAttributes(reader);
          String msg = reader.getElementText();
          String severity =
              validationProps.getProperty(Element.VALIDATION_SEVERITY_ATTR.getLocalName());
          String path = validationProps.getProperty(Element.PATH.getLocalName());
          Message ve = new Message(Severity.valueOf(severity), msg);
          ve.setPath(path);
          model.addMessage(ve);
          break;
        case METADATA:
          Properties metdataProps = getAttributes(reader);
          String type = metdataProps.getProperty(Element.TYPE.getLocalName(), "DDL");
          String schema = reader.getElementText();
          model.setSchemaSourceType(type);
          model.setSchemaText(schema);
          break;
        default:
          throw new XMLStreamException(
              AdminPlugin.Util.gs(
                  "unexpected_element5",
                  reader.getName(),
                  Element.DESCRIPTION.getLocalName(),
                  Element.PROPERTY.getLocalName(),
                  Element.SOURCE.getLocalName(),
                  Element.METADATA.getLocalName(),
                  Element.VALIDATION_ERROR.getLocalName()),
              reader.getLocation());
      }
    }
  }
Ejemplo n.º 17
0
    ModelNode parsePropertiesElement(XMLExtendedStreamReader reader) throws XMLStreamException {

      // Handle attributes
      requireNoAttributes(reader);

      ModelNode properties = new ModelNode();

      // Handle elements
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case OSGI_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              if (element == Element.PROPERTY) {
                // Handle attributes
                String name = null;
                String value = null;
                int count = reader.getAttributeCount();
                for (int i = 0; i < count; i++) {
                  requireNoNamespaceAttribute(reader, i);
                  final String attrValue = reader.getAttributeValue(i);
                  final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                  switch (attribute) {
                    case NAME:
                      {
                        name = attrValue;
                        if (properties.has(name)) {
                          throw new XMLStreamException(
                              "Property " + name + " already exists", reader.getLocation());
                        }
                        break;
                      }
                    default:
                      throw unexpectedAttribute(reader, i);
                  }
                }
                if (name == null) {
                  throw missingRequired(reader, Collections.singleton(Attribute.NAME));
                }
                value = reader.getElementText().trim();
                if (value == null || value.length() == 0) {
                  throw new XMLStreamException(
                      "Value for property " + name + " is null", reader.getLocation());
                }
                properties.get(name).set(value);
                break;
              } else {
                throw unexpectedElement(reader);
              }
            }
          default:
            throw unexpectedElement(reader);
        }
      }

      return properties;
    }
  private void parseSequencer(
      XMLExtendedStreamReader reader, String repositoryName, final List<ModelNode> sequencers)
      throws XMLStreamException {

    final ModelNode sequencer = new ModelNode();
    sequencer.get(OP).set(ADD);
    String name = null;

    sequencers.add(sequencer);

    if (reader.getAttributeCount() > 0) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attrName = reader.getAttributeLocalName(i);
        String attrValue = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(attrName);
        switch (attribute) {
          case NAME:
            name = attrValue;
            break;
          case PATH_EXPRESSION:
            ModelAttributes.PATH_EXPRESSIONS.parseAndAddParameterElement(
                attrValue, sequencer, reader);
            break;
          case CLASSNAME:
            ModelAttributes.SEQUENCER_CLASSNAME.parseAndSetParameter(attrValue, sequencer, reader);
            if (name == null) name = attrValue;
            break;
          case MODULE:
            ModelAttributes.MODULE.parseAndSetParameter(attrValue, sequencer, reader);
            break;
          default:
            // extra attributes are allowed to set sequencer-specific properties ...
            sequencer.get(ModelKeys.PROPERTIES).add(attrName, attrValue);
            break;
        }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case PATH_EXPRESSION:
          String value = reader.getElementText();
          ModelAttributes.PATH_EXPRESSIONS.parseAndAddParameterElement(value, sequencer, reader);
          break;
        default:
          throw ParseUtils.unexpectedElement(reader);
      }
    }

    sequencer
        .get(OP_ADDR)
        .add(SUBSYSTEM, ModeShapeExtension.SUBSYSTEM_NAME)
        .add(ModelKeys.REPOSITORY, repositoryName)
        .add(ModelKeys.SEQUENCER, name);
  }
Ejemplo n.º 19
0
 private static void parseVDB(XMLStreamReader reader, VDBMetaData vdb) throws XMLStreamException {
   while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
     Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case DESCRIPTION:
         vdb.setDescription(reader.getElementText());
         break;
       case PROPERTY:
         parseProperty(reader, vdb);
         break;
       case MODEL:
         ModelMetaData model = new ModelMetaData();
         parseModel(reader, model);
         vdb.addModel(model);
         break;
       case TRANSLATOR:
         VDBTranslatorMetaData translator = new VDBTranslatorMetaData();
         parseTranslator(reader, translator);
         vdb.addOverideTranslator(translator);
         break;
       case DATA_ROLE:
         DataPolicyMetadata policy = new DataPolicyMetadata();
         parseDataRole(reader, policy);
         vdb.addDataPolicy(policy);
         break;
       case IMPORT_VDB:
         VDBImportMetadata vdbImport = new VDBImportMetadata();
         Properties props = getAttributes(reader);
         vdbImport.setName(props.getProperty(Element.NAME.getLocalName()));
         vdbImport.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName())));
         vdbImport.setImportDataPolicies(
             Boolean.parseBoolean(
                 props.getProperty(Element.IMPORT_POLICIES.getLocalName(), "true")));
         vdb.getVDBImports().add(vdbImport);
         ignoreTillEnd(reader);
         break;
       case ENTRY:
         EntryMetaData entry = new EntryMetaData();
         parseEntry(reader, entry);
         vdb.getEntries().add(entry);
         break;
       default:
         throw new XMLStreamException(
             AdminPlugin.Util.gs(
                 "unexpected_element5",
                 reader.getName(),
                 Element.DESCRIPTION.getLocalName(),
                 Element.PROPERTY.getLocalName(),
                 Element.MODEL.getLocalName(),
                 Element.TRANSLATOR.getLocalName(),
                 Element.DATA_ROLE.getLocalName()),
             reader.getLocation());
     }
   }
 }
  private void parseRemoteStore(
      XMLExtendedStreamReader reader, ModelNode cache, List<ModelNode> operations)
      throws XMLStreamException {
    // ModelNode for the store add operation
    ModelNode storeAddress = cache.get(ModelDescriptionConstants.OP_ADDR).clone();
    storeAddress.add(ModelKeys.REMOTE_STORE, ModelKeys.REMOTE_STORE_NAME);
    storeAddress.protect();
    ModelNode store = Util.getEmptyOperation(ModelDescriptionConstants.ADD, storeAddress);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case CACHE:
          {
            CommonAttributes.CACHE.parseAndSetParameter(value, store, reader);
            break;
          }
        case SOCKET_TIMEOUT:
          {
            CommonAttributes.SOCKET_TIMEOUT.parseAndSetParameter(value, store, reader);
            break;
          }
        case TCP_NO_DELAY:
          {
            CommonAttributes.TCP_NO_DELAY.parseAndSetParameter(value, store, reader);
            break;
          }
        default:
          {
            this.parseStoreAttribute(reader, i, attribute, value, store);
          }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case REMOTE_SERVER:
          {
            this.parseRemoteServer(reader, store.get(ModelKeys.REMOTE_SERVERS).add());
            break;
          }
        default:
          {
            this.parseStoreProperty(reader, store);
          }
      }
    }

    if (!store.hasDefined(ModelKeys.REMOTE_SERVERS)) {
      throw ParseUtils.missingRequired(reader, Collections.singleton(Element.REMOTE_SERVER));
    }
    operations.add(store);
  }
  private void parseJDBCStoreTable(XMLExtendedStreamReader reader, ModelNode table)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case PREFIX:
          {
            table.get(ModelKeys.PREFIX).set(value);
            break;
          }
        case FETCH_SIZE:
          {
            table.get(ModelKeys.FETCH_SIZE).set(Integer.parseInt(value));
            break;
          }
        case BATCH_SIZE:
          {
            table.get(ModelKeys.BATCH_SIZE).set(Integer.parseInt(value));
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case ID_COLUMN:
          {
            this.parseJDBCStoreColumn(reader, table.get(ModelKeys.ID_COLUMN).setEmptyObject());
            break;
          }
        case DATA_COLUMN:
          {
            this.parseJDBCStoreColumn(reader, table.get(ModelKeys.DATA_COLUMN).setEmptyObject());
            break;
          }
        case TIMESTAMP_COLUMN:
          {
            this.parseJDBCStoreColumn(
                reader, table.get(ModelKeys.TIMESTAMP_COLUMN).setEmptyObject());
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
  private void parseBinaryKeyedJDBCStore(
      XMLExtendedStreamReader reader, ModelNode cache, List<ModelNode> operations)
      throws XMLStreamException {

    PathAddress storeAddress =
        PathAddress.pathAddress(cache.get(OP_ADDR))
            .append(ModelKeys.BINARY_KEYED_JDBC_STORE, ModelKeys.BINARY_KEYED_JDBC_STORE_NAME);
    ModelNode store = Util.createAddOperation(storeAddress);

    List<ModelNode> additionalConfigurationOperations = new ArrayList<ModelNode>();

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case DATASOURCE:
          {
            BaseJDBCStoreResource.DATA_SOURCE.parseAndSetParameter(value, store, reader);
            break;
          }
        default:
          {
            this.parseStoreAttribute(reader, i, attribute, value, store);
          }
      }
    }

    if (!store.hasDefined(ModelKeys.DATASOURCE)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.DATASOURCE));
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case BINARY_KEYED_TABLE:
          {
            this.parseJDBCStoreTable(
                reader, store.get(ModelKeys.BINARY_KEYED_TABLE).setEmptyObject());
            break;
          }
        case WRITE_BEHIND:
          {
            parseStoreWriteBehind(reader, store, additionalConfigurationOperations);
            break;
          }
        default:
          {
            this.parseStoreProperty(reader, store, additionalConfigurationOperations);
          }
      }
    }
    operations.add(store);
    operations.addAll(additionalConfigurationOperations);
  }
Ejemplo n.º 23
0
  protected static void readNode(XMLExtendedStreamReader reader, DistributionContentItem parent)
      throws XMLStreamException {

    String name = null;
    String directory = null;
    String comparison = "";
    String metadata = "";

    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final String value = reader.getAttributeValue(i);
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case NAME:
          name = value;
          break;
        case DIRECTORY:
          directory = value;
          break;
        case COMPARISON_HASH:
          comparison = value;
          break;
        case METADATA_HASH:
          metadata = value;
          break;
        default:
          throw unexpectedAttribute(reader, i);
      }
    }

    if (name == null) {
      throw missingRequired(reader, "name");
    }
    final DistributionItemImpl item =
        new DistributionItemImpl(
            parent,
            name,
            hexStringToByteArray(comparison),
            hexStringToByteArray(metadata),
            !Boolean.valueOf(directory));
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case NODE:
          readNode(reader, item);
          break;
        default:
          throw unexpectedElement(reader);
      }
    }
    parent.getChildren().add(item);
  }
Ejemplo n.º 24
0
 protected static void readNodes(XMLExtendedStreamReader reader, DistributionContentItem parent)
     throws XMLStreamException {
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case NODE:
         readNode(reader, parent);
         break;
       default:
         throw unexpectedElement(reader);
     }
   }
 }
Ejemplo n.º 25
0
 private static void parsePermission(XMLStreamReader reader, PermissionMetaData permission)
     throws XMLStreamException {
   while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
     Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case RESOURCE_NAME:
         permission.setResourceName(reader.getElementText());
         break;
       case ALLOW_ALTER:
         permission.setAllowAlter(Boolean.parseBoolean(reader.getElementText()));
         break;
       case ALLOW_CREATE:
         permission.setAllowCreate(Boolean.parseBoolean(reader.getElementText()));
         break;
       case ALLOW_LANGUAGE:
         permission.setAllowLanguage(Boolean.parseBoolean(reader.getElementText()));
         break;
       case ALLOW_DELETE:
         permission.setAllowDelete(Boolean.parseBoolean(reader.getElementText()));
         break;
       case ALLOW_EXECUTE:
         permission.setAllowExecute(Boolean.parseBoolean(reader.getElementText()));
         break;
       case ALLOW_READ:
         permission.setAllowRead(Boolean.parseBoolean(reader.getElementText()));
         break;
       case ALLOW_UPADTE:
         permission.setAllowUpdate(Boolean.parseBoolean(reader.getElementText()));
         break;
       case CONDITION:
         permission.setCondition(reader.getElementText());
         break;
       default:
         throw new XMLStreamException(
             AdminPlugin.Util.gs(
                 "unexpected_element7",
                 reader.getName(),
                 Element.RESOURCE_NAME.getLocalName(),
                 Element.ALLOW_ALTER.getLocalName(),
                 Element.ALLOW_CREATE.getLocalName(),
                 Element.ALLOW_DELETE.getLocalName(),
                 Element.ALLOW_EXECUTE.getLocalName(),
                 Element.ALLOW_READ.getLocalName(),
                 Element.ALLOW_UPADTE.getLocalName(),
                 Element.ALLOW_LANGUAGE.getLocalName(),
                 Element.CONDITION.getLocalName()),
             reader.getLocation());
     }
   }
 }
  private void parseIndexing(XMLExtendedStreamReader reader, ModelNode node)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      if (attribute == Attribute.INDEX) {
        CacheResource.INDEXING.parseAndSetParameter(value, node, reader);
      } else {
        throw ParseUtils.unexpectedAttribute(reader, i);
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case PROPERTY:
          {
            int attributes = reader.getAttributeCount();
            String property = null;
            for (int i = 0; i < attributes; i++) {
              String value = reader.getAttributeValue(i);
              Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
              switch (attribute) {
                case NAME:
                  {
                    property = value;
                    break;
                  }
                default:
                  {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                  }
              }
            }
            if (property == null) {
              throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.NAME));
            }
            String value = reader.getElementText();
            CacheResource.INDEXING_PROPERTIES.parseAndAddParameterElement(
                property, value, node, reader);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
    // ParseUtils.requireNoContent(reader);
  }
Ejemplo n.º 27
0
    private ModelNode parseProperties(final XMLExtendedStreamReader reader)
        throws XMLStreamException {
      ModelNode node = new ModelNode();
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Element.forName(reader.getLocalName())) {
          case PROPERTY:
            {
              final int attrCount = reader.getAttributeCount();
              String propName = null;
              String propValue = null;
              for (int i = 0; i < attrCount; i++) {
                requireNoNamespaceAttribute(reader, i);
                final String value = reader.getAttributeValue(i);
                final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                switch (attribute) {
                  case NAME:
                    {
                      propName = value;
                      break;
                    }
                  case VALUE:
                    {
                      propValue = value;
                    }
                    break;
                  default:
                    throw unexpectedAttribute(reader, i);
                }
              }
              if (propName == null || propValue == null) {
                Set<Attribute> missing = new HashSet<Attribute>();
                if (propName == null) {
                  missing.add(Attribute.NAME);
                }
                if (propValue == null) {
                  missing.add(Attribute.VALUE);
                }
                throw missingRequired(reader, missing);
              }
              node.add(propName, propValue);

              if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                throw unexpectedElement(reader);
              }
            }
        }
      }
      return node;
    }
  private void parseDistributedCache(XMLExtendedStreamReader reader, ModelNode cache)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case OWNERS:
          {
            cache.get(ModelKeys.OWNERS).set(Integer.parseInt(value));
            break;
          }
        case VIRTUAL_NODES:
          {
            cache.get(ModelKeys.VIRTUAL_NODES).set(Integer.parseInt(value));
            break;
          }
        case L1_LIFESPAN:
          {
            cache.get(ModelKeys.L1_LIFESPAN).set(Long.parseLong(value));
            break;
          }
        default:
          {
            this.parseClusteredCacheAttribute(
                reader, i, attribute, value, cache, Configuration.CacheMode.DIST_SYNC);
          }
      }
    }

    if (!cache.hasDefined(ModelKeys.NAME)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME));
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case REHASHING:
          {
            this.parseRehashing(reader, cache.get(ModelKeys.REHASHING).setEmptyObject());
            break;
          }
        default:
          {
            this.parseCacheElement(reader, element, cache);
          }
      }
    }
  }
Ejemplo n.º 29
0
 protected static void readLayers(XMLExtendedStreamReader reader, final Distribution distribution)
     throws XMLStreamException {
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case LAYER:
         readLayer(reader, distribution, false);
         break;
       case ADD_ON:
         readLayer(reader, distribution, true);
         break;
       default:
         throw unexpectedElement(reader);
     }
   }
 }
  private void parseRemoteStore(XMLExtendedStreamReader reader, ModelNode store)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case CACHE:
          {
            store.get(ModelKeys.CACHE).set(value);
            break;
          }
        case SOCKET_TIMEOUT:
          {
            store.get(ModelKeys.SOCKET_TIMEOUT).set(Long.parseLong(value));
            break;
          }
        case TCP_NO_DELAY:
          {
            store.get(ModelKeys.TCP_NO_DELAY).set(Boolean.valueOf(value));
            break;
          }
        default:
          {
            this.parseStoreAttribute(reader, i, attribute, value, store);
          }
      }
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case REMOTE_SERVER:
          {
            this.parseRemoteServer(reader, store.get(ModelKeys.REMOTE_SERVER).add());
            break;
          }
        default:
          {
            this.parseStoreProperty(reader, store);
          }
      }
    }

    if (!store.hasDefined(ModelKeys.REMOTE_SERVER)) {
      throw ParseUtils.missingRequired(reader, Collections.singleton(Element.REMOTE_SERVER));
    }
  }