Locates and processes persistence.xml file in an Application Client module. <p>

@param applInfo the application archive information
@param module   the client module archive information
324432
private void processClientModulePersistenceXml(JPAApplInfo applInfo, ContainerInfo module, ClassLoader loader) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "processClientModulePersistenceXml : " + applInfo.getApplName() +
                         "#" + module.getName());

        String archiveName = module.getName();
        Container clientContainer = module.getContainer();
        ClassLoader clientClassLoader = loader;

        // ------------------------------------------------------------------------
        // JPA 2.0 Specification - 8.2 Persistence Unit Packaging
        //
        // A persistence unit is defined by a persistence.xml file. The jar file or
        // directory whose META-INF directory contains the persistence.xml file is
        // termed the root of the persistence unit. In Java EE environments, the
        // root of a persistence unit may be one of the following:
        //
        // -> an EJB-JAR file
        // ------------------------------------------------------------------------

        // Obtain persistence.xml in META-INF
        Entry pxml = clientContainer.getEntry("META-INF/persistence.xml");
        if (pxml != null) {
            String appName = applInfo.getApplName();
            URL puRoot = getPXmlRootURL(appName, archiveName, pxml);
            applInfo.addPersistenceUnits(new OSGiJPAPXml(applInfo, archiveName, JPAPuScope.Client_Scope, puRoot, clientClassLoader, pxml));
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "processClientModulePersistenceXml : " + applInfo.getApplName() +
                        "#" + module.getName());
    }
258617
protected void appendAppId(ApplicationId appId, Message m) {
    if (appId == null) {
      return;
    }

    // check if any application-id avp is already present.
    // we could use m.getApplicationIdAvps().size() > 0 but this should spare a few cpu cycles
    for (Avp avp : m.getAvps()) {
      int code = avp.getCode();
      if (code == Avp.ACCT_APPLICATION_ID || code == Avp.AUTH_APPLICATION_ID || code == Avp.VENDOR_SPECIFIC_APPLICATION_ID) {
        return;
      }
    }

    if (appId.getVendorId() == 0) {
      if (appId.getAcctAppId() != 0) {
        m.getAvps().addAvp(Avp.ACCT_APPLICATION_ID, appId.getAcctAppId(), true, false, true);
      }
      if (appId.getAuthAppId() != 0) {
        m.getAvps().addAvp(Avp.AUTH_APPLICATION_ID, appId.getAuthAppId(), true, false, true);
      }
    }
    else {
      AvpSet avp = m.getAvps().addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, true, false);
      avp.addAvp(Avp.VENDOR_ID, appId.getVendorId(), true, false, true);
      if (appId.getAuthAppId() != 0) {
        avp.addAvp(Avp.AUTH_APPLICATION_ID, appId.getAuthAppId(), true, false, true);
      }
      if (appId.getAcctAppId() != 0) {
        avp.addAvp(Avp.ACCT_APPLICATION_ID, appId.getAcctAppId(), true, false, true);
      }
    }
  }
673167
@FFDCIgnore(value = UnableToAdaptException.class)
    public void addApplication(ApplicationInstallInfo installInfo) {
        // ...and now create the new... start by asking the handler what needs monitoring
        final Collection<Notification> notificationsToMonitor;
        final boolean listenForRootStructuralChanges;
        ApplicationMonitoringInformation ami = installInfo.getApplicationMonitoringInformation();
        if (ami != null) {
            notificationsToMonitor = ami.getNotificationsToMonitor();
            listenForRootStructuralChanges = ami.isListeningForRootStructuralChanges();
        } else {
            notificationsToMonitor = null;
            listenForRootStructuralChanges = true;
        }

        try {
            // Now create the listeners for these notifications
            ApplicationListeners listeners = new ApplicationListeners(installInfo.getUpdateHandler(), _executorService);

            /*
             * Go through all of the notifications to monitor and create a listener for it. Note we also always create a different type of listener for root so if the app is
             * deleted we
             * know about it. Optionally (based on the handler) this might also monitor for files being added or removed from the root to trigger an update, i.e. if a WAR gets
             * added to
             * the root of an EAR.
             */
            if (notificationsToMonitor != null) {
                for (Notification notificationToMonitor : notificationsToMonitor) {
                    ApplicationListener listener = new ApplicationListener(notificationToMonitor, listeners, installInfo);
                    listeners.addListener(listener);
                }

                // If the handler did request monitoring then we still need a non-recursive handler to check root
                listeners.addListener(new RootApplicationListener(installInfo.getContainer(), listenForRootStructuralChanges, listeners));
            } else {
                /*
                 * If the handler didn't give us any information about what to monitor then monitor the whole application, note we use another type of listener again here that will
                 * monitor for root deletions or updates to any part of the application
                 */
                listeners.addListener(new CompleteApplicationListener(installInfo.getContainer(), listeners));
            }

            ApplicationListeners old = _appListeners.put(installInfo.getPid(), listeners);

            if (old != null) {
                old.stopListeners(true);
            }

            // If we're actively scanning, start the new listener
            ApplicationMonitorConfig config = _config.get();
            if (config.getUpdateTrigger() != UpdateTrigger.DISABLED) {
                listeners.startListeners(config.getPollingRate(), config.getUpdateTrigger() == UpdateTrigger.MBEAN);
            }
        } catch (UnableToAdaptException e) {
            // Ignore, we just won't monitor this application but do put out a warning message
            AppMessageHelper.get(installInfo.getHandler()).warning("APPLICATION_MONITORING_FAIL", installInfo.getName());
        }
    }
