Exemplo n.º 1
0
  private void addInstanceCountResourceProperty() throws UpgradeException {
    // get the schemas dir so we can copy in the new XSD
    File dataSchemasDir = getDataSchemaDir();
    File instanceCountXsd = new File(dataSchemasDir, MetadataConstants.DATA_INSTANCE_XSD);

    // get the service's schema dir where the wsdl files live
    ServiceType baseService = getServiceInformation().getServices().getService(0);
    String serviceName = baseService.getName();
    File serviceSchemasDir = new File(getServicePath(), "schema" + File.separator + serviceName);

    // copy the schema
    File instanceCountXsdOut = new File(serviceSchemasDir, instanceCountXsd.getName());
    try {
      Utils.copyFile(instanceCountXsd, instanceCountXsdOut);
    } catch (Exception ex) {
      throw new UpgradeException(
          "Error copying data instance counts schema: " + ex.getMessage(), ex);
    }

    // add the schema to the service descriptor
    NamespaceType countNamespace = null;
    try {
      countNamespace =
          CommonTools.createNamespaceType(instanceCountXsdOut.getAbsolutePath(), serviceSchemasDir);
    } catch (Exception ex) {
      throw new UpgradeException(
          "Error creating data instance counts namespace: " + ex.getMessage(), ex);
    }
    countNamespace.setPackageName(MetadataConstants.DATA_INSTANCE_PACKAGE);
    countNamespace.setGenerateStubs(Boolean.FALSE);
    CommonTools.addNamespace(getServiceInformation().getServiceDescriptor(), countNamespace);

    if (CommonTools.getResourcePropertiesOfType(baseService, MetadataConstants.DATA_INSTANCE_QNAME)
            .length
        == 0) {
      // no resource property found, so we have to create and add it
      ResourcePropertyType countRp = new ResourcePropertyType();
      countRp.setRegister(true);
      countRp.setDescription(MetadataConstants.DATA_INSTANCE_DESCRIPTION);
      countRp.setQName(MetadataConstants.DATA_INSTANCE_QNAME);
      CommonTools.addResourcePropety(baseService, countRp);
    }

    // instance count frequency property
    if (!CommonTools.servicePropertyExists(
        getServiceInformation().getServiceDescriptor(),
        InstanceCountConstants.COUNT_UPDATE_FREQUENCY)) {
      CommonTools.setServiceProperty(
          getServiceInformation().getServiceDescriptor(),
          InstanceCountConstants.COUNT_UPDATE_FREQUENCY,
          InstanceCountConstants.COUNT_UPDATE_FREQUENCY_DEFAULT,
          false,
          InstanceCountConstants.COUNT_UPDATE_FREQUENCY_DESCRIPTION);
    }
  }
