components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/common/smf/SmfEnabledProperty.java
changeset 827 0944d8c0158b
child 1410 ca9946e5736c
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panel.common.smf;
       
    27 
       
    28 import com.oracle.solaris.scf.common.ScfException;
       
    29 import com.oracle.solaris.vp.util.misc.property.BooleanProperty;
       
    30 
       
    31 /**
       
    32  * The {@code SmfEnabledProperty} class is an {@link SmfMutableProperty} that
       
    33  * represents the enabled state of a service instance in the SMF repository.
       
    34  */
       
    35 public class SmfEnabledProperty extends BooleanProperty
       
    36     implements SmfMutableProperty<Boolean> {
       
    37 
       
    38     //
       
    39     // Static data
       
    40     //
       
    41 
       
    42     /**
       
    43      * The default name of this property ("enabled") if none is specified.
       
    44      */
       
    45     public static final String NAME = "enabled";
       
    46 
       
    47     //
       
    48     // Instance data
       
    49     //
       
    50 
       
    51     private HasService info;
       
    52 
       
    53     //
       
    54     // Constructors
       
    55     //
       
    56 
       
    57     /**
       
    58      * Constructs a {@code SmfEnabledProperty}.
       
    59      *
       
    60      * @param	    name
       
    61      *		    the name of this property
       
    62      *
       
    63      * @param	    info
       
    64      *		    source of the service
       
    65      */
       
    66     public SmfEnabledProperty(String name, HasService info) {
       
    67 	super(name);
       
    68 	this.info = info;
       
    69     }
       
    70 
       
    71     /**
       
    72      * Constructs a {@code SmfEnabledProperty} with a {@link #NAME default
       
    73      * name}.
       
    74      *
       
    75      * @param	    info
       
    76      *		    source of the service
       
    77      */
       
    78     public SmfEnabledProperty(HasService info) {
       
    79 	this(NAME, info);
       
    80     }
       
    81 
       
    82     //
       
    83     // SmfMutableProperty methods
       
    84     //
       
    85 
       
    86     @Override
       
    87     public Boolean getRepoValue() throws ScfException {
       
    88 	return info.getService().isPersistentlyEnabled();
       
    89     }
       
    90 
       
    91     @Override
       
    92     public void saveToRepo() throws ScfException {
       
    93 	Boolean value = getValue();
       
    94 	setRepoValue(value);
       
    95 	save();
       
    96     }
       
    97 
       
    98     @Override
       
    99     public void setRepoValue(Boolean value) throws ScfException {
       
   100 	ServiceMXBean service = info.getService();
       
   101 	service.setPersistentlyEnabled(value);
       
   102     }
       
   103 
       
   104     @Override
       
   105     public void updateFromRepo(boolean force) throws ScfException {
       
   106 	update(getRepoValue(), force);
       
   107     }
       
   108 }