724291
public static void resetIfAppVersionChanged(Context context) {
        SharedPreferences prefs = getSharedPreferences(context);

        int appVersionCode = Integer.MIN_VALUE;
        final int previousAppVersionCode = prefs.getInt(PREF_KEY_APP_VERSION_CODE, Integer.MIN_VALUE);
        try {
            appVersionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "Occurred PackageManager.NameNotFoundException", e);
        }

        if (previousAppVersionCode != appVersionCode) {
            SharedPreferences.Editor prefsEditor = prefs.edit();
            prefsEditor.putLong(PREF_KEY_APP_LAUNCH_COUNT, 0);
            prefsEditor.putLong(PREF_KEY_APP_THIS_VERSION_CODE_LAUNCH_COUNT, 0);
            prefsEditor.putLong(PREF_KEY_APP_FIRST_LAUNCHED_DATE, 0);
            prefsEditor.putInt(PREF_KEY_APP_VERSION_CODE, Integer.MIN_VALUE);
            prefsEditor.putLong(PREF_KEY_RATE_CLICK_DATE, 0);
            prefsEditor.putLong(PREF_KEY_REMINDER_CLICK_DATE, 0);
            prefsEditor.putBoolean(PREF_KEY_DO_NOT_SHOW_AGAIN, false);
            prefsEditor.commit();
        }
    }
408614
protected void updateApp(CmsRole role) {

        m_app.update(m_parentOU, CmsOuTreeType.ROLE, role.getId(), "");
    }
1281459
private Object processJavaColonApp(String lookupName) throws NamingException {

        ComponentMetaData cmd = getComponentMetaData(JavaColonNamespace.APP, lookupName);
        ModuleMetaData mmd = cmd.getModuleMetaData();
        ApplicationMetaData amd = mmd.getApplicationMetaData();

        Lock readLock = javaColonLock.readLock();
        readLock.lock();

        EJBBinding binding = null;
        try {
            JavaColonNamespaceBindings<EJBBinding> appMap = getAppBindingMap(amd);
            if (appMap != null) {
                binding = appMap.lookup(lookupName);
            }
        } finally {
            readLock.unlock();
        }

        return processJavaColon(binding, JavaColonNamespace.APP, lookupName);
    }
628400
@ObjectiveCName("bindRawFileWithReference:autoStart:withCallback:")
    public void bindRawFile(FileReference fileReference, boolean isAutoStart, FileCallback callback) {
        modules.getFilesModule().bindFile(fileReference, isAutoStart, callback);
    }
762705
private Map<String, EntityMetadata> getEntityMetadataCol(ApplicationMetadata appMetadata, String persistenceUnit)
    {
        Metamodel metaModel = appMetadata.getMetamodel(persistenceUnit);
        Map<String, EntityMetadata> entityMetadataMap = ((MetamodelImpl) metaModel).getEntityMetadataMap();
        return entityMetadataMap;
    }
