KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > templates > TemplateBuffer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.text.templates;
12
13 import org.eclipse.core.runtime.Assert;
14
15 /**
16  * A template buffer is a container for a string and variables.
17  * <p>
18  * Clients may instantiate this class.
19  * </p>
20  *
21  * @since 3.0
22  */

23 public final class TemplateBuffer {
24
25     /** The string of the template buffer */
26     private String JavaDoc fString;
27     /** The variable positions of the template buffer */
28     private TemplateVariable[] fVariables;
29
30     /**
31      * Creates a template buffer.
32      *
33      * @param string the string
34      * @param variables the variable positions
35      */

36     public TemplateBuffer(String JavaDoc string, TemplateVariable[] variables) {
37         setContent(string, variables);
38     }
39
40     /**
41      * Sets the content of the template buffer.
42      *
43      * @param string the string
44      * @param variables the variable positions
45      */

46     public final void setContent(String JavaDoc string, TemplateVariable[] variables) {
47         Assert.isNotNull(string);
48         Assert.isNotNull(variables);
49
50         // XXX assert non-overlapping variable properties
51

52         fString= string;
53         fVariables= copy(variables);
54     }
55
56     /**
57      * Returns a copy of the given array.
58      *
59      * @param array the array to be copied
60      * @return a copy of the given array or <code>null</code> when <code>array</code> is <code>null</code>
61      * @since 3.1
62      */

63     private static TemplateVariable[] copy(TemplateVariable[] array) {
64         if (array != null) {
65             TemplateVariable[] copy= new TemplateVariable[array.length];
66             System.arraycopy(array, 0, copy, 0, array.length);
67             return copy;
68         }
69         return null;
70     }
71
72     /**
73      * Returns the string of the template buffer.
74      *
75      * @return the string representation of the template buffer
76      */

77     public final String JavaDoc getString() {
78         return fString;
79     }
80
81     /**
82      * Returns the variable positions of the template buffer. The returned array is
83      * owned by this variable and must not be modified.
84      *
85      * @return the variable positions of the template buffer
86      */

87     public final TemplateVariable[] getVariables() {
88         return fVariables;
89     }
90
91 }
92
Popular Tags