2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.infrastructure.java.compile.singleclass;
23 import java.io.IOException;
24 import javax.tools.FileObject;
25 import javax.tools.ForwardingJavaFileManager;
26 import javax.tools.JavaCompiler;
27 import javax.tools.JavaFileObject;
28 import javax.tools.StandardJavaFileManager;
31 * The Class SingleFileManager is a {@link ForwardingJavaFileManager} which in turn implements {@code JavaFileManager}.
32 * A {@code JavaFileManager} handles source files for Java language handling tools. A {@link ForwardingJavaFileManager}
33 * is an implementation of {@code JavaFileManager} that forwards the {@code JavaFileManager} methods to a given file
36 * <p>This class instantiates and forwards those requests to a {@link StandardJavaFileManager} instance to act as a
37 * {@code JavaFileManager} for a Java single file, managing class loading for the class.
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class SingleFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
42 // THe class loader for our single class
43 private final SingleClassLoader singleClassLoader;
46 * Instantiates a new single file manager.
48 * @param compiler the compiler we are using
49 * @param byteCodeFileObject the byte code for the compiled class
51 public SingleFileManager(final JavaCompiler compiler, final SingleClassByteCodeFileObject byteCodeFileObject) {
52 super(compiler.getStandardFileManager(null, null, null));
53 singleClassLoader = new SingleClassLoader(byteCodeFileObject);
60 public JavaFileObject getJavaFileForOutput(final Location notUsed, final String className,
61 final JavaFileObject.Kind kind, final FileObject sibling) throws IOException {
62 // Return the JavaFileObject to the compiler so that it can write byte code into it
63 return singleClassLoader.getFileObject();
70 public SingleClassLoader getClassLoader(final Location location) {
71 return singleClassLoader;