460315
function parseModule(fileInfo) {

    var moduleName = file2modulename(fileInfo.relativePath);
    var sourceFile = new SourceFile(moduleName, fileInfo.content);
    var comments = [];
    var moduleTree;
    var parser = new Parser(sourceFile);

    // Configure the parser
    parser.handleComment = function(range) {
      comments.push({ range: range });
    };
    traceurOptions.setFromObject(service.traceurOptions);

    try {
      // Parse the file as a module, attaching the comments
      moduleTree = parser.parseModule();
      attachComments(moduleTree, comments);
    } catch(ex) {
      // HACK: sometime traceur crashes for various reasons including
      // Not Yet Implemented (NYI)!
      log.error(ex.stack);
      moduleTree = {};
    }
    log.debug(moduleName);
    moduleTree.moduleName = moduleName;

    // We return the module AST but also a collection of all the comments
    // since it can be helpful to iterate through them without having to
    // traverse the AST again
    return {
      moduleTree: moduleTree,
      comments: comments
    };
  }
816576
public <T extends SourceFile> void initModules(
      List<T> externs, List<JSModule> modules, CompilerOptions options) {
    initOptions(options);

    checkFirstModule(modules);

    this.externs = makeExternInputs(externs);

    // Generate the module graph, and report any errors in the module specification as errors.
    try {
      this.moduleGraph = new JSModuleGraph(modules);
    } catch (JSModuleGraph.ModuleDependenceException e) {
      // problems with the module format.  Report as an error.  The
      // message gives all details.
      report(JSError.make(MODULE_DEPENDENCY_ERROR,
          e.getModule().getName(), e.getDependentModule().getName()));
      return;
    }

    // Creating the module graph can move weak source around, and end up with empty modules.
    fillEmptyModules(getModules());

    this.commentsPerFile = new ConcurrentHashMap<>(moduleGraph.getInputCount());
    initBasedOnOptions();

    initInputsByIdMap();

    initAST();
  }
530044
static ImmutableAttributes loadAttributes(String repoType, File featureFile, ProvisioningDetails details) throws IOException {

        // This will throw exceptions if required attributes mismatch or are missing
        details.ensureValid();

        // retrieve the symbolic name and feature manifest version
        String symbolicName = details.getNameAttribute(null);
        int featureVersion = details.getIBMFeatureVersion();

        // Directive names are name attributes, but end with a colon
        Visibility visibility = Visibility.fromString(details.getNameAttribute("visibility:"));
        boolean isSingleton = Boolean.parseBoolean(details.getNameAttribute("singleton:"));

        // ignore short name for features that are not public
        String shortName = (visibility != Visibility.PUBLIC ? null : details.getMainAttributeValue(SHORT_NAME));

        // retrieve the feature/subsystem version 
        Version version = VersionUtility.stringToVersion(details.getMainAttributeValue(VERSION));

        // retrieve the app restart header
        AppForceRestart appRestart = AppForceRestart.fromString(details.getMainAttributeValue(IBM_APP_FORCE_RESTART));

        String subsystemType = details.getMainAttributeValue(TYPE);

        String value = details.getCachedRawHeader(IBM_PROVISION_CAPABILITY);
        boolean isAutoFeature = value != null && SubsystemContentType.FEATURE_TYPE.getValue().equals(subsystemType);

        value = details.getCachedRawHeader(IBM_API_SERVICE);
        boolean hasApiServices = value != null;

        value = details.getCachedRawHeader(IBM_API_PACKAGE);
        boolean hasApiPackages = value != null;

        value = details.getCachedRawHeader(IBM_SPI_PACKAGE);
        boolean hasSpiPackages = value != null;

        EnumSet<ProcessType> processTypes = ProcessType.fromString(details.getCachedRawHeader(IBM_PROCESS_TYPES));

        ImmutableAttributes iAttr = new ImmutableAttributes(emptyIfNull(repoType),
                                                            symbolicName,
                                                            nullIfEmpty(shortName),
                                                            featureVersion,
                                                            visibility,
                                                            appRestart,
                                                            version,
                                                            featureFile,
                                                            featureFile == null ? -1 : featureFile.lastModified(),
                                                            featureFile == null ? -1 : featureFile.length(),
                                                            isAutoFeature, hasApiServices,
                                                            hasApiPackages, hasSpiPackages, isSingleton,
                                                            processTypes);

        // Link the details object and immutable attributes (used for diagnostic purposes: 
        // the immutable attribute values are necessary for meaningful error messages)
        details.setImmutableAttributes(iAttr);

        return iAttr;
    }
759723
public void setApplicationData(final byte[] applicationData) {
        this.applicationData = applicationData == null || applicationData.length == 0
                ? null
                : Arrays.copyOf(applicationData, applicationData.length);
    }
