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;
25 import javax.tools.FileObject;
26 import javax.tools.ForwardingJavaFileManager;
27 import javax.tools.JavaCompiler;
28 import javax.tools.JavaFileObject;
29 import javax.tools.StandardJavaFileManager;
32 * The Class SingleFileManager is a {@link ForwardingJavaFileManager} which in turn implements {@code JavaFileManager}.
33 * A {@code JavaFileManager} handles source files for Java language handling tools. A {@link ForwardingJavaFileManager}
34 * is an implementation of {@code JavaFileManager} that forwards the {@code JavaFileManager} methods to a given file
37 * <p>This class instantiates and forwards those requests to a {@link StandardJavaFileManager} instance to act as a
38 * {@code JavaFileManager} for a Java single file, managing class loading for the class.
40 * @author Liam Fallon (liam.fallon@ericsson.com)
42 public class SingleFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
43 // THe class loader for our single class
44 private final SingleClassLoader singleClassLoader;
47 * Instantiates a new single file manager.
49 * @param compiler the compiler we are using
50 * @param byteCodeFileObject the byte code for the compiled class
52 public SingleFileManager(final JavaCompiler compiler, final SingleClassByteCodeFileObject byteCodeFileObject) {
53 super(compiler.getStandardFileManager(null, null, null));
54 singleClassLoader = new SingleClassLoader(byteCodeFileObject);
61 public JavaFileObject getJavaFileForOutput(final Location notUsed, final String className,
62 final JavaFileObject.Kind kind, final FileObject sibling) throws IOException {
63 // Return the JavaFileObject to the compiler so that it can write byte code into it
64 return singleClassLoader.getFileObject();
71 public SingleClassLoader getClassLoader(final Location location) {
72 return singleClassLoader;