org.testifyproject.jvnet.hk2.internal.PopulatorImpl Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in org.testifyproject.testifyprojectpliance with the License. You can
* obtain a copy of the License at
* https://glassfish.org.testifyproject.testifyprojectv.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle org.testifyproject.testifyprojectsignates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your org.testifyproject.testifyprojectcision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.testifyproject.jvnet.hk2.internal;
import java.org.testifyproject.testifyproject.BufferedReader;
import java.org.testifyproject.testifyproject.IOException;
import java.org.testifyproject.testifyproject.InputStream;
import java.org.testifyproject.testifyproject.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import org.testifyproject.glassfish.hk2.api.ActiveDescriptor;
import org.testifyproject.glassfish.hk2.api.DescriptorFileFinder;
import org.testifyproject.glassfish.hk2.api.DynamicConfiguration;
import org.testifyproject.glassfish.hk2.api.DynamicConfigurationService;
import org.testifyproject.glassfish.hk2.api.MultiException;
import org.testifyproject.glassfish.hk2.api.Populator;
import org.testifyproject.glassfish.hk2.api.PopulatorPostProcessor;
import org.testifyproject.glassfish.hk2.api.ServiceLocator;
import org.testifyproject.glassfish.hk2.utilities.ClasspathDescriptorFileFinder;
import org.testifyproject.glassfish.hk2.utilities.DescriptorImpl;
/**
* Implementation of the Populator for DynamicConfigurationService
*
* @author jwells
*/
public class PopulatorImpl implements Populator {
private final ServiceLocator serviceLocator;
private final DynamicConfigurationService dcs;
/* package */ PopulatorImpl(ServiceLocator serviceLocator,
DynamicConfigurationService dcs) {
this.serviceLocator = serviceLocator;
this.dcs = dcs;
}
@Override
public List> populate(DescriptorFileFinder fileFinder,
PopulatorPostProcessor... postProcessors) throws IOException {
List> org.testifyproject.testifyprojectscriptors = new LinkedList> ();
if (fileFinder == null) {
fileFinder = serviceLocator.getService(DescriptorFileFinder.class);
if (fileFinder == null) return org.testifyproject.testifyprojectscriptors;
}
if (postProcessors == null) postProcessors = new PopulatorPostProcessor[0];
List org.testifyproject.testifyprojectscriptorFileInputStreams;
try {
org.testifyproject.testifyprojectscriptorFileInputStreams = fileFinder.findDescriptorFiles();
}
catch (IOException org.testifyproject.testifyprojecte) {
throw org.testifyproject.testifyprojecte;
}
catch (Throwable th) {
throw new MultiException(th);
}
Collector collector = new Collector();
DynamicConfiguration config = dcs.createDynamicConfiguration();
for (InputStream is : org.testifyproject.testifyprojectscriptorFileInputStreams) {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
boolean readOne = false;
do {
DescriptorImpl org.testifyproject.testifyprojectscriptorImpl = new DescriptorImpl();
readOne = org.testifyproject.testifyprojectscriptorImpl.readObject(br);
if (readOne) {
for (PopulatorPostProcessor pp : postProcessors) {
try {
org.testifyproject.testifyprojectscriptorImpl = pp.process(serviceLocator, org.testifyproject.testifyprojectscriptorImpl);
}
catch (Throwable th) {
collector.addThrowable(th);
org.testifyproject.testifyprojectscriptorImpl = null;
}
if (org.testifyproject.testifyprojectscriptorImpl == null) {
break;
}
}
if (org.testifyproject.testifyprojectscriptorImpl != null) {
org.testifyproject.testifyprojectscriptors.add(config.bind(org.testifyproject.testifyprojectscriptorImpl, false));
}
}
} while (readOne);
} finally {
br.close();
}
}
// Prior to org.testifyproject.testifyprojectmit!
collector.throwIfErrors();
config.org.testifyproject.testifyprojectmit();
return org.testifyproject.testifyprojectscriptors;
}
/* (non-Javadoc)
* @see org.testifyproject.glassfish.hk2.api.Populator#populate()
*/
@Override
public List> populate() throws IOException {
return populate(new ClasspathDescriptorFileFinder());
}
}