All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ingo.pojogen-maven-plugin.4.2.0.source-code.service.vm Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
#*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *#
#if(!$package.isEmpty())
package ${package};
#end

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.olingo.client.api.EdmEnabledODataClient;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.ext.proxy.api.AbstractTerm;
import org.apache.olingo.ext.proxy.AbstractService;

public class Service extends AbstractService {

  //CHECKSTYLE:OFF (Maven checkstyle)
  private static final String COMPRESSED_METADATA = "$metadata";
  private static final String METADATA_ETAG = #if($metadataETag)"$metadataETag"#{else}null#{end};
  //CHECKSTYLE:ON (Maven checkstyle)

  private static final Map> SERVICES = new ConcurrentHashMap>();

  @SuppressWarnings("unchecked")
  private static  Service getInstance(
          final ODataServiceVersion version, final String serviceRoot, final boolean transactional) {

    if (!SERVICES.containsKey(serviceRoot)) {
      final Service instance = new Service(COMPRESSED_METADATA, METADATA_ETAG, 
          version, serviceRoot, transactional);
      SERVICES.put(serviceRoot, instance);
    }

    return (Service) SERVICES.get(serviceRoot);
  }

  /**
   * Gives an OData 4.0 instance for given service root, operating in transactions (with batch requests).
   *
   * @param serviceRoot OData service root
   * @return OData 4.0 instance for given service root, operating in transactions (with batch requests)
   */
  public static Service getV4(
          final String serviceRoot) {

    return getV4(serviceRoot, true);
  }

  /**
   * Gives an OData 4.0 instance for given service root.
   *
   * @param serviceRoot OData service root
   * @param transactional whether operating in transactions (with batch requests) or not
   * @return OData 4.0 instance for given service root
   */
  public static Service getV4(
          final String serviceRoot, final boolean transactional) {

    return getInstance(ODataServiceVersion.V40, serviceRoot, transactional);
  }

  private final Map> entityTypes = new HashMap>();

  private final Map> complexTypes = new HashMap>();

  private final Map> enumTypes = new HashMap>();

  private final Map> terms = new HashMap>();

  public Service(final String compressedMetadata, final String metadataETag,
          final ODataServiceVersion version, final String serviceRoot, final boolean transactional) {

    super(compressedMetadata, metadataETag,version, serviceRoot, transactional);

    //CHECKSTYLE:OFF (Maven checkstyle)
#foreach ($entityType in $entityTypes.entrySet())
    entityTypes.put("$entityType.key", ${entityType.value}.class);
#end
#foreach ($complexType in $complexTypes.entrySet())
    complexTypes.put("$complexType.key", ${complexType.value}.class);
#end
#foreach ($enumType in $enumTypes.entrySet())
    enumTypes.put("$enumType.key", ${enumType.value}.class);
#end
#foreach ($term in $terms.entrySet())
    terms.put("$term.key", ${term.value}.class);
#end
    //CHECKSTYLE:ON (Maven checkstyle)
  }

  @Override
  public Class getEntityTypeClass(final String name) {
    return entityTypes.get(name);
  }

  @Override
  public Class getComplexTypeClass(final String name) {
    return complexTypes.get(name);
  }

  @Override
  public Class getEnumTypeClass(final String name) {
    return enumTypes.get(name);
  }

  @Override
  public Class getTermClass(final String name) {
    return terms.get(name);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy