org.glassfish.virtualization.config.Virtualizations Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2011-2012 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 compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.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 designates 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 decision 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.glassfish.virtualization.config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.DomainExtension;
import com.sun.enterprise.util.SystemPropertyConstants;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.config.support.*;
import org.jvnet.hk2.annotations.Inject;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.*;
import java.beans.PropertyVetoException;
import java.util.List;
/**
* Top level configuration for all virtualization related config. For now, a bit of
* a mess, will need to review this past prototype stage.
*
* @author Jerome Dochez
*/
@Configured
@Singleton
public interface Virtualizations extends DomainExtension {
@Element("*")
List getVirtualizations();
@Attribute(defaultValue = "${com.sun.aas.instanceRoot}/virt/disks")
String getDisksLocation();
public void setDisksLocation();
@Attribute(defaultValue = "${com.sun.aas.instanceRoot}/virt/templates")
String getTemplatesLocation();
public void setTemplatesLocation();
// FIXME -- jgish -- is this already available somewhere else?
@Attribute(defaultValue = "${com.sun.aas.instanceRoot}/" +
SystemPropertyConstants.DOCROOT_PROPERTY)
String getDocRoot();
/**
* Returns a virtualization configuration using the virtualization name.
* @param name the virtualization configuration name
* @return the virtualization configuration if found or null;
*/
@DuckTyped
Virtualization byName(String name);
public class Duck {
public static Virtualization byName(Virtualizations self, String name) {
for (Virtualization v : self.getVirtualizations()) {
if (v.getName().equals(name)) {
return v;
}
}
return null;
}
}
@Service
public class VirtResolver implements CrudResolver {
@Inject
Domain domain;
@Inject(optional = true)
Virtualizations virt = null;
@Override
public T resolve(AdminCommandContext context, Class type) {
if (virt!=null) return (T) virt;
try {
virt = (Virtualizations) ConfigSupport.apply(new SingleConfigCode() {
@Override
public Object run(Domain wDomain) throws PropertyVetoException, TransactionFailure {
Virtualizations v = wDomain.createChild(Virtualizations.class);
wDomain.getExtensions().add(v);
return v;
}
}, domain);
} catch (TransactionFailure t) {
throw new RuntimeException(t);
}
return (T) virt;
}
}
}