List of usage examples for java.lang Module getName
public String getName()
From source file:org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl.java
public Type generatedTypeForExtendedDefinitionType(final TypeDefinition<?> typeDefinition) { Type returnType = null;//from ww w. ja v a 2 s. c om if (typeDefinition == null) { throw new IllegalArgumentException("Type Definition cannot be NULL!"); } if (typeDefinition.getQName() == null) { throw new IllegalArgumentException( "Type Definition cannot have non specified QName (QName cannot be NULL!)"); } if (typeDefinition.getQName() == null) { throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!"); } final String typedefName = typeDefinition.getQName().getLocalName(); if (typeDefinition instanceof ExtendedType) { final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition); if (!(baseTypeDef instanceof LeafrefTypeDefinition) && !(baseTypeDef instanceof IdentityrefTypeDefinition)) { final Module module = findParentModuleForTypeDefinition(schemaContext, typeDefinition); if (module != null) { final Map<String, Type> genTOs = genTypeDefsContextMap.get(module.getName()); if (genTOs != null) { returnType = genTOs.get(typedefName); } } } } return returnType; }
From source file:org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl.java
@Override public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition) { Type returnType = null;/*w w w.j ava2s . com*/ if (typeDefinition == null) { throw new IllegalArgumentException("Type Definition cannot be NULL!"); } if (typeDefinition.getQName() == null) { throw new IllegalArgumentException( "Type Definition cannot have non specified QName (QName cannot be NULL!)"); } if (typeDefinition.getQName().getLocalName() == null) { throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!"); } final String typedefName = typeDefinition.getQName().getLocalName(); if (typeDefinition instanceof ExtendedType) { final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition); if (baseTypeDef instanceof LeafrefTypeDefinition) { final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) baseTypeDef; returnType = provideTypeForLeafref(leafref); } else if (baseTypeDef instanceof IdentityrefTypeDefinition) { final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) baseTypeDef; returnType = returnTypeForIdentityref(idref); } else if (baseTypeDef instanceof EnumTypeDefinition) { final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef; returnType = resolveEnumFromTypeDefinition(enumTypeDef, typedefName); } else { final Module module = findParentModuleForTypeDefinition(schemaContext, typeDefinition); if (module != null) { final Map<String, Type> genTOs = genTypeDefsContextMap.get(module.getName()); if (genTOs != null) { returnType = genTOs.get(typedefName); } if (returnType == null) { returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER .javaTypeForSchemaDefinitionType(baseTypeDef); } } } } else { if (typeDefinition instanceof LeafrefTypeDefinition) { final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition; returnType = provideTypeForLeafref(leafref); } else if (typeDefinition instanceof IdentityrefTypeDefinition) { final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition; returnType = returnTypeForIdentityref(idref); } else { returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition); } } // TODO: add throw exception when we will be able to resolve ALL yang // types! // if (returnType == null) { // throw new IllegalArgumentException("Type Provider can't resolve " + // "type for specified Type Definition " + typedefName); // } return returnType; }
From source file:org.openmrs.module.ModuleFactory.java
/** * Execute all unrun changeSets in liquibase.xml for the given module * /* w w w. ja v a 2 s . c o m*/ * @param module the module being executed on */ private static void runLiquibase(Module module) { JarFile jarFile = null; boolean liquibaseFileExists = false; try { try { jarFile = new JarFile(module.getFile()); } catch (IOException e) { throw new ModuleException("Unable to get jar file", module.getName(), e); } //check whether module has a liquibase.xml InputStream inStream = null; ZipEntry entry = null; try { inStream = ModuleUtil.getResourceFromApi(jarFile, module.getModuleId(), module.getVersion(), MODULE_CHANGELOG_FILENAME); if (inStream == null) { // Try the old way. Loading from the root of the omod entry = jarFile.getEntry(MODULE_CHANGELOG_FILENAME); } liquibaseFileExists = (inStream != null) || (entry != null); } finally { IOUtils.closeQuietly(inStream); } } finally { try { if (jarFile != null) { jarFile.close(); } } catch (IOException e) { log.warn("Unable to close jarfile: " + jarFile.getName()); } } if (liquibaseFileExists) { try { // run liquibase.xml by Liquibase API DatabaseUpdater.executeChangelog(MODULE_CHANGELOG_FILENAME, null, null, null, getModuleClassLoader(module)); } catch (InputRequiredException ire) { // the user would be stepped through the questions returned here. throw new ModuleException("Input during database updates is not yet implemented.", module.getName(), ire); } catch (DatabaseUpdateException e) { throw new ModuleException("Unable to update data model using liquibase.xml.", module.getName(), e); } catch (Exception e) { throw new ModuleException("Unable to update data model using liquibase.xml.", module.getName(), e); } } }
From source file:org.obiba.onyx.engine.ModuleRegistrationListener.java
@SuppressWarnings("unchecked") public void startup(WebApplication application) { Map<String, Module> modules = applicationContext.getBeansOfType(Module.class); Stage conclusionStage = null;/*www.j ava 2s . c o m*/ if (modules != null) { boolean finalStageFound = false; for (Module module : modules.values()) { // check there is one and only one conclusion stage defined for (Stage stage : module.getStages()) { if (stage.isInterviewConclusion()) { if (!finalStageFound) { stage.setStageDependencyCondition(new FinalDependencyCondition(registry)); finalStageFound = true; conclusionStage = stage; } else { throw new IllegalArgumentException( "Several interview conclusion stages is not allowed."); } } } try { log.info("Initializing module '{}' of type {}", module.getName(), module.getClass().getSimpleName()); module.initialize(application); } catch (RuntimeException e) { log.error("Could not initialize module '{}'", module.getName()); log.error("Module initialisation failed due to the following exception.", e); // Try to register the other modules anyway continue; } try { registry.registerModule(module); } catch (RuntimeException e) { try { module.shutdown(application); } catch (RuntimeException ignored) { } } } if (!finalStageFound) { throw new IllegalArgumentException( "An interview conclusion stage is required. Add <interviewConclusion>true</interviewConclusion> to the conclusion stage configuration file."); } if (existsDependenciesOnConclusion(modules, conclusionStage)) throw new IllegalArgumentException( "A StageDependencyCondition based on the conclusion was found on another stage. Please remove the StageDependencyCondition: no stage should depend on the conclusion"); } }
From source file:org.openmrs.module.ModuleFactory.java
/** * Send an Alert to all super users that the given module did not start successfully. * /*w w w .j a va2 s . c o m*/ * @param mod The Module that failed */ private static void notifySuperUsersAboutModuleFailure(Module mod) { try { // Add the privileges necessary for notifySuperUsers Context.addProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); // Send an alert to all administrators Context.getAlertService().notifySuperUsers("Module.startupError.notification.message", null, mod.getName()); } catch (Exception e) { log.error("Unable to send an alert to the super users", e); } finally { // Remove added privileges Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); } }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Override @Transactional// www . j a v a 2 s .co m public void initDb(User user, String applicationName, final String moduleName, File file) throws ServiceException { logger.info("initData : " + applicationName + " - " + moduleName); Map<String, String> configShell = new HashMap<>(); Application application = applicationDAO.findByNameAndUser(user.getId(), applicationName); if (application == null) { throw new ServiceException("initData : Application not found", null); } logger.debug("Application found ID " + application.getId() + " - " + application.getName()); Collection<Module> modules = Collections2.filter(application.getModules(), new Predicate<Module>() { @Override public boolean apply(Module input) { return input.getName().equalsIgnoreCase(moduleName) ? true : false; } }); if (modules.size() < 1) { throw new ServiceException("initDb : Module not found", null); } Module module = modules.iterator().next(); logger.debug("Module found " + module.getId() + " - " + module.getName()); try { configShell.put("port", module.getSshPort()); configShell.put("dockerManagerAddress", application.getManagerIp()); String rootPassword = module.getApplication().getUser().getPassword(); configShell.put("password", rootPassword); shellUtils.sendFile(file, "root", rootPassword, module.getSshPort(), application.getManagerIp(), "/cloudunit/software/tmp/initData.sql"); shellUtils.executeShell(module.getModuleAction().getInitDataCmd(), configShell); module.setStatus(Status.START); module = this.update(module); // file.delete(); } catch (Exception e) { module.setStatus(Status.FAIL); this.saveInDB(module); throw new ServiceException(e.getLocalizedMessage(), e); } }
From source file:uk.codingbadgers.SurvivalPlus.SurvivalPlus.java
/** * Handle a player join event/* ww w . j av a 2 s. c o m*/ * * @param event The player join event */ @EventHandler(priority = EventPriority.NORMAL) public void onPlayerJoin(PlayerJoinEvent event) { FundamentalPlayer newPlayer = new FundamentalPlayer(event.getPlayer()); SurvivalPlus.Players.add(newPlayer); List<Module> modules = m_moduleLoader.getModules(); for (Module module : modules) { Class<? extends PlayerData> playerDataClass = module.getPlayerDataClass(); if (playerDataClass != null) { try { PlayerData data = (PlayerData) playerDataClass.newInstance(); newPlayer.addPlayerData(data.getGroup(), data.getName(), data); } catch (Exception ex) { SurvivalPlus.log(Level.WARNING, "Failed to create new player data for '" + event.getPlayer().getName() + "' for module '" + module.getName() + "'", ex); } } } }
From source file:uk.submergedcode.SubmergedCore.SubmergedCore.java
/** * Handle a player join event/* www. ja va 2s .c om*/ * * @param event The player join event */ @EventHandler(priority = EventPriority.NORMAL) public void onPlayerJoin(PlayerJoinEvent event) { FundamentalPlayer newPlayer = new FundamentalPlayer(event.getPlayer()); SubmergedCore.Players.add(newPlayer); List<Module> modules = m_moduleLoader.getModules(); for (Module module : modules) { Class<? extends PlayerData> playerDataClass = module.getPlayerDataClass(); if (playerDataClass != null) { try { PlayerData data = (PlayerData) playerDataClass.newInstance(); newPlayer.addPlayerData(data.getGroup(), data.getName(), data); } catch (Exception ex) { SubmergedCore.log(Level.WARNING, "Failed to create new player data for '" + event.getPlayer().getName() + "' for module '" + module.getName() + "'", ex); } } } }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
public List<String> listContainersId(String applicationName, boolean withModules) throws ServiceException { List<String> containers = new ArrayList<>(); try {// w ww. j a va 2 s. c om Application application = findByNameAndUser(authentificationUtils.getAuthentificatedUser(), applicationName); if (application != null) { try { // Serveurs List<Server> servers = application.getServers(); // Ajout des containers de type server for (Server server : servers) { DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(server.getName()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); server = containerMapper.mapDockerContainerToServer(dockerContainer, server); containers.add(server.getContainerID()); } // Ajout des containers de type module if (withModules) { List<Module> modules = application.getModules(); for (Module module : modules) { DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(module.getName()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); module = containerMapper.mapDockerContainerToModule(dockerContainer, module); containers.add(module.getContainerID()); } } } catch (Exception ex) { // Si une application sort en erreur, il ne faut pas // arrter la suite des traitements logger.error(application.toString(), ex); } } } catch (Exception e) { throw new ServiceException(e.getLocalizedMessage(), e); } return containers; }
From source file:org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl.java
public GeneratedTOBuilder addUnionGeneratedTypeDefinition(final String basePackageName, final TypeDefinition<?> typedef, String typeDefName) { if (basePackageName == null) { throw new IllegalArgumentException("Base Package Name cannot be NULL!"); }//ww w.j a va 2 s .co m if (typedef == null) { throw new IllegalArgumentException("Type Definition cannot be NULL!"); } if (typedef.getQName() == null) { throw new IllegalArgumentException( "Type Definition cannot have non specified QName (QName cannot be NULL!)"); } final TypeDefinition<?> baseTypeDefinition = typedef.getBaseType(); if ((baseTypeDefinition != null) && (baseTypeDefinition instanceof UnionTypeDefinition)) { final Module parentModule = findParentModuleForTypeDefinition(schemaContext, typedef); final UnionTypeDefinition unionTypeDef = (UnionTypeDefinition) baseTypeDefinition; final List<TypeDefinition<?>> unionTypes = unionTypeDef.getTypes(); Map<String, Type> genTOsMap = null; if (parentModule != null && parentModule.getName() != null) { genTOsMap = genTypeDefsContextMap.get(parentModule.getName()); } final GeneratedTOBuilder unionGenTransObject; if (typeDefName != null && !typeDefName.isEmpty()) { final String typeName = parseToClassName(typeDefName); unionGenTransObject = new GeneratedTOBuilderImpl(basePackageName, typeName); } else { unionGenTransObject = typedefToTransferObject(basePackageName, typedef); } unionGenTransObject.setIsUnion(true); final List<String> regularExpressions = new ArrayList<String>(); for (final TypeDefinition<?> unionType : unionTypes) { final String typeName = unionType.getQName().getLocalName(); if (unionType instanceof ExtendedType) { final Module unionTypeModule = findParentModuleForTypeDefinition(schemaContext, unionType); if (unionTypeModule != null && unionTypeModule.getName() != null) { final Map<String, Type> innerGenTOs = genTypeDefsContextMap.get(unionTypeModule.getName()); Type genTransferObject = null; if (innerGenTOs != null) { genTransferObject = innerGenTOs.get(typeName); } if (genTransferObject != null) { updateUnionTypeAsProperty(unionGenTransObject, genTransferObject, genTransferObject.getName()); } else { final TypeDefinition<?> baseType = baseTypeDefForExtendedType(unionType); if (typeName.equals(baseType.getQName().getLocalName())) { final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER .javaTypeForSchemaDefinitionType(baseType); if (javaType != null) { updateUnionTypeAsProperty(unionGenTransObject, javaType, typeName); } } if (baseType instanceof StringType) { regularExpressions .addAll(resolveRegExpressionsFromTypedef((ExtendedType) unionType)); } } } } else if (unionType instanceof EnumTypeDefinition) { final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition( (EnumTypeDefinition) unionType, typeName, unionGenTransObject); final Type enumRefType = new ReferencedTypeImpl(enumBuilder.getPackageName(), enumBuilder.getName()); updateUnionTypeAsProperty(unionGenTransObject, enumRefType, typeName); } else { final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER .javaTypeForSchemaDefinitionType(unionType); if (javaType != null) { updateUnionTypeAsProperty(unionGenTransObject, javaType, typeName); } } } if (!regularExpressions.isEmpty()) { addStringRegExAsConstant(unionGenTransObject, regularExpressions); } genTOsMap.put(typedef.getQName().getLocalName(), unionGenTransObject.toInstance()); return unionGenTransObject; } return null; }