001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.moml; 031 032import org.apache.commons.logging.Log; 033import org.apache.commons.logging.LogFactory; 034import org.kepler.objectmanager.library.LibraryManager; 035 036import ptolemy.kernel.CompositeEntity; 037import ptolemy.kernel.util.Workspace; 038import ptolemy.moml.LibraryBuilder; 039 040/** 041 * This class is used by ptolemy to initialize the library. It is one of the 042 * first things that happens during Kepler startup. It is really a wrapper for 043 * the LibraryManager which does the heavy lifting. This classes' main purpose 044 * is to return a ComponentEntity library from the buildLibrary method. The 045 * ptolemy extension point that this class is an extension of can be found in 046 * ptolemy.actor.gui.UserActorLibrary.openLibrary(Configuration,File) 047 */ 048public class KARLibraryBuilder extends LibraryBuilder { 049 private static final Log log = LogFactory.getLog(KARLibraryBuilder.class 050 .getName()); 051 private static final boolean isDebugging = log.isDebugEnabled(); 052 053 /** 054 * constructor. 055 */ 056 public KARLibraryBuilder() { 057 super(); 058 } 059 060 /** 061 * Build the library. This should be built in the form of a ComponentEntity 062 * See the ptolemy code if you want an example of what the ComponentEntity 063 * should look like 064 * 065 * @return ComponentEntity 066 * @throws Exception 067 */ 068 public CompositeEntity buildLibrary(Workspace workspace) throws Exception { 069 070 long starttime = System.currentTimeMillis(); 071 if (isDebugging) { 072 log.debug("Starting KARLibraryBuilder.buildLibrary: " + starttime 073 + " ms"); 074 } 075 076 LibraryManager lm = LibraryManager.getInstance(); 077 lm.setActorLibraryWorkspace(workspace); 078 lm.buildLibrary(); 079 080 CompositeEntity actorLib = lm.getActorLibrary(); 081 082 if (isDebugging) { 083 long stoptime = System.currentTimeMillis(); 084 log.debug("Finishing KARLibraryBuilder.buildLibrary: " 085 + (stoptime - starttime) + " ms"); 086 } 087 088 return actorLib; 089 090 } 091}