use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.
the class Archivist method processAnnotations.
/**
* Process annotations in a bundle descriptor, the annoation processing
* is dependent on the type of descriptor being passed.
*/
protected ProcessingResult processAnnotations(RootDeploymentDescriptor bundleDesc, ModuleScanner scanner, ReadableArchive archive) throws AnnotationProcessorException, IOException {
if (scanner == null) {
return null;
}
AnnotatedElementHandler aeHandler = AnnotatedElementHandlerFactory.createAnnotatedElementHandler(bundleDesc);
if (aeHandler == null) {
return null;
}
Parser parser = null;
if (archive.getParentArchive() != null) {
parser = archive.getParentArchive().getExtraData(Parser.class);
} else {
parser = archive.getExtraData(Parser.class);
}
scanner.process(archive, bundleDesc, classLoader, parser);
if (!scanner.getElements().isEmpty()) {
if (((BundleDescriptor) bundleDesc).isDDWithNoAnnotationAllowed()) {
// if we come into this block, it means an old version
// of deployment descriptor has annotation which is not correct
// throw exception in this case
String ddName = getStandardDDFile().getDeploymentDescriptorPath();
String explodedArchiveName = new File(archive.getURI()).getName();
String archiveName = FileUtils.revertFriendlyFilenameExtension(explodedArchiveName);
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.oldDDwithAnnotation", "{0} in archive {1} is of version {2}, which cannot support annotations in an application. Please upgrade the deployment descriptor to be a version supported by Java EE 5.0 (or later).", new Object[] { ddName, archiveName, bundleDesc.getSpecVersion() }));
}
boolean isFullAttribute = false;
if (bundleDesc instanceof BundleDescriptor) {
isFullAttribute = ((BundleDescriptor) bundleDesc).isFullAttribute();
}
AnnotationProcessor ap = annotationFactory.getAnnotationProcessor(isFullAttribute);
ProcessingContext ctx = ap.createContext();
ctx.setArchive(archive);
if (annotationErrorHandler != null) {
ctx.setErrorHandler(annotationErrorHandler);
}
ctx.setProcessingInput(scanner);
ctx.pushHandler(aeHandler);
// Make sure there is a classloader available on the descriptor
// during annotation processing.
ClassLoader originalBundleClassLoader = null;
try {
originalBundleClassLoader = bundleDesc.getClassLoader();
} catch (Exception e) {
// getClassLoader can throw exception if not available
}
// Only set classloader if it's not already set.
if (originalBundleClassLoader == null) {
bundleDesc.setClassLoader(classLoader);
}
try {
return ap.process(ctx);
} finally {
if (originalBundleClassLoader == null) {
bundleDesc.setClassLoader(null);
}
}
}
return null;
}
use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.
the class JavaEEScanner method initTypes.
protected void initTypes(File file) throws IOException {
ParsingContext context = new ParsingContext.Builder().build();
Parser cp = new Parser(context);
cp.parse(file, null);
try {
cp.awaitTermination();
} catch (InterruptedException e) {
throw new IOException(e);
}
types = cp.getContext().getTypes();
}
use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.
the class Utils method getServiceLocator.
public static ServiceLocator getServiceLocator(final InputStream inputStream, String name) {
try {
final ServiceLocator habitat = getNewServiceLocator(name);
final ConfigParser parser = new ConfigParser(habitat);
XMLInputFactory xif = XMLInputFactory.class.getClassLoader() == null ? XMLInputFactory.newFactory() : XMLInputFactory.newFactory(XMLInputFactory.class.getName(), XMLInputFactory.class.getClassLoader());
final DomDocument document = parser.parse(xif.createXMLStreamReader(inputStream));
ServiceLocatorUtilities.addOneConstant(habitat, document);
return habitat;
} catch (Exception e) {
e.printStackTrace();
throw new GrizzlyConfigException(e.getMessage(), e);
}
}
use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.
the class SecureAdminClientManager method prepareDomain.
private Domain prepareDomain(final String serverName, final String nodeDir, final String node, final File nodeDirRoot) {
/*
* At least one of serverName, nodeDir, or node must be non-null.
* Otherwise we'll have no way of figuring out which domain.xml to
* look in to see if we should use client authentication. This will
* often be the case, for instance, if create-local-instance is
* run directly (not from another command). In such cases, if
* secure admin is enabled the user should provide --user and
* --passwordfile on the command line to authenticate to the DAS.
*/
if (serverName == null && nodeDir == null && node == null) {
return null;
}
final ServerDirsSelector selector;
try {
final String nodeDirToUse = (nodeDir != null ? nodeDir : nodeDirRoot.getAbsolutePath());
selector = ServerDirsSelector.getInstance(null, serverName, nodeDirToUse, node);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
/*
* If the caller did not pass any of the values we can use to locate
* the domain.xml, then we cannot run in client-cert mode.
*/
final ServerDirs dirs = selector.dirs();
if (dirs == null) {
return null;
}
final File domainXMLFile = dirs.getDomainXml();
if (!domainXMLFile.exists()) {
return null;
}
try {
ServiceLocator habitat = Globals.getStaticHabitat();
ConfigParser parser = new ConfigParser(habitat);
URL domainURL = domainXMLFile.toURI().toURL();
DomDocument doc = parser.parse(domainURL);
Dom domDomain = doc.getRoot();
Domain d = domDomain.createProxy(Domain.class);
return d;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.
the class VerifyDomainXmlCommand method executeCommand.
/**
*/
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
File domainXMLFile = getDomainXml();
logger.log(Level.FINER, "Domain XML file = {0}", domainXMLFile);
try {
// get the list of JAR files from the modules directory
ArrayList<URL> urls = new ArrayList<URL>();
File idir = new File(System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
File mdir = new File(idir, "modules");
for (File f : mdir.listFiles()) {
if (f.toString().endsWith(".jar")) {
urls.add(f.toURI().toURL());
}
}
final URL[] urlsA = urls.toArray(new URL[urls.size()]);
ClassLoader cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
return new URLClassLoader(urlsA, Globals.class.getClassLoader());
}
});
ModulesRegistry registry = new StaticModulesRegistry(cl);
ServiceLocator serviceLocator = registry.createServiceLocator("default");
ConfigParser parser = new ConfigParser(serviceLocator);
URL domainURL = domainXMLFile.toURI().toURL();
DomDocument doc = parser.parse(domainURL);
Dom domDomain = doc.getRoot();
Domain domain = domDomain.createProxy(Domain.class);
DomainXmlVerifier validator = new DomainXmlVerifier(domain);
if (validator.invokeConfigValidator())
return 1;
} catch (Exception e) {
throw new CommandException(e);
}
return 0;
}
Aggregations