Exemplo n.º 2
0
  public void sync() throws SynchronizationException {
    try {

      if (service.getResourceFrameworkOptions().getMain() != null) {

        ServiceConfigurationTemplate serviceConfT = new ServiceConfigurationTemplate();
        String serviceConfS =
            serviceConfT.generate(new SpecificServiceInformation(getServiceInformation(), service));
        File serviceConfF =
            new File(
                srcDir.getAbsolutePath()
                    + File.separator
                    + CommonTools.getPackageDir(service)
                    + File.separator
                    + "service"
                    + File.separator
                    + service.getName()
                    + "Configuration.java");
        FileWriter serviceConfFW = new FileWriter(serviceConfF);
        serviceConfFW.write(serviceConfS);
        serviceConfFW.close();
      }

      if (service.getResourceFrameworkOptions().getCustom() == null) {

        ConfigurationTemplate metadataConfigurationT = new ConfigurationTemplate();
        String metadataConfigurationS =
            metadataConfigurationT.generate(
                new SpecificServiceInformation(getServiceInformation(), service));
        File metadataConfigurationF =
            new File(
                srcDir.getAbsolutePath()
                    + File.separator
                    + CommonTools.getPackageDir(service)
                    + File.separator
                    + "service"
                    + File.separator
                    + "globus"
                    + File.separator
                    + "resource"
                    + File.separator
                    + service.getName()
                    + "ResourceConfiguration.java");

        FileWriter metadataConfigurationFW = new FileWriter(metadataConfigurationF);
        metadataConfigurationFW.write(metadataConfigurationS);
        metadataConfigurationFW.close();

        ServiceConstantsBaseTemplate resourceContanstsT = new ServiceConstantsBaseTemplate();
        String resourceContanstsS =
            resourceContanstsT.generate(
                new SpecificServiceInformation(getServiceInformation(), service));
        File resourceContanstsF =
            new File(
                srcDir.getAbsolutePath()
                    + File.separator
                    + CommonTools.getPackageDir(service)
                    + File.separator
                    + "common"
                    + File.separator
                    + service.getName()
                    + "ConstantsBase.java");

        FileWriter resourceContanstsFW = new FileWriter(resourceContanstsF);
        resourceContanstsFW.write(resourceContanstsS);
        resourceContanstsFW.close();

        ResourceBaseTemplate baseResourceBaseT = new ResourceBaseTemplate();
        String baseResourceBaseS =
            baseResourceBaseT.generate(
                new SpecificServiceInformation(getServiceInformation(), service));
        File baseResourceBaseF =
            new File(
                srcDir.getAbsolutePath()
                    + File.separator
                    + CommonTools.getPackageDir(service)
                    + File.separator
                    + "service"
                    + File.separator
                    + "globus"
                    + File.separator
                    + "resource"
                    + File.separator
                    + service.getName()
                    + "ResourceBase.java");

        FileWriter baseResourceBaseFW = new FileWriter(baseResourceBaseF);
        baseResourceBaseFW.write(baseResourceBaseS);
        baseResourceBaseFW.close();
      }
    } catch (IOException e) {
      throw new SynchronizationException("Error writing file:" + e.getMessage(), e);
    }
  }
  private void editWsddForCastorMappings(ServiceInformation info) throws Exception {
    // change out the domain model validator class
    CommonTools.setServiceProperty(
        info.getServiceDescriptor(),
        DataServiceConstants.DOMAIN_MODEL_VALIDATOR_CLASS,
        ISODomainModelValidator.class.getName(),
        false);

    String mainServiceName =
        info.getIntroduceServiceProperties()
            .getProperty(IntroduceConstants.INTRODUCE_SKELETON_SERVICE_NAME);
    ServiceType mainService = CommonTools.getService(info.getServices(), mainServiceName);
    String servicePackageName = mainService.getPackageName();
    String packageDir = servicePackageName.replace('.', File.separatorChar);
    // find the client source directory, where the client-config will be located
    File clientConfigFile =
        new File(
            info.getBaseDirectory(),
            "src"
                + File.separator
                + packageDir
                + File.separator
                + "client"
                + File.separator
                + "client-config.wsdd");
    LOG.debug("Editing client config wsdd at " + clientConfigFile.getAbsolutePath());
    if (!clientConfigFile.exists()) {
      throw new CodegenExtensionException(
          "Client config file " + clientConfigFile.getAbsolutePath() + " not found!");
    }
    // find the server-config.wsdd, located in the service's root directory
    File serverConfigFile = new File(info.getBaseDirectory(), "server-config.wsdd");
    LOG.debug("Editing server config wsdd at " + serverConfigFile.getAbsolutePath());
    if (!serverConfigFile.exists()) {
      throw new CodegenExtensionException(
          "Server config file " + serverConfigFile.getAbsolutePath() + " not found!");
    }

    // edit the marshaling castor mapping to avoid serializing associations
    File castorMappingFile = new File(CastorMappingUtil.getMarshallingCastorMappingFileName(info));
    if (castorMappingFile.exists()) {
      String marshallingXmlText = Utils.fileToStringBuffer(castorMappingFile).toString();
      String editedMarshallingText =
          CastorMappingUtil.removeAssociationMappings(marshallingXmlText);
      String editedMarshallingFileName =
          CastorMappingUtil.getEditedMarshallingCastorMappingFileName(info);
      Utils.stringBufferToFile(new StringBuffer(editedMarshallingText), editedMarshallingFileName);

      // edit the unmarshaling castor mapping to avoid deserializing associations
      String unmarshallingXmlText =
          Utils.fileToStringBuffer(
                  new File(CastorMappingUtil.getUnmarshallingCastorMappingFileName(info)))
              .toString();
      String editedUnmarshallingText =
          CastorMappingUtil.removeAssociationMappings(unmarshallingXmlText);
      String editedUnmarshallingFileName =
          CastorMappingUtil.getEditedUnmarshallingCastorMappingFileName(info);
      Utils.stringBufferToFile(
          new StringBuffer(editedUnmarshallingText), editedUnmarshallingFileName);

      // set properties in the client to use the edited marshaler
      WsddUtil.setGlobalClientParameter(
          clientConfigFile.getAbsolutePath(),
          SDK43EncodingUtils.CASTOR_MARSHALLER_PROPERTY,
          CastorMappingUtil.getEditedMarshallingCastorMappingName(info));
      // and the edited unmarshaler
      WsddUtil.setGlobalClientParameter(
          clientConfigFile.getAbsolutePath(),
          SDK43EncodingUtils.CASTOR_UNMARSHALLER_PROPERTY,
          CastorMappingUtil.getEditedUnmarshallingCastorMappingName(info));

      // set properties in the server to use the edited marshaler
      WsddUtil.setServiceParameter(
          serverConfigFile.getAbsolutePath(),
          info.getServices().getService(0).getName(),
          SDK43EncodingUtils.CASTOR_MARSHALLER_PROPERTY,
          CastorMappingUtil.getEditedMarshallingCastorMappingName(info));
      // and the edited unmarshaler
      WsddUtil.setServiceParameter(
          serverConfigFile.getAbsolutePath(),
          info.getServices().getService(0).getName(),
          SDK43EncodingUtils.CASTOR_UNMARSHALLER_PROPERTY,
          CastorMappingUtil.getEditedUnmarshallingCastorMappingName(info));
    } else {
      LOG.debug(
          "Castor mapping file "
              + castorMappingFile.getAbsolutePath()
              + " not found... this is OK if you're using JaxB serialization");
    }
  }