348818
public static void saveApplicationBindings( Application app ) {

		File descDir = new File( app.getDirectory(), Constants.PROJECT_DIR_DESC );
		File appBindingsFile = new File( descDir, APP_BINDINGS_FILE );

		// Convert the bindings map
		Map<String,String> format = new HashMap<> ();
		for( Map.Entry<String,Set<String>> entry : app.getApplicationBindings().entrySet()) {
			String s = Utils.format( entry.getValue(), ", " );
			format.put( entry.getKey(), s );
		}

		// Save it
		Properties props = new Properties();
		props.putAll( format );

		try {
			Utils.createDirectory( descDir );
			Utils.writePropertiesFile( props, appBindingsFile );

		} catch( IOException e ) {
			Logger logger = Logger.getLogger( ConfigurationUtils.class.getName());
			logger.severe( "Failed to save application bindings for " + app + ". " + e.getMessage());
			Utils.logException( logger, e );
		}
	}
54784
private void updateAppLinkData(AppLinkData linkData, boolean add, J2EEName j2eeName, BeanMetaData bmd) // F743-26072
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "updateAppLinkData: " + j2eeName + ", add=" + add);

        int numBeans;
        synchronized (linkData)
        {
            linkData.ivNumBeans += add ? 1 : -1;
            numBeans = linkData.ivNumBeans;

            // Update the table of bean names for this application, in support
            // of ejb-link.                                                  d429866.1
            updateAppLinkDataTable(linkData.ivBeansByName, add, j2eeName.getComponent(), j2eeName, "ivBeansByName");

            // Update the table of bean interfaces for this application, in support
            // of auto-link.                                                 d429866.2
            updateAutoLink(linkData, add, j2eeName, bmd);

            // F743-25385CodRv d648723
            // Update the table of logical-to-physical module names, in support of
            // ejb-link.
            // F743-26072 - This will redundantly add the same entry for every
            // bean in the module, but it will remove the entry for the first bean
            // to be removed.  In other words, we do not support removing a single
            // bean from a module.
            updateAppLinkDataTable(linkData.ivModulesByLogicalName, add,
                                   bmd._moduleMetaData.ivLogicalName, j2eeName.getModule(), "ivModulesByLogicalName");
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "updateAppLinkData: " + j2eeName + ", add=" + add + ", numBeans=" + numBeans);
    }
211427
@Override
    public void register(Module module) {
        if (module == null) {
            return;
        }
        LOGGER.info("Adding JSON module {}", module.getModuleName());
        synchronized (lock) {
            modules.add(module);
            rebuildMappers();
        }
    }
