protected void writeOutAuditorConfiguration(Data extData, ServiceInformation serviceInfo) throws CodegenExtensionException { if (CommonTools.servicePropertyExists( serviceInfo.getServiceDescriptor(), DataServiceConstants.DATA_SERVICE_AUDITORS_CONFIG_FILE_PROPERTY)) { try { // get the name of the auditor config file String filename = CommonTools.getServicePropertyValue( serviceInfo.getServiceDescriptor(), DataServiceConstants.DATA_SERVICE_AUDITORS_CONFIG_FILE_PROPERTY); if (extData.getDataServiceAuditors() != null) { File outFile = new File( serviceInfo.getBaseDirectory().getAbsolutePath() + File.separator + "etc" + File.separator + filename); FileWriter writer = new FileWriter(outFile); Utils.serializeObject( extData.getDataServiceAuditors(), DataServiceConstants.DATA_SERVICE_AUDITORS_QNAME, writer); writer.flush(); writer.close(); } } catch (Exception ex) { ex.printStackTrace(); throw new CodegenExtensionException( "Error writing auditor configuration: " + ex.getMessage(), ex); } } }
protected void modifyEclipseClasspath( ServiceExtensionDescriptionType desc, ServiceInformation info) throws CodegenExtensionException { // get the eclipse classpath document File classpathFile = new File(info.getBaseDirectory(), ".classpath"); if (classpathFile.exists()) { logger.info("Modifying eclipse .classpath file"); Set<File> libs = new HashSet<File>(); ExtensionTypeExtensionData data = ExtensionTools.getExtensionData(desc, info); AdditionalLibraries additionalLibs = null; try { additionalLibs = ExtensionDataUtils.getExtensionData(data).getAdditionalLibraries(); } catch (Exception ex) { throw new CodegenExtensionException("Error retrieving extension data"); } if (additionalLibs != null && additionalLibs.getJarName() != null) { for (int i = 0; i < additionalLibs.getJarName().length; i++) { String jarFilename = additionalLibs.getJarName(i); libs.add(new File(info.getBaseDirectory(), "lib" + File.separator + jarFilename)); } } File[] libFiles = new File[libs.size()]; libs.toArray(libFiles); try { logger.info("Adding libraries to classpath file:"); for (int i = 0; i < libFiles.length; i++) { logger.info("\t" + libFiles[i].getAbsolutePath()); } ExtensionUtilities.syncEclipseClasspath(classpathFile, libFiles); } catch (Exception ex) { throw new CodegenExtensionException( "Error modifying Eclipse .classpath file: " + ex.getMessage(), ex); } } else { logger.warn("Eclipse .classpath file " + classpathFile.getAbsolutePath() + " not found!"); } }
protected void generateClassToQnameMapping(Data extData, ServiceInformation info) throws CodegenExtensionException { try { Mappings mappings = new Mappings(); List<ClassToQname> classMappings = new LinkedList<ClassToQname>(); // the first place to look for mappings is in the model information, which // is derived from the data service Domain Model. If no domain model is to be used, // the mappings are still required to do anything with caCORE SDK beans. ModelInformation modelInfo = extData.getModelInformation(); if (modelInfo != null && !ModelSourceType.none.equals(modelInfo.getSource()) && modelInfo.getModelPackage() != null) { logger.debug("Model information / domain model found in service model."); logger.debug("Generating class to qname mapping from the information"); logger.debug("stored in the service model"); // walk packages in the model for (ModelPackage pack : modelInfo.getModelPackage()) { // locate a NamsepaceType in the service model mapped to this package NamespaceType mappedNamespace = null; for (NamespaceType nsType : info.getServiceDescriptor().getNamespaces().getNamespace()) { if (pack.getPackageName().equals(nsType.getPackageName())) { mappedNamespace = nsType; break; } } if (mappedNamespace != null && pack.getModelClass() != null) { // walk classes in this package, if any exist for (ModelClass clazz : pack.getModelClass()) { if (clazz.isTargetable()) { // find a schema element type mapped to this class for (SchemaElementType element : mappedNamespace.getSchemaElement()) { if (clazz.getShortClassName().equals(element.getClassName())) { // found it! Create a mapping QName qname = new QName(mappedNamespace.getNamespace(), element.getType()); String fullClassname = pack.getPackageName() + "." + clazz.getShortClassName(); ClassToQname map = new ClassToQname(fullClassname, qname.toString()); classMappings.add(map); break; } } } } } else { logger.warn( "Model package " + pack.getPackageName() + " is not mapped to any namespace!"); } } ClassToQname[] mapArray = new ClassToQname[classMappings.size()]; classMappings.toArray(mapArray); mappings.setMapping(mapArray); } else { logger.warn("No model information / domain model found in service model."); logger.warn("Falling back to schema information for class to qname mapping."); NamespaceType[] namespaces = info.getNamespaces().getNamespace(); // a set of namespaces to ignore Set<String> nsIgnores = new HashSet<String>(); nsIgnores.add(IntroduceConstants.W3CNAMESPACE); nsIgnores.add(info.getServices().getService(0).getNamespace()); nsIgnores.add(DataServiceConstants.ENUMERATION_DATA_SERVICE_NAMESPACE); nsIgnores.add(DataServiceConstants.DATA_SERVICE_NAMESPACE); nsIgnores.add(DataServiceConstants.CQL_QUERY_URI); nsIgnores.add(DataServiceConstants.CQL_RESULT_SET_URI); for (int nsIndex = 0; nsIndex < namespaces.length; nsIndex++) { NamespaceType currentNs = namespaces[nsIndex]; // ignore any unneeded namespaces if (!nsIgnores.contains(currentNs.getNamespace())) { SchemaElementType[] schemaElements = currentNs.getSchemaElement(); for (int elemIndex = 0; schemaElements != null && elemIndex < schemaElements.length; elemIndex++) { SchemaElementType currentElement = schemaElements[elemIndex]; ClassToQname toQname = new ClassToQname(); QName qname = new QName(currentNs.getNamespace(), currentElement.getType()); String shortClassName = currentElement.getClassName(); if (shortClassName == null) { shortClassName = currentElement.getType(); } String fullClassName = currentNs.getPackageName() + "." + shortClassName; toQname.setQname(qname.toString()); toQname.setClassName(fullClassName); classMappings.add(toQname); } } } } ClassToQname[] mapArray = new ClassToQname[classMappings.size()]; classMappings.toArray(mapArray); mappings.setMapping(mapArray); // create the filename where the mapping will be stored String mappingFilename = new File( info.getBaseDirectory(), "etc" + File.separator + DataServiceConstants.CLASS_TO_QNAME_XML) .getAbsolutePath(); // serialize the mapping to that file Utils.serializeDocument(mappingFilename, mappings, DataServiceConstants.MAPPING_QNAME); } catch (Exception ex) { ex.printStackTrace(); throw new CodegenExtensionException( "Error generating class to QName mapping: " + ex.getMessage(), ex); } }
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"); } }