887340
private void loadEntityMetadata(String persistenceUnit)
    {
        if (persistenceUnit == null)
        {
            throw new IllegalArgumentException(
                    "Must have a persistenceUnitName in order to load entity metadata, you provided :"
                            + persistenceUnit);
        }

        Map<String, PersistenceUnitMetadata> persistentUnitMetadataMap = kunderaMetadata.getApplicationMetadata()
                .getPersistenceUnitMetadataMap();

        /** Classes to scan */
        List<String> classesToScan;
        URL[] resources = null;
        String client = null;
        List<URL> managedURLs = null;
        if (persistentUnitMetadataMap == null || persistentUnitMetadataMap.isEmpty())
        {
            log.error("It is necessary to load Persistence Unit metadata  for persistence unit " + persistenceUnit
                    + " first before loading entity metadata.");
            throw new MetamodelLoaderException("load Persistence Unit metadata  for persistence unit "
                    + persistenceUnit + " first before loading entity metadata.");
        }
        else
        {
            PersistenceUnitMetadata puMetadata = persistentUnitMetadataMap.get(persistenceUnit);
            classesToScan = puMetadata.getManagedClassNames();
            managedURLs = puMetadata.getManagedURLs();
            client = getClientFactoryName(persistenceUnit);
        }

        /*
         * Check whether Classes to scan was provided into persistence.xml If
         * yes, load them. Otherwise load them from classpath/ context path
         */
        Reader reader;
        ApplicationMetadata appMetadata = kunderaMetadata.getApplicationMetadata();
        if (classesToScan == null || classesToScan.isEmpty())
        {
            log.info("No class to scan for persistence unit " + persistenceUnit
                    + ". Entities will be loaded from classpath/ context-path");
            // Entity metadata is not related to any PU, and hence will be
            // stored at common place
            // persistenceUnit = Constants.COMMON_ENTITY_METADATAS;

            // Check whether all common entity metadata have already been loaded
            if (appMetadata.getMetamodelMap().get(persistenceUnit) != null)
            {
                log.info("All common entitity metadata already loaded, nothing need to be done");
                return;
            }

            reader = new ClasspathReader();
            // resources = reader.findResourcesByClasspath();
        }
        else
        {
            reader = new ClasspathReader(classesToScan);
            // resources = reader.findResourcesByContextLoader();
        }

        InputStream[] iStreams = null;
        PersistenceUnitMetadata puMetadata = persistentUnitMetadataMap.get(persistenceUnit);
        if (this.getClass().getClassLoader() instanceof URLClassLoader && !puMetadata.getExcludeUnlistedClasses())
        {
            URL[] managedClasses = reader.findResources();
            if (managedClasses != null)
            {
                List<URL> managedResources = Arrays.asList(managedClasses);
                managedURLs.addAll(managedResources);
            }
        }
        else
        {
            iStreams = reader.findResourcesAsStream();
        }

        if (managedURLs != null)
        {
            resources = managedURLs.toArray(new URL[] {});
        }

        // All entities to load should be annotated with @Entity
        reader.addValidAnnotations(Entity.class.getName());

        Metamodel metamodel = appMetadata.getMetamodel(persistenceUnit);
        if (metamodel == null)
        {
            metamodel = new MetamodelImpl();
        }

        Map<String, EntityMetadata> entityMetadataMap = ((MetamodelImpl) metamodel).getEntityMetadataMap();
        Map<String, Class<?>> entityNameToClassMap = ((MetamodelImpl) metamodel).getEntityNameToClassMap();
        Map<String, List<String>> puToClazzMap = new HashMap<String, List<String>>();
        Map<String, IdDiscriptor> entityNameToKeyDiscriptorMap = new HashMap<String, IdDiscriptor>();
        List<Class<?>> classes = new ArrayList<Class<?>>();
        if (resources != null && resources.length > 0)
        {
            for (URL resource : resources)
            {
                try
                {
                    ResourceIterator itr = reader.getResourceIterator(resource, reader.getFilter());

                    InputStream is = null;
                    while ((is = itr.next()) != null)
                    {
                        classes.addAll(scanClassAndPutMetadata(is, reader, entityMetadataMap, entityNameToClassMap,
                                persistenceUnit, client, puToClazzMap, entityNameToKeyDiscriptorMap));
                    }
                }
                catch (IOException e)
                {
                    log.error("Error while retrieving and storing entity metadata. Details:", e);
                    throw new MetamodelLoaderException("Error while retrieving and storing entity metadata");

                }
            }
        }
        else if (iStreams != null)
        {
            try
            {
                for (InputStream is : iStreams)
                {
                    try
                    {
                        classes.addAll(scanClassAndPutMetadata(is, reader, entityMetadataMap, entityNameToClassMap,
                                persistenceUnit, client, puToClazzMap, entityNameToKeyDiscriptorMap));
                    }
                    finally
                    {
                        if (is != null)
                        {
                            is.close();
                        }
                    }
                }
            }
            catch (IOException e)
            {
                log.error("Error while retrieving and storing entity metadata. Details:", e);
                throw new MetamodelLoaderException("Error while retrieving and storing entity metadata, Caused by : .",
                        e);

            }
        }
        ((MetamodelImpl) metamodel).setEntityMetadataMap(entityMetadataMap);
        appMetadata.getMetamodelMap().put(persistenceUnit, metamodel);
        appMetadata.setClazzToPuMap(puToClazzMap);
        ((MetamodelImpl) metamodel).addKeyValues(entityNameToKeyDiscriptorMap);
        // assign JPA metamodel.
        ((MetamodelImpl) metamodel).assignEmbeddables(kunderaMetadata.getApplicationMetadata()
                .getMetaModelBuilder(persistenceUnit).getEmbeddables());
        ((MetamodelImpl) metamodel).assignManagedTypes(kunderaMetadata.getApplicationMetadata()
                .getMetaModelBuilder(persistenceUnit).getManagedTypes());
        ((MetamodelImpl) metamodel).assignMappedSuperClass(kunderaMetadata.getApplicationMetadata()
                .getMetaModelBuilder(persistenceUnit).getMappedSuperClassTypes());
    }
819665
public void setAppContent(Component appContent) {

        m_appArea.removeAllComponents();
        if (appContent != null) {
            m_appArea.addComponent(appContent);
        }
    }